3 trap 'print_summary && touch $TF_FAIL && \
4 echo "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 # LOAD_LLOOP: LU-409: only load llite_lloop module if kernel < 2.6.32 or
21 # LOAD_LLOOP is true. LOAD_LLOOP is false by default.
22 export LOAD_LLOOP=${LOAD_LLOOP:-false}
24 #export PDSH="pdsh -S -Rssh -w"
25 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
26 export UMOUNT=${UMOUNT:-"umount -d"}
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}
146 export MKE2FS=$MKE2FS
147 if [ -z "$MKE2FS" ]; then
148 if which mkfs.ldiskfs >/dev/null 2>&1; then
149 export MKE2FS=mkfs.ldiskfs
155 export DEBUGFS=$DEBUGFS
156 if [ -z "$DEBUGFS" ]; then
157 if which debugfs.ldiskfs >/dev/null 2>&1; then
158 export DEBUGFS=debugfs.ldiskfs
160 export DEBUGFS=debugfs
164 export TUNE2FS=$TUNE2FS
165 if [ -z "$TUNE2FS" ]; then
166 if which tunefs.ldiskfs >/dev/null 2>&1; then
167 export TUNE2FS=tunefs.ldiskfs
169 export TUNE2FS=tune2fs
173 export E2LABEL=$E2LABEL
174 if [ -z "$E2LABEL" ]; then
175 if which label.ldiskfs >/dev/null 2>&1; then
176 export E2LABEL=label.ldiskfs
178 export E2LABEL=e2label
182 export DUMPE2FS=$DUMPE2FS
183 if [ -z "$DUMPE2FS" ]; then
184 if which dumpfs.ldiskfs >/dev/null 2>&1; then
185 export DUMPE2FS=dumpfs.ldiskfs
187 export DUMPE2FS=dumpe2fs
191 export E2FSCK=$E2FSCK
192 if [ -z "$E2FSCK" ]; then
193 if which fsck.ldiskfs >/dev/null 2>&1; then
194 export E2FSCK=fsck.ldiskfs
200 export RESIZE2FS=$RESIZE2FS
201 if [ -z "$RESIZE2FS" ]; then
202 if which resizefs.ldiskfs >/dev/null 2>&1; then
203 export RESIZE2FS=resizefs.ldiskfs
205 export RESIZE2FS=resize2fs
209 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
210 export FSCK_MAX_ERR=4 # File system errors left uncorrected
212 export ZFS=${ZFS:-zfs}
213 export ZPOOL=${ZPOOL:-zpool}
214 export ZDB=${ZDB:-zdb}
215 export PARTPROBE=${PARTPROBE:-partprobe}
217 #[ -d /r ] && export ROOT=${ROOT:-/r}
218 export TMP=${TMP:-$ROOT/tmp}
219 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
220 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
221 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
223 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
224 if ! echo $PATH | grep -q $LUSTRE/utils; then
225 export PATH=$LUSTRE/utils:$PATH
227 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
228 export PATH=$LUSTRE/utils/gss:$PATH
230 if ! echo $PATH | grep -q $LUSTRE/tests; then
231 export PATH=$LUSTRE/tests:$PATH
233 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
234 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
236 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
237 [ ! -f "$LST" ] && export LST=$(which lst)
238 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
239 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
240 export MCREATE=${MCREATE:-mcreate}
241 # Ubuntu, at least, has a truncate command in /usr/bin
242 # so fully path our truncate command.
243 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
244 export FSX=${FSX:-$LUSTRE/tests/fsx}
245 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
246 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
247 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
248 export PATH=$LUSTRE/tests/racer:$PATH:
250 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
251 export PATH=$LUSTRE/tests/mpi:$PATH
253 export RSYNC_RSH=${RSYNC_RSH:-rsh}
255 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
256 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
257 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
258 [ ! -f "$LFS" ] && export LFS=$(which lfs)
259 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
260 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
262 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
263 if [ ! -f "$L_GETIDENTITY" ]; then
264 if `which l_getidentity > /dev/null 2>&1`; then
265 export L_GETIDENTITY=$(which l_getidentity)
267 export L_GETIDENTITY=NONE
270 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
271 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
272 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
273 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
274 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
275 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
276 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
277 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
278 [ ! -f "$LUSTRE_RMMOD" ] &&
279 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
280 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
281 [ ! -f "$LFS_MIGRATE" ] &&
282 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
283 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
284 [ ! -f "$LR_READER" ] && export LR_READER=$(which lr_reader 2> /dev/null)
285 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
286 export NAME=${NAME:-local}
287 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
288 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
289 export LGSSD=$(which lgssd)
290 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
291 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
292 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
294 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
297 if [ "$ACCEPTOR_PORT" ]; then
298 export PORT_OPT="--port $ACCEPTOR_PORT"
303 echo "Using GSS/krb5 ptlrpc security flavor"
304 which lgss_keyring > /dev/null 2>&1 || \
305 error_exit "built with gss disabled! SEC=$SEC"
316 IDENTITY_UPCALL=false
320 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
322 # Paths on remote nodes, if different
323 export RLUSTRE=${RLUSTRE:-$LUSTRE}
324 export RPWD=${RPWD:-$PWD}
325 export I_MOUNTED=${I_MOUNTED:-"no"}
326 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
327 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
328 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
329 ! -f $LUSTRE/mdt/mdt.ko ]; then
330 export CLIENTMODSONLY=yes
333 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
334 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
338 while getopts "rvwf:" opt $*; do
343 w) WRITECONF=writeconf;;
348 shift $((OPTIND - 1))
351 # print the durations of each test if "true"
352 DDETAILS=${DDETAILS:-false}
353 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
358 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
365 ncpts=$(do_facet $facet "lctl get_param -n " \
366 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
368 if [ $ncpts -eq 0 ]; then
375 # Return a numeric version code based on a version string. The version
376 # code is useful for comparison two version strings to see which is newer.
378 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
379 eval set -- $(tr "[:punct:]" " " <<< $*)
381 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
384 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
385 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
387 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
389 # usage: lustre_build_version
391 # All Lustre versions support "lctl get_param" to report the version of the
392 # code running in the kernel (what our tests are interested in), but it
393 # doesn't work without modules loaded. If that fails, use "lctl version"
394 # instead, which is easy to parse and works without the kernel modules,
395 # but was only added in 2.6.50. If that also fails, fall back to calling
396 # "lctl lustre_build_version" which prints either (or both) the userspace
397 # and kernel build versions, but is deprecated and should eventually be
400 # output: prints version string to stdout in dotted-decimal format
401 lustre_build_version() {
402 local facet=${1:-client}
405 # kernel: patchless_client
406 # build: v2_6_92_0-gadb3ee4-2.6.32-431.29.2.el6_lustre.x86_64
407 local VER=$(do_facet $facet $LCTL get_param -n version 2> /dev/null |
408 awk '/lustre: / { print $2 }')
410 [ -z "$VER" ] && VER=$(do_facet $facet $LCTL --version 2>/dev/null |
412 # Lustre version: 2.5.3-gfcfd782-CHANGED-2.6.32.26-175.fc12.x86_64
413 # lctl version: 2.5.3-gfcfd782-CHANGED-2.6.32.26-175.fc12.x86_64
414 [ -z "$VER" ] && VER=$(do_facet $facet $LCTL lustre_build_version |
415 awk '/version:/ { print $3; exit; }')
416 sed -e 's/^v//' -e 's/-.*//' -e 's/_/./g' <<<$VER
419 # Report the Lustre numeric build version code for the supplied facet.
420 lustre_version_code() {
421 version_code $(lustre_build_version $1)
425 /sbin/lsmod | grep -q "^\<$1\>"
428 # Load a module on the system where this is running.
430 # usage: load_module module_name [module arguments for insmod/modprobe]
432 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
433 # will be used as the arguments. Otherwise arguments will be obtained from
434 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
441 BASE=$(basename $module $EXT)
443 module_loaded ${BASE} && return
445 # If no module arguments were passed, get them from $MODOPTS_<MODULE>,
446 # else from modprobe.conf
447 if [ $# -eq 0 ]; then
448 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
449 # Bash until 4.x, so we resort to eval.
450 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
451 eval set -- \$$optvar
452 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
453 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
455 opt=$(awk -v var="^options $BASE" '$0 ~ var \
456 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
457 set -- $(echo -n $opt)
459 # Ensure we have accept=all for lnet
460 if [ $(basename $module) = lnet ]; then
461 # OK, this is a bit wordy...
462 local arg accept_all_present=false
465 [ "$arg" = accept=all ] && \
466 accept_all_present=true
468 $accept_all_present || set -- "$@" accept=all
474 [ $# -gt 0 ] && echo "${module} options: '$*'"
476 # Note that insmod will ignore anything in modprobe.conf, which is why
477 # we're passing options on the command-line.
478 if [[ "$BASE" == "lnet_selftest" ]] &&
479 [[ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]]; then
480 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
481 elif [[ -f ${LUSTRE}/${module}${EXT} ]]; then
482 [[ "$BASE" != "ptlrpc_gss" ]] || modprobe sunrpc
483 insmod ${LUSTRE}/${module}${EXT} "$@"
485 # must be testing a "make install" or "rpm" installation
486 # note failed to load ptlrpc_gss is considered not fatal
487 if [[ "$BASE" == "ptlrpc_gss" ]]; then
488 modprobe $BASE "$@" 2>/dev/null ||
489 echo "gss/krb5 is not supported"
496 llite_lloop_enabled() {
497 local n1=$(uname -r | cut -d. -f1)
498 local n2=$(uname -r | cut -d. -f2)
499 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
501 # load the llite_lloop module for < 2.6.32 kernels
502 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
503 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
510 load_modules_local() {
511 if [ -n "$MODPROBE" ]; then
513 echo "Using modprobe to load modules"
517 echo Loading modules from $LUSTRE
521 if [ -f /sys/devices/system/cpu/online ]; then
522 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
523 echo "detected $ncpus online CPUs by sysfs"
525 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
527 if [ $rc -eq 0 ]; then
528 echo "detected $ncpus online CPUs by getconf"
530 echo "Can't detect number of CPUs"
535 # if there is only one CPU core, libcfs can only create one partition
536 # if there is more than 4 CPU cores, libcfs should create multiple CPU
537 # partitions. So we just force libcfs to create 2 partitions for
538 # system with 2 or 4 cores
539 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
540 # force to enable multiple CPU partitions
541 echo "Force libcfs to create 2 CPU partitions"
542 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
544 echo "libcfs will create CPU partition based on online CPUs"
547 load_module ../libcfs/libcfs/libcfs
549 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
550 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
551 load_module ../lnet/lnet/lnet
554 LNETLND="o2iblnd/ko2iblnd"
559 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
560 load_module ../lnet/klnds/$LNETLND
561 load_module obdclass/obdclass
562 load_module ptlrpc/ptlrpc
563 load_module ptlrpc/gss/ptlrpc_gss
571 load_module obdecho/obdecho
572 if ! client_only; then
573 SYMLIST=/proc/kallsyms
574 grep -q crc16 $SYMLIST ||
575 { modprobe crc16 2>/dev/null || true; }
576 grep -q -w jbd2 $SYMLIST ||
577 { modprobe jbd2 2>/dev/null || true; }
578 load_module lfsck/lfsck
579 [ "$LQUOTA" != "no" ] &&
580 load_module quota/lquota $LQUOTAOPTS
581 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
583 load_module osd-zfs/osd_zfs
585 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
586 grep -q exportfs_decode_fh $SYMLIST ||
587 { modprobe exportfs 2> /dev/null || true; }
588 grep -q -w mbcache $SYMLIST ||
589 { modprobe mbcache 2>/dev/null || true; }
590 load_module ../ldiskfs/ldiskfs
591 load_module osd-ldiskfs/osd_ldiskfs
603 load_module llite/lustre
604 llite_lloop_enabled && load_module llite/llite_lloop
605 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
607 rm -f $OGDB/ogdb-$HOSTNAME
608 $LCTL modules > $OGDB/ogdb-$HOSTNAME
610 # 'mount' doesn't look in $PATH, just sbin
611 local mount_lustre=$LUSTRE/utils/mount.lustre
612 if [ -f $mount_lustre ]; then
613 local sbin_mount=$(readlink -f /sbin)/mount.lustre
614 if grep -qw "$sbin_mount" /proc/mounts; then
615 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
617 if ! grep -qw "$sbin_mount" /proc/mounts; then
618 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
619 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
620 cat <<- EOF > "$sbin_mount"
623 echo "This $sbin_mount just a mountpoint." 1>&2
624 echo "It is never supposed to be run." 1>&2
625 logger -p emerg -- "using stub $sbin_mount $@"
628 chmod a+x $sbin_mount
630 mount --bind $mount_lustre $sbin_mount ||
631 error "can't bind $mount_lustre to $sbin_mount"
639 # load modules on remote nodes optionally
640 # lustre-tests have to be installed on these nodes
641 if $LOAD_MODULES_REMOTE; then
642 local list=$(comma_list $(remote_nodes_list))
643 if [ -n "$list" ]; then
644 echo "loading modules on: '$list'"
645 do_rpc_nodes "$list" load_modules_local
651 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
652 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
653 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
654 echo "$LEAK_LUSTRE" 1>&2
655 echo "$LEAK_PORTALS" 1>&2
656 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
657 echo "Memory leaks detected"
658 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
664 wait_exit_ST client # bug 12845
666 $LUSTRE_RMMOD ldiskfs || return 2
668 if $LOAD_MODULES_REMOTE; then
669 local list=$(comma_list $(remote_nodes_list))
670 if [ -n "$list" ]; then
671 echo "unloading modules on: '$list'"
672 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
673 do_rpc_nodes "$list" check_mem_leak
677 local sbin_mount=$(readlink -f /sbin)/mount.lustre
678 if grep -qe "$sbin_mount " /proc/mounts; then
679 umount $sbin_mount || true
680 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
684 check_mem_leak || return 254
686 echo "modules unloaded."
691 local facet=${1:-$SINGLEMDS}
692 local fstype=$(facet_fstype $facet)
695 ldiskfs) size=50;; # largest seen is 44, leave some headroom
696 zfs) size=400;; # largest seen is 384
702 check_gss_daemon_nodes() {
706 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
707 if [ \\\"\\\$num\\\" -ne 1 ]; then
708 echo \\\$num instance of $dname;
713 check_gss_daemon_facet() {
717 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
718 if [ $num -ne 1 ]; then
719 echo "$num instance of $dname on $facet"
728 echo Stopping $@ on $list
729 do_nodes $list "killall -2 $@ 2>/dev/null || true"
732 # start gss daemons on all nodes, or
733 # "daemon" on "list" if set
734 start_gss_daemons() {
738 if [ "$list" ] && [ "$daemon" ] ; then
739 echo "Starting gss daemon on nodes: $list"
740 do_nodes $list "$daemon" || return 8
744 local list=$(comma_list $(mdts_nodes))
745 echo "Starting gss daemon on mds: $list"
746 do_nodes $list "$LSVCGSSD -v" || return 1
748 do_nodes $list "$LGSSD -v" || return 2
751 list=$(comma_list $(osts_nodes))
752 echo "Starting gss daemon on ost: $list"
753 do_nodes $list "$LSVCGSSD -v" || return 3
754 # starting on clients
756 local clients=${CLIENTS:-`hostname`}
758 echo "Starting $LGSSD on clients $clients "
759 do_nodes $clients "$LGSSD -v" || return 4
762 # wait daemons entering "stable" status
766 # check daemons are running
768 list=$(comma_list $(mdts_nodes) $(osts_nodes))
769 check_gss_daemon_nodes $list lsvcgssd || return 5
771 list=$(comma_list $(mdts_nodes))
772 check_gss_daemon_nodes $list lgssd || return 6
775 check_gss_daemon_nodes $clients lgssd || return 7
780 local list=$(comma_list $(mdts_nodes))
782 send_sigint $list lsvcgssd lgssd
784 list=$(comma_list $(osts_nodes))
785 send_sigint $list lsvcgssd
787 list=${CLIENTS:-`hostname`}
788 send_sigint $list lgssd
793 if ! module_loaded ptlrpc_gss; then
794 load_module ptlrpc/gss/ptlrpc_gss
795 module_loaded ptlrpc_gss ||
796 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
799 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
802 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
804 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
812 # maybe cleanup credential cache?
818 local var=${facet}_svc
826 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
827 tr '[:lower:]' '[:upper:]'
833 if [ $facet == mgs ] || [ $facet == client ]; then
837 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
845 if [ -n "${!var}" ]; then
850 var=$(facet_type $facet)FSTYPE
851 if [ -n "${!var}" ]; then
856 if [ -n "$FSTYPE" ]; then
861 if [[ $facet == mgs ]] && combined_mgs_mds; then
873 local facets=$(get_facets)
876 for facet in ${facets//,/ }; do
877 if [ $node == $(facet_host $facet) ] ||
878 [ $node == "$(facet_failover_host $facet)" ]; then
879 fstype=$(facet_fstype $facet)
880 if [[ $fstypes != *$fstype* ]]; then
881 fstypes+="${fstypes:+,}$fstype"
890 local num=$(facet_number $facet)
893 if [[ $(facet_type $facet) = OST ]]; then
895 if [[ -n "${!index}" ]]; then
900 index=${OST_INDICES[num - 1]}
903 [[ -n "$index" ]] || index=$((num - 1))
911 local fstype=$(facet_fstype $facet)
915 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
917 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
918 ${dev} 2>/dev/null");;
920 error "unknown fstype!";;
928 local device=$(mdsdevname $num)
929 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
935 local device=$(ostdevname $num)
936 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
941 # Get the device of a facet.
948 mgs) device=$(mgsdevname) ;;
949 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
950 ost*) device=$(ostdevname $(facet_number $facet)) ;;
951 fs2mds) device=$(mdsdevname 1_2) ;;
952 fs2ost) device=$(ostdevname 1_2) ;;
953 fs3ost) device=$(ostdevname 2_2) ;;
961 # Get the virtual device of a facet.
968 mgs) device=$(mgsvdevname) ;;
969 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
970 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
971 fs2mds) device=$(mdsvdevname 1_2) ;;
972 fs2ost) device=$(ostvdevname 1_2) ;;
973 fs3ost) device=$(ostvdevname 2_2) ;;
981 # Re-read the partition table on failover partner host.
982 # After a ZFS storage pool is created on a shared device, the partition table
983 # on the device may change. However, the operating system on the failover
984 # host may not notice the change automatically. Without the up-to-date partition
985 # block devices, 'zpool import ..' cannot find the labels, whose positions are
986 # relative to partition rather than disk beginnings.
988 # This function performs partprobe on the failover host to make it re-read the
991 refresh_partition_table() {
996 host=$(facet_passive_host $facet)
997 if [[ -n "$host" ]]; then
998 do_node $host "$PARTPROBE $device"
1003 # Get ZFS storage pool name.
1010 device=$(facet_device $facet)
1011 # poolname is string before "/"
1012 poolname="${device%%/*}"
1018 # Create ZFS storage pool.
1025 local opts=${@:-"-o cachefile=none"}
1027 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
1028 $ZPOOL create -f $opts $poolname $vdev"
1032 # Create ZFS file system.
1038 local opts=${@:-"-o mountpoint=legacy"}
1040 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1041 $ZFS create $opts $dataset"
1045 # Export ZFS storage pool.
1046 # Before exporting the pool, all datasets within the pool should be unmounted.
1054 poolname=$(zpool_name $facet)
1056 if [[ -n "$poolname" ]]; then
1057 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1058 grep -q ^$poolname/ /proc/mounts ||
1059 $ZPOOL export $opts $poolname"
1064 # Destroy ZFS storage pool.
1065 # Destroy the given pool and free up any devices for other use. This command
1066 # tries to unmount any active datasets before destroying the pool.
1067 # -f Force any active datasets contained within the pool to be unmounted.
1071 local poolname=${2:-$(zpool_name $facet)}
1073 if [[ -n "$poolname" ]]; then
1074 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1075 $ZPOOL destroy -f $poolname"
1080 # Import ZFS storage pool.
1081 # Force importing, even if the pool appears to be potentially active.
1086 local opts=${@:-"-o cachefile=none"}
1089 poolname=$(zpool_name $facet)
1091 if [[ -n "$poolname" ]]; then
1092 opts+=" -d $(dirname $(facet_vdevice $facet))"
1093 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
1094 $ZPOOL import -f $opts $poolname"
1099 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1100 # is not automatically imported on system startup.
1102 # In a failover environment, this will provide resource level fencing which
1103 # will ensure that the same ZFS storage pool will not be imported concurrently
1104 # on different nodes.
1106 disable_zpool_cache() {
1110 poolname=$(zpool_name $facet)
1112 if [[ -n "$poolname" ]]; then
1113 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1118 # This and set_osd_param() shall be used to access OSD parameters
1119 # once existed under "obdfilter":
1124 # writethrough_cache_enable
1128 local device=${2:-$FSNAME-OST*}
1131 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1132 osd-*.$device.$name 2>&1" | grep -v 'error:'
1137 local device=${2:-$FSNAME-OST*}
1141 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1142 osd-*.$device.$name=$value 2>&1" | grep -v 'error:'
1146 local dz=${1:-$DEBUG_SIZE}
1148 if [ -f /sys/devices/system/cpu/possible ]; then
1149 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1151 local cpus=$(getconf _NPROCESSORS_CONF)
1154 # bug 19944, adjust size to be -gt num_possible_cpus()
1155 # promise 2MB for every cpu at least
1156 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1159 lctl set_param debug_mb=$dz
1162 set_default_debug () {
1163 local debug=${1:-"$PTLDEBUG"}
1164 local subsys=${2:-"$SUBSYSTEM"}
1165 local debug_size=${3:-$DEBUG_SIZE}
1167 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1168 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1170 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1173 set_default_debug_nodes () {
1176 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1177 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1181 do_rpc_nodes "$nodes" set_default_debug \
1182 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1185 set_default_debug_facet () {
1187 local node=$(facet_active_host $facet)
1188 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1190 set_default_debug_nodes $node
1194 local hostid=${1:-$(hostid)}
1196 if [ ! -s /etc/hostid ]; then
1197 printf $(echo -n $hostid |
1198 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1204 local facets=${1:-$(get_facets)}
1207 for facet in ${facets//,/ }; do
1210 [ $RC -eq 0 ] && continue
1212 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1213 skip "Restart of $facet failed!." && touch $LU482_FAILED
1215 error "Restart of $facet failed!"
1222 # Add argument "arg" (e.g., "loop") to the comma-separated list
1223 # of arguments for option "opt" (e.g., "-o") on command
1224 # line "opts" (e.g., "-o flock").
1230 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1232 if echo "$opts" | grep -q $opt_pattern; then
1233 opts=$(echo "$opts" | sed -e \
1234 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1236 opts+="${opts:+ }$opt $arg"
1244 local dev=$(facet_active $facet)_dev
1245 local opt=${facet}_opt
1246 local mntpt=$(facet_mntpt $facet)
1247 local opts="${!opt} $@"
1248 local fstype=$(facet_fstype $facet)
1251 module_loaded lustre || load_modules
1253 if [ $(facet_fstype $facet) == ldiskfs ] &&
1254 ! do_facet $facet test -b ${!dev}; then
1255 opts=$(csa_add "$opts" -o loop)
1258 if [[ $(facet_fstype $facet) == zfs ]]; then
1259 # import ZFS storage pool
1260 import_zpool $facet || return ${PIPESTATUS[0]}
1265 devicelabel=$(do_facet ${facet} "$E2LABEL ${!dev}");;
1267 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
1268 lustre:svname ${!dev}");;
1270 error "unknown fstype!";;
1273 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1274 # for testing LU-482 error handling in mount_facets() and test_0a()
1275 if [ -f $TMP/test-lu482-trigger ]; then
1278 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1283 if [ $RC -ne 0 ]; then
1284 echo "Start of ${!dev} on ${facet} failed ${RC}"
1288 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
1289 if [[ "$health" != "healthy" ]]; then
1290 error "$facet is in a unhealthy state"
1293 set_default_debug_facet $facet
1295 if [[ $facet == mds* ]]; then
1297 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 2>/dev/null
1300 if [[ $opts =~ .*nosvc.* ]]; then
1301 echo "Start ${!dev} without service"
1306 wait_update_facet ${facet} "$E2LABEL ${!dev} \
1307 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
1308 "" || error "${!dev} failed to initialize!";;
1310 wait_update_facet ${facet} "$ZFS get -H -o value \
1311 lustre:svname ${!dev} 2>/dev/null | \
1312 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
1313 error "${!dev} failed to initialize!";;
1316 error "unknown fstype!";;
1320 # commit the device label change to disk
1321 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
1322 do_facet $facet "sync; sync; sync"
1326 label=$(devicelabel ${facet} ${!dev})
1327 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1328 eval export ${facet}_svc=${label}
1329 echo Started ${label}
1334 # start facet device options
1340 eval export ${facet}_dev=${device}
1341 eval export ${facet}_opt=\"$@\"
1343 local varname=${facet}failover_dev
1344 if [ -n "${!varname}" ] ; then
1345 eval export ${facet}failover_dev=${!varname}
1347 eval export ${facet}failover_dev=$device
1350 local mntpt=$(facet_mntpt $facet)
1351 do_facet ${facet} mkdir -p $mntpt
1352 eval export ${facet}_MOUNT=$mntpt
1353 mount_facet ${facet}
1356 if [[ $facet == mds* ]]; then
1358 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1369 local HOST=`facet_active_host $facet`
1370 [ -z $HOST ] && echo stop: no host for $facet && return 0
1372 local mntpt=$(facet_mntpt $facet)
1373 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1374 if [ ${running} -ne 0 ]; then
1375 echo "Stopping $mntpt (opts:$@) on $HOST"
1376 do_facet ${facet} $UMOUNT $@ $mntpt
1379 # umount should block, but we should wait for unrelated obd's
1380 # like the MGS or MGC to also stop.
1381 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1383 if [[ $(facet_fstype $facet) == zfs ]]; then
1384 # export ZFS storage pool
1389 # save quota version (both administrative and operational quotas)
1390 # add an additional parameter if mountpoint is ever different from $MOUNT
1392 # XXX This function is kept for interoperability with old server (< 2.3.50),
1393 # it should be removed whenever we drop the interoperability for such
1395 quota_save_version() {
1396 local fsname=${2:-$FSNAME}
1398 local ver=$(tr -c -d "123" <<< $spec)
1399 local type=$(tr -c -d "ug" <<< $spec)
1401 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1403 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1405 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1407 local osts=$(get_facets OST)
1408 for ost in ${osts//,/ }; do
1410 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1414 # client could mount several lustre
1416 # XXX This function is kept for interoperability with old server (< 2.3.50),
1417 # it should be removed whenever we drop the interoperability for such
1420 local fsname=${1:-$FSNAME}
1422 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1424 do_nodes $(comma_list $(osts_nodes)) \
1425 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1429 # get mdt quota type
1431 local varsvc=${SINGLEMDS}_svc
1432 do_facet $SINGLEMDS $LCTL get_param -n \
1433 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1436 # get ost quota type
1438 # All OSTs should have same quota type
1439 local varsvc=ost1_svc
1440 do_facet ost1 $LCTL get_param -n \
1441 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1444 # restore old quota type settings
1446 if [ "$old_MDT_QUOTA_TYPE" ]; then
1447 do_facet mgs $LCTL conf_param \
1448 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1450 if [ "$old_OST_QUOTA_TYPE" ]; then
1451 do_facet mgs $LCTL conf_param \
1452 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1456 # Handle the case when there is a space in the lfs df
1457 # "filesystem summary" line the same as when there is no space.
1458 # This will allow fixing the "lfs df" summary line in the future.
1460 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1463 # Get free inodes on the MDT specified by mdt index, free indoes on
1464 # the whole filesystem will be returned when index == -1.
1470 if [ $index -eq -1 ]; then
1473 mdt_uuid=$(mdtuuid_from_index $index)
1476 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1483 # save old quota type & set new quota type
1484 local mdt_qtype=$(mdt_quota_type)
1485 local ost_qtype=$(ost_quota_type)
1487 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1488 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1490 export old_MDT_QUOTA_TYPE=$mdt_qtype
1491 export old_OST_QUOTA_TYPE=$ost_qtype
1493 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1494 error "set mdt quota type failed"
1495 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1496 error "set ost quota type failed"
1498 local quota_usrs=$QUOTA_USERS
1500 # get_filesystem_size
1501 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1502 local blk_soft=$((disksz + 1024))
1503 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1505 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1506 local i_soft=$inodes
1507 local i_hard=$((i_soft + i_soft / 20))
1509 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1510 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1511 "inode-hardlimit: $i_hard"
1514 for usr in $quota_usrs; do
1515 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1517 cmd="$LFS setquota -$type $usr -b $blk_soft"
1518 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1520 eval $cmd || error "$cmd FAILED!"
1522 # display the quota status
1523 echo "Quota settings for $usr : "
1524 $LFS quota -v -u $usr $mntpt || true
1531 local opts=${3:-$MOUNT_OPTS}
1532 opts=${opts:+-o $opts}
1533 local flags=${4:-$MOUNT_FLAGS}
1535 local device=$MGSNID:/$FSNAME$FILESET
1536 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1537 echo "Bad mount command: opt=$flags $opts dev=$device " \
1542 echo "Starting client: $client: $flags $opts $device $mnt"
1543 do_node $client mkdir -p $mnt
1544 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
1545 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1547 #disable FILESET if not supported
1548 do_nodes $client lctl get_param -n \
1549 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1550 device=$MGSNID:/$FSNAME
1551 do_node $client mkdir -p $mnt/$FILESET
1552 do_node $client "! grep -q $mnt' ' /proc/mounts ||
1555 do_node $client $MOUNT_CMD $flags $opts $device $mnt || return 1
1557 set_default_debug_nodes $client
1569 [ "$3" ] && force=-f
1570 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1571 if [ $running -ne 0 ]; then
1572 echo "Stopping client $client $mnt (opts:$force)"
1573 do_node $client lsof -t $mnt || need_kill=no
1574 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1575 pids=$(do_node $client lsof -t $mnt | sort -u);
1576 if [ -n $pids ]; then
1577 do_node $client kill -9 $pids || true
1581 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1582 if [ $busy -ne 0 ] ; then
1583 echo "$mnt is still busy, wait one second" && sleep 1
1584 do_node $client umount $force $mnt
1589 # nodes is comma list
1590 sanity_mount_check_nodes () {
1596 # FIXME: assume that all cluster nodes run the same os
1597 [ "$(uname)" = Linux ] || return 0
1600 for mnt in $mnts ; do
1601 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1602 mpts=\\\$(mount | grep -c $mnt' ');
1603 if [ \\\$running -ne \\\$mpts ]; then
1604 echo \\\$(hostname) env are INSANE!;
1607 [ $? -eq 0 ] || rc=1
1612 sanity_mount_check_servers () {
1613 [ "$CLIENTONLY" ] &&
1614 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1615 echo Checking servers environments
1617 # FIXME: modify get_facets to display all facets wo params
1618 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1622 for facet in ${facets//,/ }; do
1623 node=$(facet_host ${facet})
1624 mntpt=$(facet_mntpt $facet)
1625 sanity_mount_check_nodes $node $mntpt ||
1626 { error "server $node environments are insane!"; return 1; }
1630 sanity_mount_check_clients () {
1631 local clients=${1:-$CLIENTS}
1632 local mntpt=${2:-$MOUNT}
1633 local mntpt2=${3:-$MOUNT2}
1635 [ -z $clients ] && clients=$(hostname)
1636 echo Checking clients $clients environments
1638 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1639 error "clients environments are insane!"
1642 sanity_mount_check () {
1643 sanity_mount_check_servers || return 1
1644 sanity_mount_check_clients || return 2
1647 # mount clients if not mouted
1648 zconf_mount_clients() {
1651 local opts=${3:-$MOUNT_OPTS}
1652 opts=${opts:+-o $opts}
1653 local flags=${4:-$MOUNT_FLAGS}
1655 local device=$MGSNID:/$FSNAME$FILESET
1656 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1657 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
1662 echo "Starting client $clients: $flags $opts $device $mnt"
1663 if [ -n "$FILESET" -a ! -n "$SKIP_FILESET" ]; then
1664 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1666 do_nodes $clients $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1668 #disable FILESET if not supported
1669 do_nodes $clients lctl get_param -n \
1670 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1671 device=$MGSNID:/$FSNAME
1672 do_nodes $clients mkdir -p $mnt/$FILESET
1673 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1678 running=\\\$(mount | grep -c $mnt' ');
1680 if [ \\\$running -eq 0 ] ; then
1682 $MOUNT_CMD $flags $opts $device $mnt;
1685 exit \\\$rc" || return ${PIPESTATUS[0]}
1687 echo "Started clients $clients: "
1688 do_nodes $clients "mount | grep $mnt' '"
1690 set_default_debug_nodes $clients
1695 zconf_umount_clients() {
1700 [ "$3" ] && force=-f
1702 echo "Stopping clients: $clients $mnt (opts:$force)"
1703 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1704 if [ \\\$running -ne 0 ] ; then
1705 echo Stopping client \\\$(hostname) $mnt opts:$force;
1706 lsof $mnt || need_kill=no;
1707 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1708 pids=\\\$(lsof -t $mnt | sort -u);
1709 if [ -n \\\"\\\$pids\\\" ]; then
1713 while umount $force $mnt 2>&1 | grep -q "busy"; do
1714 echo "$mnt is still busy, wait one second" && sleep 1;
1721 echo + $POWER_DOWN $node
1725 shutdown_node_hard () {
1727 local attempts=$SHUTDOWN_ATTEMPTS
1729 for i in $(seq $attempts) ; do
1732 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1733 echo "waiting for $host to fail attempts=$attempts"
1734 [ $i -lt $attempts ] || \
1735 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1741 local mnt=${2:-$MOUNT}
1744 if [ "$FAILURE_MODE" = HARD ]; then
1745 shutdown_node_hard $client
1747 zconf_umount_clients $client $mnt -f
1753 local facets="$(get_facets OST),$(get_facets MDS)"
1756 combined_mgs_mds || facets="$facets,mgs"
1758 for facet in ${facets//,/ }; do
1759 if [ $(facet_active_host $facet) == $host ]; then
1760 affected="$affected $facet"
1764 echo $(comma_list $affected)
1769 local host=${2:-$(facet_host $facet)}
1771 local label=$(convert_facet2label $facet)
1772 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
1775 facets_up_on_host () {
1777 local facets=$(facets_on_host $host)
1780 for facet in ${facets//,/ }; do
1781 if $(facet_up $facet $host); then
1782 affected_up="$affected_up $facet"
1786 echo $(comma_list $affected_up)
1792 if [ "$FAILURE_MODE" = HARD ]; then
1793 shutdown_node_hard $(facet_active_host $facet)
1801 echo + $POWER_UP $node
1814 if [ "$FAILURE_MODE" = HARD ]; then
1815 reboot_node $(facet_active_host $facet)
1823 if [ "$FAILURE_MODE" = HARD ]; then
1833 for facet in ${facets//,/ }; do
1834 hosts=$(expand_list $hosts $(facet_host $facet) )
1840 _check_progs_installed () {
1844 for prog in $progs; do
1845 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1846 echo $prog missing on $(hostname)
1853 check_progs_installed () {
1857 do_rpc_nodes "$nodes" _check_progs_installed $@
1860 # recovery-scale functions
1862 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1865 start_client_load() {
1868 local var=$(node_var_name $client)_load
1869 eval export ${var}=$load
1871 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1872 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1873 END_RUN_FILE=$END_RUN_FILE \
1874 LOAD_PID_FILE=$LOAD_PID_FILE \
1875 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1876 TESTNAME=$TESTNAME \
1877 DBENCH_LIB=$DBENCH_LIB \
1878 DBENCH_SRC=$DBENCH_SRC \
1879 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1883 log "Started client load: ${load} on $client"
1885 # get the children process IDs
1886 local pids=$(ps --ppid $ppid -o pid= | xargs)
1887 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1891 start_client_loads () {
1892 local -a clients=(${1//,/ })
1893 local numloads=${#CLIENT_LOADS[@]}
1896 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1897 testnum=$((nodenum % numloads))
1898 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1900 # bug 22169: wait the background threads to start
1904 # only for remote client
1905 check_client_load () {
1907 local var=$(node_var_name $client)_load
1908 local TESTLOAD=run_${!var}.sh
1910 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1912 # bug 18914: try to connect several times not only when
1913 # check ps, but while check_catastrophe also
1916 while [ $RC = 254 -a $tries -gt 0 ]; do
1920 if ! check_catastrophe $client; then
1922 if [ $RC -eq 254 ]; then
1923 # FIXME: not sure how long we shuold sleep here
1927 echo "check catastrophe failed: RC=$RC "
1931 # We can continue try to connect if RC=254
1932 # Just print the warning about this
1933 if [ $RC = 254 ]; then
1934 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1937 # see if the load is still on the client
1940 while [ $RC = 254 -a $tries -gt 0 ]; do
1944 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1949 if [ $RC = 254 ]; then
1950 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1951 # see if we can diagnose a bit why this is
1956 check_client_loads () {
1957 local clients=${1//,/ }
1961 for client in $clients; do
1962 check_client_load $client
1964 if [ "$rc" != 0 ]; then
1965 log "Client load failed on node $client, rc=$rc"
1971 restart_client_loads () {
1972 local clients=${1//,/ }
1973 local expectedfail=${2:-""}
1977 for client in $clients; do
1978 check_client_load $client
1980 if [ "$rc" != 0 -a "$expectedfail" ]; then
1981 local var=$(node_var_name $client)_load
1982 start_client_load $client ${!var}
1983 echo "Restarted client load ${!var}: on $client. Checking ..."
1984 check_client_load $client
1986 if [ "$rc" != 0 ]; then
1987 log "Client load failed to restart on node $client, rc=$rc"
1988 # failure one client load means test fail
1989 # we do not need to check other
1998 # Start vmstat and save its process ID in a file.
2003 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2006 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
2007 2>/dev/null </dev/null & echo \\\$! > $pid_file"
2010 # Display the nodes on which client loads failed.
2011 print_end_run_file() {
2015 [ -s $file ] || return 0
2017 echo "Found the END_RUN_FILE file: $file"
2020 # A client load will stop if it finds the END_RUN_FILE file.
2021 # That does not mean the client load actually failed though.
2022 # The first node in END_RUN_FILE is the one we are interested in.
2025 if [ -n "$node" ]; then
2026 local var=$(node_var_name $node)_load
2028 local prefix=$TESTLOG_PREFIX
2029 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2030 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2031 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2033 echo "Client load ${!var} failed on node $node:"
2039 # Stop the process which had its PID saved in a file.
2044 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2046 do_nodes $nodes "test -f $pid_file &&
2047 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2050 # Stop all client loads.
2051 stop_client_loads() {
2052 local nodes=${1:-$CLIENTS}
2055 # stop the client loads
2056 stop_process $nodes $pid_file
2058 # clean up the processes that started them
2059 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
2061 # End recovery-scale functions
2063 # verify that lustre actually cleaned up properly
2065 VAR=$(lctl get_param -n catastrophe 2>&1)
2066 if [ $? = 0 ] ; then
2067 if [ $VAR != 0 ]; then
2068 error "LBUG/LASSERT detected"
2071 BUSY=$(dmesg | grep -i destruct || true)
2072 if [ -n "$BUSY" ]; then
2074 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2078 check_mem_leak || exit 204
2080 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2081 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2084 if module_loaded lnet || module_loaded libcfs; then
2085 echo "$TESTSUITE: modules still loaded..." 1>&2
2094 if [[ "$1" == "--verbose" ]]; then
2109 PREV_RESULT=$(do_node $node "$TEST")
2111 RESULT=$(do_node $node "$TEST")
2112 if [[ "$RESULT" == "$FINAL" ]]; then
2113 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2114 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2118 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2119 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2123 [[ $WAIT -ge $MAX ]] && break
2124 [[ $((WAIT % print)) -eq 0 ]] &&
2125 echo "Waiting $((MAX - WAIT)) secs for update"
2126 WAIT=$((WAIT + sleep))
2129 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2133 wait_update_facet() {
2135 [ "$1" = "--verbose" ] && verbose="$1" && shift
2139 wait_update $verbose $(facet_active_host $facet) "$@"
2143 do_nodes $(comma_list $(mdts_nodes)) \
2144 "lctl set_param -n osd*.*MDT*.force_sync=1"
2145 do_nodes $(comma_list $(osts_nodes)) \
2146 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
2147 grep -v 'Found no match'
2150 wait_delete_completed_mds() {
2151 local MAX_WAIT=${1:-20}
2152 # for ZFS, waiting more time for DMUs to be committed
2153 local ZFS_WAIT=${2:-5}
2155 local stime=$(date +%s)
2160 # find MDS with pending deletions
2161 for node in $(mdts_nodes); do
2162 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2163 2>/dev/null | calc_sum)
2164 if [[ $changes -eq 0 ]]; then
2167 mds2sync="$mds2sync $node"
2169 if [ -z "$mds2sync" ]; then
2172 mds2sync=$(comma_list $mds2sync)
2174 # sync MDS transactions
2175 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2177 # wait till all changes are sent and commmitted by OSTs
2178 # for ldiskfs space is released upon execution, but DMU
2179 # do this upon commit
2182 while [[ $WAIT -ne $MAX_WAIT ]]; do
2183 changes=$(do_nodes $mds2sync \
2184 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2185 #echo "$node: $changes changes on all"
2186 if [[ $changes -eq 0 ]]; then
2188 #echo "delete took $((etime - stime)) seconds"
2190 # the occupied disk space will be released
2191 # only after DMUs are committed
2192 if [[ $(facet_fstype $SINGLEMDS) == zfs ]]; then
2193 echo "sleep $ZFS_WAIT for ZFS OSD"
2204 echo "Delete is not completed in $((etime - stime)) seconds"
2205 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2211 # we can use "for" here because we are waiting the slowest
2212 for host in ${hostlist//,/ }; do
2213 check_network "$host" 900
2215 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2222 for facet in ${facetlist//,/ }; do
2223 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2225 wait_for_host $hostlist
2228 _wait_recovery_complete () {
2231 # Use default policy if $2 is not passed by caller.
2232 local MAX=${2:-$(max_recovery_time)}
2237 while [ $WAIT -lt $MAX ]; do
2238 STATUS=$(lctl get_param -n $param | grep status)
2240 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2243 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2245 echo "$param recovery not done in $MAX sec. $STATUS"
2249 wait_recovery_complete () {
2252 # with an assumption that at_max is the same on all nodes
2253 local MAX=${2:-$(max_recovery_time)}
2256 if [ "$FAILURE_MODE" = HARD ]; then
2257 facets=$(facets_on_host $(facet_active_host $facet))
2259 echo affected facets: $facets
2261 # we can use "for" here because we are waiting the slowest
2262 for facet in ${facets//,/ }; do
2263 local var_svc=${facet}_svc
2264 local param="*.${!var_svc}.recovery_status"
2266 local host=$(facet_active_host $facet)
2267 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2271 wait_mds_ost_sync () {
2272 # just because recovery is done doesn't mean we've finished
2273 # orphan cleanup. Wait for llogs to get synchronized.
2274 echo "Waiting for orphan cleanup..."
2275 # MAX value includes time needed for MDS-OST reconnection
2276 local MAX=$(( TIMEOUT * 2 ))
2277 local WAIT_TIMEOUT=${1:-$MAX}
2280 local list=$(comma_list $(mdts_nodes))
2281 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2282 if ! do_facet $SINGLEMDS \
2283 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2285 # old way, use mds_sync
2287 list=$(comma_list $(osts_nodes))
2288 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2291 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2292 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2293 local -a sync=($(do_nodes $list "$cmd"))
2296 for ((i=0; i<${#sync[@]}; i++)); do
2298 [ ${sync[$i]} -eq 1 ] && continue
2300 [ ${sync[$i]} -eq 0 ] && continue
2302 # there is a not finished MDS-OST synchronization
2306 sleep 2 # increase waiting time and cover statfs cache
2307 [ ${con} -eq 1 ] && return 0
2308 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2312 # show which nodes are not finished.
2313 do_nodes $list "$cmd"
2314 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2318 wait_destroy_complete () {
2319 echo "Waiting for local destroys to complete"
2320 # MAX value shouldn't be big as this mean server responsiveness
2321 # never increase this just to make test pass but investigate
2322 # why it takes so long time
2325 while [ $WAIT -lt $MAX ]; do
2326 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2330 for ((i=0; i<${#RPCs[@]}; i++)); do
2331 [ ${RPCs[$i]} -eq 0 ] && continue
2332 # there are still some destroy RPCs in flight
2337 [ ${con} -eq 1 ] && return 0 # done waiting
2338 echo "Waiting ${WAIT}s for local destroys to complete"
2341 echo "Local destroys weren't done in $MAX sec."
2345 wait_delete_completed() {
2346 wait_delete_completed_mds $1 || return $?
2347 wait_destroy_complete
2356 # conf-sanity 31 takes a long time cleanup
2357 while [ $WAIT -lt 300 ]; do
2358 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2359 [ -z "${running}" ] && return 0
2360 echo "waited $WAIT for${running}"
2361 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2363 WAIT=$((WAIT + INTERVAL))
2365 echo "service didn't stop after $WAIT seconds. Still running:"
2370 wait_remote_prog () {
2376 [ "$PDSH" = "no_dsh" ] && return 0
2378 while [ $WAIT -lt $2 ]; do
2379 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2380 [ -z "${running}" ] && return 0 || true
2381 echo "waited $WAIT for: "
2383 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2385 WAIT=$((WAIT + INTERVAL))
2387 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2388 [ -z "$pids" ] && return 0
2389 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2390 # FIXME: not portable
2391 for pid in $pids; do
2392 cat /proc/${pid}/status || true
2393 cat /proc/${pid}/wchan || true
2395 kill -9 $pid || true
2404 # not every config has many clients
2406 if [ ! -z "$CLIENTS" ]; then
2407 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
2409 stat -f $MOUNT > /dev/null
2415 # usually checked on particular client or locally
2417 if [ ! -z "$client" ]; then
2418 $PDSH $client "stat -f $MOUNT" > /dev/null
2420 stat -f $MOUNT > /dev/null
2428 client_reconnect_try() {
2429 uname -n >> $MOUNT/recon
2430 if [ -z "$CLIENTS" ]; then
2431 df $MOUNT; uname -n >> $MOUNT/recon
2433 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
2435 echo Connected clients:
2437 ls -l $MOUNT/recon > /dev/null
2441 client_reconnect() {
2442 # one client_reconnect_try call does not always do the job...
2444 client_reconnect_try && break
2449 affected_facets () {
2452 local host=$(facet_active_host $facet)
2453 local affected=$facet
2455 if [ "$FAILURE_MODE" = HARD ]; then
2456 affected=$(facets_up_on_host $host)
2462 local E2FSCK_ON_MDT0=false
2463 if [ "$1" == "--fsck" ]; then
2465 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2477 #Because it will only get up facets, we need get affected
2478 #facets before shutdown
2479 #For HARD Failure mode, it needs make sure facets on the same
2480 #HOST will only be shutdown and reboot once
2481 for facet in ${facets//,/ }; do
2482 local affected_facet
2484 #check whether facet has been included in other affected facets
2485 for ((index=0; index<$total; index++)); do
2486 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2489 if [ $skip -eq 0 ]; then
2490 affecteds[$total]=$(affected_facets $facet)
2495 for ((index=0; index<$total; index++)); do
2496 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2497 local host=$(facet_active_host $facet)
2498 echo "Failing ${affecteds[index]} on $host"
2499 shutdown_facet $facet
2502 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
2503 $(mdsdevname 1) "-n" || error "Running e2fsck")
2505 for ((index=0; index<$total; index++)); do
2506 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2507 echo reboot facets: ${affecteds[index]}
2511 change_active ${affecteds[index]}
2513 wait_for_facet ${affecteds[index]}
2514 # start mgs first if it is affected
2515 if ! combined_mgs_mds &&
2516 list_member ${affecteds[index]} mgs; then
2517 mount_facet mgs || error "Restart of mgs failed"
2519 # FIXME; has to be changed to mount all facets concurrently
2520 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2521 echo mount facets: ${affecteds[index]}
2522 mount_facets ${affecteds[index]}
2532 do_facet $facet "sync; sync; sync"
2535 # make sure there will be no seq change
2536 local clients=${CLIENTS:-$HOSTNAME}
2537 local f=fsa-\\\$\(hostname\)
2538 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2539 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2541 local svc=${facet}_svc
2542 do_facet $facet $LCTL --device ${!svc} notransno
2544 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2545 # in-memory state has to be cleared by either rebooting the host or
2546 # exporting and reimporting the pool.
2548 # Although the uberblocks are not updated when a pool is freezed,
2549 # transactions are still written to the disks. Modified blocks may be
2550 # cached in memory when tests try reading them back. The
2551 # export-and-reimport process also evicts any cached pool data from
2552 # memory to provide the correct "data loss" semantics.
2554 # In the test framework, the exporting and importing operations are
2555 # handled by stop() and mount_facet() separately, which are used
2556 # inside fail() and fail_abort().
2558 do_facet $facet $LCTL --device ${!svc} readonly
2559 do_facet $facet $LCTL mark "$HOSTNAME: $facet REPLAY BARRIER on ${!svc}"
2560 $LCTL mark "$HOSTNAME: local REPLAY BARRIER on ${!svc}"
2563 replay_barrier_nodf() {
2564 local facet=$1 echo running=${running}
2565 do_facet $facet "sync; sync; sync"
2566 local svc=${facet}_svc
2567 echo Replay barrier on ${!svc}
2568 do_facet $facet $LCTL --device ${!svc} notransno
2569 do_facet $facet $LCTL --device ${!svc} readonly
2570 do_facet $facet $LCTL mark "$HOSTNAME: $facet REPLAY BARRIER on ${!svc}"
2571 $LCTL mark "$HOSTNAME: local REPLAY BARRIER on ${!svc}"
2574 replay_barrier_nosync() {
2575 local facet=$1 echo running=${running}
2576 local svc=${facet}_svc
2577 echo Replay barrier on ${!svc}
2578 do_facet $facet $LCTL --device ${!svc} notransno
2579 do_facet $facet $LCTL --device ${!svc} readonly
2580 do_facet $facet $LCTL mark "$HOSTNAME: $facet REPLAY BARRIER on ${!svc}"
2581 $LCTL mark "$HOSTNAME: local REPLAY BARRIER on ${!svc}"
2585 # Get Lustre client uuid for a given Lustre mount point.
2588 local mntpnt=${1:-$MOUNT}
2590 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2591 local uuid=$($LCTL get_param -n llite.$name.uuid)
2596 mds_evict_client() {
2597 local mntpnt=${1:-$MOUNT}
2598 local uuid=$(get_client_uuid $mntpnt)
2600 do_facet $SINGLEMDS \
2601 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2604 ost_evict_client() {
2605 local mntpnt=${1:-$MOUNT}
2606 local uuid=$(get_client_uuid $mntpnt)
2609 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2614 local clients=${CLIENTS:-$HOSTNAME}
2616 facet_failover $* || error "failover: $?"
2617 wait_clients_import_state "$clients" "$facets" FULL
2618 clients_up || error "post-failover df: $?"
2623 facet_failover $facet
2629 change_active $facet
2630 wait_for_facet $facet
2631 mount_facet $facet -o abort_recovery
2632 clients_up || echo "first df failed: $?"
2633 clients_up || error "post-failover df: $?"
2637 echo There is no lmc. This is mountconf, baby.
2641 host_nids_address() {
2645 if [ -n "$kind" ]; then
2646 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2648 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2654 if [ "$1" = "'*'" ]; then echo \'*\'; else
2660 if [ "$1" = "'*'" ]; then echo \'*\'; else
2661 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2663 if [ -z "$ID" ]; then
2664 echo "Could not get a ptl id for $1..."
2673 h2name_or_ip "$1" "tcp"
2678 if [ "$1" = "'*'" ]; then echo \'*\'; else
2679 if type __h2elan >/dev/null 2>&1; then
2682 ID=`echo $1 | sed 's/[^0-9]*//g'`
2690 h2name_or_ip "$1" "o2ib"
2694 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2695 # expressions format. As a bonus we can then just pass in those variables
2696 # to pdsh. What this function does is take a HOSTLIST type string and
2697 # expand it into a space deliminated list for us.
2705 [ -z "$hostlist" ] && return
2707 # Translate the case of [..],..,[..] to [..] .. [..]
2708 list="${hostlist/],/] }"
2710 [[ "$front" == *,* ]] && {
2713 list=${list/${old}/${new}}
2716 for item in $list; do
2717 # Test if we have any []'s at all
2718 if [ "$item" != "${item/\[/}" ]; then {
2719 # Expand the [*] into list
2723 if [ "$name" != "$item" ]; then
2724 group=${item#$name[*}
2727 for range in ${group//,/ }; do
2731 # Number of leading zeros
2734 end=$(echo $end | sed 's/0*//')
2735 [[ -z "$end" ]] && end=0
2736 [[ $padlen2 -gt $padlen ]] && {
2737 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2740 begin=$(echo $begin | sed 's/0*//')
2741 [ -z $begin ] && begin=0
2743 for num in $(seq -f "%0${padlen}g" $begin $end); do
2744 value="${name#*,}${num}${back}"
2745 [ "$value" != "${value/\[/}" ] && {
2746 value=$(hostlist_expand "$value")
2748 myList="$myList $value"
2753 myList="$myList $item"
2756 myList=${myList//,/ }
2757 myList=${myList:1} # Remove first character which is a space
2759 # Filter any duplicates without sorting
2761 myList="${list%% *}"
2763 while [[ "$list" != ${myList##* } ]]; do
2764 list=${list//${list%% *} /}
2765 myList="$myList ${list%% *}"
2767 myList="${myList%* }";
2769 # We can select an object at an offset in the list
2772 for item in $myList; do
2774 [ $cnt -eq $offset ] && {
2778 [ $(get_node_count $myList) -ne 1 ] && myList=""
2787 [ "$facet" == client ] && echo -n $HOSTNAME && return
2788 varname=${facet}_HOST
2789 if [ -z "${!varname}" ]; then
2790 if [ "${facet:0:3}" == "ost" ]; then
2791 local fh=${facet%failover}_HOST
2792 eval export ${facet}_HOST=${!fh}
2793 if [ -z "${!varname}" ]; then
2794 eval export ${facet}_HOST=${ost_HOST}
2796 elif [ "${facet:0:3}" == "mdt" -o \
2797 "${facet:0:3}" == "mds" -o \
2798 "${facet:0:3}" == "mgs" ]; then
2799 eval export ${facet}_HOST=${mds_HOST}
2805 facet_failover_host() {
2809 var=${facet}failover_HOST
2810 if [ -n "${!var}" ]; then
2815 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2816 "${facet:0:3}" == "mgs" ]; then
2818 eval export ${facet}failover_host=${mds_HOST}
2823 if [[ $facet == ost* ]]; then
2824 eval export ${facet}failover_host=${ost_HOST}
2832 local activevar=${facet}active
2834 if [ -f $TMP/${facet}active ] ; then
2835 source $TMP/${facet}active
2838 active=${!activevar}
2839 if [ -z "$active" ] ; then
2846 facet_active_host() {
2847 facet_host $(facet_active $1)
2850 # Get the passive failover partner host of facet.
2851 facet_passive_host() {
2853 [[ $facet = client ]] && return
2855 local host=${facet}_HOST
2856 local failover_host=${facet}failover_HOST
2857 local active_host=$(facet_active_host $facet)
2859 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2861 if [[ $active_host = ${!host} ]]; then
2862 echo -n ${!failover_host}
2872 facetlist=$(exclude_items_from_list $facetlist mgs)
2874 for facet in ${facetlist//,/ }; do
2875 local failover=${facet}failover
2876 local host=`facet_host $failover`
2877 [ -z "$host" ] && return
2879 local curactive=`facet_active $facet`
2880 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2881 eval export ${facet}active=$facet
2883 eval export ${facet}active=$failover
2885 # save the active host for this facet
2886 local activevar=${facet}active
2887 echo "$activevar=${!activevar}" > $TMP/$activevar
2888 [[ $facet = mds1 ]] && combined_mgs_mds && \
2889 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2890 local TO=`facet_active_host $facet`
2891 echo "Failover $facet to $TO"
2897 # do not stripe off hostname if verbose, bug 19215
2898 if [ x$1 = x--verbose ]; then
2906 if [ "$HOST" = "$HOSTNAME" ]; then
2908 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2909 echo "cannot run remote command on $HOST with $myPDSH"
2913 echo "CMD: $HOST $@" >&2
2914 $myPDSH $HOST "$LCTL mark \"$HOSTNAME: $@\"" &>/dev/null || :
2917 if [ "$myPDSH" = "rsh" ]; then
2918 # we need this because rsh does not return exit code of an executed command
2919 local command_status="$TMP/cs"
2920 rsh $HOST ":> $command_status"
2921 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2922 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2923 echo command failed >$command_status"
2924 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2929 # print HOSTNAME for myPDSH="no_dsh"
2930 if [[ $myPDSH = no_dsh ]]; then
2931 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2933 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2936 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2938 return ${PIPESTATUS[0]}
2942 do_node --verbose "$@"
2945 single_local_node () {
2946 [ "$1" = "$HOSTNAME" ]
2949 # Outputs environment variable assignments that should be passed to remote nodes
2953 local facets=$(get_facets)
2956 for var in ${!MODOPTS_*}; do
2957 value=${!var//\"/\\\"}
2958 echo -n " ${var}=\"$value\""
2961 for facet in ${facets//,/ }; do
2963 if [ -n "${!var}" ]; then
2964 echo -n " $var=${!var}"
2968 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2969 if [ -n "${!var}" ]; then
2970 echo -n " $var=${!var}"
2974 for var in VERBOSE; do
2975 if [ -n "${!var}" ]; then
2976 echo -n " $var=${!var}"
2980 if [ -n "$FSTYPE" ]; then
2981 echo -n " FSTYPE=$FSTYPE"
2984 for var in LNETLND NETTYPE; do
2985 if [ -n "${!var}" ]; then
2986 echo -n " $var=${!var}"
2993 # do not stripe off hostname if verbose, bug 19215
2994 if [ x$1 = x--verbose ]; then
3002 if single_local_node $rnodes; then
3004 do_nodev $rnodes "$@"
3006 do_node $rnodes "$@"
3011 # This is part from do_node
3014 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] &&
3015 echo "cannot run remote command on $rnodes with $myPDSH" &&
3018 export FANOUT=$(get_node_count "${rnodes//,/ }")
3020 echo "CMD: $rnodes $@" >&2
3021 $myPDSH $rnodes "$LCTL mark \"$HOSTNAME: $@\"" &>/dev/null || :
3024 # do not replace anything from pdsh output if -N is used
3025 # -N Disable hostname: prefix on lines of output.
3026 if $verbose || [[ $myPDSH = *-N* ]]; then
3027 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
3029 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
3031 return ${PIPESTATUS[0]}
3035 # Execute commands on a single service's host
3037 # The \a facet (service) may be on a local or remote node, which is
3038 # determined at the time the command is run.
3040 # usage: do_facet $facet command [arg ...]
3044 local HOST=$(facet_active_host $facet)
3045 [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
3049 # Function: do_facet_random_file $FACET $FILE $SIZE
3050 # Creates FILE with random content on the given FACET of given SIZE
3052 do_facet_random_file() {
3056 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
3057 do_facet $facet "$cmd 2>/dev/null"
3060 do_facet_create_file() {
3064 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
3065 do_facet $facet "$cmd 2>/dev/null"
3069 do_nodes --verbose "$@"
3075 # make sure its not already running
3077 rm -f $TMP/${facet}active
3078 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
3079 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
3081 if [[ $(facet_fstype $facet) == zfs ]]; then
3083 # After formatting a ZFS target, "cachefile=none" property will
3084 # be set on the ZFS storage pool so that the pool is not
3085 # automatically imported on system startup. And then the pool
3086 # will be exported so as to leave the importing and exporting
3087 # operations handled by mount_facet() and stop() separately.
3089 refresh_partition_table $facet $(facet_vdevice $facet)
3090 disable_zpool_cache $facet
3095 # Device formatted as ost
3098 local DEVNAME=OSTDEV$num
3100 local fstype=$(facet_fstype ost$num)
3104 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
3105 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3107 #try $OSTZFSDEVn - independent of vdev
3108 DEVNAME=OSTZFSDEV$num
3109 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
3111 error "unknown fstype!";;
3117 # Physical device location of data
3123 local fstype=$(facet_fstype ost$num)
3127 # vdevs are not supported by ldiskfs
3130 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3131 # Device formatted by zfs
3133 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3135 error "unknown fstype!";;
3141 # Logical device formatted for lustre
3144 local DEVNAME=MDSDEV$num
3146 local fstype=$(facet_fstype mds$num)
3150 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3151 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3153 # try $MDSZFSDEVn - independent of vdev
3154 DEVNAME=MDSZFSDEV$num
3155 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3157 error "unknown fstype!";;
3163 # Physical location of data
3167 local fstype=$(facet_fstype mds$num)
3171 # vdevs are not supported by ldiskfs
3174 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3175 # Device formatted by ZFS
3176 local DEVNAME=MDSDEV$num
3177 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3179 error "unknown fstype!";;
3187 local fstype=$(facet_fstype mgs)
3191 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3192 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3193 DEVPTR=$(mdsdevname 1)
3198 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3199 ( [ -z "$MGSZFSDEV" ] &&
3200 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3201 DEVPTR=$(mdsdevname 1)
3203 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3206 error "unknown fstype!";;
3215 local fstype=$(facet_fstype mgs)
3219 # vdevs are not supported by ldiskfs
3222 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3223 ( [ -z "$MGSDEV" ] &&
3224 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3225 VDEVPTR=$(mdsvdevname 1)
3226 elif [ -n "$MGSDEV" ]; then
3230 error "unknown fstype!";;
3238 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3240 local var=${facet}_MOUNT
3241 eval mntpt=${!var:-${MOUNT}-$facet}
3248 local dev=$(facet_device $facet)
3249 local mnt=$(facet_mntpt $facet)
3252 if ! do_facet $facet test -b $dev; then
3255 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3260 local dev=$(facet_device $facet)
3261 local mnt=$(facet_mntpt $facet)
3263 do_facet $facet $UMOUNT $mnt
3267 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3272 local ds=$(facet_device $facet)
3273 local mnt=$(facet_mntpt $facet)
3278 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3279 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3280 do_facet $facet $ZFS set canmount=noauto $ds
3282 # The "legacy" mount method is used here because "zfs unmount $mnt"
3283 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3284 # targets are not available at the time, the stat(2) on $MOUNT will
3287 do_facet $facet $ZFS set mountpoint=legacy $ds
3288 do_facet $facet mount -t zfs $ds $mnt
3289 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3290 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3295 local ds=$(facet_device $facet)
3296 local mnt=$(facet_mntpt $facet)
3297 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3298 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3299 local mntpt=${!var_mntpt}
3300 local canmnt=${!var_canmnt}
3304 do_facet $facet umount $mnt
3305 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3306 do_facet $facet $ZFS set canmount=$canmnt $ds
3312 local fstype=$(facet_fstype $facet)
3314 mount_$fstype $facet
3319 local fstype=$(facet_fstype $facet)
3321 unmount_$fstype $facet
3328 # make sure we are using the primary server, so test-framework will
3329 # be able to clean up properly.
3330 activemds=`facet_active mds1`
3331 if [ $activemds != "mds1" ]; then
3335 local clients=$CLIENTS
3336 [ -z $clients ] && clients=$(hostname)
3338 zconf_umount_clients $clients $MOUNT "$*" || true
3339 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3341 [ "$CLIENTONLY" ] && return
3342 # The add fn does rm ${facet}active file, this would be enough
3343 # if we use do_facet <facet> only after the facet added, but
3344 # currently we use do_facet mds in local.sh
3345 for num in `seq $MDSCOUNT`; do
3347 rm -f ${TMP}/mds${num}active
3349 combined_mgs_mds && rm -f $TMP/mgsactive
3351 for num in `seq $OSTCOUNT`; do
3353 rm -f $TMP/ost${num}active
3356 if ! combined_mgs_mds ; then
3363 cleanup_echo_devs () {
3364 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3366 for dev in $devs; do
3367 $LCTL --device $dev cleanup
3368 $LCTL --device $dev detach
3373 nfs_client_mode && return
3374 cifs_client_mode && return
3383 combined_mgs_mds () {
3384 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3385 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3389 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3393 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3399 local fsname=${3:-"$FSNAME"}
3400 local type=$(facet_type $facet)
3401 local index=$(facet_index $facet)
3402 local fstype=$(facet_fstype $facet)
3403 local host=$(facet_host $facet)
3408 if [ $type == MGS ] || ( [ $type == MDS ] &&
3409 [ "$dev" == $(mgsdevname) ] &&
3410 [ "$host" == "$(facet_host mgs)" ] ); then
3413 opts="--mgsnode=$MGSNID"
3416 if [ $type != MGS ]; then
3417 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3421 var=${facet}failover_HOST
3422 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3423 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3426 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3427 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3429 if [ $type == MDS ]; then
3430 opts+=${SECLEVEL:+" --param=mdt.sec_level"}
3431 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3432 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3433 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3434 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3436 if [ $fstype == ldiskfs ]; then
3437 # Check for wide striping
3438 if [ $OSTCOUNT -gt 160 ]; then
3439 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3440 fs_mkfs_opts+="-O large_xattr"
3444 if [ -n "${!var}" ]; then
3445 fs_mkfs_opts+=" -J device=${!var}"
3447 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3449 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3453 if [ $type == OST ]; then
3454 opts+=${SECLEVEL:+" --param=ost.sec_level"}
3455 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3457 if [ $fstype == ldiskfs ]; then
3459 if [ -n "${!var}" ]; then
3460 fs_mkfs_opts+=" -J device=${!var}"
3462 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3467 opts+=" --backfstype=$fstype"
3470 if [ -n "${!var}" ]; then
3471 opts+=" --device-size=${!var}"
3474 var=$(upper $fstype)_MKFS_OPTS
3475 fs_mkfs_opts+=${!var:+" ${!var}"}
3477 var=${type}_FS_MKFS_OPTS
3478 fs_mkfs_opts+=${!var:+" ${!var}"}
3480 if [ -n "${fs_mkfs_opts## }" ]; then
3481 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3485 opts+=${!var:+" ${!var}"}
3490 check_ost_indices() {
3491 local index_count=${#OST_INDICES[@]}
3492 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
3494 # OST count is greater than the index count in $OST_INDEX_LIST.
3495 # We need check whether there are duplicate indices.
3499 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
3500 index=$(facet_index ost$i)
3501 for j in $(seq 0 $((index_count - 1))); do
3502 [[ $index -ne ${OST_INDICES[j]} ]] ||
3503 error "ost$i has the same index $index as ost$((j+1))"
3514 echo "Format mgs: $(mgsdevname)"
3515 reformat_external_journal mgs
3516 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3517 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
3527 echo "Format mds$num: $(mdsdevname $num)"
3528 reformat_external_journal mds$num
3529 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3530 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3531 ${quiet:+>/dev/null} || exit 10
3540 echo "Format ost$num: $(ostdevname $num)"
3541 reformat_external_journal ost$num
3542 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3543 --reformat $(ostdevname $num) $(ostvdevname ${num}) \
3544 ${quiet:+>/dev/null} || exit 10
3549 # Set hostid for ZFS/SPL zpool import protection
3550 do_rpc_nodes "$(comma_list $(remote_nodes_list))" set_hostid
3552 # We need ldiskfs here, may as well load them all
3554 [ "$CLIENTONLY" ] && return
3555 echo Formatting mgs, mds, osts
3556 if ! combined_mgs_mds ; then
3560 for num in $(seq $MDSCOUNT); do
3564 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
3566 for num in $(seq $OSTCOUNT); do
3572 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3576 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3580 # 0: success, the old identity set already.
3581 # 1: success, the old identity does not set.
3586 local j=`expr $num - 1`
3587 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3589 if [ -z "$MDT" ]; then
3593 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3596 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3598 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3601 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3603 if [ $old = "NONE" ]; then
3612 zconf_umount `hostname` $1 || error "umount failed"
3613 zconf_mount `hostname` $1 || error "mount failed"
3621 rm -f $TMP/${facet}active
3622 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3627 local mdt_count=${1:-$MDSCOUNT}
3628 local ost_count=${2:-$OSTCOUNT}
3631 for num in $(seq $mdt_count); do
3632 DEVNAME=$(mdsdevname $num)
3633 writeconf_facet mds$num $DEVNAME || rc=$?
3636 for num in $(seq $ost_count); do
3637 DEVNAME=$(ostdevname $num)
3638 writeconf_facet ost$num $DEVNAME || rc=$?
3644 nfs_client_mode && return
3645 cifs_client_mode && return
3647 sanity_mount_check ||
3648 error "environments are insane!"
3652 if [ -z "$CLIENTONLY" ]; then
3653 echo Setup mgs, mdt, osts
3654 echo $WRITECONF | grep -q "writeconf" && \
3656 if ! combined_mgs_mds ; then
3657 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3660 for num in `seq $MDSCOUNT`; do
3661 DEVNAME=$(mdsdevname $num)
3662 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3664 # We started mds, now we should set failover variables properly.
3665 # Set mds${num}failover_HOST if it is not set (the default failnode).
3666 local varname=mds${num}failover_HOST
3667 if [ -z "${!varname}" ]; then
3668 eval mds${num}failover_HOST=$(facet_host mds$num)
3671 if [ $IDENTITY_UPCALL != "default" ]; then
3672 switch_identity $num $IDENTITY_UPCALL
3675 for num in `seq $OSTCOUNT`; do
3676 DEVNAME=$(ostdevname $num)
3677 start ost$num $DEVNAME $OST_MOUNT_OPTS
3679 # We started ost$num, now we should set ost${num}failover variable properly.
3680 # Set ost${num}failover_HOST if it is not set (the default failnode).
3681 varname=ost${num}failover_HOST
3682 if [ -z "${!varname}" ]; then
3683 eval ost${num}failover_HOST=$(facet_host ost${num})
3691 # wait a while to allow sptlrpc configuration be propogated to targets,
3692 # only needed when mounting new target devices.
3697 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3699 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3702 if [ "$MOUNT_2" ]; then
3703 mount_client $MOUNT2
3704 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3709 # by remounting mdt before ost, initial connect from mdt to ost might
3710 # timeout because ost is not ready yet. wait some time to its fully
3711 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3712 # by a context negotiation rpc with $TIMEOUT.
3713 # FIXME better by monitoring import status.
3716 sleep $((TIMEOUT + 5))
3722 mounted_lustre_filesystems() {
3723 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3726 init_facet_vars () {
3727 [ "$CLIENTONLY" ] && return 0
3734 eval export ${facet}_dev=${device}
3735 eval export ${facet}_opt=\"$@\"
3737 local dev=${facet}_dev
3739 # We need to loop for the label
3740 # in case its not initialized yet.
3741 for wait_time in {0,1,3,5,10}; do
3743 if [ $wait_time -gt 0 ]; then
3744 echo "${!dev} not yet initialized,"\
3745 "waiting ${wait_time} seconds."
3749 local label=$(devicelabel ${facet} ${!dev})
3751 # Check to make sure the label does
3752 # not include ffff at the end of the label.
3753 # This indicates it has not been initialized yet.
3755 if [[ $label =~ [f|F]{4}$ ]]; then
3756 # label is not initialized, unset the result
3757 # and either try again or fail
3764 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3766 eval export ${facet}_svc=${label}
3768 local varname=${facet}failover_HOST
3769 if [ -z "${!varname}" ]; then
3770 eval export $varname=$(facet_host $facet)
3773 varname=${facet}_HOST
3774 if [ -z "${!varname}" ]; then
3775 eval export $varname=$(facet_host $facet)
3778 # ${facet}failover_dev is set in cfg file
3779 varname=${facet}failover_dev
3780 if [ -n "${!varname}" ] ; then
3781 eval export ${facet}failover_dev=${!varname}
3783 eval export ${facet}failover_dev=$device
3786 # get mount point of already mounted device
3787 # is facet_dev is already mounted then use the real
3788 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3789 # i.e. ${facet}_MOUNT if specified by user or default
3790 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3791 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3792 if [ -z $mntpt ]; then
3793 mntpt=$(facet_mntpt $facet)
3795 eval export ${facet}_MOUNT=$mntpt
3798 init_facets_vars () {
3801 if ! remote_mds_nodsh; then
3802 for num in $(seq $MDSCOUNT); do
3803 DEVNAME=`mdsdevname $num`
3804 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3808 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3810 if ! remote_ost_nodsh; then
3811 for num in $(seq $OSTCOUNT); do
3812 DEVNAME=$(ostdevname $num)
3813 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3818 osc_ensure_active () {
3823 while [ $period -lt $timeout ]; do
3824 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3825 if [ $count -eq 0 ]; then
3829 echo "There are $count OST are inactive, wait $period seconds, and try again"
3831 period=$((period+3))
3834 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3837 set_conf_param_and_check() {
3841 local ORIG=$(do_facet $myfacet "$TEST")
3842 if [ $# -gt 3 ]; then
3848 echo "Setting $PARAM from $ORIG to $FINAL"
3849 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3850 error "conf_param $PARAM failed"
3852 wait_update $(facet_host $myfacet) "$TEST" "$FINAL" ||
3853 error "check $PARAM failed!"
3856 init_param_vars () {
3858 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3860 log "Using TIMEOUT=$TIMEOUT"
3862 osc_ensure_active $SINGLEMDS $TIMEOUT
3863 osc_ensure_active client $TIMEOUT
3865 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
3866 local current_jobid_var=$($LCTL get_param -n jobid_var)
3868 if [ $JOBID_VAR = "existing" ]; then
3869 echo "keeping jobstats as $current_jobid_var"
3870 elif [ $current_jobid_var != $JOBID_VAR ]; then
3871 echo "seting jobstats to $JOBID_VAR"
3873 set_conf_param_and_check client \
3874 "$LCTL get_param -n jobid_var" \
3875 "$FSNAME.sys.jobid_var" $JOBID_VAR
3878 echo "jobstats not supported by server"
3881 if [ $QUOTA_AUTO -ne 0 ]; then
3882 if [ "$ENABLE_QUOTA" ]; then
3883 echo "enable quota as required"
3884 setup_quota $MOUNT || return 2
3886 echo "disable quota as required"
3887 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
3893 nfs_client_mode () {
3894 if [ "$NFSCLIENT" ]; then
3895 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
3896 local clients=$CLIENTS
3897 [ -z $clients ] && clients=$(hostname)
3899 # FIXME: remove hostname when 19215 fixed
3900 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
3901 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
3902 if [[ ${#nfsexport[@]} -eq 0 ]]; then
3903 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
3905 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
3911 cifs_client_mode () {
3912 [ x$CIFSCLIENT = xyes ] &&
3913 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
3916 check_config_client () {
3919 local mounted=$(mount | grep " $mntpt ")
3920 if [ "$CLIENTONLY" ]; then
3922 # CLIENTONLY should not depend on *_HOST settings
3923 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
3924 # in theory someone could create a new,
3925 # client-only config file that assumed lustre was already
3926 # configured and didn't set the MGSNID. If MGSNID is not set,
3927 # then we should use the mgs nid currently being used
3928 # as the default value. bug 18021
3929 [[ x$MGSNID = x ]] &&
3932 if [[ x$mgc != xMGC$MGSNID ]]; then
3933 if [ "$mgs_HOST" ]; then
3934 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
3935 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
3936 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
3942 local myMGS_host=$mgs_HOST
3943 if [ "$NETTYPE" = "ptl" ]; then
3944 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
3947 echo Checking config lustre mounted on $mntpt
3948 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
3949 mgshost=$(echo $mgshost | awk -F: '{print $1}')
3951 # if [ "$mgshost" != "$myMGS_host" ]; then
3952 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
3953 # Please use correct config or set mds_HOST correctly!"
3958 check_config_clients () {
3959 local clients=${CLIENTS:-$HOSTNAME}
3962 nfs_client_mode && return
3963 cifs_client_mode && return
3965 do_rpc_nodes "$clients" check_config_client $mntpt
3967 sanity_mount_check || error "environments are insane!"
3971 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3972 local cltimeout=$(lctl get_param -n timeout)
3973 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
3974 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
3981 [ -z $mntpt ] && return 1
3982 local mounted=$(mounted_lustre_filesystems)
3984 echo $mounted' ' | grep -w -q $mntpt' '
3988 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
3992 # empty lustre filesystem may have empty directories lost+found and .lustre
3994 # exclude .lustre & lost+found
3995 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
3996 -print | wc -l) = 1 ] || return 1
3997 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
3998 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
3999 # exclude .lustre/fid (LU-2780)
4000 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
4001 -print | wc -l) = 1 ] || return 1
4003 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
4008 check_and_setup_lustre() {
4010 nfs_client_mode && return
4011 cifs_client_mode && return
4013 local MOUNTED=$(mounted_lustre_filesystems)
4017 # both MOUNT and MOUNT2 are not mounted
4018 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
4019 [ "$REFORMAT" = "yes" ] && formatall
4020 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
4022 is_mounted $MOUNT || error "NAME=$NAME not mounted"
4023 export I_MOUNTED=yes
4027 elif is_mounted $MOUNT2; then
4029 # MOUNT2 is mounted, while MOUNT_2 is not set
4030 if ! [ "$MOUNT_2" ]; then
4031 cleanup_mount $MOUNT2
4032 export I_UMOUNTED2=yes
4035 # MOUNT2 is mounted, MOUNT_2 is set
4037 # FIXME: what to do if check_config failed?
4039 # 1) remote client has mounted other Lustre fs ?
4040 # 2) it has insane env ?
4041 # let's try umount MOUNT2 on all clients and mount it again:
4042 if ! check_config_clients $MOUNT2; then
4043 cleanup_mount $MOUNT2
4044 restore_mount $MOUNT2
4045 export I_MOUNTED2=yes
4050 # MOUNT is mounted MOUNT2 is not mounted
4051 elif [ "$MOUNT_2" ]; then
4052 restore_mount $MOUNT2
4053 export I_MOUNTED2=yes
4057 # FIXME: what to do if check_config failed?
4059 # 1) remote client has mounted other Lustre fs?
4060 # 2) lustre is mounted on remote_clients atall ?
4061 check_config_clients $MOUNT
4065 set_default_debug_nodes $(comma_list $(nodes_list))
4068 if [ $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ] ; then
4070 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
4071 facets="$(get_facets OST)"
4072 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
4073 facets="$facets,$(get_facets MDS)"
4074 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
4075 facets="$facets,mgs"
4076 local nodes="$(facets_hosts ${facets})"
4077 if [ -n "$nodes" ] ; then
4078 do_nodes $nodes "$LCTL set_param \
4079 osd-ldiskfs.track_declares_assert=1 || true"
4088 #Enable remote MDT create for testing
4089 for num in $(seq $MDSCOUNT); do
4091 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
4095 if [ "$ONLY" == "setup" ]; then
4101 local clients=${CLIENTS:-$HOSTNAME}
4104 zconf_mount_clients $clients $mntpt
4108 local clients=${CLIENTS:-$HOSTNAME}
4111 zconf_umount_clients $clients $mntpt
4114 cleanup_and_setup_lustre() {
4115 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
4116 lctl set_param debug=0 || true
4118 if [ "$ONLY" == "cleanup" ]; then
4122 check_and_setup_lustre
4125 # Get all of the server target devices from a given server node and type.
4132 if [ "$type" == ost ]; then
4133 devs=$(get_osd_param $node "" mntdev)
4135 devs=$(do_node $node $LCTL get_param -n osd-*.$FSNAME-M*.mntdev)
4137 for dev in $devs; do
4139 *loop*) do_node $node "losetup $dev" | \
4140 sed -e "s/.*(//" -e "s/).*//" ;;
4146 # Get all of the server target devices.
4151 # Master MDS parameters used by lfsck
4152 MDTNODE=$(facet_active_host $SINGLEMDS)
4153 MDTDEV=$(echo $(get_mnt_devs $MDTNODE mdt) | awk '{print $1}')
4157 for node in $(mdts_nodes); do
4158 MDTDEVS[i]=$(get_mnt_devs $node mdt)
4164 for node in $(osts_nodes); do
4165 OSTDEVS[i]=$(get_mnt_devs $node ost)
4170 # Run e2fsck on MDT or OST device.
4175 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
4176 local log=$TMP/e2fsck.log
4180 do_node $node $cmd 2>&1 | tee $log
4182 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
4184 if [ $MDSCOUNT -gt 1 ]; then
4185 skip "DNE mode isn't supported!"
4189 error "It's not DNE mode."
4194 [ $rc -le $FSCK_MAX_ERR ] ||
4195 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4201 # Run resize2fs on MDT or OST device.
4210 do_facet $facet "$RESIZE2FS $opts $device $size"
4213 # verify a directory is shared among nodes.
4214 check_shared_dir() {
4216 local list=${2:-$(comma_list $(nodes_list))}
4218 [ -z "$dir" ] && return 1
4219 do_rpc_nodes "$list" check_logdir $dir
4220 check_write_access $dir "$list" || return 1
4225 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
4226 $LCTL set_param printk=+lfsck
4227 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
4229 for k in $(seq $MDSCOUNT); do
4230 # wait up to 10+1 minutes for LFSCK to complete
4231 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4232 mdd.$(facet_svc mds${k}).lfsck_layout |
4233 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
4234 error "MDS${k} layout isn't the expected 'completed'"
4235 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4236 mdd.$(facet_svc mds${k}).lfsck_namespace |
4237 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
4238 error "MDS${k} namespace isn't the expected 'completed'"
4240 local rep_mdt=$(do_nodes $(comma_list $(mdts_nodes)) \
4241 $LCTL get_param -n mdd.$FSNAME-*.lfsck_* |
4242 awk '/repaired/ { print $2 }' | calc_sum)
4243 local rep_ost=$(do_nodes $(comma_list $(osts_nodes)) \
4244 $LCTL get_param -n obdfilter.$FSNAME-*.lfsck_* |
4245 awk '/repaired/ { print $2 }' | calc_sum)
4246 local repaired=$((rep_mdt + rep_ost))
4247 [ $repaired -eq 0 ] ||
4248 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
4251 dump_file_contents() {
4257 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
4258 error_noexit false \
4259 "Invalid parameters for dump_file_contents()"
4262 for node in ${nodes}; do
4263 do_node $node "for i in \\\$(find $dir -type f); do
4264 echo ====\\\${i}=======================;
4266 done" >> ${logname}.${node}.log
4270 dump_command_output() {
4276 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
4277 error_noexit false \
4278 "Invalid parameters for dump_command_output()"
4282 for node in ${nodes}; do
4283 do_node $node "echo ====${cmd}=======================;
4284 $cmd" >> ${logname}.${node}.log
4291 # dump file contents from /proc/spl in case of zfs test
4292 if [ "$(facet_fstype ost1)" = "zfs" ]; then
4293 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
4294 dump_command_output \
4295 "$(osts_nodes)" "zpool events -v" "${logname}"
4298 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
4299 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
4300 dump_command_output \
4301 "$(mdts_nodes)" "zpool events -v" "${logname}"
4305 check_and_cleanup_lustre() {
4306 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "sanity-lfsck" -a \
4307 "$TESTSUITE" != "sanity-scrub" ]; then
4311 if is_mounted $MOUNT; then
4312 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4313 error "remove sub-test dirs failed"
4314 [ "$ENABLE_QUOTA" ] && restore_quota || true
4317 if [ "$I_UMOUNTED2" = "yes" ]; then
4318 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4321 if [ "$I_MOUNTED2" = "yes" ]; then
4322 cleanup_mount $MOUNT2
4325 if [ "$I_MOUNTED" = "yes" ]; then
4326 cleanupall -f || error "cleanup failed"
4334 wait_for_function () {
4337 # suppress fn both stderr and stdout
4338 if [ "$1" = "--quiet" ]; then
4340 quiet=" > /dev/null 2>&1"
4352 eval $fn $quiet && return 0
4354 wait=$((wait + sleep))
4355 [ $wait -lt $max ] || return 1
4356 echo waiting $fn, $((max - wait)) secs left ...
4366 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4367 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4368 echo "Network not available!"
4372 echo `date +"%H:%M:%S (%s)"` network interface is UP
4380 # Convert a space-delimited list to a comma-delimited list. If the input is
4381 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4383 # echo is used to convert newlines to spaces, since it doesn't
4384 # introduce a trailing space as using "tr '\n' ' '" does
4385 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4391 echo $list | grep -qw $item
4394 # list, excluded are the comma separated lists
4395 exclude_items_from_list () {
4401 for item in ${excluded//,/ }; do
4402 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4404 echo $(comma_list $list)
4407 # list, expand are the comma separated lists
4409 local list=${1//,/ }
4410 local expand=${2//,/ }
4413 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4414 echo $(comma_list $expanded)
4417 testslist_filter () {
4418 local script=$LUSTRE/tests/${TESTSUITE}.sh
4420 [ -f $script ] || return 0
4422 local start_at=$START_AT
4423 local stop_at=$STOP_AT
4425 local var=${TESTSUITE//-/_}_START_AT
4426 [ x"${!var}" != x ] && start_at=${!var}
4427 var=${TESTSUITE//-/_}_STOP_AT
4428 [ x"${!var}" != x ] && stop_at=${!var}
4430 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4431 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4432 /^'${start_at}'$/ {flag = 0}
4433 {if (flag == 1) print $0}
4434 /^'${stop_at}'$/ { flag = 1 }'
4438 (cd `dirname $1`; echo $PWD/`basename $1`)
4442 local types=${1:-"OST MDS MGS"}
4446 for entry in $types; do
4447 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4448 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4451 MGS ) list="$list $name";;
4452 MDS|OST|AGT ) local count=${type}COUNT
4453 for ((i=1; i<=${!count}; i++)) do
4454 list="$list ${name}$i"
4456 * ) error "Invalid facet type"
4460 echo $(comma_list $list)
4463 ##################################
4464 # Adaptive Timeouts funcs
4467 # only check mds, we assume at_max is the same on all nodes
4468 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4469 if [ $at_max -eq 0 ]; then
4480 # suppose that all ost-s have the same $at value set
4481 [ $facet != "ost" ] || facet=ost1
4483 do_facet $facet "lctl get_param -n $at"
4501 if [ $facet == "ost" ]; then
4502 facet=$(get_facets OST)
4503 elif [ $facet == "mds" ]; then
4504 facet=$(get_facets MDS)
4506 hosts=$(expand_list $hosts $(facets_hosts $facet))
4509 do_nodes $hosts lctl set_param at_max=$at_max
4512 ##################################
4516 # OBD_FAIL_MDS_ALL_REQUEST_NET
4518 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4519 do_facet client "$1" || RC=$?
4520 do_facet $SINGLEMDS lctl set_param fail_loc=0
4525 # OBD_FAIL_MDS_ALL_REPLY_NET
4527 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
4529 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4533 drop_reint_reply() {
4534 # OBD_FAIL_MDS_REINT_NET_REP
4536 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
4538 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4542 drop_update_reply() {
4543 # OBD_FAIL_OUT_UPDATE_NET_REP
4547 do_facet mds${index} lctl set_param fail_loc=0x1701
4548 do_facet client "$@" || RC=$?
4549 do_facet mds${index} lctl set_param fail_loc=0
4554 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4557 local timeout=${2:-0}
4558 # default is (obd_timeout / 4) if unspecified
4559 echo "timeout is $timeout/$2"
4560 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
4561 do_facet client "$1" || RC=$?
4562 do_facet client "sync"
4563 do_facet ost1 lctl set_param fail_loc=0
4567 drop_ldlm_cancel() {
4568 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4570 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4571 do_nodes $list lctl set_param fail_loc=0x304
4573 do_facet client "$@" || RC=$?
4575 do_nodes $list lctl set_param fail_loc=0
4579 drop_bl_callback_once() {
4581 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4582 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4583 do_facet client lctl set_param fail_loc=0x80000305
4584 do_facet client "$@" || rc=$?
4585 do_facet client lctl set_param fail_loc=0
4586 do_facet client lctl set_param fail_val=0
4587 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4591 drop_bl_callback() {
4593 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4594 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4595 do_facet client lctl set_param fail_loc=0x305
4596 do_facet client "$@" || rc=$?
4597 do_facet client lctl set_param fail_loc=0
4598 do_facet client lctl set_param fail_val=0
4599 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4604 #define OBD_FAIL_LDLM_REPLY 0x30c
4606 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4607 do_nodes $list lctl set_param fail_loc=0x30c
4609 do_facet client "$@" || RC=$?
4611 do_nodes $list lctl set_param fail_loc=0
4615 drop_ldlm_reply_once() {
4616 #define OBD_FAIL_LDLM_REPLY 0x30c
4618 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4619 do_nodes $list lctl set_param fail_loc=0x8000030c
4621 do_facet client "$@" || RC=$?
4623 do_nodes $list lctl set_param fail_loc=0
4631 echo "clearing fail_loc on $facet"
4632 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4635 set_nodes_failloc () {
4636 do_nodes $(comma_list $1) lctl set_param fail_val=0 fail_loc=$2
4639 cancel_lru_locks() {
4640 #$LCTL mark "$HOSTNAME: cancel_lru_locks $1 start"
4641 $LCTL set_param -n ldlm.namespaces.*$1*.lru_size=clear
4642 $LCTL get_param ldlm.namespaces.*$1*.lock_unused_count | grep -v '=0'
4643 #$LCTL mark "$HOSTNAME: cancel_lru_locks $1 stop"
4648 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4649 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4650 echo "$DEFAULT_LRU_SIZE"
4655 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4658 lru_resize_disable()
4660 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4666 [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] && RC=1
4672 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4673 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4674 echo there is still data in page cache $FILE ?
4675 lctl get_param -n $FILE
4683 DEBUGSAVE="$(lctl get_param -n debug)"
4687 [ -n "$DEBUGSAVE" ] && \
4688 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
4693 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4696 debug_size_restore() {
4697 [ -n "$DEBUG_SIZE_SAVED" ] && \
4698 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4702 start_full_debug_logging() {
4707 local DEBUG_SIZE=150
4709 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4710 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4713 stop_full_debug_logging() {
4718 # prints bash call stack
4719 print_stack_trace() {
4722 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4723 local src=${BASH_SOURCE[$i]}
4724 local lineno=${BASH_LINENO[$i-1]}
4725 local funcname=${FUNCNAME[$i]}
4726 echo " = $src:$lineno:$funcname()"
4731 local TYPE=${TYPE:-"FAIL"}
4734 # do not dump logs if $1=false
4735 if [ "x$1" = "xfalse" ]; then
4740 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4741 (print_stack_trace 2) >&2
4743 # We need to dump the logs on all nodes
4745 gather_logs $(comma_list $(nodes_list))
4749 [ "$TESTSUITELOG" ] &&
4750 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4751 if [ -z "$*" ]; then
4752 echo "error() without useful message, please fix" > $LOGDIR/err
4754 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4755 echo "$@" > $LOGDIR/ignore
4757 echo "$@" > $LOGDIR/err
4761 # cleanup the env for failed tests
4765 ##################################
4767 ##################################
4775 local log=$TESTSUITELOG
4777 [ -f "$log" ] && grep -q FAIL $log && status=1
4791 # use only if we are ignoring failures for this test, bugno required.
4792 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4793 # e.g. error_ignore bz5494 "your message" or
4794 # error_ignore LU-5494 "your message"
4796 local TYPE="IGNORE ($1)"
4801 error_and_remount() {
4803 remount_client $MOUNT
4808 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4813 log " SKIP: $TESTSUITE $TESTNAME $@"
4815 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4816 skip_logged $TESTNAME "$@"
4819 echo "$@" > $LOGDIR/skip
4822 [[ -n "$TESTSUITELOG" ]] &&
4823 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
4826 build_test_filter() {
4827 EXCEPT="$EXCEPT $(testslist_filter)"
4830 if [[ $O = [0-9]*-[0-9]* ]]; then
4831 for num in $(seq $(echo $O | tr '-' ' ')); do
4839 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
4840 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
4841 [ "$EXCEPT_SLOW" ] && \
4842 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
4843 for E in $EXCEPT; do
4844 eval EXCEPT_${E}=true
4846 for E in $ALWAYS_EXCEPT; do
4847 eval EXCEPT_ALWAYS_${E}=true
4849 for E in $EXCEPT_SLOW; do
4850 eval EXCEPT_SLOW_${E}=true
4852 for G in $GRANT_CHECK_LIST; do
4853 eval GCHECK_ONLY_${G}=true
4858 if [[ $1 = [a-z]* ]]; then
4865 # print a newline if the last test was skipped
4866 export LAST_SKIPPED=
4867 export ALWAYS_SKIPPED=
4869 # Main entry into test-framework. This is called with the name and
4870 # description of a test. The name is used to find the function to run
4871 # the test using "test_$name".
4873 # This supports a variety of methods of specifying specific test to
4874 # run or not run. These need to be documented...
4879 export base=$(basetest $1)
4880 if [ -n "$ONLY" ]; then
4882 if [ ${!testname}x != x ]; then
4883 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4884 run_one_logged $1 "$2"
4888 if [ ${!testname}x != x ]; then
4889 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4890 run_one_logged $1 "$2"
4900 if [ ${!testname}x != x ]; then
4901 TESTNAME=test_$1 skip "skipping excluded test $1"
4904 testname=EXCEPT_$base
4905 if [ ${!testname}x != x ]; then
4906 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
4909 testname=EXCEPT_ALWAYS_$1
4910 if [ ${!testname}x != x ]; then
4911 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
4914 testname=EXCEPT_ALWAYS_$base
4915 if [ ${!testname}x != x ]; then
4916 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
4919 testname=EXCEPT_SLOW_$1
4920 if [ ${!testname}x != x ]; then
4921 TESTNAME=test_$1 skip "skipping SLOW test $1"
4924 testname=EXCEPT_SLOW_$base
4925 if [ ${!testname}x != x ]; then
4926 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
4932 run_one_logged $1 "$2"
4939 load_module ../libcfs/libcfs/libcfs
4941 local MSG="$HOSTNAME: $*"
4951 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null ||
4957 strace -o $TMP/$1.strace -ttt $*
4959 log "FINISHED: $*: rc $RC"
4966 banner test complete, duration $duration sec
4967 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
4968 echo duration $duration >>$TESTSUITELOG
4972 # Set TEST_STATUS here. It will be used for logging the result.
4975 if [[ -f $LOGDIR/err ]]; then
4977 elif [[ -f $LOGDIR/skip ]]; then
4980 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
4984 local FFREE=$(do_node $SINGLEMDS \
4985 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
4986 local FTOTAL=$(do_node $SINGLEMDS \
4987 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
4989 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
4993 echo -n "Resetting fail_loc on all nodes..."
4994 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 \
4995 fail_val=0 2>/dev/null || true"
5001 # Log a message (on all nodes) padded with "=" before and after.
5002 # Also appends a timestamp and prepends the testsuite name.
5005 EQUALS="===================================================================================================="
5007 msg="== ${TESTSUITE} $*"
5009 [[ $last != "=" && $last != " " ]] && msg="$msg "
5010 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
5011 # always include at least == after the message
5012 log "$msg== $(date +"%H:%M:%S (%s)")"
5015 check_dmesg_for_errors() {
5017 local errors="VFS: Busy inodes after unmount of\|\
5018 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
5019 group descriptors corrupted"
5021 res=$(do_nodes $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
5022 [ -z "$res" ] && return 0
5023 echo "Kernel error detected: $res"
5028 # Run a single test function and cleanup after it.
5030 # This function should be run in a subshell so the test func can
5031 # exit() without stopping the whole script.
5036 export tfile=f${testnum}.${TESTSUITE}
5037 export tdir=d${testnum}.${TESTSUITE}
5038 export TESTNAME=test_$testnum
5039 local SAVE_UMASK=`umask`
5042 if ! grep -q $DIR /proc/mounts; then
5046 banner "test $testnum: $message"
5047 test_${testnum} || error "test_$testnum failed with $?"
5050 check_grant ${testnum} || error "check_grant $testnum failed with $?"
5051 check_catastrophe || error "LBUG/LASSERT detected"
5052 check_dmesg_for_errors || error "Error in dmesg detected"
5053 if [ "$PARALLEL" != "yes" ]; then
5054 ps auxww | grep -v grep | grep -q multiop &&
5055 error "multiop still running"
5066 # Wrapper around run_one to ensure:
5067 # - test runs in subshell
5068 # - output of test is saved to separate log file for error reporting
5069 # - test result is saved to data file
5072 local BEFORE=$(date +%s)
5074 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
5075 local test_log=$LOGDIR/$name
5076 local zfs_log_name=${TESTSUITE}.test_${1}.zfs_log
5077 local zfs_debug_log=$LOGDIR/$zfs_log_name
5079 rm -rf $LOGDIR/ignore
5081 local SAVE_UMASK=$(umask)
5085 log_sub_test_begin test_${1}
5086 (run_one $1 "$2") 2>&1 | tee -i $test_log
5087 local RC=${PIPESTATUS[0]}
5089 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
5090 echo "test_$1 returned $RC" | tee $LOGDIR/err
5092 duration=$(($(date +%s) - $BEFORE))
5093 pass "$1" "(${duration}s)"
5095 if [[ -f $LOGDIR/err ]]; then
5096 TEST_ERROR=$(cat $LOGDIR/err)
5097 elif [[ -f $LOGDIR/ignore ]]; then
5098 TEST_ERROR=$(cat $LOGDIR/ignore)
5099 elif [[ -f $LOGDIR/skip ]]; then
5100 TEST_ERROR=$(cat $LOGDIR/skip)
5102 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
5104 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
5108 if [ -f $LOGDIR/err ]; then
5109 log_zfs_info "$zfs_debug_log"
5110 $FAIL_ON_ERROR && exit $RC
5119 # Print information of skipped tests to result.yml
5122 log_sub_test_begin $1
5124 log_sub_test_end "SKIP" "0" "0" "$@"
5128 (cd $(dirname $1); echo $PWD/$(basename $1))
5133 export base=$(basetest $1)
5134 [ "$CHECK_GRANT" == "no" ] && return 0
5136 testname=GCHECK_ONLY_${base}
5137 [ ${!testname}x == x ] && return 0
5139 echo -n "checking grant......"
5141 local clients=$CLIENTS
5142 [ -z "$clients" ] && clients=$(hostname)
5144 # sync all the data and make sure no pending data on server
5145 do_nodes $clients sync
5148 client_grant=$(do_nodes $clients \
5149 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
5150 awk '{ total += $1 } END { printf("%0.0f", total) }')
5153 server_grant=$(do_nodes $(comma_list $(osts_nodes)) \
5154 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
5155 awk '{ total += $1 } END { printf("%0.0f", total) }')
5157 # check whether client grant == server grant
5158 if [[ $client_grant -ne $server_grant ]]; then
5159 echo "failed: client:${client_grant} server: ${server_grant}."
5160 do_nodes $(comma_list $(osts_nodes)) \
5161 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
5162 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
5165 echo "pass: client:${client_grant} server: ${server_grant}"
5169 ########################
5175 ost=`echo $1 | awk -F_ '{print $3}'`
5176 if [ -z $ost ]; then
5177 ost=`echo $1 | sed 's/-osc.*//'`
5182 ostuuid_from_index()
5184 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5187 ostname_from_index() {
5188 local uuid=$(ostuuid_from_index $1)
5192 index_from_ostuuid()
5194 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
5197 mdtuuid_from_index()
5199 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5203 # Return unique identifier for given hostname
5206 echo $host_name | md5sum | cut -d' ' -f1
5210 # Returns list of ip addresses for each interface
5212 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
5217 # Cache address list to avoid mutiple execution of local_addr_list
5218 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
5220 for i in $LOCAL_ADDR_LIST ; do
5221 [[ "$i" == "$addr" ]] && return 0
5228 local is_local="IS_LOCAL_$(host_id $host_name)"
5229 if [ -z "${!is_local-}" ] ; then
5231 local host_ip=$($LUSTRE/tests/resolveip $host_name)
5232 is_local_addr "$host_ip" && eval $is_local=1
5234 [[ "${!is_local}" == "1" ]]
5239 local_node $node && return 1
5246 for node in $(mdts_nodes); do
5247 remote_node $node && return 0
5254 [ "$CLIENTONLY" ] && return 0 || true
5255 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
5260 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
5261 MSKIPPED=1 && return 1
5268 for node in $(osts_nodes) ; do
5269 remote_node $node && return 0
5276 [ "$CLIENTONLY" ] && return 0 || true
5277 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5282 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
5283 OSKIPPED=1 && return 1
5289 [ "$CLIENTONLY" ] && return 0 || true
5291 MGS=$(facet_host mgs)
5292 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5297 remote_mds_nodsh || remote_ost_nodsh || \
5298 $(single_local_node $(comma_list $(nodes_list)))
5302 remote_ost && remote_mds
5305 # Get the active nodes for facets.
5313 for facet in ${facets//,/ }; do
5314 nodes="$nodes $(facet_active_host $facet)"
5317 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5321 # Get all of the active MDS nodes.
5323 echo -n $(facets_nodes $(get_facets MDS))
5326 # Get all of the active OSS nodes.
5328 echo -n $(facets_nodes $(get_facets OST))
5331 # Get all of the active AGT (HSM agent) nodes.
5333 echo -n $(facets_nodes $(get_facets AGT))
5336 # Get all of the client nodes and active server nodes.
5338 local nodes=$HOSTNAME
5342 # CLIENTS (if specified) contains the local client
5343 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5345 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5346 nodes="$nodes $(facets_nodes $(get_facets))"
5349 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5353 # Get all of the remote client nodes and remote active server nodes.
5354 remote_nodes_list () {
5355 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5358 # Get all of the MDS nodes, including active and passive nodes.
5366 for i in $(seq $MDSCOUNT); do
5368 failover_host=mds${i}failover_HOST
5369 nodes="$nodes ${!host} ${!failover_host}"
5372 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5376 # Get all of the OSS nodes, including active and passive nodes.
5384 for i in $(seq $OSTCOUNT); do
5386 failover_host=ost${i}failover_HOST
5387 nodes="$nodes ${!host} ${!failover_host}"
5390 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5394 # Get all of the server nodes, including active and passive nodes.
5395 all_server_nodes () {
5400 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5402 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5406 # Get all of the client and server nodes, including active and passive nodes.
5408 local nodes=$HOSTNAME
5412 # CLIENTS (if specified) contains the local client
5413 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5415 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5416 nodes="$nodes $(all_server_nodes)"
5419 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5423 init_clients_lists () {
5424 # Sanity check: exclude the local client from RCLIENTS
5425 local clients=$(hostlist_expand "$RCLIENTS")
5426 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5428 # Sanity check: exclude the dup entries
5429 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5431 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5433 # Sanity check: exclude the dup entries from CLIENTS
5434 # for those configs which has SINGLCLIENT set to local client
5435 clients=$(for i in $clients; do echo $i; done | sort -u)
5437 CLIENTS=$(comma_list $clients)
5438 local -a remoteclients=($RCLIENTS)
5439 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5440 varname=CLIENT$((i + 2))
5441 eval $varname=${remoteclients[i]}
5444 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5447 get_random_entry () {
5450 rnodes=${rnodes//,/ }
5452 local -a nodes=($rnodes)
5453 local num=${#nodes[@]}
5454 local i=$((RANDOM * num * 2 / 65536))
5460 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
5464 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5465 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5470 echo $nodes | wc -w || true
5474 local nodes=$(osts_nodes)
5475 local osscount=$(get_node_count "$nodes")
5476 [ ! "$OSTCOUNT" = "$osscount" ]
5480 local nodes=$(mdts_nodes)
5481 local mdtcount=$(get_node_count "$nodes")
5482 [ ! "$MDSCOUNT" = "$mdtcount" ]
5485 generate_machine_file() {
5486 local nodes=${1//,/ }
5487 local machinefile=$2
5489 for node in $nodes; do
5490 echo $node >>$machinefile || \
5491 { echo "can not generate machinefile $machinefile" && return 1; }
5496 local file=$1/stripe
5499 $LFS getstripe -v $file || error "getstripe $file failed"
5503 setstripe_nfsserver () {
5506 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5507 { print $1 }' /proc/mounts | cut -f 1 -d : | head -n1)
5509 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5511 do_nodev $nfsserver lfs setstripe "$@"
5514 # Check and add a test group.
5520 local gid=$(getent group $group_name | cut -d: -f3)
5521 if [[ -n "$gid" ]]; then
5522 [[ "$gid" -eq "$group_id" ]] || {
5523 error_noexit "inconsistent group ID:" \
5524 "new: $group_id, old: $gid"
5528 groupadd -g $group_id $group_name
5535 # Check and add a test user.
5548 local uid=$(getent passwd $user_name | cut -d: -f3)
5549 if [[ -n "$uid" ]]; then
5550 if [[ "$uid" -eq "$user_id" ]]; then
5551 local dir=$(getent passwd $user_name | cut -d: -f6)
5552 if [[ "$dir" != "$home" ]]; then
5554 usermod -d $home $user_name
5558 error_noexit "inconsistent user ID:" \
5559 "new: $user_id, old: $uid"
5564 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5571 check_runas_id_ret() {
5573 local myRUNAS_UID=$1
5574 local myRUNAS_GID=$2
5577 if [ -z "$myRUNAS" ]; then
5578 error_exit "myRUNAS command must be specified for check_runas_id"
5581 $myRUNAS krb5_login.sh || \
5582 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5584 mkdir $DIR/d0_runas_test
5586 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5587 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5588 rm -rf $DIR/d0_runas_test
5593 local myRUNAS_UID=$1
5594 local myRUNAS_GID=$2
5597 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5598 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5599 Please set RUNAS_ID to some UID which exists on MDS and client or
5600 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5603 # obtain the UID/GID for MPI_USER
5607 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5608 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5610 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5611 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5614 # obtain and cache Kerberos ticket-granting ticket
5615 refresh_krb5_tgt() {
5616 local myRUNAS_UID=$1
5617 local myRUNAS_GID=$2
5620 if [ -z "$myRUNAS" ]; then
5621 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5624 CLIENTS=${CLIENTS:-$HOSTNAME}
5625 do_nodes $CLIENTS "set -x
5626 if ! $myRUNAS krb5_login.sh; then
5627 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5632 # Run multiop in the background, but wait for it to print
5633 # "PAUSING" to its stdout before returning from this function.
5634 multiop_bg_pause() {
5635 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5639 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5642 echo "$MULTIOP_PROG $FILE v$ARGS"
5643 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5645 echo "TMPPIPE=${TMPPIPE}"
5646 read -t 60 multiop_output < $TMPPIPE
5647 if [ $? -ne 0 ]; then
5652 if [ "$multiop_output" != "PAUSING" ]; then
5653 echo "Incorrect multiop output: $multiop_output"
5668 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5674 inodes_available () {
5675 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
5676 sort -un | head -n1) || return 1
5680 mdsrate_inodes_available () {
5681 local min_inodes=$(inodes_available)
5682 echo $((min_inodes * 99 / 100))
5685 # reset llite stat counters
5686 clear_llite_stats(){
5687 lctl set_param -n llite.*.stats 0
5690 # sum llite stat items
5691 calc_llite_stats() {
5692 local res=$(lctl get_param -n llite.*.stats |
5693 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5697 # reset osc stat counters
5699 lctl set_param -n osc.*.osc_stats 0
5702 # sum osc stat items
5704 local res=$(lctl get_param -n osc.*.osc_stats |
5705 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5710 awk '{sum += $1} END { printf("%0.0f", sum) }'
5713 calc_osc_kbytes () {
5714 df $MOUNT > /dev/null
5715 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5718 # save_lustre_params(comma separated facet list, parameter_mask)
5719 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5720 save_lustre_params() {
5726 for facet in ${facets//,/ }; do
5727 node=$(facet_active_host $facet)
5728 [[ *\ $node\ * = " $nodes " ]] && continue
5729 nodes="$nodes $node"
5731 do_node $node "$LCTL get_param $2 |
5732 while read s; do echo $facet \\\$s; done"
5736 # restore lustre parameters from input stream, produces by save_lustre_params
5737 restore_lustre_params() {
5742 while IFS=" =" read facet name val; do
5743 do_facet $facet "$LCTL set_param -n $name $val"
5747 check_catastrophe() {
5748 local nodes=${1:-$(comma_list $(nodes_list))}
5750 do_nodes $nodes "rc=0;
5751 val=\\\$($LCTL get_param -n catastrophe 2>&1);
5752 if [[ \\\$? -eq 0 && \\\$val -ne 0 ]]; then
5753 echo \\\$(hostname -s): \\\$val;
5759 mdsrate_cleanup () {
5761 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
5762 --nfiles $3 --dir $4 --filefmt $5 $6
5767 delayed_recovery_enabled () {
5768 local var=${SINGLEMDS}_svc
5769 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5772 ########################
5774 convert_facet2label() {
5777 if [ x$facet = xost ]; then
5781 local varsvc=${facet}_svc
5783 if [ -n ${!varsvc} ]; then
5786 error "No lablel for $facet!"
5790 get_clientosc_proc_path() {
5794 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5795 # used by MDT would not be changed.
5796 # mdt lov: fsname-mdtlov
5797 # mdt osc: fsname-OSTXXXX-osc
5798 mds_on_old_device() {
5799 local mds=${1:-"$SINGLEMDS"}
5801 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5802 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5803 > /dev/null 2>&1" && return 0
5808 get_mdtosc_proc_path() {
5810 local ost_label=${2:-"*OST*"}
5812 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5813 local mdt_label=$(convert_facet2label $mds_facet)
5814 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5816 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5817 mds_on_old_device $mds_facet; then
5818 echo "${ost_label}-osc"
5819 elif [[ $ost_label = *OST* ]]; then
5820 echo "${ost_label}-osc-${mdt_index}"
5822 echo "${ost_label}-osp-${mdt_index}"
5826 get_osc_import_name() {
5829 local label=$(convert_facet2label $ost)
5831 if [ "${facet:0:3}" = "mds" ]; then
5832 get_mdtosc_proc_path $facet $label
5836 get_clientosc_proc_path $label
5840 _wait_import_state () {
5843 local maxtime=${3:-$(max_recovery_time)}
5844 local error_on_failure=${4:-1}
5848 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5849 while [ "${CONN_STATE}" != "${expected}" ]; do
5850 if [ "${expected}" == "DISCONN" ]; then
5851 # for disconn we can check after proc entry is removed
5852 [ "x${CONN_STATE}" == "x" ] && return 0
5853 # with AT enabled, we can have connect request timeout near of
5854 # reconnect timeout and test can't see real disconnect
5855 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
5857 if [ $i -ge $maxtime ]; then
5858 [ $error_on_failure -ne 0 ] && \
5859 error "can't put import for $CONN_PROC into ${expected}" \
5860 "state after $i sec, have ${CONN_STATE}"
5864 # Add uniq for multi-mount case
5865 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5869 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
5873 wait_import_state() {
5876 local maxtime=${3:-$(max_recovery_time)}
5877 local error_on_failure=${4:-1}
5880 for param in ${params//,/ }; do
5881 _wait_import_state $state $param $maxtime $error_on_failure || return
5885 wait_import_state_mount() {
5886 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
5890 wait_import_state $*
5893 # One client request could be timed out because server was not ready
5894 # when request was sent by client.
5895 # The request timeout calculation details :
5897 # /* We give the server rq_timeout secs to process the req, and
5898 # add the network latency for our local timeout. */
5899 # request->rq_deadline = request->rq_sent + request->rq_timeout +
5900 # ptlrpc_at_get_net_latency(request) ;
5902 # ptlrpc_connect_import ()
5903 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5906 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
5907 # ptlrpc_at_get_net_latency(request) ->
5908 # at_get (max (iat_net_latency=0, at_min)) = at_min
5911 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
5912 # INITIAL_CONNECT_TIMEOUT + at_min
5914 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
5915 # because we can not get this value in runtime,
5916 # the value depends on configure options, and it is not stored in /proc.
5918 # #define CONNECTION_SWITCH_MIN 5U
5919 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5921 request_timeout () {
5924 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5925 local init_connect_timeout=$TIMEOUT
5926 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5928 local at_min=$(at_get $facet at_min)
5930 echo $(( init_connect_timeout + at_min ))
5933 _wait_osc_import_state() {
5937 local target=$(get_osc_import_name $facet $ost_facet)
5938 local param="osc.${target}.ost_server_uuid"
5942 # 1. wait the deadline of client 1st request (it could be skipped)
5943 # 2. wait the deadline of client 2nd request
5944 local maxtime=$(( 2 * $(request_timeout $facet)))
5946 if [[ $facet == client* ]]; then
5947 # During setup time, the osc might not be setup, it need wait
5948 # until list_param can return valid value. And also if there
5949 # are mulitple osc entries we should list all of them before
5951 params=$($LCTL list_param $param 2>/dev/null || true)
5952 while [ -z "$params" ]; do
5953 if [ $i -ge $maxtime ]; then
5954 echo "can't get $param in $maxtime secs"
5959 params=$($LCTL list_param $param 2>/dev/null || true)
5963 if [[ $ost_facet = mds* ]]; then
5964 # no OSP connection to itself
5965 if [[ $facet = $ost_facet ]]; then
5968 param="osp.${target}.mdt_server_uuid"
5972 if ! do_rpc_nodes "$(facet_active_host $facet)" \
5973 wait_import_state $expected "$params" $maxtime; then
5974 error "import is not in ${expected} state"
5981 wait_osc_import_state() {
5987 if [[ $facet = mds ]]; then
5988 for num in $(seq $MDSCOUNT); do
5989 _wait_osc_import_state mds$num "$ost_facet" "$expected"
5992 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
5996 _wait_mgc_import_state() {
5999 local error_on_failure=${3:-1}
6000 local param="mgc.*.mgs_server_uuid"
6004 # 1. wait the deadline of client 1st request (it could be skipped)
6005 # 2. wait the deadline of client 2nd request
6006 local maxtime=$(( 2 * $(request_timeout $facet)))
6008 if [[ $facet == client* ]]; then
6009 # During setup time, the osc might not be setup, it need wait
6010 # until list_param can return valid value. And also if there
6011 # are mulitple osc entries we should list all of them before
6013 params=$($LCTL list_param $param 2>/dev/null || true)
6014 while [ -z "$params" ]; do
6015 if [ $i -ge $maxtime ]; then
6016 echo "can't get $param in $maxtime secs"
6021 params=$($LCTL list_param $param 2>/dev/null || true)
6024 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6025 wait_import_state $expected "$params" $maxtime \
6026 $error_on_failure; then
6027 if [ $error_on_failure -ne 0 ]; then
6028 error "import is not in ${expected} state"
6036 wait_mgc_import_state() {
6039 local error_on_failure=${3:-1}
6042 if [[ $facet = mds ]]; then
6043 for num in $(seq $MDSCOUNT); do
6044 _wait_mgc_import_state mds$num "$expected" \
6045 $error_on_failure || return
6048 _wait_mgc_import_state "$facet" "$expected"
6049 $error_on_failure || return
6053 wait_dne_interconnect() {
6056 if [ $MDSCOUNT -gt 1 ]; then
6057 for num in $(seq $MDSCOUNT); do
6058 wait_osc_import_state mds mds$num FULL
6063 get_clientmdc_proc_path() {
6067 get_clientmgc_proc_path() {
6075 [ -z "$list" ] && return 0
6077 # Add paths to lustre tests for 32 and 64 bit systems.
6078 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
6079 local TESTPATH="$RLUSTRE/tests:"
6080 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
6081 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
6084 wait_clients_import_state () {
6091 if [ "$FAILURE_MODE" = HARD ]; then
6092 facets=$(facets_on_host $(facet_active_host $facet))
6095 for facet in ${facets//,/ }; do
6096 local label=$(convert_facet2label $facet)
6099 ost* ) proc_path="osc.$(get_clientosc_proc_path \
6100 $label).ost_server_uuid" ;;
6101 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
6102 $label).mds_server_uuid" ;;
6103 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
6104 $label).mgs_server_uuid" ;;
6105 *) error "unknown facet!" ;;
6108 local params=$(expand_list $params $proc_path)
6111 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params;
6113 error "import is not in ${expected} state"
6123 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
6124 $LCTL get_param obdfilter.*.kbytesavail))
6125 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
6126 $LCTL get_param -n obdfilter.*.tot_granted))
6127 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
6128 $LCTL get_param -n obdfilter.*.kbytestotal))
6129 for ((i=0; i<${#AVAILA[@]}; i++)); do
6130 local -a AVAIL1=(${AVAILA[$i]//=/ })
6131 local -a TOTAL=(${TOTALA[$i]//=/ })
6132 GRANT=$((${GRANTA[$i]}/1024))
6133 # allow 1% of total space in bavail because of delayed
6134 # allocation with ZFS which might release some free space after
6135 # txg commit. For small devices, we set a mininum of 8MB
6136 local LIMIT=$((${TOTAL} / 100 + 8000))
6137 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
6138 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
6139 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
6140 echo " FULL" || echo
6146 do_facet mgs lctl pool_list $1
6150 local fsname=${1%%.*}
6151 local poolname=${1##$fsname.}
6153 do_facet mgs lctl pool_new $1
6155 # get param should return err unless pool is created
6156 [[ $RC -ne 0 ]] && return $RC
6158 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6159 2>/dev/null || echo foo" "" || RC=1
6160 if [[ $RC -eq 0 ]]; then
6163 error "pool_new failed $1"
6168 add_pool_to_list () {
6169 local fsname=${1%%.*}
6170 local poolname=${1##$fsname.}
6172 local listvar=${fsname}_CREATED_POOLS
6173 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
6177 remove_pool_from_list () {
6178 local fsname=${1%%.*}
6179 local poolname=${1##$fsname.}
6181 local listvar=${fsname}_CREATED_POOLS
6182 local temp=${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
6186 destroy_pool_int() {
6188 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
6189 awk '$1 !~ /^Pool:/ {print $1}')
6190 for ost in $OSTS; do
6191 do_facet mgs lctl pool_remove $1 $ost
6193 do_facet mgs lctl pool_destroy $1
6196 # <fsname>.<poolname> or <poolname>
6198 local fsname=${1%%.*}
6199 local poolname=${1##$fsname.}
6201 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
6205 pool_list $fsname.$poolname || return $?
6207 destroy_pool_int $fsname.$poolname
6209 [[ $RC -ne 0 ]] && return $RC
6211 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6212 2>/dev/null || echo foo" "foo" || RC=1
6214 if [[ $RC -eq 0 ]]; then
6215 remove_pool_from_list $fsname.$poolname
6217 error "destroy pool failed $1"
6223 local fsname=${1:-$FSNAME}
6225 local listvar=${fsname}_CREATED_POOLS
6229 [ x${!listvar} = x ] && return 0
6231 echo destroy the created pools: ${!listvar}
6232 for poolname in ${!listvar//,/ }; do
6233 destroy_pool $fsname.$poolname
6238 local fsname=${1:-$FSNAME}
6240 destroy_pools $fsname
6246 local ts=$(date +%s)
6249 if [[ ! -f "$YAML_LOG" ]]; then
6250 # init_logging is not performed before gather_logs,
6251 # so the $LOGDIR needs to be checked here
6252 check_shared_dir $LOGDIR && touch $LOGDIR/shared
6255 [ -f $LOGDIR/shared ] && docp=false
6257 # dump lustre logs, dmesg
6259 prefix="$TESTLOG_PREFIX.$TESTNAME"
6261 echo "Dumping lctl log to ${prefix}.*.${suffix}"
6263 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
6264 echo "Dumping logs only on local client."
6265 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
6266 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
6271 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
6272 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
6273 if [ ! -f $LOGDIR/shared ]; then
6274 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
6287 for i in $(seq 0 $num_mntpts); do
6288 cmd="ls -laf ${mntpt_root}$i/$dir"
6294 for pid in $pids; do
6301 # check_and_start_recovery_timer()
6302 # service_time = at_est2timeout(service_time);
6303 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
6304 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
6306 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
6307 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
6308 #define CONNECTION_SWITCH_MIN 5
6309 #define CONNECTION_SWITCH_INC 5
6310 max_recovery_time() {
6311 local init_connect_timeout=$((TIMEOUT / 20))
6312 ((init_connect_timeout >= 5)) || init_connect_timeout=5
6314 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
6315 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
6317 echo -n $service_time
6320 recovery_time_min() {
6321 local connection_switch_min=5
6322 local connection_switch_inc=5
6323 local connection_switch_max
6324 local reconnect_delay_max
6325 local initial_connect_timeout
6329 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
6330 (($connection_switch_min > $TIMEOUT)) &&
6331 max=$connection_switch_min || max=$TIMEOUT
6332 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
6334 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
6335 timeout_20=$((TIMEOUT/20))
6336 (($connection_switch_min > $timeout_20)) &&
6337 initial_connect_timeout=$connection_switch_min ||
6338 initial_connect_timeout=$timeout_20
6340 reconnect_delay_max=$((connection_switch_max + connection_switch_inc + \
6341 initial_connect_timeout))
6342 echo $((2 * reconnect_delay_max))
6345 get_clients_mount_count () {
6346 local clients=${CLIENTS:-`hostname`}
6348 # we need to take into account the clients mounts and
6349 # exclude mds/ost mounts if any;
6350 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
6354 PROC_CLI="srpc_info"
6362 if [ $M -lt $N ]; then
6366 while [ $N -lt $M ]; do
6376 calc_connection_cnt() {
6379 # MDT->MDT = 2 * C(M, 2)
6383 comb_m2=$(combination $MDSCOUNT 2)
6385 local num_clients=$(get_clients_mount_count)
6387 local cnt_mdt2mdt=$((comb_m2 * 2))
6388 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
6389 local cnt_cli2ost=$((num_clients * OSTCOUNT))
6390 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
6391 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
6392 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
6393 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
6407 local cmd="$tgt.srpc.flavor"
6409 if [ $net == "any" ]; then
6414 if [ $dir != "any" ]; then
6419 log "Setting sptlrpc rule: $cmd"
6420 do_facet mgs "$LCTL conf_param $cmd"
6429 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
6430 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
6432 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
6434 if [ "x$bulkspec" != "x" ]; then
6435 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
6437 if [ "x$algs" != "x" ]; then
6438 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
6440 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
6441 if [ $bulk == "bulkn" ]; then
6442 bulk_count=`echo "$output" | grep "bulk flavor" \
6443 | grep "null/null" | wc -l`
6444 elif [ $bulk == "bulki" ]; then
6445 bulk_count=`echo "$output" | grep "bulk flavor" \
6446 | grep "/null" | grep -v "null/" | wc -l`
6448 bulk_count=`echo "$output" | grep "bulk flavor" \
6449 | grep -v "/null" | grep -v "null/" | wc -l`
6453 [ $bulk_count -lt $count ] && count=$bulk_count
6464 local clients=${CLIENTS:-`hostname`}
6466 for c in ${clients//,/ }; do
6467 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
6468 tmpcnt=`count_flvr "$output" $flavor`
6469 cnt=$((cnt + tmpcnt))
6479 local clients=${CLIENTS:-`hostname`}
6481 for c in ${clients//,/ }; do
6482 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
6483 tmpcnt=`count_flvr "$output" $flavor`
6484 cnt=$((cnt + tmpcnt))
6494 if [ $MDSCOUNT -le 1 ]; then
6499 for num in `seq $MDSCOUNT`; do
6500 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
6501 tmpcnt=`count_flvr "$output" $flavor`
6502 cnt=$((cnt + tmpcnt))
6513 for num in `seq $MDSCOUNT`; do
6514 mdtosc=$(get_mdtosc_proc_path mds$num)
6515 mdtosc=${mdtosc/-MDT*/-MDT\*}
6516 output=$(do_facet mds$num lctl get_param -n \
6517 osc.$mdtosc.$PROC_CLI 2>/dev/null)
6518 tmpcnt=`count_flvr "$output" $flavor`
6519 cnt=$((cnt + tmpcnt))
6528 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
6529 count_flvr "$output" $flavor
6534 local dir=$1 # from to
6535 local flavor=$2 # flavor expected
6538 if [ $dir == "cli2mdt" ]; then
6539 res=`flvr_cnt_cli2mdt $flavor`
6540 elif [ $dir == "cli2ost" ]; then
6541 res=`flvr_cnt_cli2ost $flavor`
6542 elif [ $dir == "mdt2mdt" ]; then
6543 res=`flvr_cnt_mdt2mdt $flavor`
6544 elif [ $dir == "mdt2ost" ]; then
6545 res=`flvr_cnt_mdt2ost $flavor`
6546 elif [ $dir == "all2ost" ]; then
6547 res1=`flvr_cnt_mdt2ost $flavor`
6548 res2=`flvr_cnt_cli2ost $flavor`
6549 res=$((res1 + res2))
6550 elif [ $dir == "all2mdt" ]; then
6551 res1=`flvr_cnt_mdt2mdt $flavor`
6552 res2=`flvr_cnt_cli2mdt $flavor`
6553 res=$((res1 + res2))
6554 elif [ $dir == "all2all" ]; then
6555 res1=`flvr_cnt_mdt2ost $flavor`
6556 res2=`flvr_cnt_cli2ost $flavor`
6557 res3=`flvr_cnt_mdt2mdt $flavor`
6558 res4=`flvr_cnt_cli2mdt $flavor`
6559 res=$((res1 + res2 + res3 + res4))
6567 local dir=$1 # from to
6568 local flavor=$2 # flavor expected
6569 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6573 for ((i=0;i<20;i++)); do
6574 echo -n "checking $dir..."
6575 res=$(do_check_flavor $dir $flavor)
6576 echo "found $res/$expect $flavor connections"
6577 [ $res -ge $expect ] && return 0
6581 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6585 restore_to_default_flavor()
6587 local proc="mgs.MGS.live.$FSNAME"
6589 echo "restoring to default flavor..."
6591 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6593 # remove all existing rules if any
6594 if [ $nrule -ne 0 ]; then
6595 echo "$nrule existing rules"
6596 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6597 echo "remove rule: $rule"
6598 spec=`echo $rule | awk -F = '{print $1}'`
6599 do_facet mgs "$LCTL conf_param -d $spec"
6603 # verify no rules left
6604 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6605 [ $nrule -ne 0 ] && error "still $nrule rules left"
6607 # wait for default flavor to be applied
6608 # currently default flavor for all connections are 'null'
6609 wait_flavor all2all null
6610 echo "now at default flavor settings"
6615 local flavor=${1:-null}
6617 echo "setting all flavor to $flavor"
6619 # FIXME need parameter to this fn
6620 # and remove global vars
6621 local cnt_all2all=$(calc_connection_cnt all2all)
6623 local res=$(do_check_flavor all2all $flavor)
6624 if [ $res -eq $cnt_all2all ]; then
6625 echo "already have total $res $flavor connections"
6629 echo "found $res $flavor out of total $cnt_all2all connections"
6630 restore_to_default_flavor
6632 [[ $flavor = null ]] && return 0
6634 set_rule $FSNAME any any $flavor
6635 wait_flavor all2all $flavor
6641 # Checking for shared logdir
6642 if [ ! -d $dir ]; then
6643 # Not found. Create local logdir
6646 touch $dir/check_file.$(hostname -s)
6651 check_write_access() {
6653 local list=${2:-$(comma_list $(nodes_list))}
6657 for node in ${list//,/ }; do
6658 file=$dir/check_file.$(short_nodename $node)
6659 if [[ ! -f "$file" ]]; then
6660 # Logdir not accessible/writable from this node.
6663 rm -f $file || return 1
6669 if [[ -n $YAML_LOG ]]; then
6672 local SAVE_UMASK=`umask`
6675 export YAML_LOG=${LOGDIR}/results.yml
6679 if [ ! -f $YAML_LOG ]; then # If the yaml log already exists then we will just append to it
6680 if check_shared_dir $LOGDIR; then
6681 touch $LOGDIR/shared
6682 echo "Logging to shared log directory: $LOGDIR"
6684 echo "Logging to local directory: $LOGDIR"
6687 yml_nodes_file $LOGDIR >> $YAML_LOG
6688 yml_results_file >> $YAML_LOG
6695 yml_log_test $1 >> $YAML_LOG
6699 yml_log_test_status $@ >> $YAML_LOG
6702 log_sub_test_begin() {
6703 yml_log_sub_test_begin "$@" >> $YAML_LOG
6706 log_sub_test_end() {
6707 yml_log_sub_test_end "$@" >> $YAML_LOG
6713 local llverdev_opts=$2
6714 local devname=$(basename $1)
6715 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6716 # loop devices aren't in /proc/partitions
6717 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6719 size=$(($size / 1024 / 1024)) # Gb
6721 local partial_arg=""
6722 # Run in partial (fast) mode if the size
6723 # of a partition > 1 GB
6724 [ $size -gt 1 ] && partial_arg="-p"
6726 llverdev --force $partial_arg $llverdev_opts $dev
6732 local llverfs_opts=$2
6733 local use_partial_arg=$3
6734 local partial_arg=""
6735 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6737 # Run in partial (fast) mode if the size
6738 # of a partition > 1 GB
6739 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6741 llverfs $partial_arg $llverfs_opts $dir
6744 #Remove objects from OST
6745 remove_ost_objects() {
6751 local mntpt=$(facet_mntpt $facet)
6752 local opts=$OST_MOUNT_OPTS
6756 echo "removing objects from $ostdev on $facet: $objids"
6757 if ! test -b $ostdev; then
6758 opts=$(csa_add "$opts" -o loop)
6760 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
6763 for i in $objids; do
6764 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
6766 umount -f $mntpt || return $?
6770 #Remove files from MDT
6771 remove_mdt_files() {
6776 local mntpt=$(facet_mntpt $facet)
6777 local opts=$MDS_MOUNT_OPTS
6779 echo "removing files from $mdtdev on $facet: $files"
6780 if [ $(facet_fstype $facet) == ldiskfs ] &&
6781 ! do_facet $facet test -b $mdtdev; then
6782 opts=$(csa_add "$opts" -o loop)
6784 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6788 rm $mntpt/ROOT/$f || { rc=$?; break; }
6790 umount -f $mntpt || return $?
6794 duplicate_mdt_files() {
6799 local mntpt=$(facet_mntpt $facet)
6800 local opts=$MDS_MOUNT_OPTS
6802 echo "duplicating files on $mdtdev on $facet: $files"
6803 mkdir -p $mntpt || return $?
6804 if [ $(facet_fstype $facet) == ldiskfs ] &&
6805 ! do_facet $facet test -b $mdtdev; then
6806 opts=$(csa_add "$opts" -o loop)
6808 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6819 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
6820 pushd $mntpt/ROOT > /dev/null || return $?
6823 touch $f.bad || return $?
6824 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
6826 [ $rc -eq 0 ] || return $rc
6827 setfattr --restore $tmp || return $?
6833 local devs=${1//,/ }
6836 local rslt=$TMP/sgpdd_survey
6838 # sgpdd-survey cleanups ${rslt}.* files
6840 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
6846 # returns the canonical name for an ldiskfs device
6851 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
6852 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
6853 echo dm-\\\${foo##*:};
6855 echo \\\$(basename \\\$dv);
6859 is_sanity_benchmark() {
6860 local benchmarks="dbench bonnie iozone fsx"
6862 for b in $benchmarks; do
6863 if [ "$b" == "$suite" ]; then
6871 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
6875 # Get the available size (KB) of a given obd target.
6882 [[ $facet != client ]] || return 0
6884 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
6889 # Get the page size (bytes) on a given facet node.
6895 size=$(do_facet $facet getconf PAGE_SIZE)
6896 [[ ${PIPESTATUS[0]} = 0 && -n "$size" ]] || size=4096
6901 # Get the block count of the filesystem.
6908 count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6909 awk '/^Block count:/ {print $3}')
6913 # Get the block size of the filesystem.
6919 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6920 awk '/^Block size:/ {print $3}')
6924 # Check whether the "large_xattr" feature is enabled or not.
6925 large_xattr_enabled() {
6926 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
6928 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6930 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
6931 grep -E -q '(ea_inode|large_xattr)'"
6932 return ${PIPESTATUS[0]}
6935 # Get the maximum xattr size supported by the filesystem.
6939 if large_xattr_enabled; then
6940 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
6943 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6944 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
6946 # maximum xattr size = size of block - size of header -
6947 # size of 1 entry - 4 null bytes
6948 size=$((block_size - 32 - 32 - 4))
6954 # Dump the value of the named xattr from a file.
6959 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
6962 # Generate a string with size of $size bytes.
6964 local size=${1:-1024} # in bytes
6966 echo "$(head -c $size < /dev/zero | tr '\0' y)"
6969 reformat_external_journal() {
6974 if [ -n "${!var}" ]; then
6975 local rcmd="do_facet $facet"
6977 echo "reformat external journal on $facet:${!var}"
6978 ${rcmd} mke2fs -O journal_dev ${!var} || return 1
6982 # MDT file-level backup/restore
6983 mds_backup_restore() {
6986 local devname=$(mdsdevname $(facet_number $facet))
6987 local mntpt=$(facet_mntpt brpt)
6988 local rcmd="do_facet $facet"
6989 local metaea=${TMP}/backup_restore.ea
6990 local metadata=${TMP}/backup_restore.tgz
6991 local opts=${MDS_MOUNT_OPTS}
6992 local svc=${facet}_svc
6994 if ! ${rcmd} test -b ${devname}; then
6995 opts=$(csa_add "$opts" -o loop)
6998 echo "file-level backup/restore on $facet:${devname}"
7000 # step 1: build mount point
7001 ${rcmd} mkdir -p $mntpt
7002 # step 2: cleanup old backup
7003 ${rcmd} rm -f $metaea $metadata
7005 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7006 if [ ! -z $igif ]; then
7007 # step 3.5: rm .lustre
7008 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
7010 # step 4: backup metaea
7012 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
7014 # step 5: backup metadata
7016 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
7018 ${rcmd} $UMOUNT $mntpt || return 4
7019 # step 8: reformat dev
7020 echo "reformat new device"
7021 format_mdt $(facet_number $facet)
7023 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
7024 # step 10: restore metadata
7026 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
7027 # step 11: restore metaea
7029 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
7030 # step 12: remove recovery logs
7031 echo "remove recovery logs"
7032 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
7033 # step 13: umount dev
7034 ${rcmd} $UMOUNT $mntpt || return 10
7035 # step 14: cleanup tmp backup
7036 ${rcmd} rm -f $metaea $metadata
7037 # step 15: reset device label - it's not virgin on
7038 ${rcmd} e2label $devname ${!svc}
7045 local devname=$(mdsdevname $(facet_number $facet))
7046 local mntpt=$(facet_mntpt brpt)
7047 local rcmd="do_facet $facet"
7048 local opts=${MDS_MOUNT_OPTS}
7050 if ! ${rcmd} test -b ${devname}; then
7051 opts=$(csa_add "$opts" -o loop)
7054 echo "removing OI files on $facet: idx=${idx}"
7056 # step 1: build mount point
7057 ${rcmd} mkdir -p $mntpt
7059 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7060 if [ -z $idx ]; then
7061 # step 3: remove all OI files
7062 ${rcmd} rm -fv $mntpt/oi.16*
7063 elif [ $idx -lt 2 ]; then
7064 ${rcmd} rm -fv $mntpt/oi.16.${idx}
7068 # others, rm oi.16.[idx, idx * idx, idx ** ...]
7069 for ((i=${idx}; i<64; i=$((i * idx)))); do
7070 ${rcmd} rm -fv $mntpt/oi.16.${i}
7074 ${rcmd} $UMOUNT $mntpt || return 2
7075 # OI files will be recreated when mounted as lustre next time.
7078 # generate maloo upload-able log file name
7079 # \param logname specify unique part of file name
7080 generate_logname() {
7081 local logname=${1:-"default_logname"}
7083 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
7086 # make directory on different MDTs
7090 local stripe_count=2
7091 local stripe_index=-1
7094 while getopts "c:i:p" opt; do
7096 c) stripe_count=$OPTARG;;
7097 i) stripe_index=$OPTARG;;
7099 \?) error "only support -i -c -p";;
7103 shift $((OPTIND - 1))
7104 [ $# -eq 1 ] || error "Only creating single directory is supported"
7107 if [ "$p_option" == "-p" ]; then
7108 local parent=$(dirname $path)
7110 [ -d $path ] && return 0
7111 [ ! -d ${parent} ] && mkdir -p ${parent}
7114 if [ $MDSCOUNT -le 1 ]; then
7117 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
7120 if [ $stripe_index -eq -1 ]; then
7121 mdt_index=$((test_num % MDSCOUNT))
7123 mdt_index=$stripe_index
7125 echo "striped dir -i$mdt_index -c$stripe_count $path"
7126 $LFS setdirstripe -i$mdt_index -c$stripe_count $path
7130 # find the smallest and not in use file descriptor
7133 local max_fd=$(ulimit -n)
7135 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
7138 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
7142 check_mount_and_prep()
7144 is_mounted $MOUNT || setupall
7146 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
7147 mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
7148 for idx in $(seq $MDSCOUNT); do
7149 local name="MDT$(printf '%04x' $((idx - 1)))"
7150 rm -rf $MOUNT/.lustre/lost+found/$name/*
7154 # calcule how many ost-objects to be created.
7155 precreated_ost_obj_count()
7159 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
7160 local ost_name="OST$(printf '%04x' $ost_idx)"
7161 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
7162 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7163 osp.$proc_path.prealloc_last_id)
7164 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7165 osp.$proc_path.prealloc_next_id)
7166 echo $((last_id - next_id + 1))
7169 check_file_in_pool()
7174 local res=$($GETSTRIPE $file | grep 0x | cut -f2)
7177 for t in $tlist ; do
7178 [ "$i" -eq "$t" ] && continue 2
7181 echo "pool list: $tlist"
7182 echo "striping: $res"
7183 error_noexit "$file not allocated in $pool"
7190 echo "Creating new pool"
7193 create_pool $FSNAME.$pool ||
7194 { error_noexit "No pool created, result code $?"; return 1; }
7195 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
7196 { error_noexit "$pool not in lfs pool_list"; return 2; }
7199 pool_add_targets() {
7200 echo "Adding targets to pool"
7206 local list=$(seq $first $step $last)
7208 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
7209 do_facet mgs $LCTL pool_add \
7210 $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
7211 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
7212 | sort -u | tr '\n' ' ' " "$t" || {
7213 error_noexit "Add to pool failed"
7216 local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
7217 local addcount=$(((last - first) / step + 1))
7218 [ $lfscount -eq $addcount ] || {
7219 error_noexit "lfs pool_list bad ost count" \
7220 "$lfscount != $addcount"
7228 echo "Setting pool on directory $tdir"
7230 $SETSTRIPE -c 2 -p $pool $tdir && return 0
7232 error_noexit "Cannot set pool $pool to $tdir"
7239 echo "Checking pool on directory $tdir"
7241 local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
7242 [ "$res" = "$pool" ] && return 0
7244 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
7248 pool_dir_rel_path() {
7249 echo "Testing relative path works well"
7254 mkdir -p $root/$tdir/$tdir
7256 pool_set_dir $pool $tdir || return 1
7257 pool_set_dir $pool ./$tdir || return 2
7258 pool_set_dir $pool ../$tdir || return 3
7259 pool_set_dir $pool ../$tdir/$tdir || return 4
7260 rm -rf $tdir; cd - > /dev/null
7263 pool_alloc_files() {
7264 echo "Checking files allocation from directory pool"
7271 for i in $(seq -w 1 $count)
7273 local file=$tdir/file-$i
7275 check_file_in_pool $file $pool "$tlist" || \
7276 failed=$((failed + 1))
7278 [ "$failed" = 0 ] && return 0
7280 error_noexit "$failed files not allocated in $pool"
7284 pool_create_files() {
7285 echo "Creating files in pool"
7293 for i in $(seq -w 1 $count)
7295 local file=$tdir/spoo-$i
7296 $SETSTRIPE -p $pool $file
7297 check_file_in_pool $file $pool "$tlist" || \
7298 failed=$((failed + 1))
7300 [ "$failed" = 0 ] && return 0
7302 error_noexit "$failed files not allocated in $pool"
7307 echo "Checking 'lfs df' output"
7310 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
7312 local res=$($LFS df --pool $FSNAME.$pool |
7314 grep "$FSNAME-OST" |
7316 [ "$res" = "$t" ] && return 0
7318 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
7322 pool_file_rel_path() {
7323 echo "Creating files in a pool with relative pathname"
7328 { error_noexit "unable to create $tdir"; return 1 ; }
7329 local file="/..$tdir/$tfile-1"
7330 $SETSTRIPE -p $pool $file ||
7331 { error_noexit "unable to create $file" ; return 2 ; }
7334 $SETSTRIPE -p $pool $tfile-2 || {
7335 error_noexit "unable to create $tfile-2 in $tdir"
7340 pool_remove_first_target() {
7341 echo "Removing first target from a pool"
7344 local pname="lov.$FSNAME-*.pools.$pool"
7345 local t=$($LCTL get_param -n $pname | head -1)
7346 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7347 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
7348 error_noexit "$t not removed from $FSNAME.$pool"
7353 pool_remove_all_targets() {
7354 echo "Removing all targets from pool"
7357 local pname="lov.$FSNAME-*.pools.$pool"
7358 for t in $($LCTL get_param -n $pname | sort -u)
7360 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7362 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
7363 error_noexit "Pool $FSNAME.$pool cannot be drained"
7366 # striping on an empty/nonexistant pool should fall back
7367 # to "pool of everything"
7369 error_noexit "failed to use fallback striping for empty pool"
7372 # setstripe on an empty pool should fail
7373 $SETSTRIPE -p $pool $file 2>/dev/null && {
7374 error_noexit "expected failure when creating file" \
7382 echo "Destroying pool"
7386 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
7389 # striping on an empty/nonexistant pool should fall back
7390 # to "pool of everything"
7392 error_noexit "failed to use fallback striping for missing pool"
7395 # setstripe on an empty pool should fail
7396 $SETSTRIPE -p $pool $file 2>/dev/null && {
7397 error_noexit "expected failure when creating file" \
7402 # get param should return err once pool is gone
7403 if wait_update $HOSTNAME "lctl get_param -n \
7404 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
7406 remove_pool_from_list $FSNAME.$pool
7409 error_noexit "Pool $FSNAME.$pool is not destroyed"
7413 # Get and check the actual stripe count of one file.
7414 # Usage: check_stripe_count <file> <expected_stripe_count>
7415 check_stripe_count() {
7420 [[ -z "$file" || -z "$expected" ]] &&
7421 error "check_stripe_count: invalid argument"
7423 local cmd="$GETSTRIPE -c $file"
7424 actual=$($cmd) || error "$cmd failed"
7425 actual=${actual%% *}
7427 if [[ $actual -ne $expected ]]; then
7428 [[ $expected -eq -1 ]] ||
7429 error "$cmd wrong: found $actual, expected $expected"
7430 [[ $actual -eq $OSTCOUNT ]] ||
7431 error "$cmd wrong: found $actual, expected $OSTCOUNT"
7435 # Get and check the actual list of OST indices on one file.
7436 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
7442 [[ -z "$file" || -z "$expected" ]] &&
7443 error "check_obdidx: invalid argument!"
7445 obdidx=$(comma_list $($GETSTRIPE $file | grep -A $OSTCOUNT obdidx |
7446 grep -v obdidx | awk '{print $1}' | xargs))
7448 [[ $obdidx = $expected ]] ||
7449 error "list of OST indices on $file is $obdidx," \
7450 "should be $expected"
7453 # Get and check the actual OST index of the first stripe on one file.
7454 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
7455 check_start_ost_idx() {
7460 [[ -z "$file" || -z "$expected" ]] &&
7461 error "check_start_ost_idx: invalid argument!"
7463 start_ost_idx=$($GETSTRIPE $file | grep -A 1 obdidx | grep -v obdidx |
7466 [[ $start_ost_idx = $expected ]] ||
7467 error "OST index of the first stripe on $file is" \
7468 "$start_ost_idx, should be $expected"
7471 killall_process () {
7472 local clients=${1:-$(hostname)}
7477 do_nodes $clients "killall $signal $name"