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
586 LNETLND="o2iblnd/ko2iblnd"
591 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
592 load_module ../lnet/klnds/$LNETLND
593 load_module obdclass/obdclass
594 load_module ptlrpc/ptlrpc
595 load_module ptlrpc/gss/ptlrpc_gss
603 load_module obdecho/obdecho
604 if ! client_only; then
605 SYMLIST=/proc/kallsyms
606 grep -q crc16 $SYMLIST ||
607 { modprobe crc16 2>/dev/null || true; }
608 grep -q -w jbd2 $SYMLIST ||
609 { modprobe jbd2 2>/dev/null || true; }
610 load_module lfsck/lfsck
611 [ "$LQUOTA" != "no" ] &&
612 load_module quota/lquota $LQUOTAOPTS
613 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
615 load_module osd-zfs/osd_zfs
617 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
618 grep -q exportfs_decode_fh $SYMLIST ||
619 { modprobe exportfs 2> /dev/null || true; }
620 grep -q -w mbcache $SYMLIST ||
621 { modprobe mbcache 2>/dev/null || true; }
622 load_module ../ldiskfs/ldiskfs
623 load_module osd-ldiskfs/osd_ldiskfs
635 load_module llite/lustre
636 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
638 rm -f $OGDB/ogdb-$HOSTNAME
639 $LCTL modules > $OGDB/ogdb-$HOSTNAME
641 # 'mount' doesn't look in $PATH, just sbin
642 local mount_lustre=$LUSTRE/utils/mount.lustre
643 if [ -f $mount_lustre ]; then
644 local sbin_mount=$(readlink -f /sbin)/mount.lustre
645 if grep -qw "$sbin_mount" /proc/mounts; then
646 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
648 if ! grep -qw "$sbin_mount" /proc/mounts; then
649 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
650 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
651 cat <<- EOF > "$sbin_mount"
654 echo "This $sbin_mount just a mountpoint." 1>&2
655 echo "It is never supposed to be run." 1>&2
656 logger -p emerg -- "using stub $sbin_mount $@"
659 chmod a+x $sbin_mount
661 mount --bind $mount_lustre $sbin_mount ||
662 error "can't bind $mount_lustre to $sbin_mount"
670 # load modules on remote nodes optionally
671 # lustre-tests have to be installed on these nodes
672 if $LOAD_MODULES_REMOTE; then
673 local list=$(comma_list $(remote_nodes_list))
674 if [ -n "$list" ]; then
675 echo "loading modules on: '$list'"
676 do_rpc_nodes "$list" load_modules_local
682 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
683 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
684 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
685 echo "$LEAK_LUSTRE" 1>&2
686 echo "$LEAK_PORTALS" 1>&2
687 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
688 echo "Memory leaks detected"
689 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
695 wait_exit_ST client # bug 12845
697 $LUSTRE_RMMOD ldiskfs || return 2
699 if $LOAD_MODULES_REMOTE; then
700 local list=$(comma_list $(remote_nodes_list))
701 if [ -n "$list" ]; then
702 echo "unloading modules on: '$list'"
703 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
704 do_rpc_nodes "$list" check_mem_leak
708 local sbin_mount=$(readlink -f /sbin)/mount.lustre
709 if grep -qe "$sbin_mount " /proc/mounts; then
710 umount $sbin_mount || true
711 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
715 check_mem_leak || return 254
717 echo "modules unloaded."
722 local facet=${1:-$SINGLEMDS}
723 local fstype=$(facet_fstype $facet)
726 ldiskfs) size=50;; # largest seen is 44, leave some headroom
727 zfs) size=400;; # largest seen is 384
734 local facet=${1:-$SINGLEMDS}
735 local fstype=$(facet_fstype $facet)
738 ldiskfs) size=4;; # ~4KB per inode
739 zfs) size=11;; # 10 to 11KB per inode
745 check_gss_daemon_nodes() {
749 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
750 if [ \\\"\\\$num\\\" -ne 1 ]; then
751 echo \\\$num instance of $dname;
756 check_gss_daemon_facet() {
760 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
761 if [ $num -ne 1 ]; then
762 echo "$num instance of $dname on $facet"
771 echo Stopping $@ on $list
772 do_nodes $list "killall -2 $@ 2>/dev/null || true"
775 # start gss daemons on all nodes, or
776 # "daemon" on "list" if set
777 start_gss_daemons() {
781 if [ "$list" ] && [ "$daemon" ] ; then
782 echo "Starting gss daemon on nodes: $list"
783 do_nodes $list "$daemon" || return 8
787 local list=$(comma_list $(mdts_nodes))
788 echo "Starting gss daemon on mds: $list"
789 do_nodes $list "$LSVCGSSD -v" || return 1
791 do_nodes $list "$LGSSD -v" || return 2
794 list=$(comma_list $(osts_nodes))
795 echo "Starting gss daemon on ost: $list"
796 do_nodes $list "$LSVCGSSD -v" || return 3
797 # starting on clients
799 local clients=${CLIENTS:-`hostname`}
801 echo "Starting $LGSSD on clients $clients "
802 do_nodes $clients "$LGSSD -v" || return 4
805 # wait daemons entering "stable" status
809 # check daemons are running
811 list=$(comma_list $(mdts_nodes) $(osts_nodes))
812 check_gss_daemon_nodes $list lsvcgssd || return 5
814 list=$(comma_list $(mdts_nodes))
815 check_gss_daemon_nodes $list lgssd || return 6
818 check_gss_daemon_nodes $clients lgssd || return 7
823 local list=$(comma_list $(mdts_nodes))
825 send_sigint $list lsvcgssd lgssd
827 list=$(comma_list $(osts_nodes))
828 send_sigint $list lsvcgssd
830 list=${CLIENTS:-`hostname`}
831 send_sigint $list lgssd
836 if ! module_loaded ptlrpc_gss; then
837 load_module ptlrpc/gss/ptlrpc_gss
838 module_loaded ptlrpc_gss ||
839 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
842 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
845 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
847 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
855 # maybe cleanup credential cache?
861 local var=${facet}_svc
869 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
870 tr '[:lower:]' '[:upper:]'
876 if [ $facet == mgs ] || [ $facet == client ]; then
880 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
888 if [ -n "${!var}" ]; then
893 var=$(facet_type $facet)FSTYPE
894 if [ -n "${!var}" ]; then
899 if [ -n "$FSTYPE" ]; then
904 if [[ $facet == mgs ]] && combined_mgs_mds; then
916 local facets=$(get_facets)
919 for facet in ${facets//,/ }; do
920 if [ $node == $(facet_host $facet) ] ||
921 [ $node == "$(facet_failover_host $facet)" ]; then
922 fstype=$(facet_fstype $facet)
923 if [[ $fstypes != *$fstype* ]]; then
924 fstypes+="${fstypes:+,}$fstype"
933 local num=$(facet_number $facet)
936 if [[ $(facet_type $facet) = OST ]]; then
938 if [[ -n "${!index}" ]]; then
943 index=${OST_INDICES[num - 1]}
946 [[ -n "$index" ]] || index=$((num - 1))
954 local fstype=$(facet_fstype $facet)
958 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
960 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
961 ${dev} 2>/dev/null");;
963 error "unknown fstype!";;
971 local device=$(mdsdevname $num)
972 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
978 local device=$(ostdevname $num)
979 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
984 # Get the device of a facet.
991 mgs) device=$(mgsdevname) ;;
992 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
993 ost*) device=$(ostdevname $(facet_number $facet)) ;;
994 fs2mds) device=$(mdsdevname 1_2) ;;
995 fs2ost) device=$(ostdevname 1_2) ;;
996 fs3ost) device=$(ostdevname 2_2) ;;
1004 # Get the virtual device of a facet.
1011 mgs) device=$(mgsvdevname) ;;
1012 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
1013 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
1014 fs2mds) device=$(mdsvdevname 1_2) ;;
1015 fs2ost) device=$(ostvdevname 1_2) ;;
1016 fs3ost) device=$(ostvdevname 2_2) ;;
1024 local virt=$(virt-what 2> /dev/null)
1026 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1028 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1031 VMware|KVM|VirtualBox|Parallels)
1032 echo $virt | tr '[A-Z]' '[a-z]' ;;
1038 # Re-read the partition table on failover partner host.
1039 # After a ZFS storage pool is created on a shared device, the partition table
1040 # on the device may change. However, the operating system on the failover
1041 # host may not notice the change automatically. Without the up-to-date partition
1042 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1043 # relative to partition rather than disk beginnings.
1045 # This function performs partprobe on the failover host to make it re-read the
1048 refresh_partition_table() {
1053 host=$(facet_passive_host $facet)
1054 if [[ -n "$host" ]]; then
1055 do_node $host "$PARTPROBE $device"
1060 # Get ZFS storage pool name.
1067 device=$(facet_device $facet)
1068 # poolname is string before "/"
1069 poolname="${device%%/*}"
1076 # Get ZFS local fsname.
1078 zfs_local_fsname() {
1080 local lfsname=$(basename $(facet_device $facet))
1086 # Create ZFS storage pool.
1093 local opts=${@:-"-o cachefile=none"}
1095 do_facet $facet "modprobe zfs;
1096 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1097 $ZPOOL create -f $opts $poolname $vdev"
1101 # Create ZFS file system.
1107 local opts=${@:-"-o mountpoint=legacy"}
1109 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1110 $ZFS create $opts $dataset"
1114 # Export ZFS storage pool.
1115 # Before exporting the pool, all datasets within the pool should be unmounted.
1123 poolname=$(zpool_name $facet)
1125 if [[ -n "$poolname" ]]; then
1126 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1127 grep -q ^$poolname/ /proc/mounts ||
1128 $ZPOOL export $opts $poolname"
1133 # Destroy ZFS storage pool.
1134 # Destroy the given pool and free up any devices for other use. This command
1135 # tries to unmount any active datasets before destroying the pool.
1136 # -f Force any active datasets contained within the pool to be unmounted.
1140 local poolname=${2:-$(zpool_name $facet)}
1142 if [[ -n "$poolname" ]]; then
1143 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1144 $ZPOOL destroy -f $poolname"
1149 # Import ZFS storage pool.
1150 # Force importing, even if the pool appears to be potentially active.
1155 local opts=${@:-"-o cachefile=none"}
1158 poolname=$(zpool_name $facet)
1160 if [[ -n "$poolname" ]]; then
1161 opts+=" -d $(dirname $(facet_vdevice $facet))"
1162 do_facet $facet "modprobe zfs;
1163 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1164 $ZPOOL import -f $opts $poolname"
1169 # Reimport ZFS storage pool with new name
1174 local opts="-o cachefile=none"
1175 local poolname=$(zpool_name $facet)
1177 opts+=" -d $(dirname $(facet_vdevice $facet))"
1178 do_facet $facet "$ZPOOL export $poolname;
1179 $ZPOOL import $opts $poolname $newpool"
1183 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1184 # is not automatically imported on system startup.
1186 # In a failover environment, this will provide resource level fencing which
1187 # will ensure that the same ZFS storage pool will not be imported concurrently
1188 # on different nodes.
1190 disable_zpool_cache() {
1194 poolname=$(zpool_name $facet)
1196 if [[ -n "$poolname" ]]; then
1197 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1202 # This and set_osd_param() shall be used to access OSD parameters
1203 # once existed under "obdfilter":
1208 # writethrough_cache_enable
1212 local device=${2:-$FSNAME-OST*}
1215 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1216 osd-*.$device.$name 2>&1" | grep -v 'error:'
1221 local device=${2:-$FSNAME-OST*}
1225 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1226 osd-*.$device.$name=$value 2>&1" | grep -v 'error:'
1230 local dz=${1:-$DEBUG_SIZE}
1232 if [ -f /sys/devices/system/cpu/possible ]; then
1233 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1235 local cpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1238 # bug 19944, adjust size to be -gt num_possible_cpus()
1239 # promise 2MB for every cpu at least
1240 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1243 lctl set_param debug_mb=$dz
1246 set_default_debug () {
1247 local debug=${1:-"$PTLDEBUG"}
1248 local subsys=${2:-"$SUBSYSTEM"}
1249 local debug_size=${3:-$DEBUG_SIZE}
1251 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1252 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1254 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1257 set_default_debug_nodes () {
1260 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1261 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1265 do_rpc_nodes "$nodes" set_default_debug \
1266 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1269 set_default_debug_facet () {
1271 local node=$(facet_active_host $facet)
1272 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1274 set_default_debug_nodes $node
1278 local hostid=${1:-$(hostid)}
1280 if [ ! -s /etc/hostid ]; then
1281 printf $(echo -n $hostid |
1282 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1288 local facets=${1:-$(get_facets)}
1291 for facet in ${facets//,/ }; do
1294 [ $RC -eq 0 ] && continue
1296 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1297 skip "Restart of $facet failed!." && touch $LU482_FAILED
1299 error "Restart of $facet failed!"
1306 # Add argument "arg" (e.g., "loop") to the comma-separated list
1307 # of arguments for option "opt" (e.g., "-o") on command
1308 # line "opts" (e.g., "-o flock").
1314 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1316 if echo "$opts" | grep -q $opt_pattern; then
1317 opts=$(echo "$opts" | sed -e \
1318 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1320 opts+="${opts:+ }$opt $arg"
1328 local dev=$(facet_active $facet)_dev
1329 local opt=${facet}_opt
1330 local mntpt=$(facet_mntpt $facet)
1331 local opts="${!opt} $@"
1332 local fstype=$(facet_fstype $facet)
1335 module_loaded lustre || load_modules
1337 if [ $(facet_fstype $facet) == ldiskfs ] &&
1338 ! do_facet $facet test -b ${!dev}; then
1339 opts=$(csa_add "$opts" -o loop)
1342 if [[ $(facet_fstype $facet) == zfs ]]; then
1343 # import ZFS storage pool
1344 import_zpool $facet || return ${PIPESTATUS[0]}
1349 devicelabel=$(do_facet ${facet} "$E2LABEL ${!dev}");;
1351 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
1352 lustre:svname ${!dev}");;
1354 error "unknown fstype!";;
1357 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1358 # for testing LU-482 error handling in mount_facets() and test_0a()
1359 if [ -f $TMP/test-lu482-trigger ]; then
1362 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1367 if [ $RC -ne 0 ]; then
1368 echo "Start of ${!dev} on ${facet} failed ${RC}"
1372 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
1373 if [[ "$health" != "healthy" ]]; then
1374 error "$facet is in a unhealthy state"
1377 set_default_debug_facet $facet
1379 if [[ $facet == mds* ]]; then
1381 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 2>/dev/null
1384 if [[ $opts =~ .*nosvc.* ]]; then
1385 echo "Start ${!dev} without service"
1390 wait_update_facet ${facet} "$E2LABEL ${!dev} \
1391 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
1392 "" || error "${!dev} failed to initialize!";;
1394 wait_update_facet ${facet} "$ZFS get -H -o value \
1395 lustre:svname ${!dev} 2>/dev/null | \
1396 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
1397 error "${!dev} failed to initialize!";;
1400 error "unknown fstype!";;
1404 # commit the device label change to disk
1405 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
1406 echo "Commit the device label on ${!dev}"
1407 do_facet $facet "sync; sleep 1; sync"
1411 label=$(devicelabel ${facet} ${!dev})
1412 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1413 eval export ${facet}_svc=${label}
1414 echo Started ${label}
1419 # start facet device options
1425 eval export ${facet}_dev=${device}
1426 eval export ${facet}_opt=\"$@\"
1428 local varname=${facet}failover_dev
1429 if [ -n "${!varname}" ] ; then
1430 eval export ${facet}failover_dev=${!varname}
1432 eval export ${facet}failover_dev=$device
1435 local mntpt=$(facet_mntpt $facet)
1436 do_facet ${facet} mkdir -p $mntpt
1437 eval export ${facet}_MOUNT=$mntpt
1438 mount_facet ${facet}
1441 if [[ $facet == mds* ]]; then
1443 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1454 local HOST=`facet_active_host $facet`
1455 [ -z $HOST ] && echo stop: no host for $facet && return 0
1457 local mntpt=$(facet_mntpt $facet)
1458 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1459 if [ ${running} -ne 0 ]; then
1460 echo "Stopping $mntpt (opts:$@) on $HOST"
1461 do_facet ${facet} $UMOUNT $@ $mntpt
1464 # umount should block, but we should wait for unrelated obd's
1465 # like the MGS or MGC to also stop.
1466 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1468 if [[ $(facet_fstype $facet) == zfs ]]; then
1469 # export ZFS storage pool
1470 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
1474 # save quota version (both administrative and operational quotas)
1475 # add an additional parameter if mountpoint is ever different from $MOUNT
1477 # XXX This function is kept for interoperability with old server (< 2.3.50),
1478 # it should be removed whenever we drop the interoperability for such
1480 quota_save_version() {
1481 local fsname=${2:-$FSNAME}
1483 local ver=$(tr -c -d "123" <<< $spec)
1484 local type=$(tr -c -d "ug" <<< $spec)
1486 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1488 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1490 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1492 local osts=$(get_facets OST)
1493 for ost in ${osts//,/ }; do
1495 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1499 # client could mount several lustre
1501 # XXX This function is kept for interoperability with old server (< 2.3.50),
1502 # it should be removed whenever we drop the interoperability for such
1505 local fsname=${1:-$FSNAME}
1507 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1509 do_nodes $(comma_list $(osts_nodes)) \
1510 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1514 # get mdt quota type
1516 local varsvc=${SINGLEMDS}_svc
1517 do_facet $SINGLEMDS $LCTL get_param -n \
1518 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1521 # get ost quota type
1523 # All OSTs should have same quota type
1524 local varsvc=ost1_svc
1525 do_facet ost1 $LCTL get_param -n \
1526 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1529 # restore old quota type settings
1531 if [ "$old_MDT_QUOTA_TYPE" ]; then
1532 do_facet mgs $LCTL conf_param \
1533 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1535 if [ "$old_OST_QUOTA_TYPE" ]; then
1536 do_facet mgs $LCTL conf_param \
1537 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1541 # Handle the case when there is a space in the lfs df
1542 # "filesystem summary" line the same as when there is no space.
1543 # This will allow fixing the "lfs df" summary line in the future.
1545 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1548 # Get free inodes on the MDT specified by mdt index, free indoes on
1549 # the whole filesystem will be returned when index == -1.
1555 if [ $index -eq -1 ]; then
1558 mdt_uuid=$(mdtuuid_from_index $index)
1561 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1566 # Get the OST device status from 'lfs df' with a given OST index.
1570 local mnt_pnt=${2:-$MOUNT}
1573 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
1574 lfs_df $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
1580 # save old quota type & set new quota type
1581 local mdt_qtype=$(mdt_quota_type)
1582 local ost_qtype=$(ost_quota_type)
1584 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1585 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1587 export old_MDT_QUOTA_TYPE=$mdt_qtype
1588 export old_OST_QUOTA_TYPE=$ost_qtype
1590 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1591 error "set mdt quota type failed"
1592 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1593 error "set ost quota type failed"
1595 local quota_usrs=$QUOTA_USERS
1597 # get_filesystem_size
1598 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1599 local blk_soft=$((disksz + 1024))
1600 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1602 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1603 local i_soft=$inodes
1604 local i_hard=$((i_soft + i_soft / 20))
1606 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1607 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1608 "inode-hardlimit: $i_hard"
1611 for usr in $quota_usrs; do
1612 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1614 cmd="$LFS setquota -$type $usr -b $blk_soft"
1615 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1617 eval $cmd || error "$cmd FAILED!"
1619 # display the quota status
1620 echo "Quota settings for $usr : "
1621 $LFS quota -v -u $usr $mntpt || true
1628 local opts=${3:-$MOUNT_OPTS}
1629 opts=${opts:+-o $opts}
1630 local flags=${4:-$MOUNT_FLAGS}
1632 local device=$MGSNID:/$FSNAME$FILESET
1633 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1634 echo "Bad mount command: opt=$flags $opts dev=$device " \
1639 echo "Starting client: $client: $flags $opts $device $mnt"
1640 do_node $client mkdir -p $mnt
1641 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
1642 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1644 #disable FILESET if not supported
1645 do_nodes $client lctl get_param -n \
1646 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1647 device=$MGSNID:/$FSNAME
1648 do_node $client mkdir -p $mnt/$FILESET
1649 do_node $client "! grep -q $mnt' ' /proc/mounts ||
1652 do_node $client $MOUNT_CMD $flags $opts $device $mnt || return 1
1654 set_default_debug_nodes $client
1666 [ "$3" ] && force=-f
1667 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1668 if [ $running -ne 0 ]; then
1669 echo "Stopping client $client $mnt (opts:$force)"
1670 do_node $client lsof -t $mnt || need_kill=no
1671 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1672 pids=$(do_node $client lsof -t $mnt | sort -u);
1673 if [ -n $pids ]; then
1674 do_node $client kill -9 $pids || true
1678 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1679 if [ $busy -ne 0 ] ; then
1680 echo "$mnt is still busy, wait one second" && sleep 1
1681 do_node $client umount $force $mnt
1686 # nodes is comma list
1687 sanity_mount_check_nodes () {
1693 # FIXME: assume that all cluster nodes run the same os
1694 [ "$(uname)" = Linux ] || return 0
1697 for mnt in $mnts ; do
1698 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1699 mpts=\\\$(mount | grep -c $mnt' ');
1700 if [ \\\$running -ne \\\$mpts ]; then
1701 echo \\\$(hostname) env are INSANE!;
1704 [ $? -eq 0 ] || rc=1
1709 sanity_mount_check_servers () {
1710 [ -n "$CLIENTONLY" ] &&
1711 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1712 echo Checking servers environments
1714 # FIXME: modify get_facets to display all facets wo params
1715 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1719 for facet in ${facets//,/ }; do
1720 node=$(facet_host ${facet})
1721 mntpt=$(facet_mntpt $facet)
1722 sanity_mount_check_nodes $node $mntpt ||
1723 { error "server $node environments are insane!"; return 1; }
1727 sanity_mount_check_clients () {
1728 local clients=${1:-$CLIENTS}
1729 local mntpt=${2:-$MOUNT}
1730 local mntpt2=${3:-$MOUNT2}
1732 [ -z $clients ] && clients=$(hostname)
1733 echo Checking clients $clients environments
1735 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1736 error "clients environments are insane!"
1739 sanity_mount_check () {
1740 sanity_mount_check_servers || return 1
1741 sanity_mount_check_clients || return 2
1744 # mount clients if not mouted
1745 zconf_mount_clients() {
1748 local opts=${3:-$MOUNT_OPTS}
1749 opts=${opts:+-o $opts}
1750 local flags=${4:-$MOUNT_FLAGS}
1752 local device=$MGSNID:/$FSNAME$FILESET
1753 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1754 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
1759 echo "Starting client $clients: $flags $opts $device $mnt"
1760 if [ -n "$FILESET" -a ! -n "$SKIP_FILESET" ]; then
1761 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1763 do_nodes $clients $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1765 #disable FILESET if not supported
1766 do_nodes $clients lctl get_param -n \
1767 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1768 device=$MGSNID:/$FSNAME
1769 do_nodes $clients mkdir -p $mnt/$FILESET
1770 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1775 running=\\\$(mount | grep -c $mnt' ');
1777 if [ \\\$running -eq 0 ] ; then
1779 $MOUNT_CMD $flags $opts $device $mnt;
1782 exit \\\$rc" || return ${PIPESTATUS[0]}
1784 echo "Started clients $clients: "
1785 do_nodes $clients "mount | grep $mnt' '"
1787 set_default_debug_nodes $clients
1792 zconf_umount_clients() {
1797 [ "$3" ] && force=-f
1799 echo "Stopping clients: $clients $mnt (opts:$force)"
1800 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1801 if [ \\\$running -ne 0 ] ; then
1802 echo Stopping client \\\$(hostname) $mnt opts:$force;
1803 lsof $mnt || need_kill=no;
1804 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1805 pids=\\\$(lsof -t $mnt | sort -u);
1806 if [ -n \\\"\\\$pids\\\" ]; then
1810 while umount $force $mnt 2>&1 | grep -q "busy"; do
1811 echo "$mnt is still busy, wait one second" && sleep 1;
1818 echo + $POWER_DOWN $node
1822 shutdown_node_hard () {
1824 local attempts=$SHUTDOWN_ATTEMPTS
1826 for i in $(seq $attempts) ; do
1829 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1830 echo "waiting for $host to fail attempts=$attempts"
1831 [ $i -lt $attempts ] || \
1832 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1838 local mnt=${2:-$MOUNT}
1841 if [ "$FAILURE_MODE" = HARD ]; then
1842 shutdown_node_hard $client
1844 zconf_umount_clients $client $mnt -f
1850 local facets="$(get_facets OST),$(get_facets MDS)"
1853 combined_mgs_mds || facets="$facets,mgs"
1855 for facet in ${facets//,/ }; do
1856 if [ $(facet_active_host $facet) == $host ]; then
1857 affected="$affected $facet"
1861 echo $(comma_list $affected)
1866 local host=${2:-$(facet_host $facet)}
1868 local label=$(convert_facet2label $facet)
1869 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
1872 facets_up_on_host () {
1874 local facets=$(facets_on_host $host)
1877 for facet in ${facets//,/ }; do
1878 if $(facet_up $facet $host); then
1879 affected_up="$affected_up $facet"
1883 echo $(comma_list $affected_up)
1889 if [ "$FAILURE_MODE" = HARD ]; then
1890 shutdown_node_hard $(facet_active_host $facet)
1898 echo + $POWER_UP $node
1911 if [ "$FAILURE_MODE" = HARD ]; then
1912 reboot_node $(facet_active_host $facet)
1920 if [ "$FAILURE_MODE" = HARD ]; then
1930 for facet in ${facets//,/ }; do
1931 hosts=$(expand_list $hosts $(facet_host $facet) )
1937 _check_progs_installed () {
1941 for prog in $progs; do
1942 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1943 echo $prog missing on $(hostname)
1950 check_progs_installed () {
1954 do_rpc_nodes "$nodes" _check_progs_installed $@
1957 # recovery-scale functions
1959 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1962 start_client_load() {
1965 local var=$(node_var_name $client)_load
1966 eval export ${var}=$load
1968 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1969 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1970 END_RUN_FILE=$END_RUN_FILE \
1971 LOAD_PID_FILE=$LOAD_PID_FILE \
1972 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1973 TESTNAME=$TESTNAME \
1974 DBENCH_LIB=$DBENCH_LIB \
1975 DBENCH_SRC=$DBENCH_SRC \
1976 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1982 log "Started client load: ${load} on $client"
1984 # get the children process IDs
1985 local pids=$(ps --ppid $ppid -o pid= | xargs)
1986 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1990 start_client_loads () {
1991 local -a clients=(${1//,/ })
1992 local numloads=${#CLIENT_LOADS[@]}
1995 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1996 testnum=$((nodenum % numloads))
1997 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1999 # bug 22169: wait the background threads to start
2003 # only for remote client
2004 check_client_load () {
2006 local var=$(node_var_name $client)_load
2007 local testload=run_${!var}.sh
2009 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
2011 # bug 18914: try to connect several times not only when
2012 # check ps, but while check_node_health also
2016 while [ $RC = 254 -a $tries -gt 0 ]; do
2020 if ! check_node_health $client; then
2022 if [ $RC -eq 254 ]; then
2023 # FIXME: not sure how long we shuold sleep here
2027 echo "check node health failed: RC=$RC "
2031 # We can continue try to connect if RC=254
2032 # Just print the warning about this
2033 if [ $RC = 254 ]; then
2034 echo "got a return status of $RC from do_node while checking " \
2035 "node health on $client"
2038 # see if the load is still on the client
2041 while [ $RC = 254 -a $tries -gt 0 ]; do
2045 if ! do_node $client \
2046 "ps auxwww | grep -v grep | grep -q $testload"; then
2051 if [ $RC = 254 ]; then
2052 echo "got a return status of $RC from do_node while checking " \
2053 "(node health and 'ps') the client load on $client"
2054 # see if we can diagnose a bit why this is
2059 check_client_loads () {
2060 local clients=${1//,/ }
2064 for client in $clients; do
2065 check_client_load $client
2067 if [ "$rc" != 0 ]; then
2068 log "Client load failed on node $client, rc=$rc"
2074 restart_client_loads () {
2075 local clients=${1//,/ }
2076 local expectedfail=${2:-""}
2080 for client in $clients; do
2081 check_client_load $client
2083 if [ "$rc" != 0 -a "$expectedfail" ]; then
2084 local var=$(node_var_name $client)_load
2085 start_client_load $client ${!var}
2086 echo "Restarted client load ${!var}: on $client. Checking ..."
2087 check_client_load $client
2089 if [ "$rc" != 0 ]; then
2090 log "Client load failed to restart on node $client, rc=$rc"
2091 # failure one client load means test fail
2092 # we do not need to check other
2101 # Start vmstat and save its process ID in a file.
2106 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2109 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
2110 2>/dev/null </dev/null & echo \\\$! > $pid_file"
2113 # Display the nodes on which client loads failed.
2114 print_end_run_file() {
2118 [ -s $file ] || return 0
2120 echo "Found the END_RUN_FILE file: $file"
2123 # A client load will stop if it finds the END_RUN_FILE file.
2124 # That does not mean the client load actually failed though.
2125 # The first node in END_RUN_FILE is the one we are interested in.
2128 if [ -n "$node" ]; then
2129 local var=$(node_var_name $node)_load
2131 local prefix=$TESTLOG_PREFIX
2132 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2133 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2134 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2136 echo "Client load ${!var} failed on node $node:"
2142 # Stop the process which had its PID saved in a file.
2147 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2149 do_nodes $nodes "test -f $pid_file &&
2150 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2153 # Stop all client loads.
2154 stop_client_loads() {
2155 local nodes=${1:-$CLIENTS}
2158 # stop the client loads
2159 stop_process $nodes $pid_file
2161 # clean up the processes that started them
2162 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
2164 # End recovery-scale functions
2166 # verify that lustre actually cleaned up properly
2168 VAR=$(lctl get_param -n catastrophe 2>&1)
2169 if [ $? = 0 ] ; then
2170 if [ $VAR != 0 ]; then
2171 error "LBUG/LASSERT detected"
2174 BUSY=$(dmesg | grep -i destruct || true)
2175 if [ -n "$BUSY" ]; then
2177 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2181 check_mem_leak || exit 204
2183 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2184 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2187 if module_loaded lnet || module_loaded libcfs; then
2188 echo "$TESTSUITE: modules still loaded..." 1>&2
2197 if [[ "$1" == "--verbose" ]]; then
2212 PREV_RESULT=$(do_node $node "$TEST")
2214 RESULT=$(do_node $node "$TEST")
2215 if [[ "$RESULT" == "$FINAL" ]]; then
2216 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2217 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2221 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2222 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2226 [[ $WAIT -ge $MAX ]] && break
2227 [[ $((WAIT % print)) -eq 0 ]] &&
2228 echo "Waiting $((MAX - WAIT)) secs for update"
2229 WAIT=$((WAIT + sleep))
2232 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2236 wait_update_facet() {
2238 [ "$1" = "--verbose" ] && verbose="$1" && shift
2242 wait_update $verbose $(facet_active_host $facet) "$@"
2246 do_nodes $(comma_list $(mdts_nodes)) \
2247 "lctl set_param -n osd*.*MDT*.force_sync=1"
2248 do_nodes $(comma_list $(osts_nodes)) \
2249 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
2250 grep -v 'Found no match'
2254 # the occupied disk space will be released
2255 # only after DMUs are committed
2256 if [[ $(facet_fstype $1) == zfs ]]; then
2257 echo "sleep $2 for ZFS OSD"
2262 wait_delete_completed_mds() {
2263 local MAX_WAIT=${1:-20}
2264 # for ZFS, waiting more time for DMUs to be committed
2265 local ZFS_WAIT=${2:-5}
2267 local stime=$(date +%s)
2272 # find MDS with pending deletions
2273 for node in $(mdts_nodes); do
2274 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2275 2>/dev/null | calc_sum)
2276 if [[ $changes -eq 0 ]]; then
2279 mds2sync="$mds2sync $node"
2281 if [ -z "$mds2sync" ]; then
2282 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2285 mds2sync=$(comma_list $mds2sync)
2287 # sync MDS transactions
2288 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2290 # wait till all changes are sent and commmitted by OSTs
2291 # for ldiskfs space is released upon execution, but DMU
2292 # do this upon commit
2295 while [[ $WAIT -ne $MAX_WAIT ]]; do
2296 changes=$(do_nodes $mds2sync \
2297 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2298 #echo "$node: $changes changes on all"
2299 if [[ $changes -eq 0 ]]; then
2300 wait_zfs_commit $SINGLEMDS $ZFS_WAIT
2308 echo "Delete is not completed in $((etime - stime)) seconds"
2309 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2315 # we can use "for" here because we are waiting the slowest
2316 for host in ${hostlist//,/ }; do
2317 check_network "$host" 900
2319 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2326 for facet in ${facetlist//,/ }; do
2327 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2329 wait_for_host $hostlist
2332 _wait_recovery_complete () {
2335 # Use default policy if $2 is not passed by caller.
2336 local MAX=${2:-$(max_recovery_time)}
2341 while [ $WAIT -lt $MAX ]; do
2342 STATUS=$(lctl get_param -n $param | grep status)
2344 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2347 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2349 echo "$param recovery not done in $MAX sec. $STATUS"
2353 wait_recovery_complete () {
2356 # with an assumption that at_max is the same on all nodes
2357 local MAX=${2:-$(max_recovery_time)}
2360 if [ "$FAILURE_MODE" = HARD ]; then
2361 facets=$(facets_on_host $(facet_active_host $facet))
2363 echo affected facets: $facets
2365 # we can use "for" here because we are waiting the slowest
2366 for facet in ${facets//,/ }; do
2367 local var_svc=${facet}_svc
2368 local param="*.${!var_svc}.recovery_status"
2370 local host=$(facet_active_host $facet)
2371 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2375 wait_mds_ost_sync () {
2376 # just because recovery is done doesn't mean we've finished
2377 # orphan cleanup. Wait for llogs to get synchronized.
2378 echo "Waiting for orphan cleanup..."
2379 # MAX value includes time needed for MDS-OST reconnection
2380 local MAX=$(( TIMEOUT * 2 ))
2381 local WAIT_TIMEOUT=${1:-$MAX}
2384 local list=$(comma_list $(mdts_nodes))
2385 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2386 if ! do_facet $SINGLEMDS \
2387 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2389 # old way, use mds_sync
2391 list=$(comma_list $(osts_nodes))
2392 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2395 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2396 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2397 local -a sync=($(do_nodes $list "$cmd"))
2400 for ((i=0; i<${#sync[@]}; i++)); do
2402 [ ${sync[$i]} -eq 1 ] && continue
2404 [ ${sync[$i]} -eq 0 ] && continue
2406 # there is a not finished MDS-OST synchronization
2410 sleep 2 # increase waiting time and cover statfs cache
2411 [ ${con} -eq 1 ] && return 0
2412 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2416 # show which nodes are not finished.
2417 do_nodes $list "$cmd"
2418 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2422 # Wait OSTs to be active on both client and MDT side.
2424 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
2425 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
2426 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
2427 error "wait_update OSTs up on client failed"
2429 cmd="$LCTL get_param -n lod.$FSNAME-MDT*-*.target_obd | sort -u |
2430 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
2431 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
2432 error "wait_update OSTs up on MDT failed"
2435 wait_destroy_complete () {
2436 echo "Waiting for local destroys to complete"
2437 # MAX value shouldn't be big as this mean server responsiveness
2438 # never increase this just to make test pass but investigate
2439 # why it takes so long time
2442 while [ $WAIT -lt $MAX ]; do
2443 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2447 for ((i=0; i<${#RPCs[@]}; i++)); do
2448 [ ${RPCs[$i]} -eq 0 ] && continue
2449 # there are still some destroy RPCs in flight
2454 [ ${con} -eq 1 ] && return 0 # done waiting
2455 echo "Waiting ${WAIT}s for local destroys to complete"
2458 echo "Local destroys weren't done in $MAX sec."
2462 wait_delete_completed() {
2463 wait_delete_completed_mds $1 || return $?
2464 wait_destroy_complete
2473 # conf-sanity 31 takes a long time cleanup
2474 while [ $WAIT -lt 300 ]; do
2475 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2476 [ -z "${running}" ] && return 0
2477 echo "waited $WAIT for${running}"
2478 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2480 WAIT=$((WAIT + INTERVAL))
2482 echo "service didn't stop after $WAIT seconds. Still running:"
2487 wait_remote_prog () {
2493 [ "$PDSH" = "no_dsh" ] && return 0
2495 while [ $WAIT -lt $2 ]; do
2496 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2497 [ -z "${running}" ] && return 0 || true
2498 echo "waited $WAIT for: "
2500 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2502 WAIT=$((WAIT + INTERVAL))
2504 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2505 [ -z "$pids" ] && return 0
2506 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2507 # FIXME: not portable
2508 for pid in $pids; do
2509 cat /proc/${pid}/status || true
2510 cat /proc/${pid}/wchan || true
2512 kill -9 $pid || true
2521 local clients=${1:-$CLIENTS}
2523 if [ -z "$clients" ]; then
2526 $PDSH $clients "$LFS df $MOUNT" > /dev/null
2532 # not every config has many clients
2538 # usually checked on particular client or locally
2547 client_reconnect_try() {
2548 local f=$MOUNT/recon
2551 if [ -z "$CLIENTS" ]; then
2552 $LFS df $MOUNT; uname -n >> $f
2554 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
2556 echo "Connected clients: $(cat $f)"
2557 ls -l $f > /dev/null
2561 client_reconnect() {
2562 # one client_reconnect_try call does not always do the job...
2564 client_reconnect_try && break
2569 affected_facets () {
2572 local host=$(facet_active_host $facet)
2573 local affected=$facet
2575 if [ "$FAILURE_MODE" = HARD ]; then
2576 affected=$(facets_up_on_host $host)
2582 local E2FSCK_ON_MDT0=false
2583 if [ "$1" == "--fsck" ]; then
2585 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2597 #Because it will only get up facets, we need get affected
2598 #facets before shutdown
2599 #For HARD Failure mode, it needs make sure facets on the same
2600 #HOST will only be shutdown and reboot once
2601 for facet in ${facets//,/ }; do
2602 local affected_facet
2604 #check whether facet has been included in other affected facets
2605 for ((index=0; index<$total; index++)); do
2606 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2609 if [ $skip -eq 0 ]; then
2610 affecteds[$total]=$(affected_facets $facet)
2615 for ((index=0; index<$total; index++)); do
2616 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2617 local host=$(facet_active_host $facet)
2618 echo "Failing ${affecteds[index]} on $host"
2619 shutdown_facet $facet
2622 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
2623 $(mdsdevname 1) "-n" || error "Running e2fsck")
2625 for ((index=0; index<$total; index++)); do
2626 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2627 echo reboot facets: ${affecteds[index]}
2631 change_active ${affecteds[index]}
2633 wait_for_facet ${affecteds[index]}
2634 # start mgs first if it is affected
2635 if ! combined_mgs_mds &&
2636 list_member ${affecteds[index]} mgs; then
2637 mount_facet mgs || error "Restart of mgs failed"
2639 # FIXME; has to be changed to mount all facets concurrently
2640 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2641 echo mount facets: ${affecteds[index]}
2642 mount_facets ${affecteds[index]}
2652 do_facet $facet "sync; sync; sync"
2655 # make sure there will be no seq change
2656 local clients=${CLIENTS:-$HOSTNAME}
2657 local f=fsa-\\\$\(hostname\)
2658 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2659 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2661 local svc=${facet}_svc
2662 do_facet $facet $LCTL --device ${!svc} notransno
2664 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2665 # in-memory state has to be cleared by either rebooting the host or
2666 # exporting and reimporting the pool.
2668 # Although the uberblocks are not updated when a pool is freezed,
2669 # transactions are still written to the disks. Modified blocks may be
2670 # cached in memory when tests try reading them back. The
2671 # export-and-reimport process also evicts any cached pool data from
2672 # memory to provide the correct "data loss" semantics.
2674 # In the test framework, the exporting and importing operations are
2675 # handled by stop() and mount_facet() separately, which are used
2676 # inside fail() and fail_abort().
2678 do_facet $facet $LCTL --device ${!svc} readonly
2679 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2680 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2683 replay_barrier_nodf() {
2684 local facet=$1 echo running=${running}
2685 do_facet $facet "sync; sync; sync"
2686 local svc=${facet}_svc
2687 echo Replay barrier on ${!svc}
2688 do_facet $facet $LCTL --device ${!svc} notransno
2689 do_facet $facet $LCTL --device ${!svc} readonly
2690 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2691 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2694 replay_barrier_nosync() {
2695 local facet=$1 echo running=${running}
2696 local svc=${facet}_svc
2697 echo Replay barrier on ${!svc}
2698 do_facet $facet $LCTL --device ${!svc} notransno
2699 do_facet $facet $LCTL --device ${!svc} readonly
2700 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2701 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2705 # Get Lustre client uuid for a given Lustre mount point.
2708 local mntpnt=${1:-$MOUNT}
2710 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2711 local uuid=$($LCTL get_param -n llite.$name.uuid)
2716 mds_evict_client() {
2717 local mntpnt=${1:-$MOUNT}
2718 local uuid=$(get_client_uuid $mntpnt)
2720 do_facet $SINGLEMDS \
2721 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2724 ost_evict_client() {
2725 local mntpnt=${1:-$MOUNT}
2726 local uuid=$(get_client_uuid $mntpnt)
2729 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2734 local clients=${CLIENTS:-$HOSTNAME}
2736 facet_failover $* || error "failover: $?"
2737 wait_clients_import_state "$clients" "$facets" FULL
2738 clients_up || error "post-failover stat: $?"
2743 facet_failover $facet
2749 change_active $facet
2750 wait_for_facet $facet
2751 mount_facet $facet -o abort_recovery
2752 clients_up || echo "first stat failed: $?"
2753 clients_up || error "post-failover stat: $?"
2757 echo There is no lmc. This is mountconf, baby.
2761 host_nids_address() {
2765 if [ -n "$kind" ]; then
2766 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2768 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2774 if [ "$1" = "'*'" ]; then echo \'*\'; else
2780 if [ "$1" = "'*'" ]; then echo \'*\'; else
2781 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2783 if [ -z "$ID" ]; then
2784 echo "Could not get a ptl id for $1..."
2793 h2name_or_ip "$1" "tcp"
2798 if [ "$1" = "'*'" ]; then echo \'*\'; else
2799 if type __h2elan >/dev/null 2>&1; then
2802 ID=`echo $1 | sed 's/[^0-9]*//g'`
2810 h2name_or_ip "$1" "o2ib"
2814 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2815 # expressions format. As a bonus we can then just pass in those variables
2816 # to pdsh. What this function does is take a HOSTLIST type string and
2817 # expand it into a space deliminated list for us.
2825 [ -z "$hostlist" ] && return
2827 # Translate the case of [..],..,[..] to [..] .. [..]
2828 list="${hostlist/],/] }"
2830 [[ "$front" == *,* ]] && {
2833 list=${list/${old}/${new}}
2836 for item in $list; do
2837 # Test if we have any []'s at all
2838 if [ "$item" != "${item/\[/}" ]; then {
2839 # Expand the [*] into list
2843 if [ "$name" != "$item" ]; then
2844 group=${item#$name[*}
2847 for range in ${group//,/ }; do
2853 # Number of leading zeros
2856 end=$(echo $end | sed 's/0*//')
2857 [[ -z "$end" ]] && end=0
2858 [[ $padlen2 -gt $padlen ]] && {
2859 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2862 begin=$(echo $begin | sed 's/0*//')
2863 [ -z $begin ] && begin=0
2865 if [ ! -z "${begin##[!0-9]*}" ]; then
2866 order=$(seq -f "%0${padlen}g" $begin $end)
2868 order=$(eval echo {$begin..$end});
2871 for num in $order; do
2872 value="${name#*,}${num}${back}"
2873 [ "$value" != "${value/\[/}" ] && {
2874 value=$(hostlist_expand "$value")
2876 myList="$myList $value"
2881 myList="$myList $item"
2884 myList=${myList//,/ }
2885 myList=${myList:1} # Remove first character which is a space
2887 # Filter any duplicates without sorting
2889 myList="${list%% *}"
2891 while [[ "$list" != ${myList##* } ]]; do
2892 local tlist=" $list"
2893 list=${tlist// ${list%% *} / }
2895 myList="$myList ${list%% *}"
2897 myList="${myList%* }";
2899 # We can select an object at an offset in the list
2902 for item in $myList; do
2904 [ $cnt -eq $offset ] && {
2908 [ $(get_node_count $myList) -ne 1 ] && myList=""
2917 [ "$facet" == client ] && echo -n $HOSTNAME && return
2918 varname=${facet}_HOST
2919 if [ -z "${!varname}" ]; then
2920 if [ "${facet:0:3}" == "ost" ]; then
2921 local fh=${facet%failover}_HOST
2922 eval export ${facet}_HOST=${!fh}
2923 if [ -z "${!varname}" ]; then
2924 eval export ${facet}_HOST=${ost_HOST}
2926 elif [ "${facet:0:3}" == "mdt" -o \
2927 "${facet:0:3}" == "mds" -o \
2928 "${facet:0:3}" == "mgs" ]; then
2929 eval export ${facet}_HOST=${mds_HOST}
2935 facet_failover_host() {
2939 var=${facet}failover_HOST
2940 if [ -n "${!var}" ]; then
2945 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2946 "${facet:0:3}" == "mgs" ]; then
2948 eval export ${facet}failover_host=${mds_HOST}
2953 if [[ $facet == ost* ]]; then
2954 eval export ${facet}failover_host=${ost_HOST}
2962 local activevar=${facet}active
2964 if [ -f $TMP/${facet}active ] ; then
2965 source $TMP/${facet}active
2968 active=${!activevar}
2969 if [ -z "$active" ] ; then
2976 facet_active_host() {
2977 facet_host $(facet_active $1)
2980 # Get the passive failover partner host of facet.
2981 facet_passive_host() {
2983 [[ $facet = client ]] && return
2985 local host=${facet}_HOST
2986 local failover_host=${facet}failover_HOST
2987 local active_host=$(facet_active_host $facet)
2989 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2991 if [[ $active_host = ${!host} ]]; then
2992 echo -n ${!failover_host}
3002 facetlist=$(exclude_items_from_list $facetlist mgs)
3004 for facet in ${facetlist//,/ }; do
3005 local failover=${facet}failover
3006 local host=`facet_host $failover`
3007 [ -z "$host" ] && return
3009 local curactive=`facet_active $facet`
3010 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
3011 eval export ${facet}active=$facet
3013 eval export ${facet}active=$failover
3015 # save the active host for this facet
3016 local activevar=${facet}active
3017 echo "$activevar=${!activevar}" > $TMP/$activevar
3018 [[ $facet = mds1 ]] && combined_mgs_mds && \
3019 echo "mgsactive=${!activevar}" > $TMP/mgsactive
3020 local TO=`facet_active_host $facet`
3021 echo "Failover $facet to $TO"
3027 # do not stripe off hostname if verbose, bug 19215
3028 if [ x$1 = x--verbose ]; then
3036 if [ "$HOST" = "$HOSTNAME" ]; then
3038 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
3039 echo "cannot run remote command on $HOST with $myPDSH"
3043 echo "CMD: $HOST $@" >&2
3044 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3047 if [ "$myPDSH" = "rsh" ]; then
3048 # we need this because rsh does not return exit code of an executed command
3049 local command_status="$TMP/cs"
3050 rsh $HOST ":> $command_status"
3051 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
3052 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
3053 echo command failed >$command_status"
3054 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
3059 # print HOSTNAME for myPDSH="no_dsh"
3060 if [[ $myPDSH = no_dsh ]]; then
3061 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
3063 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
3066 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
3068 return ${PIPESTATUS[0]}
3072 do_node --verbose "$@"
3075 single_local_node () {
3076 [ "$1" = "$HOSTNAME" ]
3079 # Outputs environment variable assignments that should be passed to remote nodes
3083 local facets=$(get_facets)
3086 for var in ${!MODOPTS_*}; do
3087 value=${!var//\"/\\\"}
3088 echo -n " ${var}=\"$value\""
3091 for facet in ${facets//,/ }; do
3093 if [ -n "${!var}" ]; then
3094 echo -n " $var=${!var}"
3098 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
3099 if [ -n "${!var}" ]; then
3100 echo -n " $var=${!var}"
3104 for var in VERBOSE; do
3105 if [ -n "${!var}" ]; then
3106 echo -n " $var=${!var}"
3110 if [ -n "$FSTYPE" ]; then
3111 echo -n " FSTYPE=$FSTYPE"
3114 for var in LNETLND NETTYPE; do
3115 if [ -n "${!var}" ]; then
3116 echo -n " $var=${!var}"
3123 # do not stripe off hostname if verbose, bug 19215
3124 if [ x$1 = x--verbose ]; then
3132 if single_local_node $rnodes; then
3134 do_nodev $rnodes "$@"
3136 do_node $rnodes "$@"
3141 # This is part from do_node
3144 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
3145 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
3147 export FANOUT=$(get_node_count "${rnodes//,/ }")
3149 echo "CMD: $rnodes $@" >&2
3150 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3153 # do not replace anything from pdsh output if -N is used
3154 # -N Disable hostname: prefix on lines of output.
3155 if $verbose || [[ $myPDSH = *-N* ]]; then
3156 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
3158 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
3160 return ${PIPESTATUS[0]}
3164 # Execute commands on a single service's host
3166 # The \a facet (service) may be on a local or remote node, which is
3167 # determined at the time the command is run.
3169 # usage: do_facet $facet command [arg ...]
3173 local HOST=$(facet_active_host $facet)
3174 [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
3178 # Function: do_facet_random_file $FACET $FILE $SIZE
3179 # Creates FILE with random content on the given FACET of given SIZE
3181 do_facet_random_file() {
3185 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
3186 do_facet $facet "$cmd 2>/dev/null"
3189 do_facet_create_file() {
3193 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
3194 do_facet $facet "$cmd 2>/dev/null"
3198 do_nodes --verbose "$@"
3204 # make sure its not already running
3206 rm -f $TMP/${facet}active
3207 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
3208 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
3210 if [[ $(facet_fstype $facet) == zfs ]]; then
3212 # After formatting a ZFS target, "cachefile=none" property will
3213 # be set on the ZFS storage pool so that the pool is not
3214 # automatically imported on system startup. And then the pool
3215 # will be exported so as to leave the importing and exporting
3216 # operations handled by mount_facet() and stop() separately.
3218 refresh_partition_table $facet $(facet_vdevice $facet)
3219 disable_zpool_cache $facet
3224 # Device formatted as ost
3227 local DEVNAME=OSTDEV$num
3229 local fstype=$(facet_fstype ost$num)
3233 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
3234 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3236 #try $OSTZFSDEVn - independent of vdev
3237 DEVNAME=OSTZFSDEV$num
3238 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
3240 error "unknown fstype!";;
3246 # Physical device location of data
3252 local fstype=$(facet_fstype ost$num)
3256 # vdevs are not supported by ldiskfs
3259 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3260 # Device formatted by zfs
3262 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3264 error "unknown fstype!";;
3270 # Logical device formatted for lustre
3273 local DEVNAME=MDSDEV$num
3275 local fstype=$(facet_fstype mds$num)
3279 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3280 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3282 # try $MDSZFSDEVn - independent of vdev
3283 DEVNAME=MDSZFSDEV$num
3284 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3286 error "unknown fstype!";;
3292 # Physical location of data
3296 local fstype=$(facet_fstype mds$num)
3300 # vdevs are not supported by ldiskfs
3303 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3304 # Device formatted by ZFS
3305 local DEVNAME=MDSDEV$num
3306 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3308 error "unknown fstype!";;
3316 local fstype=$(facet_fstype mgs)
3320 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3321 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3322 DEVPTR=$(mdsdevname 1)
3327 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3328 ( [ -z "$MGSZFSDEV" ] &&
3329 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3330 DEVPTR=$(mdsdevname 1)
3332 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3335 error "unknown fstype!";;
3344 local fstype=$(facet_fstype mgs)
3348 # vdevs are not supported by ldiskfs
3351 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3352 ( [ -z "$MGSDEV" ] &&
3353 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3354 VDEVPTR=$(mdsvdevname 1)
3355 elif [ -n "$MGSDEV" ]; then
3359 error "unknown fstype!";;
3367 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3369 local var=${facet}_MOUNT
3370 eval mntpt=${!var:-${MOUNT}-$facet}
3377 local dev=$(facet_device $facet)
3378 local mnt=${2:-$(facet_mntpt $facet)}
3381 if ! do_facet $facet test -b $dev; then
3384 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3389 local dev=$(facet_device $facet)
3390 local mnt=${2:-$(facet_mntpt $facet)}
3392 do_facet $facet $UMOUNT $mnt
3396 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3401 local ds=$(facet_device $facet)
3402 local mnt=${2:-$(facet_mntpt $facet)}
3407 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3408 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3409 do_facet $facet $ZFS set canmount=noauto $ds
3411 # The "legacy" mount method is used here because "zfs unmount $mnt"
3412 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3413 # targets are not available at the time, the stat(2) on $MOUNT will
3416 do_facet $facet $ZFS set mountpoint=legacy $ds
3417 do_facet $facet mount -t zfs $ds $mnt
3418 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3419 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3424 local ds=$(facet_device $facet)
3425 local mnt=${2:-$(facet_mntpt $facet)}
3426 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3427 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3428 local mntpt=${!var_mntpt}
3429 local canmnt=${!var_canmnt}
3433 do_facet $facet umount $mnt
3434 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3435 do_facet $facet $ZFS set canmount=$canmnt $ds
3442 local fstype=$(facet_fstype $facet)
3444 mount_$fstype $facet $mnt
3450 local fstype=$(facet_fstype $facet)
3452 unmount_$fstype $facet $mnt
3459 # make sure we are using the primary server, so test-framework will
3460 # be able to clean up properly.
3461 activemds=`facet_active mds1`
3462 if [ $activemds != "mds1" ]; then
3466 local clients=$CLIENTS
3467 [ -z $clients ] && clients=$(hostname)
3469 zconf_umount_clients $clients $MOUNT "$*" || true
3470 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3472 [ -n "$CLIENTONLY" ] && return
3474 # The add fn does rm ${facet}active file, this would be enough
3475 # if we use do_facet <facet> only after the facet added, but
3476 # currently we use do_facet mds in local.sh
3477 for num in `seq $MDSCOUNT`; do
3479 rm -f ${TMP}/mds${num}active
3481 combined_mgs_mds && rm -f $TMP/mgsactive
3483 for num in `seq $OSTCOUNT`; do
3485 rm -f $TMP/ost${num}active
3488 if ! combined_mgs_mds ; then
3495 cleanup_echo_devs () {
3498 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3500 for dev in $devs; do
3501 $LCTL --device $dev cleanup
3502 $LCTL --device $dev detach
3507 nfs_client_mode && return
3508 cifs_client_mode && return
3517 combined_mgs_mds () {
3518 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3519 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3523 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3527 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3533 local fsname=${3:-"$FSNAME"}
3534 local type=$(facet_type $facet)
3535 local index=$(facet_index $facet)
3536 local fstype=$(facet_fstype $facet)
3537 local host=$(facet_host $facet)
3542 if [ $type == MGS ] || ( [ $type == MDS ] &&
3543 [ "$dev" == $(mgsdevname) ] &&
3544 [ "$host" == "$(facet_host mgs)" ] ); then
3547 opts="--mgsnode=$MGSNID"
3550 if [ $type != MGS ]; then
3551 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3555 var=${facet}failover_HOST
3556 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3557 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3560 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3561 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3563 if [ $type == MDS ]; then
3564 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3565 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3566 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3567 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3569 if [ $fstype == ldiskfs ]; then
3570 # Check for wide striping
3571 if [ $OSTCOUNT -gt 160 ]; then
3572 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3573 fs_mkfs_opts+="-O large_xattr"
3577 if [ -n "${!var}" ]; then
3578 fs_mkfs_opts+=" -J device=${!var}"
3580 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3582 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3586 if [ $type == OST ]; then
3587 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3589 if [ $fstype == ldiskfs ]; then
3591 if [ -n "${!var}" ]; then
3592 fs_mkfs_opts+=" -J device=${!var}"
3594 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3599 opts+=" --backfstype=$fstype"
3602 if [ -n "${!var}" ]; then
3603 opts+=" --device-size=${!var}"
3606 var=$(upper $fstype)_MKFS_OPTS
3607 fs_mkfs_opts+=${!var:+" ${!var}"}
3609 var=${type}_FS_MKFS_OPTS
3610 fs_mkfs_opts+=${!var:+" ${!var}"}
3612 if [ -n "${fs_mkfs_opts## }" ]; then
3613 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3617 opts+=${!var:+" ${!var}"}
3624 local type=$(facet_type $facet)
3625 local var=${type}_MOUNT_FS_OPTS
3627 if [ -n "${!var}" ]; then
3628 opts+=" --mountfsoptions=${!var}"
3633 check_ost_indices() {
3634 local index_count=${#OST_INDICES[@]}
3635 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
3637 # OST count is greater than the index count in $OST_INDEX_LIST.
3638 # We need check whether there are duplicate indices.
3642 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
3643 index=$(facet_index ost$i)
3644 for j in $(seq 0 $((index_count - 1))); do
3645 [[ $index -ne ${OST_INDICES[j]} ]] ||
3646 error "ost$i has the same index $index as ost$((j+1))"
3657 echo "Format mgs: $(mgsdevname)"
3658 reformat_external_journal mgs
3659 add mgs $(mkfs_opts mgs $(mgsdevname)) $(mountfs_opts mgs) --reformat \
3660 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
3670 echo "Format mds$num: $(mdsdevname $num)"
3671 reformat_external_journal mds$num
3672 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3673 $(mountfs_opts mds$num) --reformat $(mdsdevname $num) \
3674 $(mdsvdevname $num) ${quiet:+>/dev/null} || exit 10
3683 echo "Format ost$num: $(ostdevname $num)"
3684 reformat_external_journal ost$num
3685 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3686 $(mountfs_opts ost$num) --reformat $(ostdevname $num) \
3687 $(ostvdevname ${num}) ${quiet:+>/dev/null} || exit 10
3692 # Set hostid for ZFS/SPL zpool import protection
3693 # (Assumes MDS version is also OSS version)
3694 if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ];
3696 do_rpc_nodes "$(comma_list $(remote_nodes_list))" set_hostid
3699 # We need ldiskfs here, may as well load them all
3701 [ -n "$CLIENTONLY" ] && return
3702 echo Formatting mgs, mds, osts
3703 if ! combined_mgs_mds ; then
3707 for num in $(seq $MDSCOUNT); do
3711 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
3713 for num in $(seq $OSTCOUNT); do
3719 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3723 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3727 # 0: success, the old identity set already.
3728 # 1: success, the old identity does not set.
3733 local j=`expr $num - 1`
3734 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3736 if [ -z "$MDT" ]; then
3740 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3743 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3745 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3748 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3750 if [ $old = "NONE" ]; then
3759 zconf_umount `hostname` $1 || error "umount failed"
3760 zconf_mount `hostname` $1 || error "mount failed"
3768 rm -f $TMP/${facet}active
3769 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3774 local mdt_count=${1:-$MDSCOUNT}
3775 local ost_count=${2:-$OSTCOUNT}
3778 for num in $(seq $mdt_count); do
3779 DEVNAME=$(mdsdevname $num)
3780 writeconf_facet mds$num $DEVNAME || rc=$?
3783 for num in $(seq $ost_count); do
3784 DEVNAME=$(ostdevname $num)
3785 writeconf_facet ost$num $DEVNAME || rc=$?
3793 nfs_client_mode && return
3794 cifs_client_mode && return
3796 sanity_mount_check || error "environments are insane!"
3800 if [ -z "$CLIENTONLY" ]; then
3801 echo Setup mgs, mdt, osts
3802 echo $WRITECONF | grep -q "writeconf" && writeconf_all
3803 if ! combined_mgs_mds ; then
3804 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3807 for num in `seq $MDSCOUNT`; do
3808 DEVNAME=$(mdsdevname $num)
3809 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3811 # We started mds, now we should set failover variables properly.
3812 # Set mds${num}failover_HOST if it is not set (the default failnode).
3813 local varname=mds${num}failover_HOST
3814 if [ -z "${!varname}" ]; then
3815 eval mds${num}failover_HOST=$(facet_host mds$num)
3818 if [ $IDENTITY_UPCALL != "default" ]; then
3819 switch_identity $num $IDENTITY_UPCALL
3822 for num in `seq $OSTCOUNT`; do
3823 DEVNAME=$(ostdevname $num)
3824 start ost$num $DEVNAME $OST_MOUNT_OPTS
3826 # We started ost$num, now we should set ost${num}failover variable properly.
3827 # Set ost${num}failover_HOST if it is not set (the default failnode).
3828 varname=ost${num}failover_HOST
3829 if [ -z "${!varname}" ]; then
3830 eval ost${num}failover_HOST=$(facet_host ost${num})
3838 # wait a while to allow sptlrpc configuration be propogated to targets,
3839 # only needed when mounting new target devices.
3844 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3846 if [ ! -z $arg1 ]; then
3847 [ "$arg1" = "server_only" ] && return
3851 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3854 if [ "$MOUNT_2" ]; then
3855 mount_client $MOUNT2
3856 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3861 # by remounting mdt before ost, initial connect from mdt to ost might
3862 # timeout because ost is not ready yet. wait some time to its fully
3863 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3864 # by a context negotiation rpc with $TIMEOUT.
3865 # FIXME better by monitoring import status.
3868 sleep $((TIMEOUT + 5))
3874 mounted_lustre_filesystems() {
3875 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3878 init_facet_vars () {
3879 [ -n "$CLIENTONLY" ] && return 0
3886 eval export ${facet}_dev=${device}
3887 eval export ${facet}_opt=\"$@\"
3889 local dev=${facet}_dev
3891 # We need to loop for the label
3892 # in case its not initialized yet.
3893 for wait_time in {0,1,3,5,10}; do
3895 if [ $wait_time -gt 0 ]; then
3896 echo "${!dev} not yet initialized,"\
3897 "waiting ${wait_time} seconds."
3901 local label=$(devicelabel ${facet} ${!dev})
3903 # Check to make sure the label does
3904 # not include ffff at the end of the label.
3905 # This indicates it has not been initialized yet.
3907 if [[ $label =~ [f|F]{4}$ ]]; then
3908 # label is not initialized, unset the result
3909 # and either try again or fail
3916 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3918 eval export ${facet}_svc=${label}
3920 local varname=${facet}failover_HOST
3921 if [ -z "${!varname}" ]; then
3922 eval export $varname=$(facet_host $facet)
3925 varname=${facet}_HOST
3926 if [ -z "${!varname}" ]; then
3927 eval export $varname=$(facet_host $facet)
3930 # ${facet}failover_dev is set in cfg file
3931 varname=${facet}failover_dev
3932 if [ -n "${!varname}" ] ; then
3933 eval export ${facet}failover_dev=${!varname}
3935 eval export ${facet}failover_dev=$device
3938 # get mount point of already mounted device
3939 # is facet_dev is already mounted then use the real
3940 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3941 # i.e. ${facet}_MOUNT if specified by user or default
3942 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3943 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3944 if [ -z $mntpt ]; then
3945 mntpt=$(facet_mntpt $facet)
3947 eval export ${facet}_MOUNT=$mntpt
3950 init_facets_vars () {
3953 if ! remote_mds_nodsh; then
3954 for num in $(seq $MDSCOUNT); do
3955 DEVNAME=`mdsdevname $num`
3956 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3960 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3962 if ! remote_ost_nodsh; then
3963 for num in $(seq $OSTCOUNT); do
3964 DEVNAME=$(ostdevname $num)
3965 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3970 osc_ensure_active () {
3975 while [ $period -lt $timeout ]; do
3976 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3977 if [ $count -eq 0 ]; then
3981 echo "There are $count OST are inactive, wait $period seconds, and try again"
3983 period=$((period+3))
3986 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3989 set_conf_param_and_check() {
3993 local ORIG=$(do_facet $myfacet "$TEST")
3994 if [ $# -gt 3 ]; then
4000 echo "Setting $PARAM from $ORIG to $FINAL"
4001 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
4002 error "conf_param $PARAM failed"
4004 wait_update_facet $myfacet "$TEST" "$FINAL" ||
4005 error "check $PARAM failed!"
4008 init_param_vars () {
4009 TIMEOUT=$(lctl get_param -n timeout)
4010 TIMEOUT=${TIMEOUT:-20}
4012 remote_mds_nodsh && log "Using TIMEOUT=$TIMEOUT" && return 0
4014 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
4015 log "Using TIMEOUT=$TIMEOUT"
4017 osc_ensure_active $SINGLEMDS $TIMEOUT
4018 osc_ensure_active client $TIMEOUT
4020 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
4021 local current_jobid_var=$($LCTL get_param -n jobid_var)
4023 if [ $JOBID_VAR = "existing" ]; then
4024 echo "keeping jobstats as $current_jobid_var"
4025 elif [ $current_jobid_var != $JOBID_VAR ]; then
4026 echo "seting jobstats to $JOBID_VAR"
4028 set_conf_param_and_check client \
4029 "$LCTL get_param -n jobid_var" \
4030 "$FSNAME.sys.jobid_var" $JOBID_VAR
4033 echo "jobstats not supported by server"
4036 if [ $QUOTA_AUTO -ne 0 ]; then
4037 if [ "$ENABLE_QUOTA" ]; then
4038 echo "enable quota as required"
4039 setup_quota $MOUNT || return 2
4041 echo "disable quota as required"
4042 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
4048 nfs_client_mode () {
4049 if [ "$NFSCLIENT" ]; then
4050 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
4051 local clients=$CLIENTS
4052 [ -z $clients ] && clients=$(hostname)
4054 # FIXME: remove hostname when 19215 fixed
4055 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
4056 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
4057 if [[ ${#nfsexport[@]} -eq 0 ]]; then
4058 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
4060 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
4066 cifs_client_mode () {
4067 [ x$CIFSCLIENT = xyes ] &&
4068 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
4071 check_config_client () {
4074 local mounted=$(mount | grep " $mntpt ")
4075 if [ -n "$CLIENTONLY" ]; then
4077 # CLIENTONLY should not depend on *_HOST settings
4078 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
4079 # in theory someone could create a new,
4080 # client-only config file that assumed lustre was already
4081 # configured and didn't set the MGSNID. If MGSNID is not set,
4082 # then we should use the mgs nid currently being used
4083 # as the default value. bug 18021
4084 [[ x$MGSNID = x ]] &&
4087 if [[ x$mgc != xMGC$MGSNID ]]; then
4088 if [ "$mgs_HOST" ]; then
4089 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
4090 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
4091 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
4097 local myMGS_host=$mgs_HOST
4098 if [ "$NETTYPE" = "ptl" ]; then
4099 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
4102 echo Checking config lustre mounted on $mntpt
4103 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
4104 mgshost=$(echo $mgshost | awk -F: '{print $1}')
4106 # if [ "$mgshost" != "$myMGS_host" ]; then
4107 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
4108 # Please use correct config or set mds_HOST correctly!"
4113 check_config_clients () {
4114 local clients=${CLIENTS:-$HOSTNAME}
4117 nfs_client_mode && return
4118 cifs_client_mode && return
4120 do_rpc_nodes "$clients" check_config_client $mntpt
4122 sanity_mount_check || error "environments are insane!"
4126 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
4127 local cltimeout=$(lctl get_param -n timeout)
4128 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
4129 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
4136 [ -z $mntpt ] && return 1
4137 local mounted=$(mounted_lustre_filesystems)
4139 echo $mounted' ' | grep -w -q $mntpt' '
4143 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
4147 # empty lustre filesystem may have empty directories lost+found and .lustre
4149 # exclude .lustre & lost+found
4150 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
4151 -print | wc -l) = 1 ] || return 1
4152 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
4153 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
4154 # exclude .lustre/fid (LU-2780)
4155 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
4156 -print | wc -l) = 1 ] || return 1
4158 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
4163 check_and_setup_lustre() {
4165 nfs_client_mode && return
4166 cifs_client_mode && return
4168 local MOUNTED=$(mounted_lustre_filesystems)
4172 # both MOUNT and MOUNT2 are not mounted
4173 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
4174 [ "$REFORMAT" = "yes" ] && formatall
4175 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
4177 is_mounted $MOUNT || error "NAME=$NAME not mounted"
4178 export I_MOUNTED=yes
4182 elif is_mounted $MOUNT2; then
4184 # MOUNT2 is mounted, while MOUNT_2 is not set
4185 if ! [ "$MOUNT_2" ]; then
4186 cleanup_mount $MOUNT2
4187 export I_UMOUNTED2=yes
4190 # MOUNT2 is mounted, MOUNT_2 is set
4192 # FIXME: what to do if check_config failed?
4194 # 1) remote client has mounted other Lustre fs ?
4195 # 2) it has insane env ?
4196 # let's try umount MOUNT2 on all clients and mount it again:
4197 if ! check_config_clients $MOUNT2; then
4198 cleanup_mount $MOUNT2
4199 restore_mount $MOUNT2
4200 export I_MOUNTED2=yes
4205 # MOUNT is mounted MOUNT2 is not mounted
4206 elif [ "$MOUNT_2" ]; then
4207 restore_mount $MOUNT2
4208 export I_MOUNTED2=yes
4212 # FIXME: what to do if check_config failed?
4214 # 1) remote client has mounted other Lustre fs?
4215 # 2) lustre is mounted on remote_clients atall ?
4216 check_config_clients $MOUNT
4220 set_default_debug_nodes $(comma_list $(nodes_list))
4223 if [ -z "$CLIENTONLY" -a $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ]; then
4225 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
4226 facets="$(get_facets OST)"
4227 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
4228 facets="$facets,$(get_facets MDS)"
4229 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
4230 facets="$facets,mgs"
4231 local nodes="$(facets_hosts ${facets})"
4232 if [ -n "$nodes" ] ; then
4233 do_nodes $nodes "$LCTL set_param \
4234 osd-ldiskfs.track_declares_assert=1 || true"
4243 if [ -z "$CLIENTONLY" ]; then
4244 # Enable remote MDT create for testing
4245 for num in $(seq $MDSCOUNT); do
4247 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
4252 if [ "$ONLY" == "setup" ]; then
4258 local clients=${CLIENTS:-$HOSTNAME}
4261 zconf_mount_clients $clients $mntpt
4265 local clients=${CLIENTS:-$HOSTNAME}
4268 zconf_umount_clients $clients $mntpt
4271 cleanup_and_setup_lustre() {
4272 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
4273 lctl set_param debug=0 || true
4275 if [ "$ONLY" == "cleanup" ]; then
4279 check_and_setup_lustre
4282 # Get all of the server target devices from a given server node and type.
4289 if [ "$type" == ost ]; then
4290 devs=$(get_osd_param $node "" mntdev)
4292 devs=$(do_node $node $LCTL get_param -n osd-*.$FSNAME-M*.mntdev)
4294 for dev in $devs; do
4296 *loop*) do_node $node "losetup $dev" | \
4297 sed -e "s/.*(//" -e "s/).*//" ;;
4303 # Get all of the server target devices.
4308 # Master MDS parameters used by lfsck
4309 MDTNODE=$(facet_active_host $SINGLEMDS)
4310 MDTDEV=$(echo $(get_mnt_devs $MDTNODE mdt) | awk '{print $1}')
4314 for node in $(mdts_nodes); do
4315 MDTDEVS[i]=$(get_mnt_devs $node mdt)
4321 for node in $(osts_nodes); do
4322 OSTDEVS[i]=$(get_mnt_devs $node ost)
4327 # Run e2fsck on MDT or OST device.
4332 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
4333 local log=$TMP/e2fsck.log
4337 do_node $node $cmd 2>&1 | tee $log
4339 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
4341 if [ $MDSCOUNT -gt 1 ]; then
4342 skip "DNE mode isn't supported!"
4346 error "It's not DNE mode."
4351 [ $rc -le $FSCK_MAX_ERR ] ||
4352 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4358 # Run resize2fs on MDT or OST device.
4367 do_facet $facet "$RESIZE2FS $opts $device $size"
4370 # verify a directory is shared among nodes.
4371 check_shared_dir() {
4373 local list=${2:-$(comma_list $(nodes_list))}
4375 [ -z "$dir" ] && return 1
4376 do_rpc_nodes "$list" check_logdir $dir
4377 check_write_access $dir "$list" || return 1
4382 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
4383 $LCTL set_param printk=+lfsck
4384 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
4386 for k in $(seq $MDSCOUNT); do
4387 # wait up to 10+1 minutes for LFSCK to complete
4388 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4389 mdd.$(facet_svc mds${k}).lfsck_layout |
4390 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
4391 error "MDS${k} layout isn't the expected 'completed'"
4392 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4393 mdd.$(facet_svc mds${k}).lfsck_namespace |
4394 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
4395 error "MDS${k} namespace isn't the expected 'completed'"
4397 local rep_mdt=$(do_nodes $(comma_list $(mdts_nodes)) \
4398 $LCTL get_param -n mdd.$FSNAME-*.lfsck_* |
4399 awk '/repaired/ { print $2 }' | calc_sum)
4400 local rep_ost=$(do_nodes $(comma_list $(osts_nodes)) \
4401 $LCTL get_param -n obdfilter.$FSNAME-*.lfsck_* |
4402 awk '/repaired/ { print $2 }' | calc_sum)
4403 local repaired=$((rep_mdt + rep_ost))
4404 [ $repaired -eq 0 ] ||
4405 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
4408 dump_file_contents() {
4414 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
4415 error_noexit false \
4416 "Invalid parameters for dump_file_contents()"
4419 for node in ${nodes}; do
4420 do_node $node "for i in \\\$(find $dir -type f); do
4421 echo ====\\\${i}=======================;
4423 done" >> ${logname}.${node}.log
4427 dump_command_output() {
4433 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
4434 error_noexit false \
4435 "Invalid parameters for dump_command_output()"
4439 for node in ${nodes}; do
4440 do_node $node "echo ====${cmd}=======================;
4441 $cmd" >> ${logname}.${node}.log
4448 # dump file contents from /proc/spl in case of zfs test
4449 if [ "$(facet_fstype ost1)" = "zfs" ]; then
4450 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
4451 dump_command_output \
4452 "$(osts_nodes)" "zpool events -v" "${logname}"
4455 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
4456 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
4457 dump_command_output \
4458 "$(mdts_nodes)" "zpool events -v" "${logname}"
4462 check_and_cleanup_lustre() {
4463 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "sanity-lfsck" -a \
4464 "$TESTSUITE" != "sanity-scrub" ]; then
4468 if is_mounted $MOUNT; then
4469 if $DO_CLEANUP; then
4470 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4471 error "remove sub-test dirs failed"
4475 [ "$ENABLE_QUOTA" ] && restore_quota || true
4478 if [ "$I_UMOUNTED2" = "yes" ]; then
4479 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4482 if [ "$I_MOUNTED2" = "yes" ]; then
4483 cleanup_mount $MOUNT2
4486 if [ "$I_MOUNTED" = "yes" ]; then
4487 cleanupall -f || error "cleanup failed"
4495 wait_for_function () {
4498 # suppress fn both stderr and stdout
4499 if [ "$1" = "--quiet" ]; then
4501 quiet=" > /dev/null 2>&1"
4513 eval $fn $quiet && return 0
4515 wait=$((wait + sleep))
4516 [ $wait -lt $max ] || return 1
4517 echo waiting $fn, $((max - wait)) secs left ...
4527 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4528 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4529 echo "Network not available!"
4533 echo `date +"%H:%M:%S (%s)"` network interface is UP
4541 # Convert a space-delimited list to a comma-delimited list. If the input is
4542 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4544 # echo is used to convert newlines to spaces, since it doesn't
4545 # introduce a trailing space as using "tr '\n' ' '" does
4546 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4552 echo $list | grep -qw $item
4555 # list, excluded are the comma separated lists
4556 exclude_items_from_list () {
4562 for item in ${excluded//,/ }; do
4563 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4565 echo $(comma_list $list)
4568 # list, expand are the comma separated lists
4570 local list=${1//,/ }
4571 local expand=${2//,/ }
4574 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4575 echo $(comma_list $expanded)
4578 testslist_filter () {
4579 local script=$LUSTRE/tests/${TESTSUITE}.sh
4581 [ -f $script ] || return 0
4583 local start_at=$START_AT
4584 local stop_at=$STOP_AT
4586 local var=${TESTSUITE//-/_}_START_AT
4587 [ x"${!var}" != x ] && start_at=${!var}
4588 var=${TESTSUITE//-/_}_STOP_AT
4589 [ x"${!var}" != x ] && stop_at=${!var}
4591 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4592 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4593 /^'${start_at}'$/ {flag = 0}
4594 {if (flag == 1) print $0}
4595 /^'${stop_at}'$/ { flag = 1 }'
4599 (cd `dirname $1`; echo $PWD/`basename $1`)
4603 local types=${1:-"OST MDS MGS"}
4607 for entry in $types; do
4608 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4609 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4612 MGS ) list="$list $name";;
4613 MDS|OST|AGT ) local count=${type}COUNT
4614 for ((i=1; i<=${!count}; i++)) do
4615 list="$list ${name}$i"
4617 * ) error "Invalid facet type"
4621 echo $(comma_list $list)
4624 ##################################
4625 # Adaptive Timeouts funcs
4628 # only check mds, we assume at_max is the same on all nodes
4629 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4630 if [ $at_max -eq 0 ]; then
4641 # suppose that all ost-s have the same $at value set
4642 [ $facet != "ost" ] || facet=ost1
4644 do_facet $facet "lctl get_param -n $at"
4662 if [ $facet == "ost" ]; then
4663 facet=$(get_facets OST)
4664 elif [ $facet == "mds" ]; then
4665 facet=$(get_facets MDS)
4667 hosts=$(expand_list $hosts $(facets_hosts $facet))
4670 do_nodes $hosts lctl set_param at_max=$at_max
4673 ##################################
4677 # OBD_FAIL_MDS_ALL_REQUEST_NET
4679 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4680 do_facet client "$1" || RC=$?
4681 do_facet $SINGLEMDS lctl set_param fail_loc=0
4686 # OBD_FAIL_MDS_ALL_REPLY_NET
4688 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
4690 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4694 drop_reint_reply() {
4695 # OBD_FAIL_MDS_REINT_NET_REP
4697 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
4699 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4703 drop_update_reply() {
4704 # OBD_FAIL_OUT_UPDATE_NET_REP
4708 do_facet mds${index} lctl set_param fail_loc=0x1701
4709 do_facet client "$@" || RC=$?
4710 do_facet mds${index} lctl set_param fail_loc=0
4715 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4718 local timeout=${2:-0}
4719 # default is (obd_timeout / 4) if unspecified
4720 echo "timeout is $timeout/$2"
4721 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
4722 do_facet client "$1" || RC=$?
4723 do_facet client "sync"
4724 do_facet ost1 lctl set_param fail_loc=0
4728 drop_ldlm_cancel() {
4729 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4731 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4732 do_nodes $list lctl set_param fail_loc=0x304
4734 do_facet client "$@" || RC=$?
4736 do_nodes $list lctl set_param fail_loc=0
4740 drop_bl_callback_once() {
4742 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4743 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4744 do_facet client lctl set_param fail_loc=0x80000305
4745 do_facet client "$@" || rc=$?
4746 do_facet client lctl set_param fail_loc=0
4747 do_facet client lctl set_param fail_val=0
4748 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4752 drop_bl_callback() {
4754 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4755 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4756 do_facet client lctl set_param fail_loc=0x305
4757 do_facet client "$@" || rc=$?
4758 do_facet client lctl set_param fail_loc=0
4759 do_facet client lctl set_param fail_val=0
4760 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4765 #define OBD_FAIL_LDLM_REPLY 0x30c
4767 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4768 do_nodes $list lctl set_param fail_loc=0x30c
4770 do_facet client "$@" || RC=$?
4772 do_nodes $list lctl set_param fail_loc=0
4776 drop_ldlm_reply_once() {
4777 #define OBD_FAIL_LDLM_REPLY 0x30c
4779 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4780 do_nodes $list lctl set_param fail_loc=0x8000030c
4782 do_facet client "$@" || RC=$?
4784 do_nodes $list lctl set_param fail_loc=0
4792 echo "clearing fail_loc on $facet"
4793 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4796 set_nodes_failloc () {
4798 do_nodes $(comma_list $1) lctl set_param fail_val=$fv fail_loc=$2
4801 cancel_lru_locks() {
4802 #$LCTL mark "cancel_lru_locks $1 start"
4803 $LCTL set_param -n ldlm.namespaces.*$1*.lru_size=clear
4804 $LCTL get_param ldlm.namespaces.*$1*.lock_unused_count | grep -v '=0'
4805 #$LCTL mark "cancel_lru_locks $1 stop"
4810 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4811 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4812 echo "$DEFAULT_LRU_SIZE"
4817 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4820 lru_resize_disable()
4822 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4828 [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] && RC=1
4834 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4835 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4836 echo there is still data in page cache $FILE ?
4837 lctl get_param -n $FILE
4845 DEBUGSAVE="$(lctl get_param -n debug)"
4846 DEBUGSAVE_SERVER=$(do_facet $SINGLEMDS "$LCTL get_param -n debug")
4850 [ -n "$DEBUGSAVE" ] &&
4851 do_nodes $CLIENTS "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\""||
4855 [ -n "$DEBUGSAVE_SERVER" ] &&
4856 do_nodes $(comma_list $(all_server_nodes)) \
4857 "$LCTL set_param debug=\\\"${DEBUGSAVE_SERVER}\\\"" ||
4863 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4866 debug_size_restore() {
4867 [ -n "$DEBUG_SIZE_SAVED" ] && \
4868 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4872 start_full_debug_logging() {
4877 local DEBUG_SIZE=150
4879 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4880 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4883 stop_full_debug_logging() {
4888 # prints bash call stack
4889 print_stack_trace() {
4892 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4893 local src=${BASH_SOURCE[$i]}
4894 local lineno=${BASH_LINENO[$i-1]}
4895 local funcname=${FUNCNAME[$i]}
4896 echo " = $src:$lineno:$funcname()"
4901 local TYPE=${TYPE:-"FAIL"}
4904 # do not dump logs if $1=false
4905 if [ "x$1" = "xfalse" ]; then
4910 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4911 (print_stack_trace 2) >&2
4913 # We need to dump the logs on all nodes
4915 gather_logs $(comma_list $(nodes_list))
4919 [ "$TESTSUITELOG" ] &&
4920 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4921 if [ -z "$*" ]; then
4922 echo "error() without useful message, please fix" > $LOGDIR/err
4924 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4925 echo "$@" > $LOGDIR/ignore
4927 echo "$@" > $LOGDIR/err
4931 # cleanup the env for failed tests
4935 ##################################
4937 ##################################
4945 local log=$TESTSUITELOG
4947 [ -f "$log" ] && grep -q FAIL $log && status=1
4961 # use only if we are ignoring failures for this test, bugno required.
4962 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4963 # e.g. error_ignore bz5494 "your message" or
4964 # error_ignore LU-5494 "your message"
4966 local TYPE="IGNORE ($1)"
4971 error_and_remount() {
4973 remount_client $MOUNT
4977 # Throw an error if it's not running in vm - usually for performance
4980 local virt=$(running_in_vm)
4981 if [[ -n "$virt" ]]; then
4982 echo "running in VM '$virt', ignore error"
4983 error_ignore env=$virt "$@"
4990 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4995 log " SKIP: $TESTSUITE $TESTNAME $@"
4997 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4998 skip_logged $TESTNAME "$@"
5001 echo "$@" > $LOGDIR/skip
5004 [[ -n "$TESTSUITELOG" ]] &&
5005 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
5008 build_test_filter() {
5009 EXCEPT="$EXCEPT $(testslist_filter)"
5012 if [[ $O = [0-9]*-[0-9]* ]]; then
5013 for num in $(seq $(echo $O | tr '-' ' ')); do
5021 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
5022 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
5023 [ "$EXCEPT_SLOW" ] && \
5024 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
5025 for E in $EXCEPT; do
5026 eval EXCEPT_${E}=true
5028 for E in $ALWAYS_EXCEPT; do
5029 eval EXCEPT_ALWAYS_${E}=true
5031 for E in $EXCEPT_SLOW; do
5032 eval EXCEPT_SLOW_${E}=true
5034 for G in $GRANT_CHECK_LIST; do
5035 eval GCHECK_ONLY_${G}=true
5040 if [[ $1 = [a-z]* ]]; then
5047 # print a newline if the last test was skipped
5048 export LAST_SKIPPED=
5049 export ALWAYS_SKIPPED=
5051 # Main entry into test-framework. This is called with the name and
5052 # description of a test. The name is used to find the function to run
5053 # the test using "test_$name".
5055 # This supports a variety of methods of specifying specific test to
5056 # run or not run. These need to be documented...
5061 export base=$(basetest $1)
5062 if [ -n "$ONLY" ]; then
5064 if [ ${!testname}x != x ]; then
5065 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
5066 run_one_logged $1 "$2"
5070 if [ ${!testname}x != x ]; then
5071 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
5072 run_one_logged $1 "$2"
5082 if [ ${!testname}x != x ]; then
5083 TESTNAME=test_$1 skip "skipping excluded test $1"
5086 testname=EXCEPT_$base
5087 if [ ${!testname}x != x ]; then
5088 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
5091 testname=EXCEPT_ALWAYS_$1
5092 if [ ${!testname}x != x ]; then
5093 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
5096 testname=EXCEPT_ALWAYS_$base
5097 if [ ${!testname}x != x ]; then
5098 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
5101 testname=EXCEPT_SLOW_$1
5102 if [ ${!testname}x != x ]; then
5103 TESTNAME=test_$1 skip "skipping SLOW test $1"
5106 testname=EXCEPT_SLOW_$base
5107 if [ ${!testname}x != x ]; then
5108 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
5114 run_one_logged $1 "$2"
5121 load_module ../libcfs/libcfs/libcfs
5133 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
5138 strace -o $TMP/$1.strace -ttt $*
5140 log "FINISHED: $*: rc $RC"
5147 banner test complete, duration $duration sec
5148 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
5149 echo duration $duration >>$TESTSUITELOG
5153 # Set TEST_STATUS here. It will be used for logging the result.
5156 if [[ -f $LOGDIR/err ]]; then
5158 elif [[ -f $LOGDIR/skip ]]; then
5161 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
5165 local FFREE=$(do_node $SINGLEMDS \
5166 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
5167 local FTOTAL=$(do_node $SINGLEMDS \
5168 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
5170 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
5174 echo -n "Resetting fail_loc on all nodes..."
5175 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 \
5176 fail_val=0 2>/dev/null" || true
5182 # Log a message (on all nodes) padded with "=" before and after.
5183 # Also appends a timestamp and prepends the testsuite name.
5186 EQUALS="===================================================================================================="
5188 msg="== ${TESTSUITE} $*"
5190 [[ $last != "=" && $last != " " ]] && msg="$msg "
5191 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
5192 # always include at least == after the message
5193 log "$msg== $(date +"%H:%M:%S (%s)")"
5196 check_dmesg_for_errors() {
5198 local errors="VFS: Busy inodes after unmount of\|\
5199 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
5200 group descriptors corrupted"
5202 res=$(do_nodes $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
5203 [ -z "$res" ] && return 0
5204 echo "Kernel error detected: $res"
5209 # Run a single test function and cleanup after it.
5211 # This function should be run in a subshell so the test func can
5212 # exit() without stopping the whole script.
5217 export tfile=f${testnum}.${TESTSUITE}
5218 export tdir=d${testnum}.${TESTSUITE}
5219 export TESTNAME=test_$testnum
5220 local SAVE_UMASK=`umask`
5223 if ! grep -q $DIR /proc/mounts; then
5227 banner "test $testnum: $message"
5228 test_${testnum} || error "test_$testnum failed with $?"
5231 check_grant ${testnum} || error "check_grant $testnum failed with $?"
5233 check_dmesg_for_errors || error "Error in dmesg detected"
5234 if [ "$PARALLEL" != "yes" ]; then
5235 ps auxww | grep -v grep | grep -q multiop &&
5236 error "multiop still running"
5247 # Wrapper around run_one to ensure:
5248 # - test runs in subshell
5249 # - output of test is saved to separate log file for error reporting
5250 # - test result is saved to data file
5253 local BEFORE=$(date +%s)
5255 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
5256 local test_log=$LOGDIR/$name
5257 local zfs_log_name=${TESTSUITE}.test_${1}.zfs_log
5258 local zfs_debug_log=$LOGDIR/$zfs_log_name
5260 rm -rf $LOGDIR/ignore
5262 local SAVE_UMASK=$(umask)
5266 log_sub_test_begin test_${1}
5267 (run_one $1 "$2") 2>&1 | tee -i $test_log
5268 local RC=${PIPESTATUS[0]}
5270 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
5271 echo "test_$1 returned $RC" | tee $LOGDIR/err
5273 duration=$(($(date +%s) - $BEFORE))
5274 pass "$1" "(${duration}s)"
5276 if [[ -f $LOGDIR/err ]]; then
5277 TEST_ERROR=$(cat $LOGDIR/err)
5278 elif [[ -f $LOGDIR/ignore ]]; then
5279 TEST_ERROR=$(cat $LOGDIR/ignore)
5280 elif [[ -f $LOGDIR/skip ]]; then
5281 TEST_ERROR=$(cat $LOGDIR/skip)
5283 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
5285 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
5289 if [ -f $LOGDIR/err ]; then
5290 log_zfs_info "$zfs_debug_log"
5291 $FAIL_ON_ERROR && exit $RC
5300 # Print information of skipped tests to result.yml
5303 log_sub_test_begin $1
5305 log_sub_test_end "SKIP" "0" "0" "$@"
5309 (cd $(dirname $1); echo $PWD/$(basename $1))
5314 export base=$(basetest $1)
5315 [ "$CHECK_GRANT" == "no" ] && return 0
5317 testname=GCHECK_ONLY_${base}
5318 [ ${!testname}x == x ] && return 0
5320 echo -n "checking grant......"
5322 local clients=$CLIENTS
5323 [ -z "$clients" ] && clients=$(hostname)
5325 # sync all the data and make sure no pending data on server
5326 do_nodes $clients sync
5329 client_grant=$(do_nodes $clients \
5330 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
5331 awk '{ total += $1 } END { printf("%0.0f", total) }')
5334 server_grant=$(do_nodes $(comma_list $(osts_nodes)) \
5335 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
5336 awk '{ total += $1 } END { printf("%0.0f", total) }')
5338 # check whether client grant == server grant
5339 if [[ $client_grant -ne $server_grant ]]; then
5340 echo "failed: client:${client_grant} server: ${server_grant}."
5341 do_nodes $(comma_list $(osts_nodes)) \
5342 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
5343 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
5346 echo "pass: client:${client_grant} server: ${server_grant}"
5350 ########################
5356 ost=`echo $1 | awk -F_ '{print $3}'`
5357 if [ -z $ost ]; then
5358 ost=`echo $1 | sed 's/-osc.*//'`
5363 ostuuid_from_index()
5365 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5368 ostname_from_index() {
5369 local uuid=$(ostuuid_from_index $1)
5373 index_from_ostuuid()
5375 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
5378 mdtuuid_from_index()
5380 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5384 # Return unique identifier for given hostname
5387 echo $host_name | md5sum | cut -d' ' -f1
5391 # Returns list of ip addresses for each interface
5393 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
5398 # Cache address list to avoid mutiple execution of local_addr_list
5399 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
5401 for i in $LOCAL_ADDR_LIST ; do
5402 [[ "$i" == "$addr" ]] && return 0
5409 local is_local="IS_LOCAL_$(host_id $host_name)"
5410 if [ -z "${!is_local-}" ] ; then
5412 local host_ip=$($LUSTRE/tests/resolveip $host_name)
5413 is_local_addr "$host_ip" && eval $is_local=1
5415 [[ "${!is_local}" == "1" ]]
5420 local_node $node && return 1
5427 for node in $(mdts_nodes); do
5428 remote_node $node && return 0
5435 [ -n "$CLIENTONLY" ] && return 0 || true
5436 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
5441 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" &&
5442 MSKIPPED=1 && return 1
5449 for node in $(osts_nodes) ; do
5450 remote_node $node && return 0
5457 [ -n "$CLIENTONLY" ] && return 0 || true
5458 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5463 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
5464 OSKIPPED=1 && return 1
5470 [ -n "$CLIENTONLY" ] && return 0 || true
5472 MGS=$(facet_host mgs)
5473 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5478 remote_mds_nodsh || remote_ost_nodsh || \
5479 $(single_local_node $(comma_list $(nodes_list)))
5483 remote_ost && remote_mds
5486 # Get the active nodes for facets.
5494 for facet in ${facets//,/ }; do
5495 nodes="$nodes $(facet_active_host $facet)"
5498 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5502 # Get all of the active MDS nodes.
5504 echo -n $(facets_nodes $(get_facets MDS))
5507 # Get all of the active OSS nodes.
5509 echo -n $(facets_nodes $(get_facets OST))
5512 # Get all of the active AGT (HSM agent) nodes.
5514 echo -n $(facets_nodes $(get_facets AGT))
5517 # Get all of the client nodes and active server nodes.
5519 local nodes=$HOSTNAME
5523 # CLIENTS (if specified) contains the local client
5524 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5526 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5527 nodes="$nodes $(facets_nodes $(get_facets))"
5530 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5534 # Get all of the remote client nodes and remote active server nodes.
5535 remote_nodes_list () {
5536 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5539 # Get all of the MDS nodes, including active and passive nodes.
5547 for i in $(seq $MDSCOUNT); do
5549 failover_host=mds${i}failover_HOST
5550 nodes="$nodes ${!host} ${!failover_host}"
5553 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5557 # Get all of the OSS nodes, including active and passive nodes.
5565 for i in $(seq $OSTCOUNT); do
5567 failover_host=ost${i}failover_HOST
5568 nodes="$nodes ${!host} ${!failover_host}"
5571 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5575 # Get all of the server nodes, including active and passive nodes.
5576 all_server_nodes () {
5581 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5583 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5587 # Get all of the client and server nodes, including active and passive nodes.
5589 local nodes=$HOSTNAME
5593 # CLIENTS (if specified) contains the local client
5594 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5596 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5597 nodes="$nodes $(all_server_nodes)"
5600 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5604 init_clients_lists () {
5605 # Sanity check: exclude the local client from RCLIENTS
5606 local clients=$(hostlist_expand "$RCLIENTS")
5607 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5609 # Sanity check: exclude the dup entries
5610 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5612 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5614 # Sanity check: exclude the dup entries from CLIENTS
5615 # for those configs which has SINGLCLIENT set to local client
5616 clients=$(for i in $clients; do echo $i; done | sort -u)
5618 CLIENTS=$(comma_list $clients)
5619 local -a remoteclients=($RCLIENTS)
5620 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5621 varname=CLIENT$((i + 2))
5622 eval $varname=${remoteclients[i]}
5625 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5628 get_random_entry () {
5631 rnodes=${rnodes//,/ }
5633 local -a nodes=($rnodes)
5634 local num=${#nodes[@]}
5635 local i=$((RANDOM * num * 2 / 65536))
5641 [ -n "$CLIENTONLY" ] || [ "x$CLIENTMODSONLY" = "xyes" ]
5645 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5646 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5651 echo $nodes | wc -w || true
5655 local nodes=$(osts_nodes)
5656 local osscount=$(get_node_count "$nodes")
5657 [ ! "$OSTCOUNT" = "$osscount" ]
5661 local nodes=$(mdts_nodes)
5662 local mdtcount=$(get_node_count "$nodes")
5663 [ ! "$MDSCOUNT" = "$mdtcount" ]
5666 generate_machine_file() {
5667 local nodes=${1//,/ }
5668 local machinefile=$2
5670 for node in $nodes; do
5671 echo $node >>$machinefile || \
5672 { echo "can not generate machinefile $machinefile" && return 1; }
5677 local file=$1/stripe
5680 $LFS getstripe -v $file || error "getstripe $file failed"
5684 setstripe_nfsserver () {
5687 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5688 { print $1 }' /proc/mounts | cut -f 1 -d : | head -n1)
5690 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5692 do_nodev $nfsserver lfs setstripe "$@"
5695 # Check and add a test group.
5701 local gid=$(getent group $group_name | cut -d: -f3)
5702 if [[ -n "$gid" ]]; then
5703 [[ "$gid" -eq "$group_id" ]] || {
5704 error_noexit "inconsistent group ID:" \
5705 "new: $group_id, old: $gid"
5709 groupadd -g $group_id $group_name
5716 # Check and add a test user.
5729 local uid=$(getent passwd $user_name | cut -d: -f3)
5730 if [[ -n "$uid" ]]; then
5731 if [[ "$uid" -eq "$user_id" ]]; then
5732 local dir=$(getent passwd $user_name | cut -d: -f6)
5733 if [[ "$dir" != "$home" ]]; then
5735 usermod -d $home $user_name
5739 error_noexit "inconsistent user ID:" \
5740 "new: $user_id, old: $uid"
5745 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5752 check_runas_id_ret() {
5754 local myRUNAS_UID=$1
5755 local myRUNAS_GID=$2
5758 if [ -z "$myRUNAS" ]; then
5759 error_exit "myRUNAS command must be specified for check_runas_id"
5762 $myRUNAS krb5_login.sh || \
5763 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5765 mkdir $DIR/d0_runas_test
5767 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5768 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5769 rm -rf $DIR/d0_runas_test
5774 local myRUNAS_UID=$1
5775 local myRUNAS_GID=$2
5778 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5779 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5780 Please set RUNAS_ID to some UID which exists on MDS and client or
5781 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5784 # obtain the UID/GID for MPI_USER
5788 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5789 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5791 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5792 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5795 # obtain and cache Kerberos ticket-granting ticket
5796 refresh_krb5_tgt() {
5797 local myRUNAS_UID=$1
5798 local myRUNAS_GID=$2
5801 if [ -z "$myRUNAS" ]; then
5802 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5805 CLIENTS=${CLIENTS:-$HOSTNAME}
5806 do_nodes $CLIENTS "set -x
5807 if ! $myRUNAS krb5_login.sh; then
5808 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5813 # Run multiop in the background, but wait for it to print
5814 # "PAUSING" to its stdout before returning from this function.
5815 multiop_bg_pause() {
5816 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5820 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5823 echo "$MULTIOP_PROG $FILE v$ARGS"
5824 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5826 echo "TMPPIPE=${TMPPIPE}"
5827 read -t 60 multiop_output < $TMPPIPE
5828 if [ $? -ne 0 ]; then
5833 if [ "$multiop_output" != "PAUSING" ]; then
5834 echo "Incorrect multiop output: $multiop_output"
5849 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5855 inodes_available () {
5856 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
5857 sort -un | head -n1) || return 1
5861 mdsrate_inodes_available () {
5862 local min_inodes=$(inodes_available)
5863 echo $((min_inodes * 99 / 100))
5866 # reset stat counters
5868 local paramfile="$1"
5869 lctl set_param -n $paramfile=0
5874 local paramfile="$1"
5876 lctl get_param -n $paramfile |
5877 awk '/^'$stat'/ { sum += $2 } END { printf("%0.0f", sum) }'
5881 awk '{sum += $1} END { printf("%0.0f", sum) }'
5884 calc_osc_kbytes () {
5885 df $MOUNT > /dev/null
5886 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5889 # save_lustre_params(comma separated facet list, parameter_mask)
5890 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5891 save_lustre_params() {
5897 for facet in ${facets//,/ }; do
5898 node=$(facet_active_host $facet)
5899 [[ *\ $node\ * = " $nodes " ]] && continue
5900 nodes="$nodes $node"
5902 do_node $node "$LCTL get_param $2 |
5903 while read s; do echo $facet \\\$s; done"
5907 # restore lustre parameters from input stream, produces by save_lustre_params
5908 restore_lustre_params() {
5913 while IFS=" =" read facet name val; do
5914 do_facet $facet "$LCTL set_param -n $name $val"
5918 check_node_health() {
5919 local nodes=${1:-$(comma_list $(nodes_list))}
5921 for node in ${nodes//,/ }; do
5922 check_network "$node" 5
5923 if [ $? -eq 0 ]; then
5924 do_node $node "rc=0;
5925 val=\\\$($LCTL get_param -n catastrophe 2>&1);
5926 if [[ \\\$? -eq 0 && \\\$val -ne 0 ]]; then
5927 echo \\\$(hostname -s): \\\$val;
5930 exit \\\$rc" || error "$node:LBUG/LASSERT detected"
5935 mdsrate_cleanup () {
5937 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
5938 --nfiles $3 --dir $4 --filefmt $5 $6
5943 delayed_recovery_enabled () {
5944 local var=${SINGLEMDS}_svc
5945 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5948 ########################
5950 convert_facet2label() {
5953 if [ x$facet = xost ]; then
5957 local varsvc=${facet}_svc
5959 if [ -n ${!varsvc} ]; then
5962 error "No lablel for $facet!"
5966 get_clientosc_proc_path() {
5970 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5971 # used by MDT would not be changed.
5972 # mdt lov: fsname-mdtlov
5973 # mdt osc: fsname-OSTXXXX-osc
5974 mds_on_old_device() {
5975 local mds=${1:-"$SINGLEMDS"}
5977 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5978 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5979 > /dev/null 2>&1" && return 0
5984 get_mdtosc_proc_path() {
5986 local ost_label=${2:-"*OST*"}
5988 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5989 local mdt_label=$(convert_facet2label $mds_facet)
5990 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5992 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5993 mds_on_old_device $mds_facet; then
5994 echo "${ost_label}-osc"
5995 elif [[ $ost_label = *OST* ]]; then
5996 echo "${ost_label}-osc-${mdt_index}"
5998 echo "${ost_label}-osp-${mdt_index}"
6002 get_osc_import_name() {
6005 local label=$(convert_facet2label $ost)
6007 if [ "${facet:0:3}" = "mds" ]; then
6008 get_mdtosc_proc_path $facet $label
6012 get_clientosc_proc_path $label
6016 _wait_import_state () {
6019 local maxtime=${3:-$(max_recovery_time)}
6020 local error_on_failure=${4:-1}
6024 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
6025 while [ "${CONN_STATE}" != "${expected}" ]; do
6026 if [ "${expected}" == "DISCONN" ]; then
6027 # for disconn we can check after proc entry is removed
6028 [ "x${CONN_STATE}" == "x" ] && return 0
6029 # with AT enabled, we can have connect request timeout near of
6030 # reconnect timeout and test can't see real disconnect
6031 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
6033 if [ $i -ge $maxtime ]; then
6034 [ $error_on_failure -ne 0 ] && \
6035 error "can't put import for $CONN_PROC into ${expected}" \
6036 "state after $i sec, have ${CONN_STATE}"
6040 # Add uniq for multi-mount case
6041 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
6045 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
6049 wait_import_state() {
6052 local maxtime=${3:-$(max_recovery_time)}
6053 local error_on_failure=${4:-1}
6056 for param in ${params//,/ }; do
6057 _wait_import_state $state $param $maxtime $error_on_failure || return
6061 wait_import_state_mount() {
6062 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
6066 wait_import_state $*
6069 # One client request could be timed out because server was not ready
6070 # when request was sent by client.
6071 # The request timeout calculation details :
6073 # /* We give the server rq_timeout secs to process the req, and
6074 # add the network latency for our local timeout. */
6075 # request->rq_deadline = request->rq_sent + request->rq_timeout +
6076 # ptlrpc_at_get_net_latency(request) ;
6078 # ptlrpc_connect_import ()
6079 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
6082 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
6083 # ptlrpc_at_get_net_latency(request) ->
6084 # at_get (max (iat_net_latency=0, at_min)) = at_min
6087 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
6088 # INITIAL_CONNECT_TIMEOUT + at_min
6090 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
6091 # because we can not get this value in runtime,
6092 # the value depends on configure options, and it is not stored in /proc.
6094 # #define CONNECTION_SWITCH_MIN 5U
6095 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
6097 request_timeout () {
6100 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
6101 local init_connect_timeout=$TIMEOUT
6102 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
6104 local at_min=$(at_get $facet at_min)
6106 echo $(( init_connect_timeout + at_min ))
6109 _wait_osc_import_state() {
6113 local target=$(get_osc_import_name $facet $ost_facet)
6114 local param="osc.${target}.ost_server_uuid"
6118 # 1. wait the deadline of client 1st request (it could be skipped)
6119 # 2. wait the deadline of client 2nd request
6120 local maxtime=$(( 2 * $(request_timeout $facet)))
6122 if [[ $facet == client* ]]; then
6123 # During setup time, the osc might not be setup, it need wait
6124 # until list_param can return valid value.
6125 param="osc.${ost%?}[^mM]*.ost_server_uuid"
6126 params=$($LCTL list_param $param 2>/dev/null || true)
6127 while [ -z "$params" ]; do
6128 if [ $i -ge $maxtime ]; then
6129 echo "can't get $param in $maxtime secs"
6134 params=$($LCTL list_param $param 2>/dev/null || true)
6138 if [[ $ost_facet = mds* ]]; then
6139 # no OSP connection to itself
6140 if [[ $facet = $ost_facet ]]; then
6143 param="osp.${target}.mdt_server_uuid"
6147 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6148 wait_import_state $expected "$params" $maxtime; then
6149 error "$facet: import is not in $expected state after $maxtime"
6156 wait_osc_import_state() {
6162 if [[ $facet = mds ]]; then
6163 for num in $(seq $MDSCOUNT); do
6164 _wait_osc_import_state mds$num "$ost_facet" "$expected"
6167 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
6171 _wait_mgc_import_state() {
6174 local error_on_failure=${3:-1}
6175 local param="mgc.*.mgs_server_uuid"
6179 # 1. wait the deadline of client 1st request (it could be skipped)
6180 # 2. wait the deadline of client 2nd request
6181 local maxtime=$(( 2 * $(request_timeout $facet)))
6183 if [[ $facet == client* ]]; then
6184 # During setup time, the osc might not be setup, it need wait
6185 # until list_param can return valid value. And also if there
6186 # are mulitple osc entries we should list all of them before
6188 params=$($LCTL list_param $param 2>/dev/null || true)
6189 while [ -z "$params" ]; do
6190 if [ $i -ge $maxtime ]; then
6191 echo "can't get $param in $maxtime secs"
6196 params=$($LCTL list_param $param 2>/dev/null || true)
6199 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6200 wait_import_state $expected "$params" $maxtime \
6201 $error_on_failure; then
6202 if [ $error_on_failure -ne 0 ]; then
6203 error "import is not in ${expected} state"
6211 wait_mgc_import_state() {
6214 local error_on_failure=${3:-1}
6217 if [[ $facet = mds ]]; then
6218 for num in $(seq $MDSCOUNT); do
6219 _wait_mgc_import_state mds$num "$expected" \
6220 $error_on_failure || return
6223 _wait_mgc_import_state "$facet" "$expected"
6224 $error_on_failure || return
6228 wait_dne_interconnect() {
6231 if [ $MDSCOUNT -gt 1 ]; then
6232 for num in $(seq $MDSCOUNT); do
6233 wait_osc_import_state mds mds$num FULL
6238 get_clientmdc_proc_path() {
6242 get_clientmgc_proc_path() {
6250 [ -z "$list" ] && return 0
6252 # Add paths to lustre tests for 32 and 64 bit systems.
6253 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
6254 local TESTPATH="$RLUSTRE/tests:"
6255 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
6256 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
6259 wait_clients_import_state () {
6266 if [ "$FAILURE_MODE" = HARD ]; then
6267 facets=$(facets_on_host $(facet_active_host $facet))
6270 for facet in ${facets//,/ }; do
6271 local label=$(convert_facet2label $facet)
6274 ost* ) proc_path="osc.$(get_clientosc_proc_path \
6275 $label).ost_server_uuid" ;;
6276 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
6277 $label).mds_server_uuid" ;;
6278 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
6279 $label).mgs_server_uuid" ;;
6280 *) error "unknown facet!" ;;
6283 local params=$(expand_list $params $proc_path)
6286 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params;
6288 error "import is not in ${expected} state"
6300 # wait until all MDTs are in the expected state
6301 for ((num = 1; num <= $MDSCOUNT; num++)); do
6302 local mdtosp=$(get_mdtosc_proc_path mds${num} ${tgt_name})
6305 if [ $facet = "mds" ]; then
6306 mproc="osp.$mdtosp.active"
6307 [ $num -eq $((tgt_idx + 1)) ] && continue
6309 mproc="osc.$mdtosp.active"
6315 local result=$(do_facet mds${num} "$LCTL get_param -n $mproc")
6319 [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $mproc"
6320 if [ $result -eq $expected ]; then
6321 echo -n "target updated after"
6322 echo "$wait sec (got $result)"
6326 if [ $wait -eq $max ]; then
6327 error "$tgt_name: wanted $expected got $result"
6329 echo "Waiting $((max - wait)) secs for $tgt_name"
6339 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
6340 $LCTL get_param obdfilter.*.kbytesavail))
6341 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
6342 $LCTL get_param -n obdfilter.*.tot_granted))
6343 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
6344 $LCTL get_param -n obdfilter.*.kbytestotal))
6345 for ((i=0; i<${#AVAILA[@]}; i++)); do
6346 local -a AVAIL1=(${AVAILA[$i]//=/ })
6347 local -a TOTAL=(${TOTALA[$i]//=/ })
6348 GRANT=$((${GRANTA[$i]}/1024))
6349 # allow 1% of total space in bavail because of delayed
6350 # allocation with ZFS which might release some free space after
6351 # txg commit. For small devices, we set a mininum of 8MB
6352 local LIMIT=$((${TOTAL} / 100 + 8000))
6353 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
6354 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
6355 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
6356 echo " FULL" || echo
6362 echo -e "$(do_facet $SINGLEMDS $LCTL pool_list $1 | sed '1d')"
6365 check_pool_not_exist() {
6366 local fsname=${1%%.*}
6367 local poolname=${1##$fsname.}
6368 [[ $# -ne 1 ]] && return 0
6369 [[ x$poolname = x ]] && return 0
6370 list_pool $fsname | grep -w $1 && return 1
6375 local fsname=${1%%.*}
6376 local poolname=${1##$fsname.}
6378 trap "destroy_test_pools $fsname" EXIT
6379 do_facet mgs lctl pool_new $1
6381 # get param should return err unless pool is created
6382 [[ $RC -ne 0 ]] && return $RC
6384 for mds_id in $(seq $MDSCOUNT); do
6385 local mdt_id=$((mds_id-1))
6386 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
6387 wait_update_facet mds$mds_id \
6388 "lctl get_param -n lod.$lodname.pools.$poolname \
6389 2>/dev/null || echo foo" "" ||
6390 error "mds$mds_id: pool_new failed $1"
6392 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6393 2>/dev/null || echo foo" "" || error "pool_new failed $1"
6399 add_pool_to_list () {
6400 local fsname=${1%%.*}
6401 local poolname=${1##$fsname.}
6403 local listvar=${fsname}_CREATED_POOLS
6404 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
6408 remove_pool_from_list () {
6409 local fsname=${1%%.*}
6410 local poolname=${1##$fsname.}
6412 local listvar=${fsname}_CREATED_POOLS
6413 local temp=${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
6417 destroy_pool_int() {
6419 local OSTS=$(list_pool $1)
6420 for ost in $OSTS; do
6421 do_facet mgs lctl pool_remove $1 $ost
6423 do_facet mgs lctl pool_destroy $1
6426 # <fsname>.<poolname> or <poolname>
6428 local fsname=${1%%.*}
6429 local poolname=${1##$fsname.}
6431 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
6435 check_pool_not_exist $fsname.$poolname
6436 [[ $? -eq 0 ]] && return 0
6438 destroy_pool_int $fsname.$poolname
6440 [[ $RC -ne 0 ]] && return $RC
6441 for mds_id in $(seq $MDSCOUNT); do
6442 local mdt_id=$((mds_id-1))
6443 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
6444 wait_update_facet mds$mds_id \
6445 "lctl get_param -n lod.$lodname.pools.$poolname \
6446 2>/dev/null || echo foo" "foo" ||
6447 error "mds$mds_id: destroy pool failed $1"
6449 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6450 2>/dev/null || echo foo" "foo" || error "destroy pool failed $1"
6452 remove_pool_from_list $fsname.$poolname
6458 local fsname=${1:-$FSNAME}
6460 local listvar=${fsname}_CREATED_POOLS
6462 [ x${!listvar} = x ] && return 0
6464 echo "Destroy the created pools: ${!listvar}"
6465 for poolname in ${!listvar//,/ }; do
6466 destroy_pool $fsname.$poolname
6470 destroy_test_pools () {
6472 local fsname=${1:-$FSNAME}
6473 destroy_pools $fsname || true
6479 local ts=$(date +%s)
6482 if [[ ! -f "$YAML_LOG" ]]; then
6483 # init_logging is not performed before gather_logs,
6484 # so the $LOGDIR needs to be checked here
6485 check_shared_dir $LOGDIR && touch $LOGDIR/shared
6488 [ -f $LOGDIR/shared ] && docp=false
6490 # dump lustre logs, dmesg
6492 prefix="$TESTLOG_PREFIX.$TESTNAME"
6494 echo "Dumping lctl log to ${prefix}.*.${suffix}"
6496 if [ -n "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
6497 echo "Dumping logs only on local client."
6498 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
6499 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
6504 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
6505 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
6506 if [ ! -f $LOGDIR/shared ]; then
6507 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
6520 for i in $(seq 0 $num_mntpts); do
6521 cmd="ls -laf ${mntpt_root}$i/$dir"
6527 for pid in $pids; do
6534 # check_and_start_recovery_timer()
6535 # service_time = at_est2timeout(service_time);
6536 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
6537 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
6539 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
6540 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
6541 #define CONNECTION_SWITCH_MIN 5
6542 #define CONNECTION_SWITCH_INC 5
6543 max_recovery_time() {
6544 local init_connect_timeout=$((TIMEOUT / 20))
6545 ((init_connect_timeout >= 5)) || init_connect_timeout=5
6547 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
6548 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
6550 echo -n $service_time
6553 recovery_time_min() {
6554 local connection_switch_min=5
6555 local connection_switch_inc=5
6556 local connection_switch_max
6557 local reconnect_delay_max
6558 local initial_connect_timeout
6562 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
6563 (($connection_switch_min > $TIMEOUT)) &&
6564 max=$connection_switch_min || max=$TIMEOUT
6565 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
6567 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
6568 timeout_20=$((TIMEOUT/20))
6569 (($connection_switch_min > $timeout_20)) &&
6570 initial_connect_timeout=$connection_switch_min ||
6571 initial_connect_timeout=$timeout_20
6573 reconnect_delay_max=$((connection_switch_max + connection_switch_inc + \
6574 initial_connect_timeout))
6575 echo $((2 * reconnect_delay_max))
6578 get_clients_mount_count () {
6579 local clients=${CLIENTS:-`hostname`}
6581 # we need to take into account the clients mounts and
6582 # exclude mds/ost mounts if any;
6583 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
6587 PROC_CLI="srpc_info"
6595 if [ $M -lt $N ]; then
6599 while [ $N -lt $M ]; do
6609 calc_connection_cnt() {
6612 # MDT->MDT = 2 * C(M, 2)
6616 comb_m2=$(combination $MDSCOUNT 2)
6618 local num_clients=$(get_clients_mount_count)
6620 local cnt_mdt2mdt=$((comb_m2 * 2))
6621 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
6622 local cnt_cli2ost=$((num_clients * OSTCOUNT))
6623 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
6624 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
6625 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
6626 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
6640 local cmd="$tgt.srpc.flavor"
6642 if [ $net == "any" ]; then
6647 if [ $dir != "any" ]; then
6652 log "Setting sptlrpc rule: $cmd"
6653 do_facet mgs "$LCTL conf_param $cmd"
6662 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
6663 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
6665 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
6667 if [ "x$bulkspec" != "x" ]; then
6668 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
6670 if [ "x$algs" != "x" ]; then
6671 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
6673 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
6674 if [ $bulk == "bulkn" ]; then
6675 bulk_count=`echo "$output" | grep "bulk flavor" \
6676 | grep "null/null" | wc -l`
6677 elif [ $bulk == "bulki" ]; then
6678 bulk_count=`echo "$output" | grep "bulk flavor" \
6679 | grep "/null" | grep -v "null/" | wc -l`
6681 bulk_count=`echo "$output" | grep "bulk flavor" \
6682 | grep -v "/null" | grep -v "null/" | wc -l`
6686 [ $bulk_count -lt $count ] && count=$bulk_count
6697 local clients=${CLIENTS:-`hostname`}
6699 for c in ${clients//,/ }; do
6700 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
6701 tmpcnt=`count_flvr "$output" $flavor`
6702 cnt=$((cnt + tmpcnt))
6712 local clients=${CLIENTS:-`hostname`}
6714 for c in ${clients//,/ }; do
6715 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
6716 tmpcnt=`count_flvr "$output" $flavor`
6717 cnt=$((cnt + tmpcnt))
6727 if [ $MDSCOUNT -le 1 ]; then
6732 for num in `seq $MDSCOUNT`; do
6733 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
6734 tmpcnt=`count_flvr "$output" $flavor`
6735 cnt=$((cnt + tmpcnt))
6746 for num in `seq $MDSCOUNT`; do
6747 mdtosc=$(get_mdtosc_proc_path mds$num)
6748 mdtosc=${mdtosc/-MDT*/-MDT\*}
6749 output=$(do_facet mds$num lctl get_param -n \
6750 osc.$mdtosc.$PROC_CLI 2>/dev/null)
6751 tmpcnt=`count_flvr "$output" $flavor`
6752 cnt=$((cnt + tmpcnt))
6761 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
6762 count_flvr "$output" $flavor
6767 local dir=$1 # from to
6768 local flavor=$2 # flavor expected
6771 if [ $dir == "cli2mdt" ]; then
6772 res=`flvr_cnt_cli2mdt $flavor`
6773 elif [ $dir == "cli2ost" ]; then
6774 res=`flvr_cnt_cli2ost $flavor`
6775 elif [ $dir == "mdt2mdt" ]; then
6776 res=`flvr_cnt_mdt2mdt $flavor`
6777 elif [ $dir == "mdt2ost" ]; then
6778 res=`flvr_cnt_mdt2ost $flavor`
6779 elif [ $dir == "all2ost" ]; then
6780 res1=`flvr_cnt_mdt2ost $flavor`
6781 res2=`flvr_cnt_cli2ost $flavor`
6782 res=$((res1 + res2))
6783 elif [ $dir == "all2mdt" ]; then
6784 res1=`flvr_cnt_mdt2mdt $flavor`
6785 res2=`flvr_cnt_cli2mdt $flavor`
6786 res=$((res1 + res2))
6787 elif [ $dir == "all2all" ]; then
6788 res1=`flvr_cnt_mdt2ost $flavor`
6789 res2=`flvr_cnt_cli2ost $flavor`
6790 res3=`flvr_cnt_mdt2mdt $flavor`
6791 res4=`flvr_cnt_cli2mdt $flavor`
6792 res=$((res1 + res2 + res3 + res4))
6800 local dir=$1 # from to
6801 local flavor=$2 # flavor expected
6802 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6806 for ((i=0;i<20;i++)); do
6807 echo -n "checking $dir..."
6808 res=$(do_check_flavor $dir $flavor)
6809 echo "found $res/$expect $flavor connections"
6810 [ $res -ge $expect ] && return 0
6814 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6818 restore_to_default_flavor()
6820 local proc="mgs.MGS.live.$FSNAME"
6822 echo "restoring to default flavor..."
6824 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6826 # remove all existing rules if any
6827 if [ $nrule -ne 0 ]; then
6828 echo "$nrule existing rules"
6829 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6830 echo "remove rule: $rule"
6831 spec=`echo $rule | awk -F = '{print $1}'`
6832 do_facet mgs "$LCTL conf_param -d $spec"
6836 # verify no rules left
6837 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6838 [ $nrule -ne 0 ] && error "still $nrule rules left"
6840 # wait for default flavor to be applied
6841 # currently default flavor for all connections are 'null'
6842 wait_flavor all2all null
6843 echo "now at default flavor settings"
6848 local flavor=${1:-null}
6850 echo "setting all flavor to $flavor"
6852 # FIXME need parameter to this fn
6853 # and remove global vars
6854 local cnt_all2all=$(calc_connection_cnt all2all)
6856 local res=$(do_check_flavor all2all $flavor)
6857 if [ $res -eq $cnt_all2all ]; then
6858 echo "already have total $res $flavor connections"
6862 echo "found $res $flavor out of total $cnt_all2all connections"
6863 restore_to_default_flavor
6865 [[ $flavor = null ]] && return 0
6867 set_rule $FSNAME any any $flavor
6868 wait_flavor all2all $flavor
6874 # Checking for shared logdir
6875 if [ ! -d $dir ]; then
6876 # Not found. Create local logdir
6879 touch $dir/check_file.$(hostname -s)
6884 check_write_access() {
6886 local list=${2:-$(comma_list $(nodes_list))}
6890 for node in ${list//,/ }; do
6891 file=$dir/check_file.$(short_nodename $node)
6892 if [[ ! -f "$file" ]]; then
6893 # Logdir not accessible/writable from this node.
6896 rm -f $file || return 1
6902 [[ -n $YAML_LOG ]] && return
6903 local save_umask=$(umask)
6906 export YAML_LOG=${LOGDIR}/results.yml
6910 # If the yaml log already exists then we will just append to it
6911 if [ ! -f $YAML_LOG ]; then
6912 if check_shared_dir $LOGDIR; then
6913 touch $LOGDIR/shared
6914 echo "Logging to shared log directory: $LOGDIR"
6916 echo "Logging to local directory: $LOGDIR"
6919 yml_nodes_file $LOGDIR >> $YAML_LOG
6920 yml_results_file >> $YAML_LOG
6925 # If modules are not yet loaded then older "lctl lustre_build_version"
6926 # will fail. Use lctl build version instead.
6927 log "Client: $($LCTL lustre_build_version)"
6928 log "MDS: $(do_facet $SINGLEMDS $LCTL lustre_build_version 2>/dev/null||
6929 do_facet $SINGLEMDS $LCTL --version)"
6930 log "OSS: $(do_facet ost1 $LCTL lustre_build_version 2> /dev/null ||
6931 do_facet ost1 $LCTL --version)"
6935 yml_log_test $1 >> $YAML_LOG
6939 yml_log_test_status $@ >> $YAML_LOG
6942 log_sub_test_begin() {
6943 yml_log_sub_test_begin "$@" >> $YAML_LOG
6946 log_sub_test_end() {
6947 yml_log_sub_test_end "$@" >> $YAML_LOG
6953 local llverdev_opts=$2
6954 local devname=$(basename $1)
6955 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6956 # loop devices aren't in /proc/partitions
6957 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6959 size=$(($size / 1024 / 1024)) # Gb
6961 local partial_arg=""
6962 # Run in partial (fast) mode if the size
6963 # of a partition > 1 GB
6964 [ $size -gt 1 ] && partial_arg="-p"
6966 llverdev --force $partial_arg $llverdev_opts $dev
6972 local llverfs_opts=$2
6973 local use_partial_arg=$3
6974 local partial_arg=""
6975 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6977 # Run in partial (fast) mode if the size
6978 # of a partition > 1 GB
6979 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6981 llverfs $partial_arg $llverfs_opts $dir
6984 #Remove objects from OST
6985 remove_ost_objects() {
6991 local mntpt=$(facet_mntpt $facet)
6992 local opts=$OST_MOUNT_OPTS
6996 echo "removing objects from $ostdev on $facet: $objids"
6997 if ! test -b $ostdev; then
6998 opts=$(csa_add "$opts" -o loop)
7000 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
7003 for i in $objids; do
7004 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
7006 umount -f $mntpt || return $?
7010 #Remove files from MDT
7011 remove_mdt_files() {
7016 local mntpt=$(facet_mntpt $facet)
7017 local opts=$MDS_MOUNT_OPTS
7019 echo "removing files from $mdtdev on $facet: $files"
7020 if [ $(facet_fstype $facet) == ldiskfs ] &&
7021 ! do_facet $facet test -b $mdtdev; then
7022 opts=$(csa_add "$opts" -o loop)
7024 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
7028 rm $mntpt/ROOT/$f || { rc=$?; break; }
7030 umount -f $mntpt || return $?
7034 duplicate_mdt_files() {
7039 local mntpt=$(facet_mntpt $facet)
7040 local opts=$MDS_MOUNT_OPTS
7042 echo "duplicating files on $mdtdev on $facet: $files"
7043 mkdir -p $mntpt || return $?
7044 if [ $(facet_fstype $facet) == ldiskfs ] &&
7045 ! do_facet $facet test -b $mdtdev; then
7046 opts=$(csa_add "$opts" -o loop)
7048 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
7059 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
7060 pushd $mntpt/ROOT > /dev/null || return $?
7063 touch $f.bad || return $?
7064 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
7066 [ $rc -eq 0 ] || return $rc
7067 setfattr --restore $tmp || return $?
7073 local devs=${1//,/ }
7076 local rslt=$TMP/sgpdd_survey
7078 # sgpdd-survey cleanups ${rslt}.* files
7080 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
7086 # returns the canonical name for an ldiskfs device
7091 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
7092 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
7093 echo dm-\\\${foo##*:};
7095 echo \\\$(basename \\\$dv);
7099 is_sanity_benchmark() {
7100 local benchmarks="dbench bonnie iozone fsx"
7102 for b in $benchmarks; do
7103 if [ "$b" == "$suite" ]; then
7111 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
7115 # Get the available size (KB) of a given obd target.
7122 [[ $facet != client ]] || return 0
7124 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
7129 # Get the page size (bytes) on a given facet node.
7133 local size=$(getconf PAGE_SIZE 2>/dev/null)
7135 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet getconf PAGE_SIZE)
7136 echo -n ${size:-4096}
7140 # Get the block count of the filesystem.
7147 [ -z "$CLIENTONLY" ] && count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
7148 awk '/^Block count:/ {print $3}')
7152 # Get the block size of the filesystem.
7158 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
7159 awk '/^Block size:/ {print $3}')
7163 # Check whether the "large_xattr" feature is enabled or not.
7164 large_xattr_enabled() {
7165 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
7167 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
7169 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
7170 grep -E -q '(ea_inode|large_xattr)'"
7171 return ${PIPESTATUS[0]}
7174 # Get the maximum xattr size supported by the filesystem.
7178 if large_xattr_enabled; then
7179 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
7182 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
7183 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
7185 # maximum xattr size = size of block - size of header -
7186 # size of 1 entry - 4 null bytes
7187 size=$((block_size - 32 - 32 - 4))
7193 # Dump the value of the named xattr from a file.
7198 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
7201 # Generate a string with size of $size bytes.
7203 local size=${1:-1024} # in bytes
7205 echo "$(head -c $size < /dev/zero | tr '\0' y)"
7208 reformat_external_journal() {
7213 if [ -n "${!var}" ]; then
7214 local rcmd="do_facet $facet"
7216 echo "reformat external journal on $facet:${!var}"
7217 ${rcmd} mke2fs -O journal_dev ${!var} || return 1
7221 # MDT file-level backup/restore
7222 mds_backup_restore() {
7225 local devname=$(mdsdevname $(facet_number $facet))
7226 local mntpt=$(facet_mntpt brpt)
7227 local rcmd="do_facet $facet"
7228 local metaea=${TMP}/backup_restore.ea
7229 local metadata=${TMP}/backup_restore.tgz
7230 local opts=${MDS_MOUNT_OPTS}
7231 local svc=${facet}_svc
7233 if ! ${rcmd} test -b ${devname}; then
7234 opts=$(csa_add "$opts" -o loop)
7237 echo "file-level backup/restore on $facet:${devname}"
7239 # step 1: build mount point
7240 ${rcmd} mkdir -p $mntpt
7241 # step 2: cleanup old backup
7242 ${rcmd} rm -f $metaea $metadata
7244 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7245 if [ ! -z $igif ]; then
7246 # step 3.5: rm .lustre
7247 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
7249 # step 4: backup metaea
7251 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
7253 # step 5: backup metadata
7255 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
7257 ${rcmd} $UMOUNT $mntpt || return 4
7258 # step 8: reformat dev
7259 echo "reformat new device"
7260 format_mdt $(facet_number $facet)
7262 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
7263 # step 10: restore metadata
7265 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
7266 # step 11: restore metaea
7268 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
7269 # step 12: remove recovery logs
7270 echo "remove recovery logs"
7271 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
7272 # step 13: umount dev
7273 ${rcmd} $UMOUNT $mntpt || return 10
7274 # step 14: cleanup tmp backup
7275 ${rcmd} rm -f $metaea $metadata
7276 # step 15: reset device label - it's not virgin on
7277 ${rcmd} e2label $devname ${!svc}
7284 local devname=$(mdsdevname $(facet_number $facet))
7285 local mntpt=$(facet_mntpt brpt)
7286 local rcmd="do_facet $facet"
7287 local opts=${MDS_MOUNT_OPTS}
7289 if ! ${rcmd} test -b ${devname}; then
7290 opts=$(csa_add "$opts" -o loop)
7293 echo "removing OI files on $facet: idx=${idx}"
7295 # step 1: build mount point
7296 ${rcmd} mkdir -p $mntpt
7298 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7299 if [ -z $idx ]; then
7300 # step 3: remove all OI files
7301 ${rcmd} rm -fv $mntpt/oi.16*
7302 elif [ $idx -lt 2 ]; then
7303 ${rcmd} rm -fv $mntpt/oi.16.${idx}
7307 # others, rm oi.16.[idx, idx * idx, idx ** ...]
7308 for ((i=${idx}; i<64; i=$((i * idx)))); do
7309 ${rcmd} rm -fv $mntpt/oi.16.${i}
7313 ${rcmd} $UMOUNT $mntpt || return 2
7314 # OI files will be recreated when mounted as lustre next time.
7317 # generate maloo upload-able log file name
7318 # \param logname specify unique part of file name
7319 generate_logname() {
7320 local logname=${1:-"default_logname"}
7322 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
7325 # make directory on different MDTs
7329 local stripe_count=2
7330 local stripe_index=-1
7333 while getopts "c:i:p" opt; do
7335 c) stripe_count=$OPTARG;;
7336 i) stripe_index=$OPTARG;;
7338 \?) error "only support -i -c -p";;
7342 shift $((OPTIND - 1))
7343 [ $# -eq 1 ] || error "Only creating single directory is supported"
7346 if [ "$p_option" == "-p" ]; then
7347 local parent=$(dirname $path)
7349 [ -d $path ] && return 0
7350 [ ! -d ${parent} ] && mkdir -p ${parent}
7353 if [ $MDSCOUNT -le 1 ]; then
7356 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
7359 if [ $stripe_index -eq -1 ]; then
7360 mdt_index=$((test_num % MDSCOUNT))
7362 mdt_index=$stripe_index
7364 echo "striped dir -i$mdt_index -c$stripe_count $path"
7365 $LFS setdirstripe -i$mdt_index -c$stripe_count $path
7369 # free_fd: find the smallest and not in use file descriptor [above @last_fd]
7371 # If called many times, passing @last_fd will avoid repeated searching
7372 # already-open FDs repeatedly if we know they are still in use.
7374 # usage: free_fd [last_fd]
7377 local max_fd=$(ulimit -n)
7378 local fd=$((${1:-2} + 1))
7380 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
7383 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
7387 check_mount_and_prep()
7389 is_mounted $MOUNT || setupall
7391 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
7392 mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
7393 for idx in $(seq $MDSCOUNT); do
7394 local name="MDT$(printf '%04x' $((idx - 1)))"
7395 rm -rf $MOUNT/.lustre/lost+found/$name/*
7399 # calcule how many ost-objects to be created.
7400 precreated_ost_obj_count()
7404 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
7405 local ost_name="OST$(printf '%04x' $ost_idx)"
7406 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
7407 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7408 osp.$proc_path.prealloc_last_id)
7409 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7410 osp.$proc_path.prealloc_next_id)
7411 echo $((last_id - next_id + 1))
7414 check_file_in_pool()
7419 local res=$($GETSTRIPE $file | grep 0x | cut -f2)
7422 for t in $tlist ; do
7423 [ "$i" -eq "$t" ] && continue 2
7426 echo "pool list: $tlist"
7427 echo "striping: $res"
7428 error_noexit "$file not allocated in $pool"
7435 echo "Creating new pool"
7438 create_pool $FSNAME.$pool ||
7439 { error_noexit "No pool created, result code $?"; return 1; }
7440 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
7441 { error_noexit "$pool not in lfs pool_list"; return 2; }
7444 pool_add_targets() {
7445 echo "Adding targets to pool"
7451 local list=$(seq $first $step $last)
7453 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
7454 do_facet mgs $LCTL pool_add \
7455 $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
7457 # wait for OSTs to be added to the pool
7458 for mds_id in $(seq $MDSCOUNT); do
7459 local mdt_id=$((mds_id-1))
7460 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7461 wait_update_facet mds$mds_id \
7462 "lctl get_param -n lod.$lodname.pools.$pool |
7463 sort -u | tr '\n' ' ' " "$t" || {
7464 error_noexit "mds$mds_id: Add to pool failed"
7468 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
7469 | sort -u | tr '\n' ' ' " "$t" || {
7470 error_noexit "Add to pool failed"
7473 local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
7474 local addcount=$(((last - first) / step + 1))
7475 [ $lfscount -eq $addcount ] || {
7476 error_noexit "lfs pool_list bad ost count" \
7477 "$lfscount != $addcount"
7485 echo "Setting pool on directory $tdir"
7487 $SETSTRIPE -c 2 -p $pool $tdir && return 0
7489 error_noexit "Cannot set pool $pool to $tdir"
7496 echo "Checking pool on directory $tdir"
7498 local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
7499 [ "$res" = "$pool" ] && return 0
7501 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
7505 pool_dir_rel_path() {
7506 echo "Testing relative path works well"
7511 mkdir -p $root/$tdir/$tdir
7513 pool_set_dir $pool $tdir || return 1
7514 pool_set_dir $pool ./$tdir || return 2
7515 pool_set_dir $pool ../$tdir || return 3
7516 pool_set_dir $pool ../$tdir/$tdir || return 4
7517 rm -rf $tdir; cd - > /dev/null
7520 pool_alloc_files() {
7521 echo "Checking files allocation from directory pool"
7528 for i in $(seq -w 1 $count)
7530 local file=$tdir/file-$i
7532 check_file_in_pool $file $pool "$tlist" || \
7533 failed=$((failed + 1))
7535 [ "$failed" = 0 ] && return 0
7537 error_noexit "$failed files not allocated in $pool"
7541 pool_create_files() {
7542 echo "Creating files in pool"
7550 for i in $(seq -w 1 $count)
7552 local file=$tdir/spoo-$i
7553 $SETSTRIPE -p $pool $file
7554 check_file_in_pool $file $pool "$tlist" || \
7555 failed=$((failed + 1))
7557 [ "$failed" = 0 ] && return 0
7559 error_noexit "$failed files not allocated in $pool"
7564 echo "Checking 'lfs df' output"
7567 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
7569 local res=$($LFS df --pool $FSNAME.$pool |
7571 grep "$FSNAME-OST" |
7573 [ "$res" = "$t" ] && return 0
7575 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
7579 pool_file_rel_path() {
7580 echo "Creating files in a pool with relative pathname"
7585 { error_noexit "unable to create $tdir"; return 1 ; }
7586 local file="/..$tdir/$tfile-1"
7587 $SETSTRIPE -p $pool $file ||
7588 { error_noexit "unable to create $file" ; return 2 ; }
7591 $SETSTRIPE -p $pool $tfile-2 || {
7592 error_noexit "unable to create $tfile-2 in $tdir"
7597 pool_remove_first_target() {
7598 echo "Removing first target from a pool"
7601 local pname="lov.$FSNAME-*.pools.$pool"
7602 local t=$($LCTL get_param -n $pname | head -1)
7603 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7604 for mds_id in $(seq $MDSCOUNT); do
7605 local mdt_id=$((mds_id-1))
7606 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7607 wait_update_facet mds$mds_id \
7608 "lctl get_param -n lod.$lodname.pools.$pool |
7610 error_noexit "mds$mds_id: $t not removed from" \
7615 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
7616 error_noexit "$t not removed from $FSNAME.$pool"
7621 pool_remove_all_targets() {
7622 echo "Removing all targets from pool"
7625 local pname="lov.$FSNAME-*.pools.$pool"
7626 for t in $($LCTL get_param -n $pname | sort -u)
7628 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7630 for mds_id in $(seq $MDSCOUNT); do
7631 local mdt_id=$((mds_id-1))
7632 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
7633 wait_update_facet mds$mds_id "lctl get_param -n \
7634 lod.$lodname.pools.$pool" "" || {
7635 error_noexit "mds$mds_id: Pool $pool not drained"
7639 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
7640 error_noexit "Pool $FSNAME.$pool cannot be drained"
7643 # striping on an empty/nonexistant pool should fall back
7644 # to "pool of everything"
7646 error_noexit "failed to use fallback striping for empty pool"
7649 # setstripe on an empty pool should fail
7650 $SETSTRIPE -p $pool $file 2>/dev/null && {
7651 error_noexit "expected failure when creating file" \
7659 echo "Destroying pool"
7663 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
7666 # striping on an empty/nonexistant pool should fall back
7667 # to "pool of everything"
7669 error_noexit "failed to use fallback striping for missing pool"
7672 # setstripe on an empty pool should fail
7673 $SETSTRIPE -p $pool $file 2>/dev/null && {
7674 error_noexit "expected failure when creating file" \
7679 # get param should return err once pool is gone
7680 if wait_update $HOSTNAME "lctl get_param -n \
7681 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
7683 remove_pool_from_list $FSNAME.$pool
7686 error_noexit "Pool $FSNAME.$pool is not destroyed"
7690 # Get and check the actual stripe count of one file.
7691 # Usage: check_stripe_count <file> <expected_stripe_count>
7692 check_stripe_count() {
7697 [[ -z "$file" || -z "$expected" ]] &&
7698 error "check_stripe_count: invalid argument"
7700 local cmd="$GETSTRIPE -c $file"
7701 actual=$($cmd) || error "$cmd failed"
7702 actual=${actual%% *}
7704 if [[ $actual -ne $expected ]]; then
7705 [[ $expected -eq -1 ]] ||
7706 error "$cmd wrong: found $actual, expected $expected"
7707 [[ $actual -eq $OSTCOUNT ]] ||
7708 error "$cmd wrong: found $actual, expected $OSTCOUNT"
7712 # Get and check the actual list of OST indices on one file.
7713 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
7719 [[ -z "$file" || -z "$expected" ]] &&
7720 error "check_obdidx: invalid argument!"
7722 obdidx=$(comma_list $($GETSTRIPE $file | grep -A $OSTCOUNT obdidx |
7723 grep -v obdidx | awk '{print $1}' | xargs))
7725 [[ $obdidx = $expected ]] ||
7726 error "list of OST indices on $file is $obdidx," \
7727 "should be $expected"
7730 # Get and check the actual OST index of the first stripe on one file.
7731 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
7732 check_start_ost_idx() {
7737 [[ -z "$file" || -z "$expected" ]] &&
7738 error "check_start_ost_idx: invalid argument!"
7740 start_ost_idx=$($GETSTRIPE $file | grep -A 1 obdidx | grep -v obdidx |
7743 [[ $start_ost_idx = $expected ]] ||
7744 error "OST index of the first stripe on $file is" \
7745 "$start_ost_idx, should be $expected"
7748 killall_process () {
7749 local clients=${1:-$(hostname)}
7754 do_nodes $clients "killall $signal $name"
7759 do_facet mgs "$LCTL snapshot_create -F $FSNAME $*"
7764 do_facet mgs "$LCTL snapshot_destroy -F $FSNAME $*"
7769 do_facet mgs "$LCTL snapshot_modify -F $FSNAME $*"
7774 do_facet mgs "$LCTL snapshot_list -F $FSNAME $*"
7779 do_facet mgs "$LCTL snapshot_mount -F $FSNAME $*"
7784 do_facet mgs "$LCTL snapshot_umount -F $FSNAME $*"
7791 do_facet mgs "cat $LSNAPSHOT_LOG"
7797 echo "Cleaning test environment ..."
7799 # Every lsnapshot command takes exclusive lock with others,
7800 # so can NOT destroy the snapshot during list with 'xargs'.
7802 local ssname=$(lsnapshot_list | grep snapshot_name |
7803 grep lss_ | awk '{ print $2 }' | head -n 1)
7804 [ -z "$ssname" ] && break
7806 lsnapshot_destroy -n $ssname -f ||
7807 lss_err "Fail to destroy $ssname by force"
7817 local host=$(facet_active_host $facet)
7818 local dir=$(dirname $(facet_vdevice $facet))
7819 local pool=$(zpool_name $facet)
7820 local lfsname=$(zfs_local_fsname $facet)
7821 local label=${FSNAME}-${role}$(printf '%04x' $idx)
7824 "echo '$host - $label zfs:${dir}/${pool}/${lfsname} - -' >> \
7830 do_facet mgs "rm -f $LSNAPSHOT_CONF"
7831 echo "Generating $LSNAPSHOT_CONF on MGS ..."
7833 if ! combined_mgs_mds ; then
7834 [ $(facet_fstype mgs) != zfs ] &&
7835 skip "Lustre snapshot 1 only works for ZFS backend" &&
7838 local host=$(facet_active_host mgs)
7839 local dir=$(dirname $(facet_vdevice mgs))
7840 local pool=$(zpool_name mgs)
7841 local lfsname=$(zfs_local_fsname mgs)
7844 "echo '$host - MGS zfs:${dir}/${pool}/${lfsname} - -' \
7845 >> $LSNAPSHOT_CONF" || lss_err "generate lss conf (mgs)"
7848 for num in `seq $MDSCOUNT`; do
7849 [ $(facet_fstype mds$num) != zfs ] &&
7850 skip "Lustre snapshot 1 only works for ZFS backend" &&
7853 lss_gen_conf_one mds$num MDT $((num - 1)) ||
7854 lss_err "generate lss conf (mds$num)"
7857 for num in `seq $OSTCOUNT`; do
7858 [ $(facet_fstype ost$num) != zfs ] &&
7859 skip "Lustre snapshot 1 only works for ZFS backend" &&
7862 lss_gen_conf_one ost$num OST $((num - 1)) ||
7863 lss_err "generate lss conf (ost$num)"
7866 do_facet mgs "cat $LSNAPSHOT_CONF"
7872 local val=$(awk '{print $2}' <<< $line)
7874 if [[ $line =~ ^"lmm_stripe_count:" ]]; then
7876 elif [[ $line =~ ^"lmm_stripe_size:" ]]; then
7878 elif [[ $line =~ ^"lmm_stripe_offset:" ]]; then
7883 parse_layout_param()
7890 if [[ -z $mode ]]; then
7891 if [[ $line =~ ^"stripe_count:" ]]; then
7893 elif [[ $line =~ ^"lmm_stripe_count:" ]]; then
7895 elif [[ $line =~ ^"lcm_layout_gen:" ]]; then
7900 if [[ $mode = "plain_dir" ]]; then
7901 param=$(echo $line |
7902 awk '{printf("-c %d -S %d -i %d",$2,$4,$6)}')
7903 elif [[ $mode = "plain_file" ]]; then
7904 val=$(parse_plain_param "$line")
7905 [[ ! -z $val ]] && param="$param $val"
7906 elif [[ $mode = "pfl" ]]; then
7907 val=$(echo $line | awk '{print $2}')
7908 if [[ $line =~ ^"lcme_extent.e_end:" ]]; then
7909 if [[ $val = "EOF" ]]; then
7910 param="$param -E -1"
7912 param="$param -E $val"
7914 elif [[ $line =~ ^"stripe_count:" ]]; then
7917 awk '{printf("-c %d -S %d -i %d",$2,$4,$6)}')
7921 val=$(parse_plain_param "$line")
7922 [[ ! -z $val ]] && param="$param $val"
7931 local param=$($LFS getstripe -d $1 | parse_layout_param)