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\>"
454 msg="$(insmod $module $args 2>&1)" && return 0 || rc=$?
457 # parallels can't load modules directly from prlfs, use /tmp instead
458 if $PRLFS || [[ "$(stat -f -c%t $module)" == "7c7c6673" ]]; then
459 local target="$(mktemp)"
461 cp "$module" "$target"
464 [[ $rc == 0 ]] && PRLFS=true
472 # Load a module on the system where this is running.
474 # usage: load_module module_name [module arguments for insmod/modprobe]
476 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
477 # will be used as the arguments. Otherwise arguments will be obtained from
478 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
485 BASE=$(basename $module $EXT)
487 module_loaded ${BASE} && return
489 # If no module arguments were passed, get them from $MODOPTS_<MODULE>,
490 # else from modprobe.conf
491 if [ $# -eq 0 ]; then
492 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
493 # Bash until 4.x, so we resort to eval.
494 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
495 eval set -- \$$optvar
496 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
497 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
499 opt=$(awk -v var="^options $BASE" '$0 ~ var \
500 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
501 set -- $(echo -n $opt)
503 # Ensure we have accept=all for lnet
504 if [ $(basename $module) = lnet ]; then
505 # OK, this is a bit wordy...
506 local arg accept_all_present=false
509 [ "$arg" = accept=all ] && \
510 accept_all_present=true
512 $accept_all_present || set -- "$@" accept=all
518 [ $# -gt 0 ] && echo "${module} options: '$*'"
520 # Note that insmod will ignore anything in modprobe.conf, which is why
521 # we're passing options on the command-line.
522 if [[ "$BASE" == "lnet_selftest" ]] &&
523 [[ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]]; then
524 lustre_insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
525 elif [[ -f ${LUSTRE}/${module}${EXT} ]]; then
526 [[ "$BASE" != "ptlrpc_gss" ]] || modprobe sunrpc
527 lustre_insmod ${LUSTRE}/${module}${EXT} "$@"
529 # must be testing a "make install" or "rpm" installation
530 # note failed to load ptlrpc_gss is considered not fatal
531 if [[ "$BASE" == "ptlrpc_gss" ]]; then
532 modprobe $BASE "$@" 2>/dev/null ||
533 echo "gss/krb5 is not supported"
540 load_modules_local() {
541 if [ -n "$MODPROBE" ]; then
543 echo "Using modprobe to load modules"
547 echo Loading modules from $LUSTRE
551 if [ -f /sys/devices/system/cpu/online ]; then
552 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
553 echo "detected $ncpus online CPUs by sysfs"
555 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
557 if [ $rc -eq 0 ]; then
558 echo "detected $ncpus online CPUs by getconf"
560 echo "Can't detect number of CPUs"
565 # if there is only one CPU core, libcfs can only create one partition
566 # if there is more than 4 CPU cores, libcfs should create multiple CPU
567 # partitions. So we just force libcfs to create 2 partitions for
568 # system with 2 or 4 cores
569 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
570 # force to enable multiple CPU partitions
571 echo "Force libcfs to create 2 CPU partitions"
572 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
574 echo "libcfs will create CPU partition based on online CPUs"
577 load_module ../libcfs/libcfs/libcfs
578 # Prevent local MODOPTS_LIBCFS being passed as part of environment
579 # variable to remote nodes
583 load_module ../lnet/lnet/lnet
585 LNDPATH=${LNDPATH:-"../lnet/klnds"}
586 if [ -z "$LNETLND" ]; then
588 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
589 tcp*) LNETLND="socklnd/ksocklnd" ;;
590 *) local lnd="${NETTYPE%%[0-9]}lnd"
591 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
592 LNETLND="$lnd/k$lnd" ||
593 LNETLND="socklnd/ksocklnd"
596 load_module ../lnet/klnds/$LNETLND
597 load_module obdclass/obdclass
598 load_module ptlrpc/ptlrpc
599 load_module ptlrpc/gss/ptlrpc_gss
607 load_module obdecho/obdecho
608 if ! client_only; then
609 SYMLIST=/proc/kallsyms
610 grep -q crc16 $SYMLIST ||
611 { modprobe crc16 2>/dev/null || true; }
612 grep -q -w jbd2 $SYMLIST ||
613 { modprobe jbd2 2>/dev/null || true; }
614 load_module lfsck/lfsck
615 [ "$LQUOTA" != "no" ] &&
616 load_module quota/lquota $LQUOTAOPTS
617 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
618 lsmod | grep zfs >&/dev/null || modprobe zfs
619 load_module osd-zfs/osd_zfs
621 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
622 grep -q exportfs_decode_fh $SYMLIST ||
623 { modprobe exportfs 2> /dev/null || true; }
624 grep -q -w mbcache $SYMLIST ||
625 { modprobe mbcache 2>/dev/null || true; }
626 load_module ../ldiskfs/ldiskfs
627 load_module osd-ldiskfs/osd_ldiskfs
639 load_module llite/lustre
640 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
642 rm -f $OGDB/ogdb-$HOSTNAME
643 $LCTL modules > $OGDB/ogdb-$HOSTNAME
645 # 'mount' doesn't look in $PATH, just sbin
646 local mount_lustre=$LUSTRE/utils/mount.lustre
647 if [ -f $mount_lustre ]; then
648 local sbin_mount=$(readlink -f /sbin)/mount.lustre
649 if grep -qw "$sbin_mount" /proc/mounts; then
650 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
652 if ! grep -qw "$sbin_mount" /proc/mounts; then
653 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
654 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
655 cat <<- EOF > "$sbin_mount"
658 echo "This $sbin_mount just a mountpoint." 1>&2
659 echo "It is never supposed to be run." 1>&2
660 logger -p emerg -- "using stub $sbin_mount $@"
663 chmod a+x $sbin_mount
665 mount --bind $mount_lustre $sbin_mount ||
666 error "can't bind $mount_lustre to $sbin_mount"
674 # load modules on remote nodes optionally
675 # lustre-tests have to be installed on these nodes
676 if $LOAD_MODULES_REMOTE; then
677 local list=$(comma_list $(remote_nodes_list))
678 if [ -n "$list" ]; then
679 echo "loading modules on: '$list'"
680 do_rpc_nodes "$list" load_modules_local
686 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
687 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
688 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
689 echo "$LEAK_LUSTRE" 1>&2
690 echo "$LEAK_PORTALS" 1>&2
691 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
692 echo "Memory leaks detected"
693 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
699 wait_exit_ST client # bug 12845
701 $LUSTRE_RMMOD ldiskfs || return 2
703 if $LOAD_MODULES_REMOTE; then
704 local list=$(comma_list $(remote_nodes_list))
705 if [ -n "$list" ]; then
706 echo "unloading modules on: '$list'"
707 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
708 do_rpc_nodes "$list" check_mem_leak
712 local sbin_mount=$(readlink -f /sbin)/mount.lustre
713 if grep -qe "$sbin_mount " /proc/mounts; then
714 umount $sbin_mount || true
715 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
719 check_mem_leak || return 254
721 echo "modules unloaded."
726 local facet=${1:-$SINGLEMDS}
727 local fstype=$(facet_fstype $facet)
730 ldiskfs) size=50;; # largest seen is 44, leave some headroom
731 zfs) size=400;; # largest seen is 384
738 local facet=${1:-$SINGLEMDS}
739 local fstype=$(facet_fstype $facet)
742 ldiskfs) size=4;; # ~4KB per inode
743 zfs) size=11;; # 10 to 11KB per inode
749 check_gss_daemon_nodes() {
753 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
754 if [ \\\"\\\$num\\\" -ne 1 ]; then
755 echo \\\$num instance of $dname;
760 check_gss_daemon_facet() {
764 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
765 if [ $num -ne 1 ]; then
766 echo "$num instance of $dname on $facet"
775 echo Stopping $@ on $list
776 do_nodes $list "killall -2 $@ 2>/dev/null || true"
779 # start gss daemons on all nodes, or
780 # "daemon" on "list" if set
781 start_gss_daemons() {
785 if [ "$list" ] && [ "$daemon" ] ; then
786 echo "Starting gss daemon on nodes: $list"
787 do_nodes $list "$daemon" || return 8
791 local list=$(comma_list $(mdts_nodes))
792 echo "Starting gss daemon on mds: $list"
793 do_nodes $list "$LSVCGSSD -v" || return 1
795 do_nodes $list "$LGSSD -v" || return 2
798 list=$(comma_list $(osts_nodes))
799 echo "Starting gss daemon on ost: $list"
800 do_nodes $list "$LSVCGSSD -v" || return 3
801 # starting on clients
803 local clients=${CLIENTS:-`hostname`}
805 echo "Starting $LGSSD on clients $clients "
806 do_nodes $clients "$LGSSD -v" || return 4
809 # wait daemons entering "stable" status
813 # check daemons are running
815 list=$(comma_list $(mdts_nodes) $(osts_nodes))
816 check_gss_daemon_nodes $list lsvcgssd || return 5
818 list=$(comma_list $(mdts_nodes))
819 check_gss_daemon_nodes $list lgssd || return 6
822 check_gss_daemon_nodes $clients lgssd || return 7
827 local list=$(comma_list $(mdts_nodes))
829 send_sigint $list lsvcgssd lgssd
831 list=$(comma_list $(osts_nodes))
832 send_sigint $list lsvcgssd
834 list=${CLIENTS:-`hostname`}
835 send_sigint $list lgssd
840 if ! module_loaded ptlrpc_gss; then
841 load_module ptlrpc/gss/ptlrpc_gss
842 module_loaded ptlrpc_gss ||
843 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
846 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
849 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
851 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
859 # maybe cleanup credential cache?
865 local var=${facet}_svc
873 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
874 tr '[:lower:]' '[:upper:]'
880 if [ $facet == mgs ] || [ $facet == client ]; then
884 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
892 if [ -n "${!var}" ]; then
897 var=$(facet_type $facet)FSTYPE
898 if [ -n "${!var}" ]; then
903 if [ -n "$FSTYPE" ]; then
908 if [[ $facet == mgs ]] && combined_mgs_mds; then
920 local facets=$(get_facets)
923 for facet in ${facets//,/ }; do
924 if [ $node == $(facet_host $facet) ] ||
925 [ $node == "$(facet_failover_host $facet)" ]; then
926 fstype=$(facet_fstype $facet)
927 if [[ $fstypes != *$fstype* ]]; then
928 fstypes+="${fstypes:+,}$fstype"
937 local num=$(facet_number $facet)
940 if [[ $(facet_type $facet) = OST ]]; then
942 if [[ -n "${!index}" ]]; then
947 index=${OST_INDICES[num - 1]}
950 [[ -n "$index" ]] || index=$((num - 1))
958 local fstype=$(facet_fstype $facet)
962 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
964 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
965 ${dev} 2>/dev/null");;
967 error "unknown fstype!";;
975 local device=$(mdsdevname $num)
976 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
982 local device=$(ostdevname $num)
983 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
988 # Get the device of a facet.
995 mgs) device=$(mgsdevname) ;;
996 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
997 ost*) device=$(ostdevname $(facet_number $facet)) ;;
998 fs2mds) device=$(mdsdevname 1_2) ;;
999 fs2ost) device=$(ostdevname 1_2) ;;
1000 fs3ost) device=$(ostdevname 2_2) ;;
1008 # Get the virtual device of a facet.
1015 mgs) device=$(mgsvdevname) ;;
1016 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
1017 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
1018 fs2mds) device=$(mdsvdevname 1_2) ;;
1019 fs2ost) device=$(ostvdevname 1_2) ;;
1020 fs3ost) device=$(ostvdevname 2_2) ;;
1028 local virt=$(virt-what 2> /dev/null)
1030 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1032 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1035 VMware|KVM|VirtualBox|Parallels)
1036 echo $virt | tr '[A-Z]' '[a-z]' ;;
1042 # Re-read the partition table on failover partner host.
1043 # After a ZFS storage pool is created on a shared device, the partition table
1044 # on the device may change. However, the operating system on the failover
1045 # host may not notice the change automatically. Without the up-to-date partition
1046 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1047 # relative to partition rather than disk beginnings.
1049 # This function performs partprobe on the failover host to make it re-read the
1052 refresh_partition_table() {
1057 host=$(facet_passive_host $facet)
1058 if [[ -n "$host" ]]; then
1059 do_node $host "$PARTPROBE $device"
1064 # Get ZFS storage pool name.
1071 device=$(facet_device $facet)
1072 # poolname is string before "/"
1073 poolname="${device%%/*}"
1080 # Get ZFS local fsname.
1082 zfs_local_fsname() {
1084 local lfsname=$(basename $(facet_device $facet))
1090 # Create ZFS storage pool.
1097 local opts=${@:-"-o cachefile=none"}
1099 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1100 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1101 $ZPOOL create -f $opts $poolname $vdev"
1105 # Create ZFS file system.
1111 local opts=${@:-"-o mountpoint=legacy"}
1113 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1114 $ZFS create $opts $dataset"
1118 # Export ZFS storage pool.
1119 # Before exporting the pool, all datasets within the pool should be unmounted.
1127 poolname=$(zpool_name $facet)
1129 if [[ -n "$poolname" ]]; then
1130 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1131 grep -q ^$poolname/ /proc/mounts ||
1132 $ZPOOL export $opts $poolname"
1137 # Destroy ZFS storage pool.
1138 # Destroy the given pool and free up any devices for other use. This command
1139 # tries to unmount any active datasets before destroying the pool.
1140 # -f Force any active datasets contained within the pool to be unmounted.
1144 local poolname=${2:-$(zpool_name $facet)}
1146 if [[ -n "$poolname" ]]; then
1147 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1148 $ZPOOL destroy -f $poolname"
1153 # Import ZFS storage pool.
1154 # Force importing, even if the pool appears to be potentially active.
1159 local opts=${@:-"-o cachefile=none"}
1162 poolname=$(zpool_name $facet)
1164 if [[ -n "$poolname" ]]; then
1165 opts+=" -d $(dirname $(facet_vdevice $facet))"
1166 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1167 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1168 $ZPOOL import -f $opts $poolname"
1173 # Reimport ZFS storage pool with new name
1178 local opts="-o cachefile=none"
1179 local poolname=$(zpool_name $facet)
1181 opts+=" -d $(dirname $(facet_vdevice $facet))"
1182 do_facet $facet "$ZPOOL export $poolname;
1183 $ZPOOL import $opts $poolname $newpool"
1187 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1188 # is not automatically imported on system startup.
1190 # In a failover environment, this will provide resource level fencing which
1191 # will ensure that the same ZFS storage pool will not be imported concurrently
1192 # on different nodes.
1194 disable_zpool_cache() {
1198 poolname=$(zpool_name $facet)
1200 if [[ -n "$poolname" ]]; then
1201 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1206 # This and set_osd_param() shall be used to access OSD parameters
1207 # once existed under "obdfilter":
1212 # writethrough_cache_enable
1216 local device=${2:-$FSNAME-OST*}
1219 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1220 osd-*.$device.$name 2>&1" | grep -v 'error:'
1225 local device=${2:-$FSNAME-OST*}
1229 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1230 osd-*.$device.$name=$value 2>&1" | grep -v 'error:'
1234 local dz=${1:-$DEBUG_SIZE}
1236 if [ -f /sys/devices/system/cpu/possible ]; then
1237 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1239 local cpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1242 # bug 19944, adjust size to be -gt num_possible_cpus()
1243 # promise 2MB for every cpu at least
1244 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1247 lctl set_param debug_mb=$dz
1250 set_default_debug () {
1251 local debug=${1:-"$PTLDEBUG"}
1252 local subsys=${2:-"$SUBSYSTEM"}
1253 local debug_size=${3:-$DEBUG_SIZE}
1255 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1256 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1258 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1261 set_default_debug_nodes () {
1264 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1265 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1269 do_rpc_nodes "$nodes" set_default_debug \
1270 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1273 set_default_debug_facet () {
1275 local node=$(facet_active_host $facet)
1276 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1278 set_default_debug_nodes $node
1282 local hostid=${1:-$(hostid)}
1284 if [ ! -s /etc/hostid ]; then
1285 printf $(echo -n $hostid |
1286 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1292 local facets=${1:-$(get_facets)}
1295 for facet in ${facets//,/ }; do
1298 [ $RC -eq 0 ] && continue
1300 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1301 skip "Restart of $facet failed!." && touch $LU482_FAILED
1303 error "Restart of $facet failed!"
1310 # Add argument "arg" (e.g., "loop") to the comma-separated list
1311 # of arguments for option "opt" (e.g., "-o") on command
1312 # line "opts" (e.g., "-o flock").
1318 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1320 if echo "$opts" | grep -q $opt_pattern; then
1321 opts=$(echo "$opts" | sed -e \
1322 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1324 opts+="${opts:+ }$opt $arg"
1332 local dev=$(facet_active $facet)_dev
1333 local opt=${facet}_opt
1334 local mntpt=$(facet_mntpt $facet)
1335 local opts="${!opt} $@"
1336 local fstype=$(facet_fstype $facet)
1339 module_loaded lustre || load_modules
1341 if [ $(facet_fstype $facet) == ldiskfs ] &&
1342 ! do_facet $facet test -b ${!dev}; then
1343 opts=$(csa_add "$opts" -o loop)
1346 if [[ $(facet_fstype $facet) == zfs ]]; then
1347 # import ZFS storage pool
1348 import_zpool $facet || return ${PIPESTATUS[0]}
1353 devicelabel=$(do_facet ${facet} "$E2LABEL ${!dev}");;
1355 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
1356 lustre:svname ${!dev}");;
1358 error "unknown fstype!";;
1361 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1362 # for testing LU-482 error handling in mount_facets() and test_0a()
1363 if [ -f $TMP/test-lu482-trigger ]; then
1366 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1371 if [ $RC -ne 0 ]; then
1372 echo "Start of ${!dev} on ${facet} failed ${RC}"
1376 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
1377 if [[ "$health" != "healthy" ]]; then
1378 error "$facet is in a unhealthy state"
1381 set_default_debug_facet $facet
1383 if [[ $facet == mds* ]]; then
1385 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 2>/dev/null
1388 if [[ $opts =~ .*nosvc.* ]]; then
1389 echo "Start ${!dev} without service"
1394 wait_update_facet ${facet} "$E2LABEL ${!dev} \
1395 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
1396 "" || error "${!dev} failed to initialize!";;
1398 wait_update_facet ${facet} "$ZFS get -H -o value \
1399 lustre:svname ${!dev} 2>/dev/null | \
1400 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
1401 error "${!dev} failed to initialize!";;
1404 error "unknown fstype!";;
1408 # commit the device label change to disk
1409 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
1410 echo "Commit the device label on ${!dev}"
1411 do_facet $facet "sync; sleep 1; sync"
1415 label=$(devicelabel ${facet} ${!dev})
1416 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1417 eval export ${facet}_svc=${label}
1418 echo Started ${label}
1423 # start facet device options
1429 eval export ${facet}_dev=${device}
1430 eval export ${facet}_opt=\"$@\"
1432 local varname=${facet}failover_dev
1433 if [ -n "${!varname}" ] ; then
1434 eval export ${facet}failover_dev=${!varname}
1436 eval export ${facet}failover_dev=$device
1439 local mntpt=$(facet_mntpt $facet)
1440 do_facet ${facet} mkdir -p $mntpt
1441 eval export ${facet}_MOUNT=$mntpt
1442 mount_facet ${facet}
1445 if [[ $facet == mds* ]]; then
1447 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1458 local HOST=`facet_active_host $facet`
1459 [ -z $HOST ] && echo stop: no host for $facet && return 0
1461 local mntpt=$(facet_mntpt $facet)
1462 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1463 if [ ${running} -ne 0 ]; then
1464 echo "Stopping $mntpt (opts:$@) on $HOST"
1465 do_facet ${facet} $UMOUNT $@ $mntpt
1468 # umount should block, but we should wait for unrelated obd's
1469 # like the MGS or MGC to also stop.
1470 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1472 if [[ $(facet_fstype $facet) == zfs ]]; then
1473 # export ZFS storage pool
1474 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
1478 # save quota version (both administrative and operational quotas)
1479 # add an additional parameter if mountpoint is ever different from $MOUNT
1481 # XXX This function is kept for interoperability with old server (< 2.3.50),
1482 # it should be removed whenever we drop the interoperability for such
1484 quota_save_version() {
1485 local fsname=${2:-$FSNAME}
1487 local ver=$(tr -c -d "123" <<< $spec)
1488 local type=$(tr -c -d "ug" <<< $spec)
1490 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1492 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1494 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1496 local osts=$(get_facets OST)
1497 for ost in ${osts//,/ }; do
1499 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1503 # client could mount several lustre
1505 # XXX This function is kept for interoperability with old server (< 2.3.50),
1506 # it should be removed whenever we drop the interoperability for such
1509 local fsname=${1:-$FSNAME}
1511 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1513 do_nodes $(comma_list $(osts_nodes)) \
1514 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1518 # get mdt quota type
1520 local varsvc=${SINGLEMDS}_svc
1521 do_facet $SINGLEMDS $LCTL get_param -n \
1522 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1525 # get ost quota type
1527 # All OSTs should have same quota type
1528 local varsvc=ost1_svc
1529 do_facet ost1 $LCTL get_param -n \
1530 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1533 # restore old quota type settings
1535 if [ "$old_MDT_QUOTA_TYPE" ]; then
1536 do_facet mgs $LCTL conf_param \
1537 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1539 if [ "$old_OST_QUOTA_TYPE" ]; then
1540 do_facet mgs $LCTL conf_param \
1541 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1545 # Handle the case when there is a space in the lfs df
1546 # "filesystem summary" line the same as when there is no space.
1547 # This will allow fixing the "lfs df" summary line in the future.
1549 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1552 # Get free inodes on the MDT specified by mdt index, free indoes on
1553 # the whole filesystem will be returned when index == -1.
1559 if [ $index -eq -1 ]; then
1562 mdt_uuid=$(mdtuuid_from_index $index)
1565 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1570 # Get the OST device status from 'lfs df' with a given OST index.
1574 local mnt_pnt=${2:-$MOUNT}
1577 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
1578 lfs_df $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
1584 # save old quota type & set new quota type
1585 local mdt_qtype=$(mdt_quota_type)
1586 local ost_qtype=$(ost_quota_type)
1588 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1589 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1591 export old_MDT_QUOTA_TYPE=$mdt_qtype
1592 export old_OST_QUOTA_TYPE=$ost_qtype
1594 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1595 error "set mdt quota type failed"
1596 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1597 error "set ost quota type failed"
1599 local quota_usrs=$QUOTA_USERS
1601 # get_filesystem_size
1602 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1603 local blk_soft=$((disksz + 1024))
1604 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1606 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1607 local i_soft=$inodes
1608 local i_hard=$((i_soft + i_soft / 20))
1610 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1611 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1612 "inode-hardlimit: $i_hard"
1615 for usr in $quota_usrs; do
1616 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1618 cmd="$LFS setquota -$type $usr -b $blk_soft"
1619 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1621 eval $cmd || error "$cmd FAILED!"
1623 # display the quota status
1624 echo "Quota settings for $usr : "
1625 $LFS quota -v -u $usr $mntpt || true
1632 local opts=${3:-$MOUNT_OPTS}
1633 opts=${opts:+-o $opts}
1634 local flags=${4:-$MOUNT_FLAGS}
1636 local device=$MGSNID:/$FSNAME$FILESET
1637 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1638 echo "Bad mount command: opt=$flags $opts dev=$device " \
1643 echo "Starting client: $client: $flags $opts $device $mnt"
1644 do_node $client mkdir -p $mnt
1645 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
1646 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1648 #disable FILESET if not supported
1649 do_nodes $client lctl get_param -n \
1650 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1651 device=$MGSNID:/$FSNAME
1652 do_node $client mkdir -p $mnt/$FILESET
1653 do_node $client "! grep -q $mnt' ' /proc/mounts ||
1656 do_node $client $MOUNT_CMD $flags $opts $device $mnt || return 1
1658 set_default_debug_nodes $client
1670 [ "$3" ] && force=-f
1671 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1672 if [ $running -ne 0 ]; then
1673 echo "Stopping client $client $mnt (opts:$force)"
1674 do_node $client lsof -t $mnt || need_kill=no
1675 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1676 pids=$(do_node $client lsof -t $mnt | sort -u);
1677 if [ -n $pids ]; then
1678 do_node $client kill -9 $pids || true
1682 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1683 if [ $busy -ne 0 ] ; then
1684 echo "$mnt is still busy, wait one second" && sleep 1
1685 do_node $client umount $force $mnt
1690 # nodes is comma list
1691 sanity_mount_check_nodes () {
1697 # FIXME: assume that all cluster nodes run the same os
1698 [ "$(uname)" = Linux ] || return 0
1701 for mnt in $mnts ; do
1702 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1703 mpts=\\\$(mount | grep -c $mnt' ');
1704 if [ \\\$running -ne \\\$mpts ]; then
1705 echo \\\$(hostname) env are INSANE!;
1708 [ $? -eq 0 ] || rc=1
1713 sanity_mount_check_servers () {
1714 [ -n "$CLIENTONLY" ] &&
1715 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1716 echo Checking servers environments
1718 # FIXME: modify get_facets to display all facets wo params
1719 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1723 for facet in ${facets//,/ }; do
1724 node=$(facet_host ${facet})
1725 mntpt=$(facet_mntpt $facet)
1726 sanity_mount_check_nodes $node $mntpt ||
1727 { error "server $node environments are insane!"; return 1; }
1731 sanity_mount_check_clients () {
1732 local clients=${1:-$CLIENTS}
1733 local mntpt=${2:-$MOUNT}
1734 local mntpt2=${3:-$MOUNT2}
1736 [ -z $clients ] && clients=$(hostname)
1737 echo Checking clients $clients environments
1739 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1740 error "clients environments are insane!"
1743 sanity_mount_check () {
1744 sanity_mount_check_servers || return 1
1745 sanity_mount_check_clients || return 2
1748 # mount clients if not mouted
1749 zconf_mount_clients() {
1752 local opts=${3:-$MOUNT_OPTS}
1753 opts=${opts:+-o $opts}
1754 local flags=${4:-$MOUNT_FLAGS}
1756 local device=$MGSNID:/$FSNAME$FILESET
1757 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1758 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
1763 echo "Starting client $clients: $flags $opts $device $mnt"
1764 if [ -n "$FILESET" -a ! -n "$SKIP_FILESET" ]; then
1765 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1767 do_nodes $clients $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1769 #disable FILESET if not supported
1770 do_nodes $clients lctl get_param -n \
1771 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1772 device=$MGSNID:/$FSNAME
1773 do_nodes $clients mkdir -p $mnt/$FILESET
1774 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1779 running=\\\$(mount | grep -c $mnt' ');
1781 if [ \\\$running -eq 0 ] ; then
1783 $MOUNT_CMD $flags $opts $device $mnt;
1786 exit \\\$rc" || return ${PIPESTATUS[0]}
1788 echo "Started clients $clients: "
1789 do_nodes $clients "mount | grep $mnt' '"
1791 set_default_debug_nodes $clients
1796 zconf_umount_clients() {
1801 [ "$3" ] && force=-f
1803 echo "Stopping clients: $clients $mnt (opts:$force)"
1804 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1805 if [ \\\$running -ne 0 ] ; then
1806 echo Stopping client \\\$(hostname) $mnt opts:$force;
1807 lsof $mnt || need_kill=no;
1808 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1809 pids=\\\$(lsof -t $mnt | sort -u);
1810 if [ -n \\\"\\\$pids\\\" ]; then
1814 while umount $force $mnt 2>&1 | grep -q "busy"; do
1815 echo "$mnt is still busy, wait one second" && sleep 1;
1822 echo + $POWER_DOWN $node
1826 shutdown_node_hard () {
1828 local attempts=$SHUTDOWN_ATTEMPTS
1830 for i in $(seq $attempts) ; do
1833 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1834 echo "waiting for $host to fail attempts=$attempts"
1835 [ $i -lt $attempts ] || \
1836 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1842 local mnt=${2:-$MOUNT}
1845 if [ "$FAILURE_MODE" = HARD ]; then
1846 shutdown_node_hard $client
1848 zconf_umount_clients $client $mnt -f
1854 local facets="$(get_facets OST),$(get_facets MDS)"
1857 combined_mgs_mds || facets="$facets,mgs"
1859 for facet in ${facets//,/ }; do
1860 if [ $(facet_active_host $facet) == $host ]; then
1861 affected="$affected $facet"
1865 echo $(comma_list $affected)
1870 local host=${2:-$(facet_host $facet)}
1872 local label=$(convert_facet2label $facet)
1873 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
1876 facets_up_on_host () {
1878 local facets=$(facets_on_host $host)
1881 for facet in ${facets//,/ }; do
1882 if $(facet_up $facet $host); then
1883 affected_up="$affected_up $facet"
1887 echo $(comma_list $affected_up)
1893 if [ "$FAILURE_MODE" = HARD ]; then
1894 shutdown_node_hard $(facet_active_host $facet)
1902 echo + $POWER_UP $node
1915 if [ "$FAILURE_MODE" = HARD ]; then
1916 reboot_node $(facet_active_host $facet)
1924 if [ "$FAILURE_MODE" = HARD ]; then
1934 for facet in ${facets//,/ }; do
1935 hosts=$(expand_list $hosts $(facet_host $facet) )
1941 _check_progs_installed () {
1945 for prog in $progs; do
1946 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1947 echo $prog missing on $(hostname)
1954 check_progs_installed () {
1958 do_rpc_nodes "$nodes" _check_progs_installed $@
1961 # recovery-scale functions
1963 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1966 start_client_load() {
1969 local var=$(node_var_name $client)_load
1970 eval export ${var}=$load
1972 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1973 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1974 END_RUN_FILE=$END_RUN_FILE \
1975 LOAD_PID_FILE=$LOAD_PID_FILE \
1976 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1977 TESTNAME=$TESTNAME \
1978 DBENCH_LIB=$DBENCH_LIB \
1979 DBENCH_SRC=$DBENCH_SRC \
1980 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1986 log "Started client load: ${load} on $client"
1988 # get the children process IDs
1989 local pids=$(ps --ppid $ppid -o pid= | xargs)
1990 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1994 start_client_loads () {
1995 local -a clients=(${1//,/ })
1996 local numloads=${#CLIENT_LOADS[@]}
1999 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
2000 testnum=$((nodenum % numloads))
2001 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
2003 # bug 22169: wait the background threads to start
2007 # only for remote client
2008 check_client_load () {
2010 local var=$(node_var_name $client)_load
2011 local testload=run_${!var}.sh
2013 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
2015 # bug 18914: try to connect several times not only when
2016 # check ps, but while check_node_health also
2020 while [ $RC = 254 -a $tries -gt 0 ]; do
2024 if ! check_node_health $client; then
2026 if [ $RC -eq 254 ]; then
2027 # FIXME: not sure how long we shuold sleep here
2031 echo "check node health failed: RC=$RC "
2035 # We can continue try to connect if RC=254
2036 # Just print the warning about this
2037 if [ $RC = 254 ]; then
2038 echo "got a return status of $RC from do_node while checking " \
2039 "node health on $client"
2042 # see if the load is still on the client
2045 while [ $RC = 254 -a $tries -gt 0 ]; do
2049 if ! do_node $client \
2050 "ps auxwww | grep -v grep | grep -q $testload"; then
2055 if [ $RC = 254 ]; then
2056 echo "got a return status of $RC from do_node while checking " \
2057 "(node health and 'ps') the client load on $client"
2058 # see if we can diagnose a bit why this is
2063 check_client_loads () {
2064 local clients=${1//,/ }
2068 for client in $clients; do
2069 check_client_load $client
2071 if [ "$rc" != 0 ]; then
2072 log "Client load failed on node $client, rc=$rc"
2078 restart_client_loads () {
2079 local clients=${1//,/ }
2080 local expectedfail=${2:-""}
2084 for client in $clients; do
2085 check_client_load $client
2087 if [ "$rc" != 0 -a "$expectedfail" ]; then
2088 local var=$(node_var_name $client)_load
2089 start_client_load $client ${!var}
2090 echo "Restarted client load ${!var}: on $client. Checking ..."
2091 check_client_load $client
2093 if [ "$rc" != 0 ]; then
2094 log "Client load failed to restart on node $client, rc=$rc"
2095 # failure one client load means test fail
2096 # we do not need to check other
2105 # Start vmstat and save its process ID in a file.
2110 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2113 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
2114 2>/dev/null </dev/null & echo \\\$! > $pid_file"
2117 # Display the nodes on which client loads failed.
2118 print_end_run_file() {
2122 [ -s $file ] || return 0
2124 echo "Found the END_RUN_FILE file: $file"
2127 # A client load will stop if it finds the END_RUN_FILE file.
2128 # That does not mean the client load actually failed though.
2129 # The first node in END_RUN_FILE is the one we are interested in.
2132 if [ -n "$node" ]; then
2133 local var=$(node_var_name $node)_load
2135 local prefix=$TESTLOG_PREFIX
2136 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2137 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2138 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2140 echo "Client load ${!var} failed on node $node:"
2146 # Stop the process which had its PID saved in a file.
2151 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2153 do_nodes $nodes "test -f $pid_file &&
2154 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2157 # Stop all client loads.
2158 stop_client_loads() {
2159 local nodes=${1:-$CLIENTS}
2162 # stop the client loads
2163 stop_process $nodes $pid_file
2165 # clean up the processes that started them
2166 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
2168 # End recovery-scale functions
2170 # verify that lustre actually cleaned up properly
2172 VAR=$(lctl get_param -n catastrophe 2>&1)
2173 if [ $? = 0 ] ; then
2174 if [ $VAR != 0 ]; then
2175 error "LBUG/LASSERT detected"
2178 BUSY=$(dmesg | grep -i destruct || true)
2179 if [ -n "$BUSY" ]; then
2181 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2185 check_mem_leak || exit 204
2187 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2188 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2191 if module_loaded lnet || module_loaded libcfs; then
2192 echo "$TESTSUITE: modules still loaded..." 1>&2
2201 if [[ "$1" == "--verbose" ]]; then
2216 PREV_RESULT=$(do_node $node "$TEST")
2218 RESULT=$(do_node $node "$TEST")
2219 if [[ "$RESULT" == "$FINAL" ]]; then
2220 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2221 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2225 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2226 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2230 [[ $WAIT -ge $MAX ]] && break
2231 [[ $((WAIT % print)) -eq 0 ]] &&
2232 echo "Waiting $((MAX - WAIT)) secs for update"
2233 WAIT=$((WAIT + sleep))
2236 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2240 wait_update_facet() {
2242 [ "$1" = "--verbose" ] && verbose="$1" && shift
2246 wait_update $verbose $(facet_active_host $facet) "$@"
2250 do_nodes $(comma_list $(mdts_nodes)) \
2251 "lctl set_param -n osd*.*MDT*.force_sync=1"
2252 do_nodes $(comma_list $(osts_nodes)) \
2253 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
2254 grep -v 'Found no match'
2258 # the occupied disk space will be released
2259 # only after DMUs are committed
2260 if [[ $(facet_fstype $1) == zfs ]]; then
2261 echo "sleep $2 for ZFS OSD"
2266 wait_delete_completed_mds() {
2267 local MAX_WAIT=${1:-20}
2268 # for ZFS, waiting more time for DMUs to be committed
2269 local ZFS_WAIT=${2:-5}
2271 local stime=$(date +%s)
2276 # find MDS with pending deletions
2277 for node in $(mdts_nodes); do
2278 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2279 2>/dev/null | calc_sum)
2280 if [[ $changes -eq 0 ]]; then
2283 mds2sync="$mds2sync $node"
2285 if [ -z "$mds2sync" ]; then
2286 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2289 mds2sync=$(comma_list $mds2sync)
2291 # sync MDS transactions
2292 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2294 # wait till all changes are sent and commmitted by OSTs
2295 # for ldiskfs space is released upon execution, but DMU
2296 # do this upon commit
2299 while [[ $WAIT -ne $MAX_WAIT ]]; do
2300 changes=$(do_nodes $mds2sync \
2301 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2302 #echo "$node: $changes changes on all"
2303 if [[ $changes -eq 0 ]]; then
2304 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2312 echo "Delete is not completed in $((etime - stime)) seconds"
2313 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2319 # we can use "for" here because we are waiting the slowest
2320 for host in ${hostlist//,/ }; do
2321 check_network "$host" 900
2323 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2330 for facet in ${facetlist//,/ }; do
2331 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2333 wait_for_host $hostlist
2336 _wait_recovery_complete () {
2339 # Use default policy if $2 is not passed by caller.
2340 local MAX=${2:-$(max_recovery_time)}
2345 while [ $WAIT -lt $MAX ]; do
2346 STATUS=$(lctl get_param -n $param | grep status)
2348 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2351 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2353 echo "$param recovery not done in $MAX sec. $STATUS"
2357 wait_recovery_complete () {
2360 # with an assumption that at_max is the same on all nodes
2361 local MAX=${2:-$(max_recovery_time)}
2364 if [ "$FAILURE_MODE" = HARD ]; then
2365 facets=$(facets_on_host $(facet_active_host $facet))
2367 echo affected facets: $facets
2369 # we can use "for" here because we are waiting the slowest
2370 for facet in ${facets//,/ }; do
2371 local var_svc=${facet}_svc
2372 local param="*.${!var_svc}.recovery_status"
2374 local host=$(facet_active_host $facet)
2375 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2379 wait_mds_ost_sync () {
2380 # just because recovery is done doesn't mean we've finished
2381 # orphan cleanup. Wait for llogs to get synchronized.
2382 echo "Waiting for orphan cleanup..."
2383 # MAX value includes time needed for MDS-OST reconnection
2384 local MAX=$(( TIMEOUT * 2 ))
2385 local WAIT_TIMEOUT=${1:-$MAX}
2388 local list=$(comma_list $(mdts_nodes))
2389 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2390 if ! do_facet $SINGLEMDS \
2391 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2393 # old way, use mds_sync
2395 list=$(comma_list $(osts_nodes))
2396 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2399 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2400 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2401 local -a sync=($(do_nodes $list "$cmd"))
2404 for ((i=0; i<${#sync[@]}; i++)); do
2406 [ ${sync[$i]} -eq 1 ] && continue
2408 [ ${sync[$i]} -eq 0 ] && continue
2410 # there is a not finished MDS-OST synchronization
2414 sleep 2 # increase waiting time and cover statfs cache
2415 [ ${con} -eq 1 ] && return 0
2416 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2420 # show which nodes are not finished.
2421 do_nodes $list "$cmd"
2422 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2426 # Wait OSTs to be active on both client and MDT side.
2428 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
2429 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
2430 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
2431 error "wait_update OSTs up on client failed"
2433 cmd="$LCTL get_param -n lod.$FSNAME-MDT*-*.target_obd | sort -u |
2434 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
2435 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
2436 error "wait_update OSTs up on MDT failed"
2439 wait_destroy_complete () {
2440 echo "Waiting for local destroys to complete"
2441 # MAX value shouldn't be big as this mean server responsiveness
2442 # never increase this just to make test pass but investigate
2443 # why it takes so long time
2446 while [ $WAIT -lt $MAX ]; do
2447 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2451 for ((i=0; i<${#RPCs[@]}; i++)); do
2452 [ ${RPCs[$i]} -eq 0 ] && continue
2453 # there are still some destroy RPCs in flight
2458 [ ${con} -eq 1 ] && return 0 # done waiting
2459 echo "Waiting ${WAIT}s for local destroys to complete"
2462 echo "Local destroys weren't done in $MAX sec."
2466 wait_delete_completed() {
2467 wait_delete_completed_mds $1 || return $?
2468 wait_destroy_complete
2477 # conf-sanity 31 takes a long time cleanup
2478 while [ $WAIT -lt 300 ]; do
2479 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2480 [ -z "${running}" ] && return 0
2481 echo "waited $WAIT for${running}"
2482 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2484 WAIT=$((WAIT + INTERVAL))
2486 echo "service didn't stop after $WAIT seconds. Still running:"
2491 wait_remote_prog () {
2497 [ "$PDSH" = "no_dsh" ] && return 0
2499 while [ $WAIT -lt $2 ]; do
2500 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2501 [ -z "${running}" ] && return 0 || true
2502 echo "waited $WAIT for: "
2504 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2506 WAIT=$((WAIT + INTERVAL))
2508 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2509 [ -z "$pids" ] && return 0
2510 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2511 # FIXME: not portable
2512 for pid in $pids; do
2513 cat /proc/${pid}/status || true
2514 cat /proc/${pid}/wchan || true
2516 kill -9 $pid || true
2525 local clients=${1:-$CLIENTS}
2527 if [ -z "$clients" ]; then
2530 $PDSH $clients "$LFS df $MOUNT" > /dev/null
2536 # not every config has many clients
2542 # usually checked on particular client or locally
2551 client_reconnect_try() {
2552 local f=$MOUNT/recon
2555 if [ -z "$CLIENTS" ]; then
2556 $LFS df $MOUNT; uname -n >> $f
2558 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
2560 echo "Connected clients: $(cat $f)"
2561 ls -l $f > /dev/null
2565 client_reconnect() {
2566 # one client_reconnect_try call does not always do the job...
2568 client_reconnect_try && break
2573 affected_facets () {
2576 local host=$(facet_active_host $facet)
2577 local affected=$facet
2579 if [ "$FAILURE_MODE" = HARD ]; then
2580 affected=$(facets_up_on_host $host)
2586 local E2FSCK_ON_MDT0=false
2587 if [ "$1" == "--fsck" ]; then
2589 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2601 #Because it will only get up facets, we need get affected
2602 #facets before shutdown
2603 #For HARD Failure mode, it needs make sure facets on the same
2604 #HOST will only be shutdown and reboot once
2605 for facet in ${facets//,/ }; do
2606 local affected_facet
2608 #check whether facet has been included in other affected facets
2609 for ((index=0; index<$total; index++)); do
2610 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2613 if [ $skip -eq 0 ]; then
2614 affecteds[$total]=$(affected_facets $facet)
2619 for ((index=0; index<$total; index++)); do
2620 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2621 local host=$(facet_active_host $facet)
2622 echo "Failing ${affecteds[index]} on $host"
2623 shutdown_facet $facet
2626 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
2627 $(mdsdevname 1) "-n" || error "Running e2fsck")
2629 for ((index=0; index<$total; index++)); do
2630 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2631 echo reboot facets: ${affecteds[index]}
2635 change_active ${affecteds[index]}
2637 wait_for_facet ${affecteds[index]}
2638 # start mgs first if it is affected
2639 if ! combined_mgs_mds &&
2640 list_member ${affecteds[index]} mgs; then
2641 mount_facet mgs || error "Restart of mgs failed"
2643 # FIXME; has to be changed to mount all facets concurrently
2644 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2645 echo mount facets: ${affecteds[index]}
2646 mount_facets ${affecteds[index]}
2656 do_facet $facet "sync; sync; sync"
2659 # make sure there will be no seq change
2660 local clients=${CLIENTS:-$HOSTNAME}
2661 local f=fsa-\\\$\(hostname\)
2662 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2663 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2665 local svc=${facet}_svc
2666 do_facet $facet $LCTL --device ${!svc} notransno
2668 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2669 # in-memory state has to be cleared by either rebooting the host or
2670 # exporting and reimporting the pool.
2672 # Although the uberblocks are not updated when a pool is freezed,
2673 # transactions are still written to the disks. Modified blocks may be
2674 # cached in memory when tests try reading them back. The
2675 # export-and-reimport process also evicts any cached pool data from
2676 # memory to provide the correct "data loss" semantics.
2678 # In the test framework, the exporting and importing operations are
2679 # handled by stop() and mount_facet() separately, which are used
2680 # inside fail() and fail_abort().
2682 do_facet $facet $LCTL --device ${!svc} readonly
2683 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2684 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2687 replay_barrier_nodf() {
2688 local facet=$1 echo running=${running}
2689 do_facet $facet "sync; sync; sync"
2690 local svc=${facet}_svc
2691 echo Replay barrier on ${!svc}
2692 do_facet $facet $LCTL --device ${!svc} notransno
2693 do_facet $facet $LCTL --device ${!svc} readonly
2694 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2695 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2698 replay_barrier_nosync() {
2699 local facet=$1 echo running=${running}
2700 local svc=${facet}_svc
2701 echo Replay barrier on ${!svc}
2702 do_facet $facet $LCTL --device ${!svc} notransno
2703 do_facet $facet $LCTL --device ${!svc} readonly
2704 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2705 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2709 # Get Lustre client uuid for a given Lustre mount point.
2712 local mntpnt=${1:-$MOUNT}
2714 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2715 local uuid=$($LCTL get_param -n llite.$name.uuid)
2720 mds_evict_client() {
2721 local mntpnt=${1:-$MOUNT}
2722 local uuid=$(get_client_uuid $mntpnt)
2724 do_facet $SINGLEMDS \
2725 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2728 ost_evict_client() {
2729 local mntpnt=${1:-$MOUNT}
2730 local uuid=$(get_client_uuid $mntpnt)
2733 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2738 local clients=${CLIENTS:-$HOSTNAME}
2740 facet_failover $* || error "failover: $?"
2741 wait_clients_import_state "$clients" "$facets" FULL
2742 clients_up || error "post-failover stat: $?"
2747 facet_failover $facet
2753 change_active $facet
2754 wait_for_facet $facet
2755 mount_facet $facet -o abort_recovery
2756 clients_up || echo "first stat failed: $?"
2757 clients_up || error "post-failover stat: $?"
2760 host_nids_address() {
2764 do_nodes $nodes "$LCTL list_nids | grep $net | cut -f 1 -d @"
2768 if [ "$1" = "'*'" ]; then echo \'*\'; else
2774 if [[ -v NETTYPE ]]; then
2775 h2name_or_ip "$1" "$NETTYPE"
2777 h2name_or_ip "$1" "$2"
2780 declare -fx h2nettype
2782 # Wrapper function to print the deprecation warning
2784 echo "h2tcp: deprecated, use h2nettype instead" 1>&2
2785 if [[ -v NETTYPE ]]; then
2788 h2nettype "$1" "tcp"
2792 # Wrapper function to print the deprecation warning
2794 echo "h2o2ib: deprecated, use h2nettype instead" 1>&2
2795 if [[ -v NETTYPE ]]; then
2798 h2nettype "$1" "o2ib"
2802 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2803 # expressions format. As a bonus we can then just pass in those variables
2804 # to pdsh. What this function does is take a HOSTLIST type string and
2805 # expand it into a space deliminated list for us.
2813 [ -z "$hostlist" ] && return
2815 # Translate the case of [..],..,[..] to [..] .. [..]
2816 list="${hostlist/],/] }"
2818 [[ "$front" == *,* ]] && {
2821 list=${list/${old}/${new}}
2824 for item in $list; do
2825 # Test if we have any []'s at all
2826 if [ "$item" != "${item/\[/}" ]; then {
2827 # Expand the [*] into list
2831 if [ "$name" != "$item" ]; then
2832 group=${item#$name[*}
2835 for range in ${group//,/ }; do
2841 # Number of leading zeros
2844 end=$(echo $end | sed 's/0*//')
2845 [[ -z "$end" ]] && end=0
2846 [[ $padlen2 -gt $padlen ]] && {
2847 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2850 begin=$(echo $begin | sed 's/0*//')
2851 [ -z $begin ] && begin=0
2853 if [ ! -z "${begin##[!0-9]*}" ]; then
2854 order=$(seq -f "%0${padlen}g" $begin $end)
2856 order=$(eval echo {$begin..$end});
2859 for num in $order; do
2860 value="${name#*,}${num}${back}"
2861 [ "$value" != "${value/\[/}" ] && {
2862 value=$(hostlist_expand "$value")
2864 myList="$myList $value"
2869 myList="$myList $item"
2872 myList=${myList//,/ }
2873 myList=${myList:1} # Remove first character which is a space
2875 # Filter any duplicates without sorting
2877 myList="${list%% *}"
2879 while [[ "$list" != ${myList##* } ]]; do
2880 local tlist=" $list"
2881 list=${tlist// ${list%% *} / }
2883 myList="$myList ${list%% *}"
2885 myList="${myList%* }";
2887 # We can select an object at an offset in the list
2890 for item in $myList; do
2892 [ $cnt -eq $offset ] && {
2896 [ $(get_node_count $myList) -ne 1 ] && myList=""
2905 [ "$facet" == client ] && echo -n $HOSTNAME && return
2906 varname=${facet}_HOST
2907 if [ -z "${!varname}" ]; then
2908 if [ "${facet:0:3}" == "ost" ]; then
2909 local fh=${facet%failover}_HOST
2910 eval export ${facet}_HOST=${!fh}
2911 if [ -z "${!varname}" ]; then
2912 eval export ${facet}_HOST=${ost_HOST}
2914 elif [ "${facet:0:3}" == "mdt" -o \
2915 "${facet:0:3}" == "mds" -o \
2916 "${facet:0:3}" == "mgs" ]; then
2917 eval export ${facet}_HOST=${mds_HOST}
2923 facet_failover_host() {
2927 var=${facet}failover_HOST
2928 if [ -n "${!var}" ]; then
2933 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2934 "${facet:0:3}" == "mgs" ]; then
2936 eval export ${facet}failover_host=${mds_HOST}
2941 if [[ $facet == ost* ]]; then
2942 eval export ${facet}failover_host=${ost_HOST}
2950 local activevar=${facet}active
2952 if [ -f $TMP/${facet}active ] ; then
2953 source $TMP/${facet}active
2956 active=${!activevar}
2957 if [ -z "$active" ] ; then
2964 facet_active_host() {
2965 facet_host $(facet_active $1)
2968 # Get the passive failover partner host of facet.
2969 facet_passive_host() {
2971 [[ $facet = client ]] && return
2973 local host=${facet}_HOST
2974 local failover_host=${facet}failover_HOST
2975 local active_host=$(facet_active_host $facet)
2977 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2979 if [[ $active_host = ${!host} ]]; then
2980 echo -n ${!failover_host}
2990 facetlist=$(exclude_items_from_list $facetlist mgs)
2992 for facet in ${facetlist//,/ }; do
2993 local failover=${facet}failover
2994 local host=`facet_host $failover`
2995 [ -z "$host" ] && return
2997 local curactive=`facet_active $facet`
2998 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2999 eval export ${facet}active=$facet
3001 eval export ${facet}active=$failover
3003 # save the active host for this facet
3004 local activevar=${facet}active
3005 echo "$activevar=${!activevar}" > $TMP/$activevar
3006 [[ $facet = mds1 ]] && combined_mgs_mds && \
3007 echo "mgsactive=${!activevar}" > $TMP/mgsactive
3008 local TO=`facet_active_host $facet`
3009 echo "Failover $facet to $TO"
3015 # do not stripe off hostname if verbose, bug 19215
3016 if [ x$1 = x--verbose ]; then
3024 if [ "$HOST" = "$HOSTNAME" ]; then
3026 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
3027 echo "cannot run remote command on $HOST with $myPDSH"
3031 echo "CMD: $HOST $@" >&2
3032 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3035 if [ "$myPDSH" = "rsh" ]; then
3036 # we need this because rsh does not return exit code of an executed command
3037 local command_status="$TMP/cs"
3038 rsh $HOST ":> $command_status"
3039 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
3040 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
3041 echo command failed >$command_status"
3042 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
3047 # print HOSTNAME for myPDSH="no_dsh"
3048 if [[ $myPDSH = no_dsh ]]; then
3049 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
3051 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
3054 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
3056 return ${PIPESTATUS[0]}
3060 do_node --verbose "$@"
3063 single_local_node () {
3064 [ "$1" = "$HOSTNAME" ]
3067 # Outputs environment variable assignments that should be passed to remote nodes
3071 local facets=$(get_facets)
3074 for var in ${!MODOPTS_*}; do
3075 value=${!var//\"/\\\"}
3076 echo -n " ${var}=\"$value\""
3079 for facet in ${facets//,/ }; do
3081 if [ -n "${!var}" ]; then
3082 echo -n " $var=${!var}"
3086 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
3087 if [ -n "${!var}" ]; then
3088 echo -n " $var=${!var}"
3092 for var in VERBOSE; do
3093 if [ -n "${!var}" ]; then
3094 echo -n " $var=${!var}"
3098 if [ -n "$FSTYPE" ]; then
3099 echo -n " FSTYPE=$FSTYPE"
3102 for var in LNETLND NETTYPE; do
3103 if [ -n "${!var}" ]; then
3104 echo -n " $var=${!var}"
3111 # do not stripe off hostname if verbose, bug 19215
3112 if [ x$1 = x--verbose ]; then
3120 if single_local_node $rnodes; then
3122 do_nodev $rnodes "$@"
3124 do_node $rnodes "$@"
3129 # This is part from do_node
3132 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
3133 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
3135 export FANOUT=$(get_node_count "${rnodes//,/ }")
3137 echo "CMD: $rnodes $@" >&2
3138 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3141 # do not replace anything from pdsh output if -N is used
3142 # -N Disable hostname: prefix on lines of output.
3143 if $verbose || [[ $myPDSH = *-N* ]]; then
3144 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
3146 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
3148 return ${PIPESTATUS[0]}
3152 # Execute commands on a single service's host
3154 # The \a facet (service) may be on a local or remote node, which is
3155 # determined at the time the command is run.
3157 # usage: do_facet $facet command [arg ...]
3161 local HOST=$(facet_active_host $facet)
3162 [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
3166 # Function: do_facet_random_file $FACET $FILE $SIZE
3167 # Creates FILE with random content on the given FACET of given SIZE
3169 do_facet_random_file() {
3173 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
3174 do_facet $facet "$cmd 2>/dev/null"
3177 do_facet_create_file() {
3181 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
3182 do_facet $facet "$cmd 2>/dev/null"
3186 do_nodes --verbose "$@"
3192 # make sure its not already running
3194 rm -f $TMP/${facet}active
3195 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
3196 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
3198 if [[ $(facet_fstype $facet) == zfs ]]; then
3200 # After formatting a ZFS target, "cachefile=none" property will
3201 # be set on the ZFS storage pool so that the pool is not
3202 # automatically imported on system startup. And then the pool
3203 # will be exported so as to leave the importing and exporting
3204 # operations handled by mount_facet() and stop() separately.
3206 refresh_partition_table $facet $(facet_vdevice $facet)
3207 disable_zpool_cache $facet
3212 # Device formatted as ost
3215 local DEVNAME=OSTDEV$num
3217 local fstype=$(facet_fstype ost$num)
3221 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
3222 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3224 #try $OSTZFSDEVn - independent of vdev
3225 DEVNAME=OSTZFSDEV$num
3226 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
3228 error "unknown fstype!";;
3234 # Physical device location of data
3240 local fstype=$(facet_fstype ost$num)
3244 # vdevs are not supported by ldiskfs
3247 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3248 # Device formatted by zfs
3250 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3252 error "unknown fstype!";;
3258 # Logical device formatted for lustre
3261 local DEVNAME=MDSDEV$num
3263 local fstype=$(facet_fstype mds$num)
3267 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3268 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3270 # try $MDSZFSDEVn - independent of vdev
3271 DEVNAME=MDSZFSDEV$num
3272 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3274 error "unknown fstype!";;
3280 # Physical location of data
3284 local fstype=$(facet_fstype mds$num)
3288 # vdevs are not supported by ldiskfs
3291 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3292 # Device formatted by ZFS
3293 local DEVNAME=MDSDEV$num
3294 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3296 error "unknown fstype!";;
3304 local fstype=$(facet_fstype mgs)
3308 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3309 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3310 DEVPTR=$(mdsdevname 1)
3315 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3316 ( [ -z "$MGSZFSDEV" ] &&
3317 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3318 DEVPTR=$(mdsdevname 1)
3320 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3323 error "unknown fstype!";;
3332 local fstype=$(facet_fstype mgs)
3336 # vdevs are not supported by ldiskfs
3339 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3340 ( [ -z "$MGSDEV" ] &&
3341 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3342 VDEVPTR=$(mdsvdevname 1)
3343 elif [ -n "$MGSDEV" ]; then
3347 error "unknown fstype!";;
3355 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3357 local var=${facet}_MOUNT
3358 eval mntpt=${!var:-${MOUNT}-$facet}
3365 local dev=$(facet_device $facet)
3366 local mnt=${2:-$(facet_mntpt $facet)}
3369 if ! do_facet $facet test -b $dev; then
3372 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3377 local dev=$(facet_device $facet)
3378 local mnt=${2:-$(facet_mntpt $facet)}
3380 do_facet $facet $UMOUNT $mnt
3384 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3389 local ds=$(facet_device $facet)
3390 local mnt=${2:-$(facet_mntpt $facet)}
3395 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3396 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3397 do_facet $facet $ZFS set canmount=noauto $ds
3399 # The "legacy" mount method is used here because "zfs unmount $mnt"
3400 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3401 # targets are not available at the time, the stat(2) on $MOUNT will
3404 do_facet $facet $ZFS set mountpoint=legacy $ds
3405 do_facet $facet mount -t zfs $ds $mnt
3406 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3407 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3412 local ds=$(facet_device $facet)
3413 local mnt=${2:-$(facet_mntpt $facet)}
3414 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3415 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3416 local mntpt=${!var_mntpt}
3417 local canmnt=${!var_canmnt}
3421 do_facet $facet umount $mnt
3422 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3423 do_facet $facet $ZFS set canmount=$canmnt $ds
3430 local fstype=$(facet_fstype $facet)
3432 mount_$fstype $facet $mnt
3438 local fstype=$(facet_fstype $facet)
3440 unmount_$fstype $facet $mnt
3447 # make sure we are using the primary server, so test-framework will
3448 # be able to clean up properly.
3449 activemds=`facet_active mds1`
3450 if [ $activemds != "mds1" ]; then
3454 local clients=$CLIENTS
3455 [ -z $clients ] && clients=$(hostname)
3457 zconf_umount_clients $clients $MOUNT "$*" || true
3458 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3460 [ -n "$CLIENTONLY" ] && return
3462 # The add fn does rm ${facet}active file, this would be enough
3463 # if we use do_facet <facet> only after the facet added, but
3464 # currently we use do_facet mds in local.sh
3465 for num in `seq $MDSCOUNT`; do
3467 rm -f ${TMP}/mds${num}active
3469 combined_mgs_mds && rm -f $TMP/mgsactive
3471 for num in `seq $OSTCOUNT`; do
3473 rm -f $TMP/ost${num}active
3476 if ! combined_mgs_mds ; then
3483 cleanup_echo_devs () {
3486 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3488 for dev in $devs; do
3489 $LCTL --device $dev cleanup
3490 $LCTL --device $dev detach
3495 nfs_client_mode && return
3496 cifs_client_mode && return
3505 combined_mgs_mds () {
3506 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3507 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3511 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3515 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3521 local fsname=${3:-"$FSNAME"}
3522 local type=$(facet_type $facet)
3523 local index=$(facet_index $facet)
3524 local fstype=$(facet_fstype $facet)
3525 local host=$(facet_host $facet)
3530 if [ $type == MGS ] || ( [ $type == MDS ] &&
3531 [ "$dev" == $(mgsdevname) ] &&
3532 [ "$host" == "$(facet_host mgs)" ] ); then
3535 opts="--mgsnode=$MGSNID"
3538 if [ $type != MGS ]; then
3539 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3543 var=${facet}failover_HOST
3544 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3545 opts+=" --failnode=$(h2nettype ${!var})"
3548 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3549 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3551 if [ $type == MDS ]; then
3552 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3553 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3554 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3555 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3557 if [ $fstype == ldiskfs ]; then
3558 # Check for wide striping
3559 if [ $OSTCOUNT -gt 160 ]; then
3560 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3561 fs_mkfs_opts+="-O large_xattr"
3565 if [ -n "${!var}" ]; then
3566 fs_mkfs_opts+=" -J device=${!var}"
3568 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3570 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3574 if [ $type == OST ]; then
3575 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3577 if [ $fstype == ldiskfs ]; then
3579 if [ -n "${!var}" ]; then
3580 fs_mkfs_opts+=" -J device=${!var}"
3582 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3587 opts+=" --backfstype=$fstype"
3590 if [ -n "${!var}" ]; then
3591 opts+=" --device-size=${!var}"
3594 var=$(upper $fstype)_MKFS_OPTS
3595 fs_mkfs_opts+=${!var:+" ${!var}"}
3597 var=${type}_FS_MKFS_OPTS
3598 fs_mkfs_opts+=${!var:+" ${!var}"}
3600 if [ -n "${fs_mkfs_opts## }" ]; then
3601 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3605 opts+=${!var:+" ${!var}"}
3612 local type=$(facet_type $facet)
3613 local var=${type}_MOUNT_FS_OPTS
3615 if [ -n "${!var}" ]; then
3616 opts+=" --mountfsoptions=${!var}"
3621 check_ost_indices() {
3622 local index_count=${#OST_INDICES[@]}
3623 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
3625 # OST count is greater than the index count in $OST_INDEX_LIST.
3626 # We need check whether there are duplicate indices.
3630 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
3631 index=$(facet_index ost$i)
3632 for j in $(seq 0 $((index_count - 1))); do
3633 [[ $index -ne ${OST_INDICES[j]} ]] ||
3634 error "ost$i has the same index $index as ost$((j+1))"
3645 echo "Format mgs: $(mgsdevname)"
3646 reformat_external_journal mgs
3647 add mgs $(mkfs_opts mgs $(mgsdevname)) $(mountfs_opts mgs) --reformat \
3648 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
3658 echo "Format mds$num: $(mdsdevname $num)"
3659 reformat_external_journal mds$num
3660 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3661 $(mountfs_opts mds$num) --reformat $(mdsdevname $num) \
3662 $(mdsvdevname $num) ${quiet:+>/dev/null} || exit 10
3671 echo "Format ost$num: $(ostdevname $num)"
3672 reformat_external_journal ost$num
3673 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3674 $(mountfs_opts ost$num) --reformat $(ostdevname $num) \
3675 $(ostvdevname ${num}) ${quiet:+>/dev/null} || exit 10
3680 # Set hostid for ZFS/SPL zpool import protection
3681 # (Assumes MDS version is also OSS version)
3682 if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ];
3684 do_rpc_nodes "$(comma_list $(remote_nodes_list))" set_hostid
3687 # We need ldiskfs here, may as well load them all
3689 [ -n "$CLIENTONLY" ] && return
3690 echo Formatting mgs, mds, osts
3691 if ! combined_mgs_mds ; then
3695 for num in $(seq $MDSCOUNT); do
3699 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
3701 for num in $(seq $OSTCOUNT); do
3707 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3711 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3715 # 0: success, the old identity set already.
3716 # 1: success, the old identity does not set.
3721 local j=`expr $num - 1`
3722 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3724 if [ -z "$MDT" ]; then
3728 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3731 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3733 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3736 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3738 if [ $old = "NONE" ]; then
3747 zconf_umount `hostname` $1 || error "umount failed"
3748 zconf_mount `hostname` $1 || error "mount failed"
3756 rm -f $TMP/${facet}active
3757 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3762 local mdt_count=${1:-$MDSCOUNT}
3763 local ost_count=${2:-$OSTCOUNT}
3766 for num in $(seq $mdt_count); do
3767 DEVNAME=$(mdsdevname $num)
3768 writeconf_facet mds$num $DEVNAME || rc=$?
3771 for num in $(seq $ost_count); do
3772 DEVNAME=$(ostdevname $num)
3773 writeconf_facet ost$num $DEVNAME || rc=$?
3781 nfs_client_mode && return
3782 cifs_client_mode && return
3784 sanity_mount_check || error "environments are insane!"
3788 if [ -z "$CLIENTONLY" ]; then
3789 echo Setup mgs, mdt, osts
3790 echo $WRITECONF | grep -q "writeconf" && writeconf_all
3791 if ! combined_mgs_mds ; then
3792 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3795 for num in `seq $MDSCOUNT`; do
3796 DEVNAME=$(mdsdevname $num)
3797 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3799 # We started mds, now we should set failover variables properly.
3800 # Set mds${num}failover_HOST if it is not set (the default failnode).
3801 local varname=mds${num}failover_HOST
3802 if [ -z "${!varname}" ]; then
3803 eval mds${num}failover_HOST=$(facet_host mds$num)
3806 if [ $IDENTITY_UPCALL != "default" ]; then
3807 switch_identity $num $IDENTITY_UPCALL
3810 for num in `seq $OSTCOUNT`; do
3811 DEVNAME=$(ostdevname $num)
3812 start ost$num $DEVNAME $OST_MOUNT_OPTS
3814 # We started ost$num, now we should set ost${num}failover variable properly.
3815 # Set ost${num}failover_HOST if it is not set (the default failnode).
3816 varname=ost${num}failover_HOST
3817 if [ -z "${!varname}" ]; then
3818 eval ost${num}failover_HOST=$(facet_host ost${num})
3826 # wait a while to allow sptlrpc configuration be propogated to targets,
3827 # only needed when mounting new target devices.
3832 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3834 if [ ! -z $arg1 ]; then
3835 [ "$arg1" = "server_only" ] && return
3839 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3842 if [ "$MOUNT_2" ]; then
3843 mount_client $MOUNT2
3844 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3849 # by remounting mdt before ost, initial connect from mdt to ost might
3850 # timeout because ost is not ready yet. wait some time to its fully
3851 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3852 # by a context negotiation rpc with $TIMEOUT.
3853 # FIXME better by monitoring import status.
3856 sleep $((TIMEOUT + 5))
3862 mounted_lustre_filesystems() {
3863 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3866 init_facet_vars () {
3867 [ -n "$CLIENTONLY" ] && return 0
3874 eval export ${facet}_dev=${device}
3875 eval export ${facet}_opt=\"$@\"
3877 local dev=${facet}_dev
3879 # We need to loop for the label
3880 # in case its not initialized yet.
3881 for wait_time in {0,1,3,5,10}; do
3883 if [ $wait_time -gt 0 ]; then
3884 echo "${!dev} not yet initialized,"\
3885 "waiting ${wait_time} seconds."
3889 local label=$(devicelabel ${facet} ${!dev})
3891 # Check to make sure the label does
3892 # not include ffff at the end of the label.
3893 # This indicates it has not been initialized yet.
3895 if [[ $label =~ [f|F]{4}$ ]]; then
3896 # label is not initialized, unset the result
3897 # and either try again or fail
3904 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3906 eval export ${facet}_svc=${label}
3908 local varname=${facet}failover_HOST
3909 if [ -z "${!varname}" ]; then
3910 eval export $varname=$(facet_host $facet)
3913 varname=${facet}_HOST
3914 if [ -z "${!varname}" ]; then
3915 eval export $varname=$(facet_host $facet)
3918 # ${facet}failover_dev is set in cfg file
3919 varname=${facet}failover_dev
3920 if [ -n "${!varname}" ] ; then
3921 eval export ${facet}failover_dev=${!varname}
3923 eval export ${facet}failover_dev=$device
3926 # get mount point of already mounted device
3927 # is facet_dev is already mounted then use the real
3928 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3929 # i.e. ${facet}_MOUNT if specified by user or default
3930 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3931 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3932 if [ -z $mntpt ]; then
3933 mntpt=$(facet_mntpt $facet)
3935 eval export ${facet}_MOUNT=$mntpt
3938 init_facets_vars () {
3941 if ! remote_mds_nodsh; then
3942 for num in $(seq $MDSCOUNT); do
3943 DEVNAME=`mdsdevname $num`
3944 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3948 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3950 if ! remote_ost_nodsh; then
3951 for num in $(seq $OSTCOUNT); do
3952 DEVNAME=$(ostdevname $num)
3953 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3958 osc_ensure_active () {
3963 while [ $period -lt $timeout ]; do
3964 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3965 if [ $count -eq 0 ]; then
3969 echo "There are $count OST are inactive, wait $period seconds, and try again"
3971 period=$((period+3))
3974 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3977 set_conf_param_and_check() {
3981 local ORIG=$(do_facet $myfacet "$TEST")
3982 if [ $# -gt 3 ]; then
3988 echo "Setting $PARAM from $ORIG to $FINAL"
3989 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3990 error "conf_param $PARAM failed"
3992 wait_update_facet $myfacet "$TEST" "$FINAL" ||
3993 error "check $PARAM failed!"
3996 init_param_vars () {
3997 TIMEOUT=$(lctl get_param -n timeout)
3998 TIMEOUT=${TIMEOUT:-20}
4000 remote_mds_nodsh && log "Using TIMEOUT=$TIMEOUT" && return 0
4002 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
4003 log "Using TIMEOUT=$TIMEOUT"
4005 osc_ensure_active $SINGLEMDS $TIMEOUT
4006 osc_ensure_active client $TIMEOUT
4008 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
4009 local current_jobid_var=$($LCTL get_param -n jobid_var)
4011 if [ $JOBID_VAR = "existing" ]; then
4012 echo "keeping jobstats as $current_jobid_var"
4013 elif [ $current_jobid_var != $JOBID_VAR ]; then
4014 echo "seting jobstats to $JOBID_VAR"
4016 set_conf_param_and_check client \
4017 "$LCTL get_param -n jobid_var" \
4018 "$FSNAME.sys.jobid_var" $JOBID_VAR
4021 echo "jobstats not supported by server"
4024 if [ $QUOTA_AUTO -ne 0 ]; then
4025 if [ "$ENABLE_QUOTA" ]; then
4026 echo "enable quota as required"
4027 setup_quota $MOUNT || return 2
4029 echo "disable quota as required"
4030 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
4036 nfs_client_mode () {
4037 if [ "$NFSCLIENT" ]; then
4038 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
4039 local clients=$CLIENTS
4040 [ -z $clients ] && clients=$(hostname)
4042 # FIXME: remove hostname when 19215 fixed
4043 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
4044 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
4045 if [[ ${#nfsexport[@]} -eq 0 ]]; then
4046 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
4048 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
4054 cifs_client_mode () {
4055 [ x$CIFSCLIENT = xyes ] &&
4056 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
4059 check_config_client () {
4062 local mounted=$(mount | grep " $mntpt ")
4063 if [ -n "$CLIENTONLY" ]; then
4065 # CLIENTONLY should not depend on *_HOST settings
4066 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
4067 # in theory someone could create a new,
4068 # client-only config file that assumed lustre was already
4069 # configured and didn't set the MGSNID. If MGSNID is not set,
4070 # then we should use the mgs nid currently being used
4071 # as the default value. bug 18021
4072 [[ x$MGSNID = x ]] &&
4075 if [[ x$mgc != xMGC$MGSNID ]]; then
4076 if [ "$mgs_HOST" ]; then
4077 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
4078 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
4079 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
4085 echo Checking config lustre mounted on $mntpt
4086 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
4087 mgshost=$(echo $mgshost | awk -F: '{print $1}')
4091 check_config_clients () {
4092 local clients=${CLIENTS:-$HOSTNAME}
4095 nfs_client_mode && return
4096 cifs_client_mode && return
4098 do_rpc_nodes "$clients" check_config_client $mntpt
4100 sanity_mount_check || error "environments are insane!"
4104 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
4105 local cltimeout=$(lctl get_param -n timeout)
4106 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
4107 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
4114 [ -z $mntpt ] && return 1
4115 local mounted=$(mounted_lustre_filesystems)
4117 echo $mounted' ' | grep -w -q $mntpt' '
4121 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
4125 # empty lustre filesystem may have empty directories lost+found and .lustre
4127 # exclude .lustre & lost+found
4128 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
4129 -print | wc -l) = 1 ] || return 1
4130 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
4131 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
4132 # exclude .lustre/fid (LU-2780)
4133 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
4134 -print | wc -l) = 1 ] || return 1
4136 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
4141 check_and_setup_lustre() {
4143 nfs_client_mode && return
4144 cifs_client_mode && return
4146 local MOUNTED=$(mounted_lustre_filesystems)
4150 # both MOUNT and MOUNT2 are not mounted
4151 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
4152 [ "$REFORMAT" = "yes" ] && formatall
4153 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
4155 is_mounted $MOUNT || error "NAME=$NAME not mounted"
4156 export I_MOUNTED=yes
4160 elif is_mounted $MOUNT2; then
4162 # MOUNT2 is mounted, while MOUNT_2 is not set
4163 if ! [ "$MOUNT_2" ]; then
4164 cleanup_mount $MOUNT2
4165 export I_UMOUNTED2=yes
4168 # MOUNT2 is mounted, MOUNT_2 is set
4170 # FIXME: what to do if check_config failed?
4172 # 1) remote client has mounted other Lustre fs ?
4173 # 2) it has insane env ?
4174 # let's try umount MOUNT2 on all clients and mount it again:
4175 if ! check_config_clients $MOUNT2; then
4176 cleanup_mount $MOUNT2
4177 restore_mount $MOUNT2
4178 export I_MOUNTED2=yes
4183 # MOUNT is mounted MOUNT2 is not mounted
4184 elif [ "$MOUNT_2" ]; then
4185 restore_mount $MOUNT2
4186 export I_MOUNTED2=yes
4190 # FIXME: what to do if check_config failed?
4192 # 1) remote client has mounted other Lustre fs?
4193 # 2) lustre is mounted on remote_clients atall ?
4194 check_config_clients $MOUNT
4198 set_default_debug_nodes $(comma_list $(nodes_list))
4201 if [ -z "$CLIENTONLY" -a $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ]; then
4203 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
4204 facets="$(get_facets OST)"
4205 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
4206 facets="$facets,$(get_facets MDS)"
4207 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
4208 facets="$facets,mgs"
4209 local nodes="$(facets_hosts ${facets})"
4210 if [ -n "$nodes" ] ; then
4211 do_nodes $nodes "$LCTL set_param \
4212 osd-ldiskfs.track_declares_assert=1 || true"
4221 if [ -z "$CLIENTONLY" ]; then
4222 # Enable remote MDT create for testing
4223 for num in $(seq $MDSCOUNT); do
4225 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
4230 if [ "$ONLY" == "setup" ]; then
4236 local clients=${CLIENTS:-$HOSTNAME}
4239 zconf_mount_clients $clients $mntpt
4243 local clients=${CLIENTS:-$HOSTNAME}
4246 zconf_umount_clients $clients $mntpt
4249 cleanup_and_setup_lustre() {
4250 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
4251 lctl set_param debug=0 || true
4253 if [ "$ONLY" == "cleanup" ]; then
4257 check_and_setup_lustre
4260 # Get all of the server target devices from a given server node and type.
4267 if [ "$type" == ost ]; then
4268 devs=$(get_osd_param $node "" mntdev)
4270 devs=$(do_node $node $LCTL get_param -n osd-*.$FSNAME-M*.mntdev)
4272 for dev in $devs; do
4274 *loop*) do_node $node "losetup $dev" | \
4275 sed -e "s/.*(//" -e "s/).*//" ;;
4281 # Get all of the server target devices.
4286 # Master MDS parameters used by lfsck
4287 MDTNODE=$(facet_active_host $SINGLEMDS)
4288 MDTDEV=$(echo $(get_mnt_devs $MDTNODE mdt) | awk '{print $1}')
4292 for node in $(mdts_nodes); do
4293 MDTDEVS[i]=$(get_mnt_devs $node mdt)
4299 for node in $(osts_nodes); do
4300 OSTDEVS[i]=$(get_mnt_devs $node ost)
4305 # Run e2fsck on MDT or OST device.
4310 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
4311 local log=$TMP/e2fsck.log
4315 do_node $node $cmd 2>&1 | tee $log
4317 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
4319 if [ $MDSCOUNT -gt 1 ]; then
4320 skip "DNE mode isn't supported!"
4324 error "It's not DNE mode."
4329 [ $rc -le $FSCK_MAX_ERR ] ||
4330 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4336 # Run resize2fs on MDT or OST device.
4345 do_facet $facet "$RESIZE2FS $opts $device $size"
4348 # verify a directory is shared among nodes.
4349 check_shared_dir() {
4351 local list=${2:-$(comma_list $(nodes_list))}
4353 [ -z "$dir" ] && return 1
4354 do_rpc_nodes "$list" check_logdir $dir
4355 check_write_access $dir "$list" || return 1
4360 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
4361 $LCTL set_param printk=+lfsck
4362 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
4364 for k in $(seq $MDSCOUNT); do
4365 # wait up to 10+1 minutes for LFSCK to complete
4366 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4367 mdd.$(facet_svc mds${k}).lfsck_layout |
4368 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
4369 error "MDS${k} layout isn't the expected 'completed'"
4370 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4371 mdd.$(facet_svc mds${k}).lfsck_namespace |
4372 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
4373 error "MDS${k} namespace isn't the expected 'completed'"
4375 local rep_mdt=$(do_nodes $(comma_list $(mdts_nodes)) \
4376 $LCTL get_param -n mdd.$FSNAME-*.lfsck_* |
4377 awk '/repaired/ { print $2 }' | calc_sum)
4378 local rep_ost=$(do_nodes $(comma_list $(osts_nodes)) \
4379 $LCTL get_param -n obdfilter.$FSNAME-*.lfsck_* |
4380 awk '/repaired/ { print $2 }' | calc_sum)
4381 local repaired=$((rep_mdt + rep_ost))
4382 [ $repaired -eq 0 ] ||
4383 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
4386 dump_file_contents() {
4392 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
4393 error_noexit false \
4394 "Invalid parameters for dump_file_contents()"
4397 for node in ${nodes}; do
4398 do_node $node "for i in \\\$(find $dir -type f); do
4399 echo ====\\\${i}=======================;
4401 done" >> ${logname}.${node}.log
4405 dump_command_output() {
4411 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
4412 error_noexit false \
4413 "Invalid parameters for dump_command_output()"
4417 for node in ${nodes}; do
4418 do_node $node "echo ====${cmd}=======================;
4419 $cmd" >> ${logname}.${node}.log
4426 # dump file contents from /proc/spl in case of zfs test
4427 if [ "$(facet_fstype ost1)" = "zfs" ]; then
4428 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
4429 dump_command_output \
4430 "$(osts_nodes)" "zpool events -v" "${logname}"
4433 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
4434 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
4435 dump_command_output \
4436 "$(mdts_nodes)" "zpool events -v" "${logname}"
4440 check_and_cleanup_lustre() {
4441 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "sanity-lfsck" -a \
4442 "$TESTSUITE" != "sanity-scrub" ]; then
4446 if is_mounted $MOUNT; then
4447 if $DO_CLEANUP; then
4448 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4449 error "remove sub-test dirs failed"
4453 [ "$ENABLE_QUOTA" ] && restore_quota || true
4456 if [ "$I_UMOUNTED2" = "yes" ]; then
4457 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4460 if [ "$I_MOUNTED2" = "yes" ]; then
4461 cleanup_mount $MOUNT2
4464 if [ "$I_MOUNTED" = "yes" ]; then
4465 cleanupall -f || error "cleanup failed"
4473 wait_for_function () {
4476 # suppress fn both stderr and stdout
4477 if [ "$1" = "--quiet" ]; then
4479 quiet=" > /dev/null 2>&1"
4491 eval $fn $quiet && return 0
4493 wait=$((wait + sleep))
4494 [ $wait -lt $max ] || return 1
4495 echo waiting $fn, $((max - wait)) secs left ...
4505 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4506 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4507 echo "Network not available!"
4511 echo `date +"%H:%M:%S (%s)"` network interface is UP
4519 # Convert a space-delimited list to a comma-delimited list. If the input is
4520 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4522 # echo is used to convert newlines to spaces, since it doesn't
4523 # introduce a trailing space as using "tr '\n' ' '" does
4524 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4530 echo $list | grep -qw $item
4533 # list, excluded are the comma separated lists
4534 exclude_items_from_list () {
4540 for item in ${excluded//,/ }; do
4541 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4543 echo $(comma_list $list)
4546 # list, expand are the comma separated lists
4548 local list=${1//,/ }
4549 local expand=${2//,/ }
4552 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4553 echo $(comma_list $expanded)
4556 testslist_filter () {
4557 local script=$LUSTRE/tests/${TESTSUITE}.sh
4559 [ -f $script ] || return 0
4561 local start_at=$START_AT
4562 local stop_at=$STOP_AT
4564 local var=${TESTSUITE//-/_}_START_AT
4565 [ x"${!var}" != x ] && start_at=${!var}
4566 var=${TESTSUITE//-/_}_STOP_AT
4567 [ x"${!var}" != x ] && stop_at=${!var}
4569 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4570 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4571 /^'${start_at}'$/ {flag = 0}
4572 {if (flag == 1) print $0}
4573 /^'${stop_at}'$/ { flag = 1 }'
4577 (cd `dirname $1`; echo $PWD/`basename $1`)
4581 local types=${1:-"OST MDS MGS"}
4585 for entry in $types; do
4586 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4587 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4590 MGS ) list="$list $name";;
4591 MDS|OST|AGT ) local count=${type}COUNT
4592 for ((i=1; i<=${!count}; i++)) do
4593 list="$list ${name}$i"
4595 * ) error "Invalid facet type"
4599 echo $(comma_list $list)
4602 ##################################
4603 # Adaptive Timeouts funcs
4606 # only check mds, we assume at_max is the same on all nodes
4607 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4608 if [ $at_max -eq 0 ]; then
4619 # suppose that all ost-s have the same $at value set
4620 [ $facet != "ost" ] || facet=ost1
4622 do_facet $facet "lctl get_param -n $at"
4640 if [ $facet == "ost" ]; then
4641 facet=$(get_facets OST)
4642 elif [ $facet == "mds" ]; then
4643 facet=$(get_facets MDS)
4645 hosts=$(expand_list $hosts $(facets_hosts $facet))
4648 do_nodes $hosts lctl set_param at_max=$at_max
4651 ##################################
4655 # OBD_FAIL_MDS_ALL_REQUEST_NET
4657 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4658 do_facet client "$1" || RC=$?
4659 do_facet $SINGLEMDS lctl set_param fail_loc=0
4664 # OBD_FAIL_MDS_ALL_REPLY_NET
4666 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
4668 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4672 drop_reint_reply() {
4673 # OBD_FAIL_MDS_REINT_NET_REP
4675 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
4677 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4681 drop_update_reply() {
4682 # OBD_FAIL_OUT_UPDATE_NET_REP
4686 do_facet mds${index} lctl set_param fail_loc=0x1701
4687 do_facet client "$@" || RC=$?
4688 do_facet mds${index} lctl set_param fail_loc=0
4693 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4696 local timeout=${2:-0}
4697 # default is (obd_timeout / 4) if unspecified
4698 echo "timeout is $timeout/$2"
4699 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
4700 do_facet client "$1" || RC=$?
4701 do_facet client "sync"
4702 do_facet ost1 lctl set_param fail_loc=0
4706 drop_ldlm_cancel() {
4707 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4709 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4710 do_nodes $list lctl set_param fail_loc=0x304
4712 do_facet client "$@" || RC=$?
4714 do_nodes $list lctl set_param fail_loc=0
4718 drop_bl_callback_once() {
4720 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4721 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4722 do_facet client lctl set_param fail_loc=0x80000305
4723 do_facet client "$@" || rc=$?
4724 do_facet client lctl set_param fail_loc=0
4725 do_facet client lctl set_param fail_val=0
4726 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4730 drop_bl_callback() {
4732 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4733 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4734 do_facet client lctl set_param fail_loc=0x305
4735 do_facet client "$@" || rc=$?
4736 do_facet client lctl set_param fail_loc=0
4737 do_facet client lctl set_param fail_val=0
4738 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4743 #define OBD_FAIL_LDLM_REPLY 0x30c
4745 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4746 do_nodes $list lctl set_param fail_loc=0x30c
4748 do_facet client "$@" || RC=$?
4750 do_nodes $list lctl set_param fail_loc=0
4754 drop_ldlm_reply_once() {
4755 #define OBD_FAIL_LDLM_REPLY 0x30c
4757 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4758 do_nodes $list lctl set_param fail_loc=0x8000030c
4760 do_facet client "$@" || RC=$?
4762 do_nodes $list lctl set_param fail_loc=0
4770 echo "clearing fail_loc on $facet"
4771 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4774 set_nodes_failloc () {
4776 do_nodes $(comma_list $1) lctl set_param fail_val=$fv fail_loc=$2
4779 cancel_lru_locks() {
4780 #$LCTL mark "cancel_lru_locks $1 start"
4781 $LCTL set_param -n ldlm.namespaces.*$1*.lru_size=clear
4782 $LCTL get_param ldlm.namespaces.*$1*.lock_unused_count | grep -v '=0'
4783 #$LCTL mark "cancel_lru_locks $1 stop"
4788 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4789 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4790 echo "$DEFAULT_LRU_SIZE"
4795 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4798 lru_resize_disable()
4800 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4806 [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] && RC=1
4812 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4813 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4814 echo there is still data in page cache $FILE ?
4815 lctl get_param -n $FILE
4823 DEBUGSAVE="$(lctl get_param -n debug)"
4824 DEBUGSAVE_SERVER=$(do_facet $SINGLEMDS "$LCTL get_param -n debug")
4828 [ -n "$DEBUGSAVE" ] &&
4829 do_nodes $CLIENTS "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\""||
4833 [ -n "$DEBUGSAVE_SERVER" ] &&
4834 do_nodes $(comma_list $(all_server_nodes)) \
4835 "$LCTL set_param debug=\\\"${DEBUGSAVE_SERVER}\\\"" ||
4841 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4844 debug_size_restore() {
4845 [ -n "$DEBUG_SIZE_SAVED" ] && \
4846 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4850 start_full_debug_logging() {
4855 local DEBUG_SIZE=150
4857 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4858 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4861 stop_full_debug_logging() {
4866 # prints bash call stack
4867 print_stack_trace() {
4870 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4871 local src=${BASH_SOURCE[$i]}
4872 local lineno=${BASH_LINENO[$i-1]}
4873 local funcname=${FUNCNAME[$i]}
4874 echo " = $src:$lineno:$funcname()"
4879 local TYPE=${TYPE:-"FAIL"}
4882 # do not dump logs if $1=false
4883 if [ "x$1" = "xfalse" ]; then
4888 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4889 (print_stack_trace 2) >&2
4891 # We need to dump the logs on all nodes
4893 gather_logs $(comma_list $(nodes_list))
4897 [ "$TESTSUITELOG" ] &&
4898 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4899 if [ -z "$*" ]; then
4900 echo "error() without useful message, please fix" > $LOGDIR/err
4902 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4903 echo "$@" > $LOGDIR/ignore
4905 echo "$@" > $LOGDIR/err
4909 # cleanup the env for failed tests
4913 ##################################
4915 ##################################
4923 local log=$TESTSUITELOG
4925 [ -f "$log" ] && grep -q FAIL $log && status=1
4939 # use only if we are ignoring failures for this test, bugno required.
4940 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4941 # e.g. error_ignore bz5494 "your message" or
4942 # error_ignore LU-5494 "your message"
4944 local TYPE="IGNORE ($1)"
4949 error_and_remount() {
4951 remount_client $MOUNT
4955 # Throw an error if it's not running in vm - usually for performance
4958 local virt=$(running_in_vm)
4959 if [[ -n "$virt" ]]; then
4960 echo "running in VM '$virt', ignore error"
4961 error_ignore env=$virt "$@"
4968 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4973 log " SKIP: $TESTSUITE $TESTNAME $@"
4975 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4976 skip_logged $TESTNAME "$@"
4979 echo "$@" > $LOGDIR/skip
4982 [[ -n "$TESTSUITELOG" ]] &&
4983 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
4986 build_test_filter() {
4987 EXCEPT="$EXCEPT $(testslist_filter)"
4990 if [[ $O = [0-9]*-[0-9]* ]]; then
4991 for num in $(seq $(echo $O | tr '-' ' ')); do
4999 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
5000 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
5001 [ "$EXCEPT_SLOW" ] && \
5002 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
5003 for E in $EXCEPT; do
5004 eval EXCEPT_${E}=true
5006 for E in $ALWAYS_EXCEPT; do
5007 eval EXCEPT_ALWAYS_${E}=true
5009 for E in $EXCEPT_SLOW; do
5010 eval EXCEPT_SLOW_${E}=true
5012 for G in $GRANT_CHECK_LIST; do
5013 eval GCHECK_ONLY_${G}=true
5018 if [[ $1 = [a-z]* ]]; then
5025 # print a newline if the last test was skipped
5026 export LAST_SKIPPED=
5027 export ALWAYS_SKIPPED=
5029 # Main entry into test-framework. This is called with the name and
5030 # description of a test. The name is used to find the function to run
5031 # the test using "test_$name".
5033 # This supports a variety of methods of specifying specific test to
5034 # run or not run. These need to be documented...
5039 export base=$(basetest $1)
5040 if [ -n "$ONLY" ]; then
5042 if [ ${!testname}x != x ]; then
5043 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
5044 run_one_logged $1 "$2"
5048 if [ ${!testname}x != x ]; then
5049 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
5050 run_one_logged $1 "$2"
5060 if [ ${!testname}x != x ]; then
5061 TESTNAME=test_$1 skip "skipping excluded test $1"
5064 testname=EXCEPT_$base
5065 if [ ${!testname}x != x ]; then
5066 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
5069 testname=EXCEPT_ALWAYS_$1
5070 if [ ${!testname}x != x ]; then
5071 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
5074 testname=EXCEPT_ALWAYS_$base
5075 if [ ${!testname}x != x ]; then
5076 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
5079 testname=EXCEPT_SLOW_$1
5080 if [ ${!testname}x != x ]; then
5081 TESTNAME=test_$1 skip "skipping SLOW test $1"
5084 testname=EXCEPT_SLOW_$base
5085 if [ ${!testname}x != x ]; then
5086 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
5092 run_one_logged $1 "$2"
5099 load_module ../libcfs/libcfs/libcfs
5111 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
5116 strace -o $TMP/$1.strace -ttt $*
5118 log "FINISHED: $*: rc $RC"
5125 banner test complete, duration $duration sec
5126 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
5127 echo duration $duration >>$TESTSUITELOG
5131 # Set TEST_STATUS here. It will be used for logging the result.
5134 if [[ -f $LOGDIR/err ]]; then
5136 elif [[ -f $LOGDIR/skip ]]; then
5139 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
5143 local FFREE=$(do_node $SINGLEMDS \
5144 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
5145 local FTOTAL=$(do_node $SINGLEMDS \
5146 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
5148 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
5152 echo -n "Resetting fail_loc on all nodes..."
5153 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 \
5154 fail_val=0 2>/dev/null" || true
5160 # Log a message (on all nodes) padded with "=" before and after.
5161 # Also appends a timestamp and prepends the testsuite name.
5164 EQUALS="===================================================================================================="
5166 msg="== ${TESTSUITE} $*"
5168 [[ $last != "=" && $last != " " ]] && msg="$msg "
5169 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
5170 # always include at least == after the message
5171 log "$msg== $(date +"%H:%M:%S (%s)")"
5174 check_dmesg_for_errors() {
5176 local errors="VFS: Busy inodes after unmount of\|\
5177 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
5178 group descriptors corrupted"
5180 res=$(do_nodes $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
5181 [ -z "$res" ] && return 0
5182 echo "Kernel error detected: $res"
5187 # Run a single test function and cleanup after it.
5189 # This function should be run in a subshell so the test func can
5190 # exit() without stopping the whole script.
5195 export tfile=f${testnum}.${TESTSUITE}
5196 export tdir=d${testnum}.${TESTSUITE}
5197 export TESTNAME=test_$testnum
5198 local SAVE_UMASK=`umask`
5201 if ! grep -q $DIR /proc/mounts; then
5205 banner "test $testnum: $message"
5206 test_${testnum} || error "test_$testnum failed with $?"
5209 check_grant ${testnum} || error "check_grant $testnum failed with $?"
5211 check_dmesg_for_errors || error "Error in dmesg detected"
5212 if [ "$PARALLEL" != "yes" ]; then
5213 ps auxww | grep -v grep | grep -q multiop &&
5214 error "multiop still running"
5225 # Wrapper around run_one to ensure:
5226 # - test runs in subshell
5227 # - output of test is saved to separate log file for error reporting
5228 # - test result is saved to data file
5231 local BEFORE=$(date +%s)
5233 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
5234 local test_log=$LOGDIR/$name
5235 local zfs_log_name=${TESTSUITE}.test_${1}.zfs_log
5236 local zfs_debug_log=$LOGDIR/$zfs_log_name
5238 rm -rf $LOGDIR/ignore
5240 local SAVE_UMASK=$(umask)
5244 log_sub_test_begin test_${1}
5245 (run_one $1 "$2") 2>&1 | tee -i $test_log
5246 local RC=${PIPESTATUS[0]}
5248 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
5249 echo "test_$1 returned $RC" | tee $LOGDIR/err
5251 duration=$(($(date +%s) - $BEFORE))
5252 pass "$1" "(${duration}s)"
5254 if [[ -f $LOGDIR/err ]]; then
5255 TEST_ERROR=$(cat $LOGDIR/err)
5256 elif [[ -f $LOGDIR/ignore ]]; then
5257 TEST_ERROR=$(cat $LOGDIR/ignore)
5258 elif [[ -f $LOGDIR/skip ]]; then
5259 TEST_ERROR=$(cat $LOGDIR/skip)
5261 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
5263 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
5267 if [ -f $LOGDIR/err ]; then
5268 log_zfs_info "$zfs_debug_log"
5269 $FAIL_ON_ERROR && exit $RC
5278 # Print information of skipped tests to result.yml
5281 log_sub_test_begin $1
5283 log_sub_test_end "SKIP" "0" "0" "$@"
5287 (cd $(dirname $1); echo $PWD/$(basename $1))
5292 export base=$(basetest $1)
5293 [ "$CHECK_GRANT" == "no" ] && return 0
5295 testnamebase=GCHECK_ONLY_${base}
5296 testname=GCHECK_ONLY_$1
5297 [ ${!testnamebase}x == x -a ${!testname}x == x ] && return 0
5299 echo -n "checking grant......"
5301 local clients=$CLIENTS
5302 [ -z "$clients" ] && clients=$(hostname)
5304 # sync all the data and make sure no pending data on server
5305 do_nodes $clients sync
5308 client_grant=$(do_nodes $clients \
5309 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
5310 awk '{ total += $1 } END { printf("%0.0f", total) }')
5313 # which is tot_granted less grant_precreate
5314 server_grant=$(do_nodes $(comma_list $(osts_nodes)) \
5316 "obdfilter.${FSNAME}-OST*.{tot_granted,tot_pending,grant_precreate}" |
5317 sed 's/=/ /'| awk '/tot_granted/{ total += $2 };
5318 /tot_pending/{ total -= $2 };
5319 /grant_precreate/{ total -= $2 };
5320 END { printf("%0.0f", total) }')
5322 # check whether client grant == server grant
5323 if [[ $client_grant -ne $server_grant ]]; then
5324 do_nodes $(comma_list $(osts_nodes)) \
5325 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*" \
5326 "obdfilter.${FSNAME}-OST*.grant_*"
5327 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
5328 error "failed: client:${client_grant} server: ${server_grant}."
5330 echo "pass: client:${client_grant} server: ${server_grant}"
5334 ########################
5340 ost=`echo $1 | awk -F_ '{print $3}'`
5341 if [ -z $ost ]; then
5342 ost=`echo $1 | sed 's/-osc.*//'`
5347 ostuuid_from_index()
5349 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5352 ostname_from_index() {
5353 local uuid=$(ostuuid_from_index $1)
5357 index_from_ostuuid()
5359 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
5362 mdtuuid_from_index()
5364 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5368 # Return unique identifier for given hostname
5371 echo $host_name | md5sum | cut -d' ' -f1
5375 # Returns list of ip addresses for each interface
5377 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
5382 # Cache address list to avoid mutiple execution of local_addr_list
5383 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
5385 for i in $LOCAL_ADDR_LIST ; do
5386 [[ "$i" == "$addr" ]] && return 0
5393 local is_local="IS_LOCAL_$(host_id $host_name)"
5394 if [ -z "${!is_local-}" ] ; then
5396 local host_ip=$($LUSTRE/tests/resolveip $host_name)
5397 is_local_addr "$host_ip" && eval $is_local=1
5399 [[ "${!is_local}" == "1" ]]
5404 local_node $node && return 1
5411 for node in $(mdts_nodes); do
5412 remote_node $node && return 0
5419 [ -n "$CLIENTONLY" ] && return 0 || true
5420 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
5425 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" &&
5426 MSKIPPED=1 && return 1
5433 for node in $(osts_nodes) ; do
5434 remote_node $node && return 0
5441 [ -n "$CLIENTONLY" ] && return 0 || true
5442 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5447 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
5448 OSKIPPED=1 && return 1
5454 [ -n "$CLIENTONLY" ] && return 0 || true
5456 MGS=$(facet_host mgs)
5457 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5462 remote_mds_nodsh || remote_ost_nodsh || \
5463 $(single_local_node $(comma_list $(nodes_list)))
5467 remote_ost && remote_mds
5470 # Get the active nodes for facets.
5478 for facet in ${facets//,/ }; do
5479 nodes="$nodes $(facet_active_host $facet)"
5482 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5486 # Get all of the active MDS nodes.
5488 echo -n $(facets_nodes $(get_facets MDS))
5491 # Get all of the active OSS nodes.
5493 echo -n $(facets_nodes $(get_facets OST))
5496 # Get all of the active AGT (HSM agent) nodes.
5498 echo -n $(facets_nodes $(get_facets AGT))
5501 # Get all of the client nodes and active server nodes.
5503 local nodes=$HOSTNAME
5507 # CLIENTS (if specified) contains the local client
5508 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5510 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5511 nodes="$nodes $(facets_nodes $(get_facets))"
5514 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5518 # Get all of the remote client nodes and remote active server nodes.
5519 remote_nodes_list () {
5520 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5523 # Get all of the MDS nodes, including active and passive nodes.
5531 for i in $(seq $MDSCOUNT); do
5533 failover_host=mds${i}failover_HOST
5534 nodes="$nodes ${!host} ${!failover_host}"
5537 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5541 # Get all of the OSS nodes, including active and passive nodes.
5549 for i in $(seq $OSTCOUNT); do
5551 failover_host=ost${i}failover_HOST
5552 nodes="$nodes ${!host} ${!failover_host}"
5555 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5559 # Get all of the server nodes, including active and passive nodes.
5560 all_server_nodes () {
5565 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5567 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5571 # Get all of the client and server nodes, including active and passive nodes.
5573 local nodes=$HOSTNAME
5577 # CLIENTS (if specified) contains the local client
5578 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5580 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5581 nodes="$nodes $(all_server_nodes)"
5584 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5588 init_clients_lists () {
5589 # Sanity check: exclude the local client from RCLIENTS
5590 local clients=$(hostlist_expand "$RCLIENTS")
5591 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5593 # Sanity check: exclude the dup entries
5594 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5596 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5598 # Sanity check: exclude the dup entries from CLIENTS
5599 # for those configs which has SINGLCLIENT set to local client
5600 clients=$(for i in $clients; do echo $i; done | sort -u)
5602 CLIENTS=$(comma_list $clients)
5603 local -a remoteclients=($RCLIENTS)
5604 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5605 varname=CLIENT$((i + 2))
5606 eval $varname=${remoteclients[i]}
5609 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5612 get_random_entry () {
5615 rnodes=${rnodes//,/ }
5617 local -a nodes=($rnodes)
5618 local num=${#nodes[@]}
5619 local i=$((RANDOM * num * 2 / 65536))
5625 [ -n "$CLIENTONLY" ] || [ "x$CLIENTMODSONLY" = "xyes" ]
5629 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5630 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5635 echo $nodes | wc -w || true
5639 local nodes=$(osts_nodes)
5640 local osscount=$(get_node_count "$nodes")
5641 [ ! "$OSTCOUNT" = "$osscount" ]
5645 local nodes=$(mdts_nodes)
5646 local mdtcount=$(get_node_count "$nodes")
5647 [ ! "$MDSCOUNT" = "$mdtcount" ]
5650 generate_machine_file() {
5651 local nodes=${1//,/ }
5652 local machinefile=$2
5654 for node in $nodes; do
5655 echo $node >>$machinefile || \
5656 { echo "can not generate machinefile $machinefile" && return 1; }
5661 local file=$1/stripe
5664 $LFS getstripe -v $file || error "getstripe $file failed"
5668 setstripe_nfsserver () {
5671 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5672 { print $1 }' /proc/mounts | cut -f 1 -d : | head -n1)
5674 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5676 do_nodev $nfsserver lfs setstripe "$@"
5679 # Check and add a test group.
5685 local gid=$(getent group $group_name | cut -d: -f3)
5686 if [[ -n "$gid" ]]; then
5687 [[ "$gid" -eq "$group_id" ]] || {
5688 error_noexit "inconsistent group ID:" \
5689 "new: $group_id, old: $gid"
5693 groupadd -g $group_id $group_name
5700 # Check and add a test user.
5713 local uid=$(getent passwd $user_name | cut -d: -f3)
5714 if [[ -n "$uid" ]]; then
5715 if [[ "$uid" -eq "$user_id" ]]; then
5716 local dir=$(getent passwd $user_name | cut -d: -f6)
5717 if [[ "$dir" != "$home" ]]; then
5719 usermod -d $home $user_name
5723 error_noexit "inconsistent user ID:" \
5724 "new: $user_id, old: $uid"
5729 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5736 check_runas_id_ret() {
5738 local myRUNAS_UID=$1
5739 local myRUNAS_GID=$2
5742 if [ -z "$myRUNAS" ]; then
5743 error_exit "myRUNAS command must be specified for check_runas_id"
5746 $myRUNAS krb5_login.sh || \
5747 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5749 mkdir $DIR/d0_runas_test
5751 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5752 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5753 rm -rf $DIR/d0_runas_test
5758 local myRUNAS_UID=$1
5759 local myRUNAS_GID=$2
5762 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5763 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5764 Please set RUNAS_ID to some UID which exists on MDS and client or
5765 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5768 # obtain the UID/GID for MPI_USER
5772 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5773 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5775 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5776 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5779 # obtain and cache Kerberos ticket-granting ticket
5780 refresh_krb5_tgt() {
5781 local myRUNAS_UID=$1
5782 local myRUNAS_GID=$2
5785 if [ -z "$myRUNAS" ]; then
5786 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5789 CLIENTS=${CLIENTS:-$HOSTNAME}
5790 do_nodes $CLIENTS "set -x
5791 if ! $myRUNAS krb5_login.sh; then
5792 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5797 # Run multiop in the background, but wait for it to print
5798 # "PAUSING" to its stdout before returning from this function.
5799 multiop_bg_pause() {
5800 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5804 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5807 echo "$MULTIOP_PROG $FILE v$ARGS"
5808 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5810 echo "TMPPIPE=${TMPPIPE}"
5811 read -t 60 multiop_output < $TMPPIPE
5812 if [ $? -ne 0 ]; then
5817 if [ "$multiop_output" != "PAUSING" ]; then
5818 echo "Incorrect multiop output: $multiop_output"
5833 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5839 inodes_available () {
5840 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
5841 sort -un | head -n1) || return 1
5845 mdsrate_inodes_available () {
5846 local min_inodes=$(inodes_available)
5847 echo $((min_inodes * 99 / 100))
5850 # reset stat counters
5852 local paramfile="$1"
5853 lctl set_param -n $paramfile=0
5858 local paramfile="$1"
5860 lctl get_param -n $paramfile |
5861 awk '/^'$stat'/ { sum += $2 } END { printf("%0.0f", sum) }'
5865 awk '{sum += $1} END { printf("%0.0f", sum) }'
5868 calc_osc_kbytes () {
5869 df $MOUNT > /dev/null
5870 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5873 # save_lustre_params(comma separated facet list, parameter_mask)
5874 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5875 save_lustre_params() {
5881 for facet in ${facets//,/ }; do
5882 node=$(facet_active_host $facet)
5883 [[ *\ $node\ * = " $nodes " ]] && continue
5884 nodes="$nodes $node"
5886 do_node $node "$LCTL get_param $2 |
5887 while read s; do echo $facet \\\$s; done"
5891 # restore lustre parameters from input stream, produces by save_lustre_params
5892 restore_lustre_params() {
5897 while IFS=" =" read facet name val; do
5898 do_facet $facet "$LCTL set_param -n $name $val"
5902 check_node_health() {
5903 local nodes=${1:-$(comma_list $(nodes_list))}
5905 for node in ${nodes//,/ }; do
5906 check_network "$node" 5
5907 if [ $? -eq 0 ]; then
5908 do_node $node "rc=0;
5909 val=\\\$($LCTL get_param -n catastrophe 2>&1);
5910 if [[ \\\$? -eq 0 && \\\$val -ne 0 ]]; then
5911 echo \\\$(hostname -s): \\\$val;
5914 exit \\\$rc" || error "$node:LBUG/LASSERT detected"
5919 mdsrate_cleanup () {
5921 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
5922 --nfiles $3 --dir $4 --filefmt $5 $6
5927 delayed_recovery_enabled () {
5928 local var=${SINGLEMDS}_svc
5929 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5932 ########################
5934 convert_facet2label() {
5937 if [ x$facet = xost ]; then
5941 local varsvc=${facet}_svc
5943 if [ -n ${!varsvc} ]; then
5946 error "No lablel for $facet!"
5950 get_clientosc_proc_path() {
5954 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5955 # used by MDT would not be changed.
5956 # mdt lov: fsname-mdtlov
5957 # mdt osc: fsname-OSTXXXX-osc
5958 mds_on_old_device() {
5959 local mds=${1:-"$SINGLEMDS"}
5961 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5962 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5963 > /dev/null 2>&1" && return 0
5968 get_mdtosc_proc_path() {
5970 local ost_label=${2:-"*OST*"}
5972 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5973 local mdt_label=$(convert_facet2label $mds_facet)
5974 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5976 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5977 mds_on_old_device $mds_facet; then
5978 echo "${ost_label}-osc"
5979 elif [[ $ost_label = *OST* ]]; then
5980 echo "${ost_label}-osc-${mdt_index}"
5982 echo "${ost_label}-osp-${mdt_index}"
5986 get_osc_import_name() {
5989 local label=$(convert_facet2label $ost)
5991 if [ "${facet:0:3}" = "mds" ]; then
5992 get_mdtosc_proc_path $facet $label
5996 get_clientosc_proc_path $label
6000 _wait_import_state () {
6003 local maxtime=${3:-$(max_recovery_time)}
6004 local error_on_failure=${4:-1}
6008 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
6009 while [ "${CONN_STATE}" != "${expected}" ]; do
6010 if [ "${expected}" == "DISCONN" ]; then
6011 # for disconn we can check after proc entry is removed
6012 [ "x${CONN_STATE}" == "x" ] && return 0
6013 # with AT enabled, we can have connect request timeout near of
6014 # reconnect timeout and test can't see real disconnect
6015 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
6017 if [ $i -ge $maxtime ]; then
6018 [ $error_on_failure -ne 0 ] && \
6019 error "can't put import for $CONN_PROC into ${expected}" \
6020 "state after $i sec, have ${CONN_STATE}"
6024 # Add uniq for multi-mount case
6025 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
6029 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
6033 wait_import_state() {
6036 local maxtime=${3:-$(max_recovery_time)}
6037 local error_on_failure=${4:-1}
6040 for param in ${params//,/ }; do
6041 _wait_import_state $state $param $maxtime $error_on_failure || return
6045 wait_import_state_mount() {
6046 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
6050 wait_import_state $*
6053 # One client request could be timed out because server was not ready
6054 # when request was sent by client.
6055 # The request timeout calculation details :
6057 # /* We give the server rq_timeout secs to process the req, and
6058 # add the network latency for our local timeout. */
6059 # request->rq_deadline = request->rq_sent + request->rq_timeout +
6060 # ptlrpc_at_get_net_latency(request) ;
6062 # ptlrpc_connect_import ()
6063 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
6066 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
6067 # ptlrpc_at_get_net_latency(request) ->
6068 # at_get (max (iat_net_latency=0, at_min)) = at_min
6071 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
6072 # INITIAL_CONNECT_TIMEOUT + at_min
6074 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
6075 # because we can not get this value in runtime,
6076 # the value depends on configure options, and it is not stored in /proc.
6078 # #define CONNECTION_SWITCH_MIN 5U
6079 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
6081 request_timeout () {
6084 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
6085 local init_connect_timeout=$TIMEOUT
6086 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
6088 local at_min=$(at_get $facet at_min)
6090 echo $(( init_connect_timeout + at_min ))
6093 _wait_osc_import_state() {
6097 local target=$(get_osc_import_name $facet $ost_facet)
6098 local param="osc.${target}.ost_server_uuid"
6102 # 1. wait the deadline of client 1st request (it could be skipped)
6103 # 2. wait the deadline of client 2nd request
6104 local maxtime=$(( 2 * $(request_timeout $facet)))
6106 if [[ $facet == client* ]]; then
6107 # During setup time, the osc might not be setup, it need wait
6108 # until list_param can return valid value.
6109 params=$($LCTL list_param $param 2>/dev/null || true)
6110 while [ -z "$params" ]; do
6111 if [ $i -ge $maxtime ]; then
6112 echo "can't get $param in $maxtime secs"
6117 params=$($LCTL list_param $param 2>/dev/null || true)
6121 if [[ $ost_facet = mds* ]]; then
6122 # no OSP connection to itself
6123 if [[ $facet = $ost_facet ]]; then
6126 param="osp.${target}.mdt_server_uuid"
6130 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6131 wait_import_state $expected "$params" $maxtime; then
6132 error "$facet: import is not in $expected state after $maxtime"
6139 wait_osc_import_state() {
6145 if [[ $facet = mds ]]; then
6146 for num in $(seq $MDSCOUNT); do
6147 _wait_osc_import_state mds$num "$ost_facet" "$expected"
6150 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
6154 _wait_mgc_import_state() {
6157 local error_on_failure=${3:-1}
6158 local param="mgc.*.mgs_server_uuid"
6162 # 1. wait the deadline of client 1st request (it could be skipped)
6163 # 2. wait the deadline of client 2nd request
6164 local maxtime=$(( 2 * $(request_timeout $facet)))
6166 if [[ $facet == client* ]]; then
6167 # During setup time, the osc might not be setup, it need wait
6168 # until list_param can return valid value. And also if there
6169 # are mulitple osc entries we should list all of them before
6171 params=$($LCTL list_param $param 2>/dev/null || true)
6172 while [ -z "$params" ]; do
6173 if [ $i -ge $maxtime ]; then
6174 echo "can't get $param in $maxtime secs"
6179 params=$($LCTL list_param $param 2>/dev/null || true)
6182 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6183 wait_import_state $expected "$params" $maxtime \
6184 $error_on_failure; then
6185 if [ $error_on_failure -ne 0 ]; then
6186 error "import is not in ${expected} state"
6194 wait_mgc_import_state() {
6197 local error_on_failure=${3:-1}
6200 if [[ $facet = mds ]]; then
6201 for num in $(seq $MDSCOUNT); do
6202 _wait_mgc_import_state mds$num "$expected" \
6203 $error_on_failure || return
6206 _wait_mgc_import_state "$facet" "$expected"
6207 $error_on_failure || return
6211 wait_dne_interconnect() {
6214 if [ $MDSCOUNT -gt 1 ]; then
6215 for num in $(seq $MDSCOUNT); do
6216 wait_osc_import_state mds mds$num FULL
6221 get_clientmdc_proc_path() {
6225 get_clientmgc_proc_path() {
6233 [ -z "$list" ] && return 0
6235 # Add paths to lustre tests for 32 and 64 bit systems.
6236 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
6237 local TESTPATH="$RLUSTRE/tests:"
6238 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
6239 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
6242 wait_clients_import_state () {
6249 if [ "$FAILURE_MODE" = HARD ]; then
6250 facets=$(facets_on_host $(facet_active_host $facet))
6253 for facet in ${facets//,/ }; do
6254 local label=$(convert_facet2label $facet)
6257 ost* ) proc_path="osc.$(get_clientosc_proc_path \
6258 $label).ost_server_uuid" ;;
6259 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
6260 $label).mds_server_uuid" ;;
6261 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
6262 $label).mgs_server_uuid" ;;
6263 *) error "unknown facet!" ;;
6266 local params=$(expand_list $params $proc_path)
6269 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params;
6271 error "import is not in ${expected} state"
6283 # wait until all MDTs are in the expected state
6284 for ((num = 1; num <= $MDSCOUNT; num++)); do
6285 local mdtosp=$(get_mdtosc_proc_path mds${num} ${tgt_name})
6288 if [ $facet = "mds" ]; then
6289 mproc="osp.$mdtosp.active"
6290 [ $num -eq $((tgt_idx + 1)) ] && continue
6292 mproc="osc.$mdtosp.active"
6298 local result=$(do_facet mds${num} "$LCTL get_param -n $mproc")
6302 [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $mproc"
6303 if [ $result -eq $expected ]; then
6304 echo -n "target updated after"
6305 echo "$wait sec (got $result)"
6309 if [ $wait -eq $max ]; then
6310 error "$tgt_name: wanted $expected got $result"
6312 echo "Waiting $((max - wait)) secs for $tgt_name"
6322 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
6323 $LCTL get_param obdfilter.*.kbytesavail))
6324 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
6325 $LCTL get_param -n obdfilter.*.tot_granted))
6326 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
6327 $LCTL get_param -n obdfilter.*.kbytestotal))
6328 for ((i=0; i<${#AVAILA[@]}; i++)); do
6329 local -a AVAIL1=(${AVAILA[$i]//=/ })
6330 local -a TOTAL=(${TOTALA[$i]//=/ })
6331 GRANT=$((${GRANTA[$i]}/1024))
6332 # allow 1% of total space in bavail because of delayed
6333 # allocation with ZFS which might release some free space after
6334 # txg commit. For small devices, we set a mininum of 8MB
6335 local LIMIT=$((${TOTAL} / 100 + 8000))
6336 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
6337 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
6338 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
6339 echo " FULL" || echo
6345 echo -e "$(do_facet $SINGLEMDS $LCTL pool_list $1 | sed '1d')"
6348 check_pool_not_exist() {
6349 local fsname=${1%%.*}
6350 local poolname=${1##$fsname.}
6351 [[ $# -ne 1 ]] && return 0
6352 [[ x$poolname = x ]] && return 0
6353 list_pool $fsname | grep -w $1 && return 1
6358 local fsname=${1%%.*}
6359 local poolname=${1##$fsname.}
6361 trap "destroy_test_pools $fsname" EXIT
6362 do_facet mgs lctl pool_new $1
6364 # get param should return err unless pool is created
6365 [[ $RC -ne 0 ]] && return $RC
6367 for mds_id in $(seq $MDSCOUNT); do
6368 local mdt_id=$((mds_id-1))
6369 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
6370 wait_update_facet mds$mds_id \
6371 "lctl get_param -n lod.$lodname.pools.$poolname \
6372 2>/dev/null || echo foo" "" ||
6373 error "mds$mds_id: pool_new failed $1"
6375 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6376 2>/dev/null || echo foo" "" || error "pool_new failed $1"
6382 add_pool_to_list () {
6383 local fsname=${1%%.*}
6384 local poolname=${1##$fsname.}
6386 local listvar=${fsname}_CREATED_POOLS
6387 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
6391 remove_pool_from_list () {
6392 local fsname=${1%%.*}
6393 local poolname=${1##$fsname.}
6395 local listvar=${fsname}_CREATED_POOLS
6396 local temp=${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
6400 destroy_pool_int() {
6402 local OSTS=$(list_pool $1)
6403 for ost in $OSTS; do
6404 do_facet mgs lctl pool_remove $1 $ost
6406 do_facet mgs lctl pool_destroy $1
6409 # <fsname>.<poolname> or <poolname>
6411 local fsname=${1%%.*}
6412 local poolname=${1##$fsname.}
6414 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
6418 check_pool_not_exist $fsname.$poolname
6419 [[ $? -eq 0 ]] && return 0
6421 destroy_pool_int $fsname.$poolname
6423 [[ $RC -ne 0 ]] && return $RC
6424 for mds_id in $(seq $MDSCOUNT); do
6425 local mdt_id=$((mds_id-1))
6426 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
6427 wait_update_facet mds$mds_id \
6428 "lctl get_param -n lod.$lodname.pools.$poolname \
6429 2>/dev/null || echo foo" "foo" ||
6430 error "mds$mds_id: destroy pool failed $1"
6432 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6433 2>/dev/null || echo foo" "foo" || error "destroy pool failed $1"
6435 remove_pool_from_list $fsname.$poolname
6441 local fsname=${1:-$FSNAME}
6443 local listvar=${fsname}_CREATED_POOLS
6445 [ x${!listvar} = x ] && return 0
6447 echo "Destroy the created pools: ${!listvar}"
6448 for poolname in ${!listvar//,/ }; do
6449 destroy_pool $fsname.$poolname
6453 destroy_test_pools () {
6455 local fsname=${1:-$FSNAME}
6456 destroy_pools $fsname || true
6462 local ts=$(date +%s)
6465 if [[ ! -f "$YAML_LOG" ]]; then
6466 # init_logging is not performed before gather_logs,
6467 # so the $LOGDIR needs to be checked here
6468 check_shared_dir $LOGDIR && touch $LOGDIR/shared
6471 [ -f $LOGDIR/shared ] && docp=false
6473 # dump lustre logs, dmesg
6475 prefix="$TESTLOG_PREFIX.$TESTNAME"
6477 echo "Dumping lctl log to ${prefix}.*.${suffix}"
6479 if [ -n "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
6480 echo "Dumping logs only on local client."
6481 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
6482 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
6487 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
6488 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
6489 if [ ! -f $LOGDIR/shared ]; then
6490 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
6503 for i in $(seq 0 $num_mntpts); do
6504 cmd="ls -laf ${mntpt_root}$i/$dir"
6510 for pid in $pids; do
6517 # check_and_start_recovery_timer()
6518 # service_time = at_est2timeout(service_time);
6519 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
6520 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
6522 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
6523 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
6524 #define CONNECTION_SWITCH_MIN 5
6525 #define CONNECTION_SWITCH_INC 5
6526 max_recovery_time() {
6527 local init_connect_timeout=$((TIMEOUT / 20))
6528 ((init_connect_timeout >= 5)) || init_connect_timeout=5
6530 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
6531 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
6533 echo -n $service_time
6536 recovery_time_min() {
6537 local connection_switch_min=5
6538 local connection_switch_inc=5
6539 local connection_switch_max
6540 local reconnect_delay_max
6541 local initial_connect_timeout
6545 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
6546 (($connection_switch_min > $TIMEOUT)) &&
6547 max=$connection_switch_min || max=$TIMEOUT
6548 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
6550 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
6551 timeout_20=$((TIMEOUT/20))
6552 (($connection_switch_min > $timeout_20)) &&
6553 initial_connect_timeout=$connection_switch_min ||
6554 initial_connect_timeout=$timeout_20
6556 reconnect_delay_max=$((connection_switch_max + connection_switch_inc + \
6557 initial_connect_timeout))
6558 echo $((2 * reconnect_delay_max))
6561 get_clients_mount_count () {
6562 local clients=${CLIENTS:-`hostname`}
6564 # we need to take into account the clients mounts and
6565 # exclude mds/ost mounts if any;
6566 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
6570 PROC_CLI="srpc_info"
6578 if [ $M -lt $N ]; then
6582 while [ $N -lt $M ]; do
6592 calc_connection_cnt() {
6595 # MDT->MDT = 2 * C(M, 2)
6599 comb_m2=$(combination $MDSCOUNT 2)
6601 local num_clients=$(get_clients_mount_count)
6603 local cnt_mdt2mdt=$((comb_m2 * 2))
6604 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
6605 local cnt_cli2ost=$((num_clients * OSTCOUNT))
6606 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
6607 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
6608 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
6609 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
6623 local cmd="$tgt.srpc.flavor"
6625 if [ $net == "any" ]; then
6630 if [ $dir != "any" ]; then
6635 log "Setting sptlrpc rule: $cmd"
6636 do_facet mgs "$LCTL conf_param $cmd"
6645 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
6646 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
6648 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
6650 if [ "x$bulkspec" != "x" ]; then
6651 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
6653 if [ "x$algs" != "x" ]; then
6654 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
6656 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
6657 if [ $bulk == "bulkn" ]; then
6658 bulk_count=`echo "$output" | grep "bulk flavor" \
6659 | grep "null/null" | wc -l`
6660 elif [ $bulk == "bulki" ]; then
6661 bulk_count=`echo "$output" | grep "bulk flavor" \
6662 | grep "/null" | grep -v "null/" | wc -l`
6664 bulk_count=`echo "$output" | grep "bulk flavor" \
6665 | grep -v "/null" | grep -v "null/" | wc -l`
6669 [ $bulk_count -lt $count ] && count=$bulk_count
6680 local clients=${CLIENTS:-`hostname`}
6682 for c in ${clients//,/ }; do
6683 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
6684 tmpcnt=`count_flvr "$output" $flavor`
6685 cnt=$((cnt + tmpcnt))
6695 local clients=${CLIENTS:-`hostname`}
6697 for c in ${clients//,/ }; do
6698 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
6699 tmpcnt=`count_flvr "$output" $flavor`
6700 cnt=$((cnt + tmpcnt))
6710 if [ $MDSCOUNT -le 1 ]; then
6715 for num in `seq $MDSCOUNT`; do
6716 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
6717 tmpcnt=`count_flvr "$output" $flavor`
6718 cnt=$((cnt + tmpcnt))
6729 for num in `seq $MDSCOUNT`; do
6730 mdtosc=$(get_mdtosc_proc_path mds$num)
6731 mdtosc=${mdtosc/-MDT*/-MDT\*}
6732 output=$(do_facet mds$num lctl get_param -n \
6733 osc.$mdtosc.$PROC_CLI 2>/dev/null)
6734 tmpcnt=`count_flvr "$output" $flavor`
6735 cnt=$((cnt + tmpcnt))
6744 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
6745 count_flvr "$output" $flavor
6750 local dir=$1 # from to
6751 local flavor=$2 # flavor expected
6754 if [ $dir == "cli2mdt" ]; then
6755 res=`flvr_cnt_cli2mdt $flavor`
6756 elif [ $dir == "cli2ost" ]; then
6757 res=`flvr_cnt_cli2ost $flavor`
6758 elif [ $dir == "mdt2mdt" ]; then
6759 res=`flvr_cnt_mdt2mdt $flavor`
6760 elif [ $dir == "mdt2ost" ]; then
6761 res=`flvr_cnt_mdt2ost $flavor`
6762 elif [ $dir == "all2ost" ]; then
6763 res1=`flvr_cnt_mdt2ost $flavor`
6764 res2=`flvr_cnt_cli2ost $flavor`
6765 res=$((res1 + res2))
6766 elif [ $dir == "all2mdt" ]; then
6767 res1=`flvr_cnt_mdt2mdt $flavor`
6768 res2=`flvr_cnt_cli2mdt $flavor`
6769 res=$((res1 + res2))
6770 elif [ $dir == "all2all" ]; then
6771 res1=`flvr_cnt_mdt2ost $flavor`
6772 res2=`flvr_cnt_cli2ost $flavor`
6773 res3=`flvr_cnt_mdt2mdt $flavor`
6774 res4=`flvr_cnt_cli2mdt $flavor`
6775 res=$((res1 + res2 + res3 + res4))
6783 local dir=$1 # from to
6784 local flavor=$2 # flavor expected
6785 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6789 for ((i=0;i<20;i++)); do
6790 echo -n "checking $dir..."
6791 res=$(do_check_flavor $dir $flavor)
6792 echo "found $res/$expect $flavor connections"
6793 [ $res -ge $expect ] && return 0
6797 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6801 restore_to_default_flavor()
6803 local proc="mgs.MGS.live.$FSNAME"
6805 echo "restoring to default flavor..."
6807 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6809 # remove all existing rules if any
6810 if [ $nrule -ne 0 ]; then
6811 echo "$nrule existing rules"
6812 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6813 echo "remove rule: $rule"
6814 spec=`echo $rule | awk -F = '{print $1}'`
6815 do_facet mgs "$LCTL conf_param -d $spec"
6819 # verify no rules left
6820 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6821 [ $nrule -ne 0 ] && error "still $nrule rules left"
6823 # wait for default flavor to be applied
6824 # currently default flavor for all connections are 'null'
6825 wait_flavor all2all null
6826 echo "now at default flavor settings"
6831 local flavor=${1:-null}
6833 echo "setting all flavor to $flavor"
6835 # FIXME need parameter to this fn
6836 # and remove global vars
6837 local cnt_all2all=$(calc_connection_cnt all2all)
6839 local res=$(do_check_flavor all2all $flavor)
6840 if [ $res -eq $cnt_all2all ]; then
6841 echo "already have total $res $flavor connections"
6845 echo "found $res $flavor out of total $cnt_all2all connections"
6846 restore_to_default_flavor
6848 [[ $flavor = null ]] && return 0
6850 set_rule $FSNAME any any $flavor
6851 wait_flavor all2all $flavor
6857 # Checking for shared logdir
6858 if [ ! -d $dir ]; then
6859 # Not found. Create local logdir
6862 touch $dir/check_file.$(hostname -s)
6867 check_write_access() {
6869 local list=${2:-$(comma_list $(nodes_list))}
6873 for node in ${list//,/ }; do
6874 file=$dir/check_file.$(short_nodename $node)
6875 if [[ ! -f "$file" ]]; then
6876 # Logdir not accessible/writable from this node.
6879 rm -f $file || return 1
6885 [[ -n $YAML_LOG ]] && return
6886 local save_umask=$(umask)
6889 export YAML_LOG=${LOGDIR}/results.yml
6893 # If the yaml log already exists then we will just append to it
6894 if [ ! -f $YAML_LOG ]; then
6895 if check_shared_dir $LOGDIR; then
6896 touch $LOGDIR/shared
6897 echo "Logging to shared log directory: $LOGDIR"
6899 echo "Logging to local directory: $LOGDIR"
6902 yml_nodes_file $LOGDIR >> $YAML_LOG
6903 yml_results_file >> $YAML_LOG
6908 # If modules are not yet loaded then older "lctl lustre_build_version"
6909 # will fail. Use lctl build version instead.
6910 log "Client: $($LCTL lustre_build_version)"
6911 log "MDS: $(do_facet $SINGLEMDS $LCTL lustre_build_version 2>/dev/null||
6912 do_facet $SINGLEMDS $LCTL --version)"
6913 log "OSS: $(do_facet ost1 $LCTL lustre_build_version 2> /dev/null ||
6914 do_facet ost1 $LCTL --version)"
6918 yml_log_test $1 >> $YAML_LOG
6922 yml_log_test_status $@ >> $YAML_LOG
6925 log_sub_test_begin() {
6926 yml_log_sub_test_begin "$@" >> $YAML_LOG
6929 log_sub_test_end() {
6930 yml_log_sub_test_end "$@" >> $YAML_LOG
6936 local llverdev_opts=$2
6937 local devname=$(basename $1)
6938 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6939 # loop devices aren't in /proc/partitions
6940 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6942 size=$(($size / 1024 / 1024)) # Gb
6944 local partial_arg=""
6945 # Run in partial (fast) mode if the size
6946 # of a partition > 1 GB
6947 [ $size -gt 1 ] && partial_arg="-p"
6949 llverdev --force $partial_arg $llverdev_opts $dev
6955 local llverfs_opts=$2
6956 local use_partial_arg=$3
6957 local partial_arg=""
6958 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6960 # Run in partial (fast) mode if the size
6961 # of a partition > 1 GB
6962 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6964 llverfs $partial_arg $llverfs_opts $dir
6967 #Remove objects from OST
6968 remove_ost_objects() {
6974 local mntpt=$(facet_mntpt $facet)
6975 local opts=$OST_MOUNT_OPTS
6979 echo "removing objects from $ostdev on $facet: $objids"
6980 if ! test -b $ostdev; then
6981 opts=$(csa_add "$opts" -o loop)
6983 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
6986 for i in $objids; do
6987 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
6989 umount -f $mntpt || return $?
6993 #Remove files from MDT
6994 remove_mdt_files() {
6999 local mntpt=$(facet_mntpt $facet)
7000 local opts=$MDS_MOUNT_OPTS
7002 echo "removing files from $mdtdev on $facet: $files"
7003 if [ $(facet_fstype $facet) == ldiskfs ] &&
7004 ! do_facet $facet test -b $mdtdev; then
7005 opts=$(csa_add "$opts" -o loop)
7007 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
7011 rm $mntpt/ROOT/$f || { rc=$?; break; }
7013 umount -f $mntpt || return $?
7017 duplicate_mdt_files() {
7022 local mntpt=$(facet_mntpt $facet)
7023 local opts=$MDS_MOUNT_OPTS
7025 echo "duplicating files on $mdtdev on $facet: $files"
7026 mkdir -p $mntpt || return $?
7027 if [ $(facet_fstype $facet) == ldiskfs ] &&
7028 ! do_facet $facet test -b $mdtdev; then
7029 opts=$(csa_add "$opts" -o loop)
7031 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
7042 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
7043 pushd $mntpt/ROOT > /dev/null || return $?
7046 touch $f.bad || return $?
7047 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
7049 [ $rc -eq 0 ] || return $rc
7050 setfattr --restore $tmp || return $?
7056 local devs=${1//,/ }
7059 local rslt=$TMP/sgpdd_survey
7061 # sgpdd-survey cleanups ${rslt}.* files
7063 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
7069 # returns the canonical name for an ldiskfs device
7074 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
7075 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
7076 echo dm-\\\${foo##*:};
7078 echo \\\$(basename \\\$dv);
7082 is_sanity_benchmark() {
7083 local benchmarks="dbench bonnie iozone fsx"
7085 for b in $benchmarks; do
7086 if [ "$b" == "$suite" ]; then
7094 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
7098 # Get the available size (KB) of a given obd target.
7105 [[ $facet != client ]] || return 0
7107 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
7112 # Get the page size (bytes) on a given facet node.
7116 local size=$(getconf PAGE_SIZE 2>/dev/null)
7118 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet getconf PAGE_SIZE)
7119 echo -n ${size:-4096}
7123 # Get the block count of the filesystem.
7130 [ -z "$CLIENTONLY" ] && count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
7131 awk '/^Block count:/ {print $3}')
7135 # Get the block size of the filesystem.
7141 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
7142 awk '/^Block size:/ {print $3}')
7146 # Check whether the "large_xattr" feature is enabled or not.
7147 large_xattr_enabled() {
7148 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
7150 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
7152 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
7153 grep -E -q '(ea_inode|large_xattr)'"
7154 return ${PIPESTATUS[0]}
7157 # Get the maximum xattr size supported by the filesystem.
7161 if large_xattr_enabled; then
7162 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
7165 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
7166 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
7168 # maximum xattr size = size of block - size of header -
7169 # size of 1 entry - 4 null bytes
7170 size=$((block_size - 32 - 32 - 4))
7176 # Dump the value of the named xattr from a file.
7181 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
7184 # Generate a string with size of $size bytes.
7186 local size=${1:-1024} # in bytes
7188 echo "$(head -c $size < /dev/zero | tr '\0' y)"
7191 reformat_external_journal() {
7196 if [ -n "${!var}" ]; then
7197 local rcmd="do_facet $facet"
7199 echo "reformat external journal on $facet:${!var}"
7200 ${rcmd} mke2fs -O journal_dev ${!var} || return 1
7204 # MDT file-level backup/restore
7205 mds_backup_restore() {
7208 local devname=$(mdsdevname $(facet_number $facet))
7209 local mntpt=$(facet_mntpt brpt)
7210 local rcmd="do_facet $facet"
7211 local metaea=${TMP}/backup_restore.ea
7212 local metadata=${TMP}/backup_restore.tgz
7213 local opts=${MDS_MOUNT_OPTS}
7214 local svc=${facet}_svc
7216 if ! ${rcmd} test -b ${devname}; then
7217 opts=$(csa_add "$opts" -o loop)
7220 echo "file-level backup/restore on $facet:${devname}"
7222 # step 1: build mount point
7223 ${rcmd} mkdir -p $mntpt
7224 # step 2: cleanup old backup
7225 ${rcmd} rm -f $metaea $metadata
7227 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7228 if [ ! -z $igif ]; then
7229 # step 3.5: rm .lustre
7230 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
7232 # step 4: backup metaea
7234 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
7236 # step 5: backup metadata
7238 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
7240 ${rcmd} $UMOUNT $mntpt || return 4
7241 # step 8: reformat dev
7242 echo "reformat new device"
7243 format_mdt $(facet_number $facet)
7245 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
7246 # step 10: restore metadata
7248 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
7249 # step 11: restore metaea
7251 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
7252 # step 12: remove recovery logs
7253 echo "remove recovery logs"
7254 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
7255 # step 13: umount dev
7256 ${rcmd} $UMOUNT $mntpt || return 10
7257 # step 14: cleanup tmp backup
7258 ${rcmd} rm -f $metaea $metadata
7259 # step 15: reset device label - it's not virgin on
7260 ${rcmd} e2label $devname ${!svc}
7267 local devname=$(mdsdevname $(facet_number $facet))
7268 local mntpt=$(facet_mntpt brpt)
7269 local rcmd="do_facet $facet"
7270 local opts=${MDS_MOUNT_OPTS}
7272 if ! ${rcmd} test -b ${devname}; then
7273 opts=$(csa_add "$opts" -o loop)
7276 echo "removing OI files on $facet: idx=${idx}"
7278 # step 1: build mount point
7279 ${rcmd} mkdir -p $mntpt
7281 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7282 if [ -z $idx ]; then
7283 # step 3: remove all OI files
7284 ${rcmd} rm -fv $mntpt/oi.16*
7285 elif [ $idx -lt 2 ]; then
7286 ${rcmd} rm -fv $mntpt/oi.16.${idx}
7290 # others, rm oi.16.[idx, idx * idx, idx ** ...]
7291 for ((i=${idx}; i<64; i=$((i * idx)))); do
7292 ${rcmd} rm -fv $mntpt/oi.16.${i}
7296 ${rcmd} $UMOUNT $mntpt || return 2
7297 # OI files will be recreated when mounted as lustre next time.
7300 # generate maloo upload-able log file name
7301 # \param logname specify unique part of file name
7302 generate_logname() {
7303 local logname=${1:-"default_logname"}
7305 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
7308 # make directory on different MDTs
7312 local stripe_count=2
7313 local stripe_index=-1
7316 while getopts "c:i:p" opt; do
7318 c) stripe_count=$OPTARG;;
7319 i) stripe_index=$OPTARG;;
7321 \?) error "only support -i -c -p";;
7325 shift $((OPTIND - 1))
7326 [ $# -eq 1 ] || error "Only creating single directory is supported"
7329 if [ "$p_option" == "-p" ]; then
7330 local parent=$(dirname $path)
7332 [ -d $path ] && return 0
7333 [ ! -d ${parent} ] && mkdir -p ${parent}
7336 if [ $MDSCOUNT -le 1 ]; then
7339 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
7342 if [ $stripe_index -eq -1 ]; then
7343 mdt_index=$((test_num % MDSCOUNT))
7345 mdt_index=$stripe_index
7347 echo "striped dir -i$mdt_index -c$stripe_count $path"
7348 $LFS setdirstripe -i$mdt_index -c$stripe_count $path
7352 # free_fd: find the smallest and not in use file descriptor [above @last_fd]
7354 # If called many times, passing @last_fd will avoid repeated searching
7355 # already-open FDs repeatedly if we know they are still in use.
7357 # usage: free_fd [last_fd]
7360 local max_fd=$(ulimit -n)
7361 local fd=$((${1:-2} + 1))
7363 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
7366 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
7370 check_mount_and_prep()
7372 is_mounted $MOUNT || setupall
7374 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
7375 mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
7376 for idx in $(seq $MDSCOUNT); do
7377 local name="MDT$(printf '%04x' $((idx - 1)))"
7378 rm -rf $MOUNT/.lustre/lost+found/$name/*
7382 # calcule how many ost-objects to be created.
7383 precreated_ost_obj_count()
7387 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
7388 local ost_name="OST$(printf '%04x' $ost_idx)"
7389 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
7390 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7391 osp.$proc_path.prealloc_last_id)
7392 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7393 osp.$proc_path.prealloc_next_id)
7394 echo $((last_id - next_id + 1))
7397 check_file_in_pool()
7402 local res=$($GETSTRIPE $file | grep 0x | cut -f2)
7405 for t in $tlist ; do
7406 [ "$i" -eq "$t" ] && continue 2
7409 echo "pool list: $tlist"
7410 echo "striping: $res"
7411 error_noexit "$file not allocated in $pool"
7418 echo "Creating new pool"
7421 create_pool $FSNAME.$pool ||
7422 { error_noexit "No pool created, result code $?"; return 1; }
7423 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
7424 { error_noexit "$pool not in lfs pool_list"; return 2; }
7427 pool_add_targets() {
7428 echo "Adding targets to pool"
7434 local list=$(seq $first $step $last)
7436 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
7437 do_facet mgs $LCTL pool_add \
7438 $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
7440 # wait for OSTs to be added to the pool
7441 for mds_id in $(seq $MDSCOUNT); do
7442 local mdt_id=$((mds_id-1))
7443 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7444 wait_update_facet mds$mds_id \
7445 "lctl get_param -n lod.$lodname.pools.$pool |
7446 sort -u | tr '\n' ' ' " "$t" || {
7447 error_noexit "mds$mds_id: Add to pool failed"
7451 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
7452 | sort -u | tr '\n' ' ' " "$t" || {
7453 error_noexit "Add to pool failed"
7456 local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
7457 local addcount=$(((last - first) / step + 1))
7458 [ $lfscount -eq $addcount ] || {
7459 error_noexit "lfs pool_list bad ost count" \
7460 "$lfscount != $addcount"
7468 echo "Setting pool on directory $tdir"
7470 $SETSTRIPE -c 2 -p $pool $tdir && return 0
7472 error_noexit "Cannot set pool $pool to $tdir"
7479 echo "Checking pool on directory $tdir"
7481 local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
7482 [ "$res" = "$pool" ] && return 0
7484 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
7488 pool_dir_rel_path() {
7489 echo "Testing relative path works well"
7494 mkdir -p $root/$tdir/$tdir
7496 pool_set_dir $pool $tdir || return 1
7497 pool_set_dir $pool ./$tdir || return 2
7498 pool_set_dir $pool ../$tdir || return 3
7499 pool_set_dir $pool ../$tdir/$tdir || return 4
7500 rm -rf $tdir; cd - > /dev/null
7503 pool_alloc_files() {
7504 echo "Checking files allocation from directory pool"
7511 for i in $(seq -w 1 $count)
7513 local file=$tdir/file-$i
7515 check_file_in_pool $file $pool "$tlist" || \
7516 failed=$((failed + 1))
7518 [ "$failed" = 0 ] && return 0
7520 error_noexit "$failed files not allocated in $pool"
7524 pool_create_files() {
7525 echo "Creating files in pool"
7533 for i in $(seq -w 1 $count)
7535 local file=$tdir/spoo-$i
7536 $SETSTRIPE -p $pool $file
7537 check_file_in_pool $file $pool "$tlist" || \
7538 failed=$((failed + 1))
7540 [ "$failed" = 0 ] && return 0
7542 error_noexit "$failed files not allocated in $pool"
7547 echo "Checking 'lfs df' output"
7550 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
7552 local res=$($LFS df --pool $FSNAME.$pool |
7554 grep "$FSNAME-OST" |
7556 [ "$res" = "$t" ] && return 0
7558 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
7562 pool_file_rel_path() {
7563 echo "Creating files in a pool with relative pathname"
7568 { error_noexit "unable to create $tdir"; return 1 ; }
7569 local file="/..$tdir/$tfile-1"
7570 $SETSTRIPE -p $pool $file ||
7571 { error_noexit "unable to create $file" ; return 2 ; }
7574 $SETSTRIPE -p $pool $tfile-2 || {
7575 error_noexit "unable to create $tfile-2 in $tdir"
7580 pool_remove_first_target() {
7581 echo "Removing first target from a pool"
7584 local pname="lov.$FSNAME-*.pools.$pool"
7585 local t=$($LCTL get_param -n $pname | head -1)
7586 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7587 for mds_id in $(seq $MDSCOUNT); do
7588 local mdt_id=$((mds_id-1))
7589 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7590 wait_update_facet mds$mds_id \
7591 "lctl get_param -n lod.$lodname.pools.$pool |
7593 error_noexit "mds$mds_id: $t not removed from" \
7598 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
7599 error_noexit "$t not removed from $FSNAME.$pool"
7604 pool_remove_all_targets() {
7605 echo "Removing all targets from pool"
7608 local pname="lov.$FSNAME-*.pools.$pool"
7609 for t in $($LCTL get_param -n $pname | sort -u)
7611 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7613 for mds_id in $(seq $MDSCOUNT); do
7614 local mdt_id=$((mds_id-1))
7615 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7616 wait_update_facet mds$mds_id "lctl get_param -n \
7617 lod.$lodname.pools.$pool" "" || {
7618 error_noexit "mds$mds_id: Pool $pool not drained"
7622 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
7623 error_noexit "Pool $FSNAME.$pool cannot be drained"
7626 # striping on an empty/nonexistant pool should fall back
7627 # to "pool of everything"
7629 error_noexit "failed to use fallback striping for empty pool"
7632 # setstripe on an empty pool should fail
7633 $SETSTRIPE -p $pool $file 2>/dev/null && {
7634 error_noexit "expected failure when creating file" \
7642 echo "Destroying pool"
7646 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
7649 # striping on an empty/nonexistant pool should fall back
7650 # to "pool of everything"
7652 error_noexit "failed to use fallback striping for missing pool"
7655 # setstripe on an empty pool should fail
7656 $SETSTRIPE -p $pool $file 2>/dev/null && {
7657 error_noexit "expected failure when creating file" \
7662 # get param should return err once pool is gone
7663 if wait_update $HOSTNAME "lctl get_param -n \
7664 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
7666 remove_pool_from_list $FSNAME.$pool
7669 error_noexit "Pool $FSNAME.$pool is not destroyed"
7673 # Get and check the actual stripe count of one file.
7674 # Usage: check_stripe_count <file> <expected_stripe_count>
7675 check_stripe_count() {
7680 [[ -z "$file" || -z "$expected" ]] &&
7681 error "check_stripe_count: invalid argument"
7683 local cmd="$GETSTRIPE -c $file"
7684 actual=$($cmd) || error "$cmd failed"
7685 actual=${actual%% *}
7687 if [[ $actual -ne $expected ]]; then
7688 [[ $expected -eq -1 ]] ||
7689 error "$cmd wrong: found $actual, expected $expected"
7690 [[ $actual -eq $OSTCOUNT ]] ||
7691 error "$cmd wrong: found $actual, expected $OSTCOUNT"
7695 # Get and check the actual list of OST indices on one file.
7696 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
7702 [[ -z "$file" || -z "$expected" ]] &&
7703 error "check_obdidx: invalid argument!"
7705 obdidx=$(comma_list $($GETSTRIPE $file | grep -A $OSTCOUNT obdidx |
7706 grep -v obdidx | awk '{print $1}' | xargs))
7708 [[ $obdidx = $expected ]] ||
7709 error "list of OST indices on $file is $obdidx," \
7710 "should be $expected"
7713 # Get and check the actual OST index of the first stripe on one file.
7714 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
7715 check_start_ost_idx() {
7720 [[ -z "$file" || -z "$expected" ]] &&
7721 error "check_start_ost_idx: invalid argument!"
7723 start_ost_idx=$($GETSTRIPE $file | grep -A 1 obdidx | grep -v obdidx |
7726 [[ $start_ost_idx = $expected ]] ||
7727 error "OST index of the first stripe on $file is" \
7728 "$start_ost_idx, should be $expected"
7731 killall_process () {
7732 local clients=${1:-$(hostname)}
7737 do_nodes $clients "killall $signal $name"
7742 do_facet mgs "$LCTL snapshot_create -F $FSNAME $*"
7747 do_facet mgs "$LCTL snapshot_destroy -F $FSNAME $*"
7752 do_facet mgs "$LCTL snapshot_modify -F $FSNAME $*"
7757 do_facet mgs "$LCTL snapshot_list -F $FSNAME $*"
7762 do_facet mgs "$LCTL snapshot_mount -F $FSNAME $*"
7767 do_facet mgs "$LCTL snapshot_umount -F $FSNAME $*"
7774 do_facet mgs "cat $LSNAPSHOT_LOG"
7780 echo "Cleaning test environment ..."
7782 # Every lsnapshot command takes exclusive lock with others,
7783 # so can NOT destroy the snapshot during list with 'xargs'.
7785 local ssname=$(lsnapshot_list | grep snapshot_name |
7786 grep lss_ | awk '{ print $2 }' | head -n 1)
7787 [ -z "$ssname" ] && break
7789 lsnapshot_destroy -n $ssname -f ||
7790 lss_err "Fail to destroy $ssname by force"
7800 local host=$(facet_active_host $facet)
7801 local dir=$(dirname $(facet_vdevice $facet))
7802 local pool=$(zpool_name $facet)
7803 local lfsname=$(zfs_local_fsname $facet)
7804 local label=${FSNAME}-${role}$(printf '%04x' $idx)
7807 "echo '$host - $label zfs:${dir}/${pool}/${lfsname} - -' >> \
7813 do_facet mgs "rm -f $LSNAPSHOT_CONF"
7814 echo "Generating $LSNAPSHOT_CONF on MGS ..."
7816 if ! combined_mgs_mds ; then
7817 [ $(facet_fstype mgs) != zfs ] &&
7818 skip "Lustre snapshot 1 only works for ZFS backend" &&
7821 local host=$(facet_active_host mgs)
7822 local dir=$(dirname $(facet_vdevice mgs))
7823 local pool=$(zpool_name mgs)
7824 local lfsname=$(zfs_local_fsname mgs)
7827 "echo '$host - MGS zfs:${dir}/${pool}/${lfsname} - -' \
7828 >> $LSNAPSHOT_CONF" || lss_err "generate lss conf (mgs)"
7831 for num in `seq $MDSCOUNT`; do
7832 [ $(facet_fstype mds$num) != zfs ] &&
7833 skip "Lustre snapshot 1 only works for ZFS backend" &&
7836 lss_gen_conf_one mds$num MDT $((num - 1)) ||
7837 lss_err "generate lss conf (mds$num)"
7840 for num in `seq $OSTCOUNT`; do
7841 [ $(facet_fstype ost$num) != zfs ] &&
7842 skip "Lustre snapshot 1 only works for ZFS backend" &&
7845 lss_gen_conf_one ost$num OST $((num - 1)) ||
7846 lss_err "generate lss conf (ost$num)"
7849 do_facet mgs "cat $LSNAPSHOT_CONF"
7855 local val=$(awk '{print $2}' <<< $line)
7857 if [[ $line =~ ^"lmm_stripe_count:" ]]; then
7859 elif [[ $line =~ ^"lmm_stripe_size:" ]]; then
7861 elif [[ $line =~ ^"lmm_stripe_offset:" ]]; then
7866 parse_layout_param()
7873 if [[ -z $mode ]]; then
7874 if [[ $line =~ ^"stripe_count:" ]]; then
7876 elif [[ $line =~ ^"lmm_stripe_count:" ]]; then
7878 elif [[ $line =~ ^"lcm_layout_gen:" ]]; then
7883 if [[ $mode = "plain_dir" ]]; then
7884 param=$(echo $line |
7885 awk '{printf("-c %d -S %d -i %d",$2,$4,$6)}')
7886 elif [[ $mode = "plain_file" ]]; then
7887 val=$(parse_plain_param "$line")
7888 [[ ! -z $val ]] && param="$param $val"
7889 elif [[ $mode = "pfl" ]]; then
7890 val=$(echo $line | awk '{print $2}')
7891 if [[ $line =~ ^"lcme_extent.e_end:" ]]; then
7892 if [[ $val = "EOF" ]]; then
7893 param="$param -E -1"
7895 param="$param -E $val"
7897 elif [[ $line =~ ^"stripe_count:" ]]; then
7900 awk '{printf("-c %d -S %d -i %d",$2,$4,$6)}')
7904 val=$(parse_plain_param "$line")
7905 [[ ! -z $val ]] && param="$param $val"
7914 local param=$($LFS getstripe -d $1 | parse_layout_param)