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}
145 export DO_CLEANUP=${DO_CLEANUP:-true}
147 export MKE2FS=$MKE2FS
148 if [ -z "$MKE2FS" ]; then
149 if which mkfs.ldiskfs >/dev/null 2>&1; then
150 export MKE2FS=mkfs.ldiskfs
156 export DEBUGFS=$DEBUGFS
157 if [ -z "$DEBUGFS" ]; then
158 if which debugfs.ldiskfs >/dev/null 2>&1; then
159 export DEBUGFS=debugfs.ldiskfs
161 export DEBUGFS=debugfs
165 export TUNE2FS=$TUNE2FS
166 if [ -z "$TUNE2FS" ]; then
167 if which tunefs.ldiskfs >/dev/null 2>&1; then
168 export TUNE2FS=tunefs.ldiskfs
170 export TUNE2FS=tune2fs
174 export E2LABEL=$E2LABEL
175 if [ -z "$E2LABEL" ]; then
176 if which label.ldiskfs >/dev/null 2>&1; then
177 export E2LABEL=label.ldiskfs
179 export E2LABEL=e2label
183 export DUMPE2FS=$DUMPE2FS
184 if [ -z "$DUMPE2FS" ]; then
185 if which dumpfs.ldiskfs >/dev/null 2>&1; then
186 export DUMPE2FS=dumpfs.ldiskfs
188 export DUMPE2FS=dumpe2fs
192 export E2FSCK=$E2FSCK
193 if [ -z "$E2FSCK" ]; then
194 if which fsck.ldiskfs >/dev/null 2>&1; then
195 export E2FSCK=fsck.ldiskfs
201 export RESIZE2FS=$RESIZE2FS
202 if [ -z "$RESIZE2FS" ]; then
203 if which resizefs.ldiskfs >/dev/null 2>&1; then
204 export RESIZE2FS=resizefs.ldiskfs
206 export RESIZE2FS=resize2fs
210 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
211 export FSCK_MAX_ERR=4 # File system errors left uncorrected
213 export ZFS=${ZFS:-zfs}
214 export ZPOOL=${ZPOOL:-zpool}
215 export ZDB=${ZDB:-zdb}
216 export PARTPROBE=${PARTPROBE:-partprobe}
218 #[ -d /r ] && export ROOT=${ROOT:-/r}
219 export TMP=${TMP:-$ROOT/tmp}
220 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
221 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
222 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
224 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
225 if ! echo $PATH | grep -q $LUSTRE/utils; then
226 export PATH=$LUSTRE/utils:$PATH
228 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
229 export PATH=$LUSTRE/utils/gss:$PATH
231 if ! echo $PATH | grep -q $LUSTRE/tests; then
232 export PATH=$LUSTRE/tests:$PATH
234 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
235 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
237 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
238 [ ! -f "$LST" ] && export LST=$(which lst)
239 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
240 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
241 export MCREATE=${MCREATE:-mcreate}
242 # Ubuntu, at least, has a truncate command in /usr/bin
243 # so fully path our truncate command.
244 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
245 export FSX=${FSX:-$LUSTRE/tests/fsx}
246 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
247 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
248 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
249 export PATH=$LUSTRE/tests/racer:$PATH:
251 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
252 export PATH=$LUSTRE/tests/mpi:$PATH
254 export RSYNC_RSH=${RSYNC_RSH:-rsh}
256 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
257 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
258 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
259 [ ! -f "$LFS" ] && export LFS=$(which lfs)
260 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
261 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
263 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
264 if [ ! -f "$L_GETIDENTITY" ]; then
265 if `which l_getidentity > /dev/null 2>&1`; then
266 export L_GETIDENTITY=$(which l_getidentity)
268 export L_GETIDENTITY=NONE
271 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
272 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
273 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
274 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
275 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
276 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
277 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
278 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
279 [ ! -f "$LUSTRE_RMMOD" ] &&
280 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
281 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
282 [ ! -f "$LFS_MIGRATE" ] &&
283 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
284 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
285 [ ! -f "$LR_READER" ] && export LR_READER=$(which lr_reader 2> /dev/null)
286 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
287 export NAME=${NAME:-local}
288 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
289 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
290 export LGSSD=$(which lgssd)
291 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
292 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
293 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
295 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
297 export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
298 [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
300 if [ "$ACCEPTOR_PORT" ]; then
301 export PORT_OPT="--port $ACCEPTOR_PORT"
306 echo "Using GSS/krb5 ptlrpc security flavor"
307 which lgss_keyring > /dev/null 2>&1 || \
308 error_exit "built with gss disabled! SEC=$SEC"
319 IDENTITY_UPCALL=false
323 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
325 # Paths on remote nodes, if different
326 export RLUSTRE=${RLUSTRE:-$LUSTRE}
327 export RPWD=${RPWD:-$PWD}
328 export I_MOUNTED=${I_MOUNTED:-"no"}
329 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
330 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
331 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
332 ! -f $LUSTRE/mdt/mdt.ko ]; then
333 export CLIENTMODSONLY=yes
336 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
337 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
341 while getopts "rvwf:" opt $*; do
346 w) WRITECONF=writeconf;;
351 shift $((OPTIND - 1))
354 # print the durations of each test if "true"
355 DDETAILS=${DDETAILS:-false}
356 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
361 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
368 ncpts=$(do_facet $facet "lctl get_param -n " \
369 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
371 if [ $ncpts -eq 0 ]; then
378 # Return a numeric version code based on a version string. The version
379 # code is useful for comparison two version strings to see which is newer.
381 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
382 eval set -- $(tr "[:punct:]" " " <<< $*)
384 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
387 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
388 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
390 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
392 # usage: lustre_build_version
394 # All Lustre versions support "lctl get_param" to report the version of the
395 # code running in the kernel (what our tests are interested in), but it
396 # doesn't work without modules loaded. If that fails, use "lctl version"
397 # instead, which is easy to parse and works without the kernel modules,
398 # but was only added in 2.6.50. If that also fails, fall back to calling
399 # "lctl lustre_build_version" which prints either (or both) the userspace
400 # and kernel build versions, but is deprecated and should eventually be
403 # output: prints version string to stdout in dotted-decimal format
404 lustre_build_version() {
405 local facet=${1:-client}
408 local VER=$(do_facet $facet $LCTL get_param -n version 2> /dev/null |
409 awk '/lustre: / { print $2 }')
411 [ -z "$VER" ] && VER=$(do_facet $facet $LCTL --version 2>/dev/null |
413 # Lustre version: 2.5.3-gfcfd782-CHANGED-2.6.32.26-175.fc12.x86_64
414 # lctl version: 2.5.3-gfcfd782-CHANGED-2.6.32.26-175.fc12.x86_64
415 [ -z "$VER" ] && VER=$(do_facet $facet $LCTL lustre_build_version |
416 awk '/version:/ { print $3; exit; }')
417 sed -e 's/^v//' -e 's/-.*//' -e 's/_/./g' <<<$VER
420 # Report the Lustre numeric build version code for the supplied facet.
421 lustre_version_code() {
422 version_code $(lustre_build_version $1)
426 /sbin/lsmod | grep -q "^\<$1\>"
429 # Load a module on the system where this is running.
431 # usage: load_module module_name [module arguments for insmod/modprobe]
433 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
434 # will be used as the arguments. Otherwise arguments will be obtained from
435 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
442 BASE=$(basename $module $EXT)
444 module_loaded ${BASE} && return
446 # If no module arguments were passed, get them from $MODOPTS_<MODULE>,
447 # else from modprobe.conf
448 if [ $# -eq 0 ]; then
449 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
450 # Bash until 4.x, so we resort to eval.
451 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
452 eval set -- \$$optvar
453 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
454 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
456 opt=$(awk -v var="^options $BASE" '$0 ~ var \
457 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
458 set -- $(echo -n $opt)
460 # Ensure we have accept=all for lnet
461 if [ $(basename $module) = lnet ]; then
462 # OK, this is a bit wordy...
463 local arg accept_all_present=false
466 [ "$arg" = accept=all ] && \
467 accept_all_present=true
469 $accept_all_present || set -- "$@" accept=all
475 [ $# -gt 0 ] && echo "${module} options: '$*'"
477 # Note that insmod will ignore anything in modprobe.conf, which is why
478 # we're passing options on the command-line.
479 if [[ "$BASE" == "lnet_selftest" ]] &&
480 [[ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]]; then
481 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
482 elif [[ -f ${LUSTRE}/${module}${EXT} ]]; then
483 [[ "$BASE" != "ptlrpc_gss" ]] || modprobe sunrpc
484 insmod ${LUSTRE}/${module}${EXT} "$@"
486 # must be testing a "make install" or "rpm" installation
487 # note failed to load ptlrpc_gss is considered not fatal
488 if [[ "$BASE" == "ptlrpc_gss" ]]; then
489 modprobe $BASE "$@" 2>/dev/null ||
490 echo "gss/krb5 is not supported"
497 llite_lloop_enabled() {
498 local n1=$(uname -r | cut -d. -f1)
499 local n2=$(uname -r | cut -d. -f2)
500 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
502 # load the llite_lloop module for < 2.6.32 kernels
503 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
504 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
511 load_modules_local() {
512 if [ -n "$MODPROBE" ]; then
514 echo "Using modprobe to load modules"
518 echo Loading modules from $LUSTRE
522 if [ -f /sys/devices/system/cpu/online ]; then
523 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
524 echo "detected $ncpus online CPUs by sysfs"
526 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
528 if [ $rc -eq 0 ]; then
529 echo "detected $ncpus online CPUs by getconf"
531 echo "Can't detect number of CPUs"
536 # if there is only one CPU core, libcfs can only create one partition
537 # if there is more than 4 CPU cores, libcfs should create multiple CPU
538 # partitions. So we just force libcfs to create 2 partitions for
539 # system with 2 or 4 cores
540 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
541 # force to enable multiple CPU partitions
542 echo "Force libcfs to create 2 CPU partitions"
543 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
545 echo "libcfs will create CPU partition based on online CPUs"
548 load_module ../libcfs/libcfs/libcfs
550 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
551 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
552 load_module ../lnet/lnet/lnet
555 LNETLND="o2iblnd/ko2iblnd"
560 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
561 load_module ../lnet/klnds/$LNETLND
562 load_module obdclass/obdclass
563 load_module ptlrpc/ptlrpc
564 load_module ptlrpc/gss/ptlrpc_gss
572 load_module obdecho/obdecho
573 if ! client_only; then
574 SYMLIST=/proc/kallsyms
575 grep -q crc16 $SYMLIST ||
576 { modprobe crc16 2>/dev/null || true; }
577 grep -q -w jbd2 $SYMLIST ||
578 { modprobe jbd2 2>/dev/null || true; }
579 load_module lfsck/lfsck
580 [ "$LQUOTA" != "no" ] &&
581 load_module quota/lquota $LQUOTAOPTS
582 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
584 load_module osd-zfs/osd_zfs
586 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
587 grep -q exportfs_decode_fh $SYMLIST ||
588 { modprobe exportfs 2> /dev/null || true; }
589 grep -q -w mbcache $SYMLIST ||
590 { modprobe mbcache 2>/dev/null || true; }
591 load_module ../ldiskfs/ldiskfs
592 load_module osd-ldiskfs/osd_ldiskfs
604 load_module llite/lustre
605 llite_lloop_enabled && load_module llite/llite_lloop
606 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
608 rm -f $OGDB/ogdb-$HOSTNAME
609 $LCTL modules > $OGDB/ogdb-$HOSTNAME
611 # 'mount' doesn't look in $PATH, just sbin
612 local mount_lustre=$LUSTRE/utils/mount.lustre
613 if [ -f $mount_lustre ]; then
614 local sbin_mount=$(readlink -f /sbin)/mount.lustre
615 if grep -qw "$sbin_mount" /proc/mounts; then
616 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
618 if ! grep -qw "$sbin_mount" /proc/mounts; then
619 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
620 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
621 cat <<- EOF > "$sbin_mount"
624 echo "This $sbin_mount just a mountpoint." 1>&2
625 echo "It is never supposed to be run." 1>&2
626 logger -p emerg -- "using stub $sbin_mount $@"
629 chmod a+x $sbin_mount
631 mount --bind $mount_lustre $sbin_mount ||
632 error "can't bind $mount_lustre to $sbin_mount"
640 # load modules on remote nodes optionally
641 # lustre-tests have to be installed on these nodes
642 if $LOAD_MODULES_REMOTE; then
643 local list=$(comma_list $(remote_nodes_list))
644 if [ -n "$list" ]; then
645 echo "loading modules on: '$list'"
646 do_rpc_nodes "$list" load_modules_local
652 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
653 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
654 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
655 echo "$LEAK_LUSTRE" 1>&2
656 echo "$LEAK_PORTALS" 1>&2
657 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
658 echo "Memory leaks detected"
659 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
665 wait_exit_ST client # bug 12845
667 $LUSTRE_RMMOD ldiskfs || return 2
669 if $LOAD_MODULES_REMOTE; then
670 local list=$(comma_list $(remote_nodes_list))
671 if [ -n "$list" ]; then
672 echo "unloading modules on: '$list'"
673 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
674 do_rpc_nodes "$list" check_mem_leak
678 local sbin_mount=$(readlink -f /sbin)/mount.lustre
679 if grep -qe "$sbin_mount " /proc/mounts; then
680 umount $sbin_mount || true
681 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
685 check_mem_leak || return 254
687 echo "modules unloaded."
692 local facet=${1:-$SINGLEMDS}
693 local fstype=$(facet_fstype $facet)
696 ldiskfs) size=50;; # largest seen is 44, leave some headroom
697 zfs) size=400;; # largest seen is 384
703 check_gss_daemon_nodes() {
707 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
708 if [ \\\"\\\$num\\\" -ne 1 ]; then
709 echo \\\$num instance of $dname;
714 check_gss_daemon_facet() {
718 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
719 if [ $num -ne 1 ]; then
720 echo "$num instance of $dname on $facet"
729 echo Stopping $@ on $list
730 do_nodes $list "killall -2 $@ 2>/dev/null || true"
733 # start gss daemons on all nodes, or
734 # "daemon" on "list" if set
735 start_gss_daemons() {
739 if [ "$list" ] && [ "$daemon" ] ; then
740 echo "Starting gss daemon on nodes: $list"
741 do_nodes $list "$daemon" || return 8
745 local list=$(comma_list $(mdts_nodes))
746 echo "Starting gss daemon on mds: $list"
747 do_nodes $list "$LSVCGSSD -v" || return 1
749 do_nodes $list "$LGSSD -v" || return 2
752 list=$(comma_list $(osts_nodes))
753 echo "Starting gss daemon on ost: $list"
754 do_nodes $list "$LSVCGSSD -v" || return 3
755 # starting on clients
757 local clients=${CLIENTS:-`hostname`}
759 echo "Starting $LGSSD on clients $clients "
760 do_nodes $clients "$LGSSD -v" || return 4
763 # wait daemons entering "stable" status
767 # check daemons are running
769 list=$(comma_list $(mdts_nodes) $(osts_nodes))
770 check_gss_daemon_nodes $list lsvcgssd || return 5
772 list=$(comma_list $(mdts_nodes))
773 check_gss_daemon_nodes $list lgssd || return 6
776 check_gss_daemon_nodes $clients lgssd || return 7
781 local list=$(comma_list $(mdts_nodes))
783 send_sigint $list lsvcgssd lgssd
785 list=$(comma_list $(osts_nodes))
786 send_sigint $list lsvcgssd
788 list=${CLIENTS:-`hostname`}
789 send_sigint $list lgssd
794 if ! module_loaded ptlrpc_gss; then
795 load_module ptlrpc/gss/ptlrpc_gss
796 module_loaded ptlrpc_gss ||
797 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
800 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
803 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
805 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
813 # maybe cleanup credential cache?
819 local var=${facet}_svc
827 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
828 tr '[:lower:]' '[:upper:]'
834 if [ $facet == mgs ] || [ $facet == client ]; then
838 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
846 if [ -n "${!var}" ]; then
851 var=$(facet_type $facet)FSTYPE
852 if [ -n "${!var}" ]; then
857 if [ -n "$FSTYPE" ]; then
862 if [[ $facet == mgs ]] && combined_mgs_mds; then
874 local facets=$(get_facets)
877 for facet in ${facets//,/ }; do
878 if [ $node == $(facet_host $facet) ] ||
879 [ $node == "$(facet_failover_host $facet)" ]; then
880 fstype=$(facet_fstype $facet)
881 if [[ $fstypes != *$fstype* ]]; then
882 fstypes+="${fstypes:+,}$fstype"
891 local num=$(facet_number $facet)
894 if [[ $(facet_type $facet) = OST ]]; then
896 if [[ -n "${!index}" ]]; then
901 index=${OST_INDICES[num - 1]}
904 [[ -n "$index" ]] || index=$((num - 1))
912 local fstype=$(facet_fstype $facet)
916 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
918 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
919 ${dev} 2>/dev/null");;
921 error "unknown fstype!";;
929 local device=$(mdsdevname $num)
930 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
936 local device=$(ostdevname $num)
937 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
942 # Get the device of a facet.
949 mgs) device=$(mgsdevname) ;;
950 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
951 ost*) device=$(ostdevname $(facet_number $facet)) ;;
952 fs2mds) device=$(mdsdevname 1_2) ;;
953 fs2ost) device=$(ostdevname 1_2) ;;
954 fs3ost) device=$(ostdevname 2_2) ;;
962 # Get the virtual device of a facet.
969 mgs) device=$(mgsvdevname) ;;
970 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
971 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
972 fs2mds) device=$(mdsvdevname 1_2) ;;
973 fs2ost) device=$(ostvdevname 1_2) ;;
974 fs3ost) device=$(ostvdevname 2_2) ;;
982 local virt=$(virt-what 2> /dev/null)
984 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
986 virt=$(dmidecode -s system-product-name | awk '{print $1}')
989 VMware|KVM|VirtualBox|Parallels) echo ${virt,,} ;;
995 # Re-read the partition table on failover partner host.
996 # After a ZFS storage pool is created on a shared device, the partition table
997 # on the device may change. However, the operating system on the failover
998 # host may not notice the change automatically. Without the up-to-date partition
999 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1000 # relative to partition rather than disk beginnings.
1002 # This function performs partprobe on the failover host to make it re-read the
1005 refresh_partition_table() {
1010 host=$(facet_passive_host $facet)
1011 if [[ -n "$host" ]]; then
1012 do_node $host "$PARTPROBE $device"
1017 # Get ZFS storage pool name.
1024 device=$(facet_device $facet)
1025 # poolname is string before "/"
1026 poolname="${device%%/*}"
1032 # Create ZFS storage pool.
1039 local opts=${@:-"-o cachefile=none"}
1041 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
1042 $ZPOOL create -f $opts $poolname $vdev"
1046 # Create ZFS file system.
1052 local opts=${@:-"-o mountpoint=legacy"}
1054 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1055 $ZFS create $opts $dataset"
1059 # Export ZFS storage pool.
1060 # Before exporting the pool, all datasets within the pool should be unmounted.
1068 poolname=$(zpool_name $facet)
1070 if [[ -n "$poolname" ]]; then
1071 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1072 grep -q ^$poolname/ /proc/mounts ||
1073 $ZPOOL export $opts $poolname"
1078 # Destroy ZFS storage pool.
1079 # Destroy the given pool and free up any devices for other use. This command
1080 # tries to unmount any active datasets before destroying the pool.
1081 # -f Force any active datasets contained within the pool to be unmounted.
1085 local poolname=${2:-$(zpool_name $facet)}
1087 if [[ -n "$poolname" ]]; then
1088 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1089 $ZPOOL destroy -f $poolname"
1094 # Import ZFS storage pool.
1095 # Force importing, even if the pool appears to be potentially active.
1100 local opts=${@:-"-o cachefile=none"}
1103 poolname=$(zpool_name $facet)
1105 if [[ -n "$poolname" ]]; then
1106 opts+=" -d $(dirname $(facet_vdevice $facet))"
1107 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
1108 $ZPOOL import -f $opts $poolname"
1113 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1114 # is not automatically imported on system startup.
1116 # In a failover environment, this will provide resource level fencing which
1117 # will ensure that the same ZFS storage pool will not be imported concurrently
1118 # on different nodes.
1120 disable_zpool_cache() {
1124 poolname=$(zpool_name $facet)
1126 if [[ -n "$poolname" ]]; then
1127 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1132 # This and set_osd_param() shall be used to access OSD parameters
1133 # once existed under "obdfilter":
1138 # writethrough_cache_enable
1142 local device=${2:-$FSNAME-OST*}
1145 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1146 osd-*.$device.$name 2>&1" | grep -v 'error:'
1151 local device=${2:-$FSNAME-OST*}
1155 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1156 osd-*.$device.$name=$value 2>&1" | grep -v 'error:'
1160 local dz=${1:-$DEBUG_SIZE}
1162 if [ -f /sys/devices/system/cpu/possible ]; then
1163 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1165 local cpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1168 # bug 19944, adjust size to be -gt num_possible_cpus()
1169 # promise 2MB for every cpu at least
1170 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1173 lctl set_param debug_mb=$dz
1176 set_default_debug () {
1177 local debug=${1:-"$PTLDEBUG"}
1178 local subsys=${2:-"$SUBSYSTEM"}
1179 local debug_size=${3:-$DEBUG_SIZE}
1181 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1182 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1184 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1187 set_default_debug_nodes () {
1190 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1191 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1195 do_rpc_nodes "$nodes" set_default_debug \
1196 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1199 set_default_debug_facet () {
1201 local node=$(facet_active_host $facet)
1202 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1204 set_default_debug_nodes $node
1208 local hostid=${1:-$(hostid)}
1210 if [ ! -s /etc/hostid ]; then
1211 printf $(echo -n $hostid |
1212 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1218 local facets=${1:-$(get_facets)}
1221 for facet in ${facets//,/ }; do
1224 [ $RC -eq 0 ] && continue
1226 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1227 skip "Restart of $facet failed!." && touch $LU482_FAILED
1229 error "Restart of $facet failed!"
1236 # Add argument "arg" (e.g., "loop") to the comma-separated list
1237 # of arguments for option "opt" (e.g., "-o") on command
1238 # line "opts" (e.g., "-o flock").
1244 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1246 if echo "$opts" | grep -q $opt_pattern; then
1247 opts=$(echo "$opts" | sed -e \
1248 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1250 opts+="${opts:+ }$opt $arg"
1258 local dev=$(facet_active $facet)_dev
1259 local opt=${facet}_opt
1260 local mntpt=$(facet_mntpt $facet)
1261 local opts="${!opt} $@"
1262 local fstype=$(facet_fstype $facet)
1265 module_loaded lustre || load_modules
1267 if [ $(facet_fstype $facet) == ldiskfs ] &&
1268 ! do_facet $facet test -b ${!dev}; then
1269 opts=$(csa_add "$opts" -o loop)
1272 if [[ $(facet_fstype $facet) == zfs ]]; then
1273 # import ZFS storage pool
1274 import_zpool $facet || return ${PIPESTATUS[0]}
1279 devicelabel=$(do_facet ${facet} "$E2LABEL ${!dev}");;
1281 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
1282 lustre:svname ${!dev}");;
1284 error "unknown fstype!";;
1287 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1288 # for testing LU-482 error handling in mount_facets() and test_0a()
1289 if [ -f $TMP/test-lu482-trigger ]; then
1292 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1297 if [ $RC -ne 0 ]; then
1298 echo "Start of ${!dev} on ${facet} failed ${RC}"
1302 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
1303 if [[ "$health" != "healthy" ]]; then
1304 error "$facet is in a unhealthy state"
1307 set_default_debug_facet $facet
1309 if [[ $facet == mds* ]]; then
1311 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 2>/dev/null
1314 if [[ $opts =~ .*nosvc.* ]]; then
1315 echo "Start ${!dev} without service"
1320 wait_update_facet ${facet} "$E2LABEL ${!dev} \
1321 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
1322 "" || error "${!dev} failed to initialize!";;
1324 wait_update_facet ${facet} "$ZFS get -H -o value \
1325 lustre:svname ${!dev} 2>/dev/null | \
1326 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
1327 error "${!dev} failed to initialize!";;
1330 error "unknown fstype!";;
1334 # commit the device label change to disk
1335 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
1336 do_facet $facet "sync; sync; sync"
1340 label=$(devicelabel ${facet} ${!dev})
1341 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1342 eval export ${facet}_svc=${label}
1343 echo Started ${label}
1348 # start facet device options
1354 eval export ${facet}_dev=${device}
1355 eval export ${facet}_opt=\"$@\"
1357 local varname=${facet}failover_dev
1358 if [ -n "${!varname}" ] ; then
1359 eval export ${facet}failover_dev=${!varname}
1361 eval export ${facet}failover_dev=$device
1364 local mntpt=$(facet_mntpt $facet)
1365 do_facet ${facet} mkdir -p $mntpt
1366 eval export ${facet}_MOUNT=$mntpt
1367 mount_facet ${facet}
1370 if [[ $facet == mds* ]]; then
1372 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1383 local HOST=`facet_active_host $facet`
1384 [ -z $HOST ] && echo stop: no host for $facet && return 0
1386 local mntpt=$(facet_mntpt $facet)
1387 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1388 if [ ${running} -ne 0 ]; then
1389 echo "Stopping $mntpt (opts:$@) on $HOST"
1390 do_facet ${facet} $UMOUNT $@ $mntpt
1393 # umount should block, but we should wait for unrelated obd's
1394 # like the MGS or MGC to also stop.
1395 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1397 if [[ $(facet_fstype $facet) == zfs ]]; then
1398 # export ZFS storage pool
1403 # save quota version (both administrative and operational quotas)
1404 # add an additional parameter if mountpoint is ever different from $MOUNT
1406 # XXX This function is kept for interoperability with old server (< 2.3.50),
1407 # it should be removed whenever we drop the interoperability for such
1409 quota_save_version() {
1410 local fsname=${2:-$FSNAME}
1412 local ver=$(tr -c -d "123" <<< $spec)
1413 local type=$(tr -c -d "ug" <<< $spec)
1415 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1417 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1419 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1421 local osts=$(get_facets OST)
1422 for ost in ${osts//,/ }; do
1424 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1428 # client could mount several lustre
1430 # XXX This function is kept for interoperability with old server (< 2.3.50),
1431 # it should be removed whenever we drop the interoperability for such
1434 local fsname=${1:-$FSNAME}
1436 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1438 do_nodes $(comma_list $(osts_nodes)) \
1439 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1443 # get mdt quota type
1445 local varsvc=${SINGLEMDS}_svc
1446 do_facet $SINGLEMDS $LCTL get_param -n \
1447 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1450 # get ost quota type
1452 # All OSTs should have same quota type
1453 local varsvc=ost1_svc
1454 do_facet ost1 $LCTL get_param -n \
1455 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1458 # restore old quota type settings
1460 if [ "$old_MDT_QUOTA_TYPE" ]; then
1461 do_facet mgs $LCTL conf_param \
1462 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1464 if [ "$old_OST_QUOTA_TYPE" ]; then
1465 do_facet mgs $LCTL conf_param \
1466 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1470 # Handle the case when there is a space in the lfs df
1471 # "filesystem summary" line the same as when there is no space.
1472 # This will allow fixing the "lfs df" summary line in the future.
1474 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1477 # Get free inodes on the MDT specified by mdt index, free indoes on
1478 # the whole filesystem will be returned when index == -1.
1484 if [ $index -eq -1 ]; then
1487 mdt_uuid=$(mdtuuid_from_index $index)
1490 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1497 # save old quota type & set new quota type
1498 local mdt_qtype=$(mdt_quota_type)
1499 local ost_qtype=$(ost_quota_type)
1501 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1502 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1504 export old_MDT_QUOTA_TYPE=$mdt_qtype
1505 export old_OST_QUOTA_TYPE=$ost_qtype
1507 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1508 error "set mdt quota type failed"
1509 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1510 error "set ost quota type failed"
1512 local quota_usrs=$QUOTA_USERS
1514 # get_filesystem_size
1515 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1516 local blk_soft=$((disksz + 1024))
1517 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1519 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1520 local i_soft=$inodes
1521 local i_hard=$((i_soft + i_soft / 20))
1523 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1524 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1525 "inode-hardlimit: $i_hard"
1528 for usr in $quota_usrs; do
1529 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1531 cmd="$LFS setquota -$type $usr -b $blk_soft"
1532 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1534 eval $cmd || error "$cmd FAILED!"
1536 # display the quota status
1537 echo "Quota settings for $usr : "
1538 $LFS quota -v -u $usr $mntpt || true
1545 local opts=${3:-$MOUNT_OPTS}
1546 opts=${opts:+-o $opts}
1547 local flags=${4:-$MOUNT_FLAGS}
1549 local device=$MGSNID:/$FSNAME$FILESET
1550 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1551 echo "Bad mount command: opt=$flags $opts dev=$device " \
1556 echo "Starting client: $client: $flags $opts $device $mnt"
1557 do_node $client mkdir -p $mnt
1558 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
1559 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1561 #disable FILESET if not supported
1562 do_nodes $client lctl get_param -n \
1563 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1564 device=$MGSNID:/$FSNAME
1565 do_node $client mkdir -p $mnt/$FILESET
1566 do_node $client "! grep -q $mnt' ' /proc/mounts ||
1569 do_node $client $MOUNT_CMD $flags $opts $device $mnt || return 1
1571 set_default_debug_nodes $client
1583 [ "$3" ] && force=-f
1584 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1585 if [ $running -ne 0 ]; then
1586 echo "Stopping client $client $mnt (opts:$force)"
1587 do_node $client lsof -t $mnt || need_kill=no
1588 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1589 pids=$(do_node $client lsof -t $mnt | sort -u);
1590 if [ -n $pids ]; then
1591 do_node $client kill -9 $pids || true
1595 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1596 if [ $busy -ne 0 ] ; then
1597 echo "$mnt is still busy, wait one second" && sleep 1
1598 do_node $client umount $force $mnt
1603 # nodes is comma list
1604 sanity_mount_check_nodes () {
1610 # FIXME: assume that all cluster nodes run the same os
1611 [ "$(uname)" = Linux ] || return 0
1614 for mnt in $mnts ; do
1615 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1616 mpts=\\\$(mount | grep -c $mnt' ');
1617 if [ \\\$running -ne \\\$mpts ]; then
1618 echo \\\$(hostname) env are INSANE!;
1621 [ $? -eq 0 ] || rc=1
1626 sanity_mount_check_servers () {
1627 [ -n "$CLIENTONLY" ] &&
1628 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1629 echo Checking servers environments
1631 # FIXME: modify get_facets to display all facets wo params
1632 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1636 for facet in ${facets//,/ }; do
1637 node=$(facet_host ${facet})
1638 mntpt=$(facet_mntpt $facet)
1639 sanity_mount_check_nodes $node $mntpt ||
1640 { error "server $node environments are insane!"; return 1; }
1644 sanity_mount_check_clients () {
1645 local clients=${1:-$CLIENTS}
1646 local mntpt=${2:-$MOUNT}
1647 local mntpt2=${3:-$MOUNT2}
1649 [ -z $clients ] && clients=$(hostname)
1650 echo Checking clients $clients environments
1652 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1653 error "clients environments are insane!"
1656 sanity_mount_check () {
1657 sanity_mount_check_servers || return 1
1658 sanity_mount_check_clients || return 2
1661 # mount clients if not mouted
1662 zconf_mount_clients() {
1665 local opts=${3:-$MOUNT_OPTS}
1666 opts=${opts:+-o $opts}
1667 local flags=${4:-$MOUNT_FLAGS}
1669 local device=$MGSNID:/$FSNAME$FILESET
1670 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1671 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
1676 echo "Starting client $clients: $flags $opts $device $mnt"
1677 if [ -n "$FILESET" -a ! -n "$SKIP_FILESET" ]; then
1678 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1680 do_nodes $clients $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
1682 #disable FILESET if not supported
1683 do_nodes $clients lctl get_param -n \
1684 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
1685 device=$MGSNID:/$FSNAME
1686 do_nodes $clients mkdir -p $mnt/$FILESET
1687 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
1692 running=\\\$(mount | grep -c $mnt' ');
1694 if [ \\\$running -eq 0 ] ; then
1696 $MOUNT_CMD $flags $opts $device $mnt;
1699 exit \\\$rc" || return ${PIPESTATUS[0]}
1701 echo "Started clients $clients: "
1702 do_nodes $clients "mount | grep $mnt' '"
1704 set_default_debug_nodes $clients
1709 zconf_umount_clients() {
1714 [ "$3" ] && force=-f
1716 echo "Stopping clients: $clients $mnt (opts:$force)"
1717 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1718 if [ \\\$running -ne 0 ] ; then
1719 echo Stopping client \\\$(hostname) $mnt opts:$force;
1720 lsof $mnt || need_kill=no;
1721 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1722 pids=\\\$(lsof -t $mnt | sort -u);
1723 if [ -n \\\"\\\$pids\\\" ]; then
1727 while umount $force $mnt 2>&1 | grep -q "busy"; do
1728 echo "$mnt is still busy, wait one second" && sleep 1;
1735 echo + $POWER_DOWN $node
1739 shutdown_node_hard () {
1741 local attempts=$SHUTDOWN_ATTEMPTS
1743 for i in $(seq $attempts) ; do
1746 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1747 echo "waiting for $host to fail attempts=$attempts"
1748 [ $i -lt $attempts ] || \
1749 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1755 local mnt=${2:-$MOUNT}
1758 if [ "$FAILURE_MODE" = HARD ]; then
1759 shutdown_node_hard $client
1761 zconf_umount_clients $client $mnt -f
1767 local facets="$(get_facets OST),$(get_facets MDS)"
1770 combined_mgs_mds || facets="$facets,mgs"
1772 for facet in ${facets//,/ }; do
1773 if [ $(facet_active_host $facet) == $host ]; then
1774 affected="$affected $facet"
1778 echo $(comma_list $affected)
1783 local host=${2:-$(facet_host $facet)}
1785 local label=$(convert_facet2label $facet)
1786 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
1789 facets_up_on_host () {
1791 local facets=$(facets_on_host $host)
1794 for facet in ${facets//,/ }; do
1795 if $(facet_up $facet $host); then
1796 affected_up="$affected_up $facet"
1800 echo $(comma_list $affected_up)
1806 if [ "$FAILURE_MODE" = HARD ]; then
1807 shutdown_node_hard $(facet_active_host $facet)
1815 echo + $POWER_UP $node
1828 if [ "$FAILURE_MODE" = HARD ]; then
1829 reboot_node $(facet_active_host $facet)
1837 if [ "$FAILURE_MODE" = HARD ]; then
1847 for facet in ${facets//,/ }; do
1848 hosts=$(expand_list $hosts $(facet_host $facet) )
1854 _check_progs_installed () {
1858 for prog in $progs; do
1859 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1860 echo $prog missing on $(hostname)
1867 check_progs_installed () {
1871 do_rpc_nodes "$nodes" _check_progs_installed $@
1874 # recovery-scale functions
1876 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1879 start_client_load() {
1882 local var=$(node_var_name $client)_load
1883 eval export ${var}=$load
1885 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1886 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1887 END_RUN_FILE=$END_RUN_FILE \
1888 LOAD_PID_FILE=$LOAD_PID_FILE \
1889 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1890 TESTNAME=$TESTNAME \
1891 DBENCH_LIB=$DBENCH_LIB \
1892 DBENCH_SRC=$DBENCH_SRC \
1893 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1897 log "Started client load: ${load} on $client"
1899 # get the children process IDs
1900 local pids=$(ps --ppid $ppid -o pid= | xargs)
1901 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1905 start_client_loads () {
1906 local -a clients=(${1//,/ })
1907 local numloads=${#CLIENT_LOADS[@]}
1910 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1911 testnum=$((nodenum % numloads))
1912 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1914 # bug 22169: wait the background threads to start
1918 # only for remote client
1919 check_client_load () {
1921 local var=$(node_var_name $client)_load
1922 local TESTLOAD=run_${!var}.sh
1924 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1926 # bug 18914: try to connect several times not only when
1927 # check ps, but while check_catastrophe also
1930 while [ $RC = 254 -a $tries -gt 0 ]; do
1934 if ! check_catastrophe $client; then
1936 if [ $RC -eq 254 ]; then
1937 # FIXME: not sure how long we shuold sleep here
1941 echo "check catastrophe failed: RC=$RC "
1945 # We can continue try to connect if RC=254
1946 # Just print the warning about this
1947 if [ $RC = 254 ]; then
1948 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1951 # see if the load is still on the client
1954 while [ $RC = 254 -a $tries -gt 0 ]; do
1958 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1963 if [ $RC = 254 ]; then
1964 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1965 # see if we can diagnose a bit why this is
1970 check_client_loads () {
1971 local clients=${1//,/ }
1975 for client in $clients; do
1976 check_client_load $client
1978 if [ "$rc" != 0 ]; then
1979 log "Client load failed on node $client, rc=$rc"
1985 restart_client_loads () {
1986 local clients=${1//,/ }
1987 local expectedfail=${2:-""}
1991 for client in $clients; do
1992 check_client_load $client
1994 if [ "$rc" != 0 -a "$expectedfail" ]; then
1995 local var=$(node_var_name $client)_load
1996 start_client_load $client ${!var}
1997 echo "Restarted client load ${!var}: on $client. Checking ..."
1998 check_client_load $client
2000 if [ "$rc" != 0 ]; then
2001 log "Client load failed to restart on node $client, rc=$rc"
2002 # failure one client load means test fail
2003 # we do not need to check other
2012 # Start vmstat and save its process ID in a file.
2017 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2020 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
2021 2>/dev/null </dev/null & echo \\\$! > $pid_file"
2024 # Display the nodes on which client loads failed.
2025 print_end_run_file() {
2029 [ -s $file ] || return 0
2031 echo "Found the END_RUN_FILE file: $file"
2034 # A client load will stop if it finds the END_RUN_FILE file.
2035 # That does not mean the client load actually failed though.
2036 # The first node in END_RUN_FILE is the one we are interested in.
2039 if [ -n "$node" ]; then
2040 local var=$(node_var_name $node)_load
2042 local prefix=$TESTLOG_PREFIX
2043 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2044 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2045 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2047 echo "Client load ${!var} failed on node $node:"
2053 # Stop the process which had its PID saved in a file.
2058 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2060 do_nodes $nodes "test -f $pid_file &&
2061 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2064 # Stop all client loads.
2065 stop_client_loads() {
2066 local nodes=${1:-$CLIENTS}
2069 # stop the client loads
2070 stop_process $nodes $pid_file
2072 # clean up the processes that started them
2073 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
2075 # End recovery-scale functions
2077 # verify that lustre actually cleaned up properly
2079 VAR=$(lctl get_param -n catastrophe 2>&1)
2080 if [ $? = 0 ] ; then
2081 if [ $VAR != 0 ]; then
2082 error "LBUG/LASSERT detected"
2085 BUSY=$(dmesg | grep -i destruct || true)
2086 if [ -n "$BUSY" ]; then
2088 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2092 check_mem_leak || exit 204
2094 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2095 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2098 if module_loaded lnet || module_loaded libcfs; then
2099 echo "$TESTSUITE: modules still loaded..." 1>&2
2108 if [[ "$1" == "--verbose" ]]; then
2123 PREV_RESULT=$(do_node $node "$TEST")
2125 RESULT=$(do_node $node "$TEST")
2126 if [[ "$RESULT" == "$FINAL" ]]; then
2127 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2128 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2132 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2133 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2137 [[ $WAIT -ge $MAX ]] && break
2138 [[ $((WAIT % print)) -eq 0 ]] &&
2139 echo "Waiting $((MAX - WAIT)) secs for update"
2140 WAIT=$((WAIT + sleep))
2143 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2147 wait_update_facet() {
2149 [ "$1" = "--verbose" ] && verbose="$1" && shift
2153 wait_update $verbose $(facet_active_host $facet) "$@"
2157 do_nodes $(comma_list $(mdts_nodes)) \
2158 "lctl set_param -n osd*.*MDT*.force_sync=1"
2159 do_nodes $(comma_list $(osts_nodes)) \
2160 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
2161 grep -v 'Found no match'
2164 wait_delete_completed_mds() {
2165 local MAX_WAIT=${1:-20}
2166 # for ZFS, waiting more time for DMUs to be committed
2167 local ZFS_WAIT=${2:-5}
2169 local stime=$(date +%s)
2174 # find MDS with pending deletions
2175 for node in $(mdts_nodes); do
2176 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2177 2>/dev/null | calc_sum)
2178 if [[ $changes -eq 0 ]]; then
2181 mds2sync="$mds2sync $node"
2183 if [ -z "$mds2sync" ]; then
2186 mds2sync=$(comma_list $mds2sync)
2188 # sync MDS transactions
2189 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2191 # wait till all changes are sent and commmitted by OSTs
2192 # for ldiskfs space is released upon execution, but DMU
2193 # do this upon commit
2196 while [[ $WAIT -ne $MAX_WAIT ]]; do
2197 changes=$(do_nodes $mds2sync \
2198 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2199 #echo "$node: $changes changes on all"
2200 if [[ $changes -eq 0 ]]; then
2202 #echo "delete took $((etime - stime)) seconds"
2204 # the occupied disk space will be released
2205 # only after DMUs are committed
2206 if [[ $(facet_fstype $SINGLEMDS) == zfs ]]; then
2207 echo "sleep $ZFS_WAIT for ZFS OSD"
2218 echo "Delete is not completed in $((etime - stime)) seconds"
2219 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2225 # we can use "for" here because we are waiting the slowest
2226 for host in ${hostlist//,/ }; do
2227 check_network "$host" 900
2229 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2236 for facet in ${facetlist//,/ }; do
2237 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2239 wait_for_host $hostlist
2242 _wait_recovery_complete () {
2245 # Use default policy if $2 is not passed by caller.
2246 local MAX=${2:-$(max_recovery_time)}
2251 while [ $WAIT -lt $MAX ]; do
2252 STATUS=$(lctl get_param -n $param | grep status)
2254 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2257 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2259 echo "$param recovery not done in $MAX sec. $STATUS"
2263 wait_recovery_complete () {
2266 # with an assumption that at_max is the same on all nodes
2267 local MAX=${2:-$(max_recovery_time)}
2270 if [ "$FAILURE_MODE" = HARD ]; then
2271 facets=$(facets_on_host $(facet_active_host $facet))
2273 echo affected facets: $facets
2275 # we can use "for" here because we are waiting the slowest
2276 for facet in ${facets//,/ }; do
2277 local var_svc=${facet}_svc
2278 local param="*.${!var_svc}.recovery_status"
2280 local host=$(facet_active_host $facet)
2281 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2285 wait_mds_ost_sync () {
2286 # just because recovery is done doesn't mean we've finished
2287 # orphan cleanup. Wait for llogs to get synchronized.
2288 echo "Waiting for orphan cleanup..."
2289 # MAX value includes time needed for MDS-OST reconnection
2290 local MAX=$(( TIMEOUT * 2 ))
2291 local WAIT_TIMEOUT=${1:-$MAX}
2294 local list=$(comma_list $(mdts_nodes))
2295 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2296 if ! do_facet $SINGLEMDS \
2297 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2299 # old way, use mds_sync
2301 list=$(comma_list $(osts_nodes))
2302 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2305 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2306 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2307 local -a sync=($(do_nodes $list "$cmd"))
2310 for ((i=0; i<${#sync[@]}; i++)); do
2312 [ ${sync[$i]} -eq 1 ] && continue
2314 [ ${sync[$i]} -eq 0 ] && continue
2316 # there is a not finished MDS-OST synchronization
2320 sleep 2 # increase waiting time and cover statfs cache
2321 [ ${con} -eq 1 ] && return 0
2322 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2326 # show which nodes are not finished.
2327 do_nodes $list "$cmd"
2328 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2332 wait_destroy_complete () {
2333 echo "Waiting for local destroys to complete"
2334 # MAX value shouldn't be big as this mean server responsiveness
2335 # never increase this just to make test pass but investigate
2336 # why it takes so long time
2339 while [ $WAIT -lt $MAX ]; do
2340 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2344 for ((i=0; i<${#RPCs[@]}; i++)); do
2345 [ ${RPCs[$i]} -eq 0 ] && continue
2346 # there are still some destroy RPCs in flight
2351 [ ${con} -eq 1 ] && return 0 # done waiting
2352 echo "Waiting ${WAIT}s for local destroys to complete"
2355 echo "Local destroys weren't done in $MAX sec."
2359 wait_delete_completed() {
2360 wait_delete_completed_mds $1 || return $?
2361 wait_destroy_complete
2370 # conf-sanity 31 takes a long time cleanup
2371 while [ $WAIT -lt 300 ]; do
2372 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2373 [ -z "${running}" ] && return 0
2374 echo "waited $WAIT for${running}"
2375 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2377 WAIT=$((WAIT + INTERVAL))
2379 echo "service didn't stop after $WAIT seconds. Still running:"
2384 wait_remote_prog () {
2390 [ "$PDSH" = "no_dsh" ] && return 0
2392 while [ $WAIT -lt $2 ]; do
2393 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2394 [ -z "${running}" ] && return 0 || true
2395 echo "waited $WAIT for: "
2397 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2399 WAIT=$((WAIT + INTERVAL))
2401 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2402 [ -z "$pids" ] && return 0
2403 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2404 # FIXME: not portable
2405 for pid in $pids; do
2406 cat /proc/${pid}/status || true
2407 cat /proc/${pid}/wchan || true
2409 kill -9 $pid || true
2418 # not every config has many clients
2420 if [ ! -z "$CLIENTS" ]; then
2421 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
2423 stat -f $MOUNT > /dev/null
2429 # usually checked on particular client or locally
2431 if [ ! -z "$client" ]; then
2432 $PDSH $client "stat -f $MOUNT" > /dev/null
2434 stat -f $MOUNT > /dev/null
2442 client_reconnect_try() {
2443 local f=$MOUNT/recon
2446 if [ -z "$CLIENTS" ]; then
2447 $LFS df $MOUNT; uname -n >> $f
2449 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
2451 echo "Connected clients: $(cat $f)"
2452 ls -l $f > /dev/null
2456 client_reconnect() {
2457 # one client_reconnect_try call does not always do the job...
2459 client_reconnect_try && break
2464 affected_facets () {
2467 local host=$(facet_active_host $facet)
2468 local affected=$facet
2470 if [ "$FAILURE_MODE" = HARD ]; then
2471 affected=$(facets_up_on_host $host)
2477 local E2FSCK_ON_MDT0=false
2478 if [ "$1" == "--fsck" ]; then
2480 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2492 #Because it will only get up facets, we need get affected
2493 #facets before shutdown
2494 #For HARD Failure mode, it needs make sure facets on the same
2495 #HOST will only be shutdown and reboot once
2496 for facet in ${facets//,/ }; do
2497 local affected_facet
2499 #check whether facet has been included in other affected facets
2500 for ((index=0; index<$total; index++)); do
2501 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2504 if [ $skip -eq 0 ]; then
2505 affecteds[$total]=$(affected_facets $facet)
2510 for ((index=0; index<$total; index++)); do
2511 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2512 local host=$(facet_active_host $facet)
2513 echo "Failing ${affecteds[index]} on $host"
2514 shutdown_facet $facet
2517 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
2518 $(mdsdevname 1) "-n" || error "Running e2fsck")
2520 for ((index=0; index<$total; index++)); do
2521 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2522 echo reboot facets: ${affecteds[index]}
2526 change_active ${affecteds[index]}
2528 wait_for_facet ${affecteds[index]}
2529 # start mgs first if it is affected
2530 if ! combined_mgs_mds &&
2531 list_member ${affecteds[index]} mgs; then
2532 mount_facet mgs || error "Restart of mgs failed"
2534 # FIXME; has to be changed to mount all facets concurrently
2535 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2536 echo mount facets: ${affecteds[index]}
2537 mount_facets ${affecteds[index]}
2547 do_facet $facet "sync; sync; sync"
2550 # make sure there will be no seq change
2551 local clients=${CLIENTS:-$HOSTNAME}
2552 local f=fsa-\\\$\(hostname\)
2553 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2554 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2556 local svc=${facet}_svc
2557 do_facet $facet $LCTL --device ${!svc} notransno
2559 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2560 # in-memory state has to be cleared by either rebooting the host or
2561 # exporting and reimporting the pool.
2563 # Although the uberblocks are not updated when a pool is freezed,
2564 # transactions are still written to the disks. Modified blocks may be
2565 # cached in memory when tests try reading them back. The
2566 # export-and-reimport process also evicts any cached pool data from
2567 # memory to provide the correct "data loss" semantics.
2569 # In the test framework, the exporting and importing operations are
2570 # handled by stop() and mount_facet() separately, which are used
2571 # inside fail() and fail_abort().
2573 do_facet $facet $LCTL --device ${!svc} readonly
2574 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2575 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2578 replay_barrier_nodf() {
2579 local facet=$1 echo running=${running}
2580 do_facet $facet "sync; sync; sync"
2581 local svc=${facet}_svc
2582 echo Replay barrier on ${!svc}
2583 do_facet $facet $LCTL --device ${!svc} notransno
2584 do_facet $facet $LCTL --device ${!svc} readonly
2585 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2586 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2589 replay_barrier_nosync() {
2590 local facet=$1 echo running=${running}
2591 local svc=${facet}_svc
2592 echo Replay barrier on ${!svc}
2593 do_facet $facet $LCTL --device ${!svc} notransno
2594 do_facet $facet $LCTL --device ${!svc} readonly
2595 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2596 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2600 # Get Lustre client uuid for a given Lustre mount point.
2603 local mntpnt=${1:-$MOUNT}
2605 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2606 local uuid=$($LCTL get_param -n llite.$name.uuid)
2611 mds_evict_client() {
2612 local mntpnt=${1:-$MOUNT}
2613 local uuid=$(get_client_uuid $mntpnt)
2615 do_facet $SINGLEMDS \
2616 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2619 ost_evict_client() {
2620 local mntpnt=${1:-$MOUNT}
2621 local uuid=$(get_client_uuid $mntpnt)
2624 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2629 local clients=${CLIENTS:-$HOSTNAME}
2631 facet_failover $* || error "failover: $?"
2632 wait_clients_import_state "$clients" "$facets" FULL
2633 clients_up || error "post-failover stat: $?"
2638 facet_failover $facet
2644 change_active $facet
2645 wait_for_facet $facet
2646 mount_facet $facet -o abort_recovery
2647 clients_up || echo "first stat failed: $?"
2648 clients_up || error "post-failover stat: $?"
2652 echo There is no lmc. This is mountconf, baby.
2656 host_nids_address() {
2660 if [ -n "$kind" ]; then
2661 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2663 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2669 if [ "$1" = "'*'" ]; then echo \'*\'; else
2675 if [ "$1" = "'*'" ]; then echo \'*\'; else
2676 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2678 if [ -z "$ID" ]; then
2679 echo "Could not get a ptl id for $1..."
2688 h2name_or_ip "$1" "tcp"
2693 if [ "$1" = "'*'" ]; then echo \'*\'; else
2694 if type __h2elan >/dev/null 2>&1; then
2697 ID=`echo $1 | sed 's/[^0-9]*//g'`
2705 h2name_or_ip "$1" "o2ib"
2709 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2710 # expressions format. As a bonus we can then just pass in those variables
2711 # to pdsh. What this function does is take a HOSTLIST type string and
2712 # expand it into a space deliminated list for us.
2720 [ -z "$hostlist" ] && return
2722 # Translate the case of [..],..,[..] to [..] .. [..]
2723 list="${hostlist/],/] }"
2725 [[ "$front" == *,* ]] && {
2728 list=${list/${old}/${new}}
2731 for item in $list; do
2732 # Test if we have any []'s at all
2733 if [ "$item" != "${item/\[/}" ]; then {
2734 # Expand the [*] into list
2738 if [ "$name" != "$item" ]; then
2739 group=${item#$name[*}
2742 for range in ${group//,/ }; do
2746 # Number of leading zeros
2749 end=$(echo $end | sed 's/0*//')
2750 [[ -z "$end" ]] && end=0
2751 [[ $padlen2 -gt $padlen ]] && {
2752 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2755 begin=$(echo $begin | sed 's/0*//')
2756 [ -z $begin ] && begin=0
2758 for num in $(seq -f "%0${padlen}g" $begin $end); do
2759 value="${name#*,}${num}${back}"
2760 [ "$value" != "${value/\[/}" ] && {
2761 value=$(hostlist_expand "$value")
2763 myList="$myList $value"
2768 myList="$myList $item"
2771 myList=${myList//,/ }
2772 myList=${myList:1} # Remove first character which is a space
2774 # Filter any duplicates without sorting
2776 myList="${list%% *}"
2778 while [[ "$list" != ${myList##* } ]]; do
2779 list=${list//${list%% *} /}
2780 myList="$myList ${list%% *}"
2782 myList="${myList%* }";
2784 # We can select an object at an offset in the list
2787 for item in $myList; do
2789 [ $cnt -eq $offset ] && {
2793 [ $(get_node_count $myList) -ne 1 ] && myList=""
2802 [ "$facet" == client ] && echo -n $HOSTNAME && return
2803 varname=${facet}_HOST
2804 if [ -z "${!varname}" ]; then
2805 if [ "${facet:0:3}" == "ost" ]; then
2806 local fh=${facet%failover}_HOST
2807 eval export ${facet}_HOST=${!fh}
2808 if [ -z "${!varname}" ]; then
2809 eval export ${facet}_HOST=${ost_HOST}
2811 elif [ "${facet:0:3}" == "mdt" -o \
2812 "${facet:0:3}" == "mds" -o \
2813 "${facet:0:3}" == "mgs" ]; then
2814 eval export ${facet}_HOST=${mds_HOST}
2820 facet_failover_host() {
2824 var=${facet}failover_HOST
2825 if [ -n "${!var}" ]; then
2830 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2831 "${facet:0:3}" == "mgs" ]; then
2833 eval export ${facet}failover_host=${mds_HOST}
2838 if [[ $facet == ost* ]]; then
2839 eval export ${facet}failover_host=${ost_HOST}
2847 local activevar=${facet}active
2849 if [ -f $TMP/${facet}active ] ; then
2850 source $TMP/${facet}active
2853 active=${!activevar}
2854 if [ -z "$active" ] ; then
2861 facet_active_host() {
2862 facet_host $(facet_active $1)
2865 # Get the passive failover partner host of facet.
2866 facet_passive_host() {
2868 [[ $facet = client ]] && return
2870 local host=${facet}_HOST
2871 local failover_host=${facet}failover_HOST
2872 local active_host=$(facet_active_host $facet)
2874 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2876 if [[ $active_host = ${!host} ]]; then
2877 echo -n ${!failover_host}
2887 facetlist=$(exclude_items_from_list $facetlist mgs)
2889 for facet in ${facetlist//,/ }; do
2890 local failover=${facet}failover
2891 local host=`facet_host $failover`
2892 [ -z "$host" ] && return
2894 local curactive=`facet_active $facet`
2895 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2896 eval export ${facet}active=$facet
2898 eval export ${facet}active=$failover
2900 # save the active host for this facet
2901 local activevar=${facet}active
2902 echo "$activevar=${!activevar}" > $TMP/$activevar
2903 [[ $facet = mds1 ]] && combined_mgs_mds && \
2904 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2905 local TO=`facet_active_host $facet`
2906 echo "Failover $facet to $TO"
2912 # do not stripe off hostname if verbose, bug 19215
2913 if [ x$1 = x--verbose ]; then
2921 if [ "$HOST" = "$HOSTNAME" ]; then
2923 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2924 echo "cannot run remote command on $HOST with $myPDSH"
2928 echo "CMD: $HOST $@" >&2
2929 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2932 if [ "$myPDSH" = "rsh" ]; then
2933 # we need this because rsh does not return exit code of an executed command
2934 local command_status="$TMP/cs"
2935 rsh $HOST ":> $command_status"
2936 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2937 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2938 echo command failed >$command_status"
2939 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2944 # print HOSTNAME for myPDSH="no_dsh"
2945 if [[ $myPDSH = no_dsh ]]; then
2946 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2948 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2951 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2953 return ${PIPESTATUS[0]}
2957 do_node --verbose "$@"
2960 single_local_node () {
2961 [ "$1" = "$HOSTNAME" ]
2964 # Outputs environment variable assignments that should be passed to remote nodes
2968 local facets=$(get_facets)
2971 for var in ${!MODOPTS_*}; do
2972 value=${!var//\"/\\\"}
2973 echo -n " ${var}=\"$value\""
2976 for facet in ${facets//,/ }; do
2978 if [ -n "${!var}" ]; then
2979 echo -n " $var=${!var}"
2983 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2984 if [ -n "${!var}" ]; then
2985 echo -n " $var=${!var}"
2989 for var in VERBOSE; do
2990 if [ -n "${!var}" ]; then
2991 echo -n " $var=${!var}"
2995 if [ -n "$FSTYPE" ]; then
2996 echo -n " FSTYPE=$FSTYPE"
2999 for var in LNETLND NETTYPE; do
3000 if [ -n "${!var}" ]; then
3001 echo -n " $var=${!var}"
3008 # do not stripe off hostname if verbose, bug 19215
3009 if [ x$1 = x--verbose ]; then
3017 if single_local_node $rnodes; then
3019 do_nodev $rnodes "$@"
3021 do_node $rnodes "$@"
3026 # This is part from do_node
3029 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
3030 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
3032 export FANOUT=$(get_node_count "${rnodes//,/ }")
3034 echo "CMD: $rnodes $@" >&2
3035 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3038 # do not replace anything from pdsh output if -N is used
3039 # -N Disable hostname: prefix on lines of output.
3040 if $verbose || [[ $myPDSH = *-N* ]]; then
3041 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
3043 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
3045 return ${PIPESTATUS[0]}
3049 # Execute commands on a single service's host
3051 # The \a facet (service) may be on a local or remote node, which is
3052 # determined at the time the command is run.
3054 # usage: do_facet $facet command [arg ...]
3058 local HOST=$(facet_active_host $facet)
3059 [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
3063 # Function: do_facet_random_file $FACET $FILE $SIZE
3064 # Creates FILE with random content on the given FACET of given SIZE
3066 do_facet_random_file() {
3070 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
3071 do_facet $facet "$cmd 2>/dev/null"
3074 do_facet_create_file() {
3078 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
3079 do_facet $facet "$cmd 2>/dev/null"
3083 do_nodes --verbose "$@"
3089 # make sure its not already running
3091 rm -f $TMP/${facet}active
3092 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
3093 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
3095 if [[ $(facet_fstype $facet) == zfs ]]; then
3097 # After formatting a ZFS target, "cachefile=none" property will
3098 # be set on the ZFS storage pool so that the pool is not
3099 # automatically imported on system startup. And then the pool
3100 # will be exported so as to leave the importing and exporting
3101 # operations handled by mount_facet() and stop() separately.
3103 refresh_partition_table $facet $(facet_vdevice $facet)
3104 disable_zpool_cache $facet
3109 # Device formatted as ost
3112 local DEVNAME=OSTDEV$num
3114 local fstype=$(facet_fstype ost$num)
3118 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
3119 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3121 #try $OSTZFSDEVn - independent of vdev
3122 DEVNAME=OSTZFSDEV$num
3123 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
3125 error "unknown fstype!";;
3131 # Physical device location of data
3137 local fstype=$(facet_fstype ost$num)
3141 # vdevs are not supported by ldiskfs
3144 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3145 # Device formatted by zfs
3147 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3149 error "unknown fstype!";;
3155 # Logical device formatted for lustre
3158 local DEVNAME=MDSDEV$num
3160 local fstype=$(facet_fstype mds$num)
3164 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3165 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3167 # try $MDSZFSDEVn - independent of vdev
3168 DEVNAME=MDSZFSDEV$num
3169 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3171 error "unknown fstype!";;
3177 # Physical location of data
3181 local fstype=$(facet_fstype mds$num)
3185 # vdevs are not supported by ldiskfs
3188 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3189 # Device formatted by ZFS
3190 local DEVNAME=MDSDEV$num
3191 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3193 error "unknown fstype!";;
3201 local fstype=$(facet_fstype mgs)
3205 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3206 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3207 DEVPTR=$(mdsdevname 1)
3212 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3213 ( [ -z "$MGSZFSDEV" ] &&
3214 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3215 DEVPTR=$(mdsdevname 1)
3217 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3220 error "unknown fstype!";;
3229 local fstype=$(facet_fstype mgs)
3233 # vdevs are not supported by ldiskfs
3236 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3237 ( [ -z "$MGSDEV" ] &&
3238 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3239 VDEVPTR=$(mdsvdevname 1)
3240 elif [ -n "$MGSDEV" ]; then
3244 error "unknown fstype!";;
3252 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3254 local var=${facet}_MOUNT
3255 eval mntpt=${!var:-${MOUNT}-$facet}
3262 local dev=$(facet_device $facet)
3263 local mnt=${2:-$(facet_mntpt $facet)}
3266 if ! do_facet $facet test -b $dev; then
3269 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3274 local dev=$(facet_device $facet)
3275 local mnt=${2:-$(facet_mntpt $facet)}
3277 do_facet $facet $UMOUNT $mnt
3281 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3286 local ds=$(facet_device $facet)
3287 local mnt=${2:-$(facet_mntpt $facet)}
3292 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3293 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3294 do_facet $facet $ZFS set canmount=noauto $ds
3296 # The "legacy" mount method is used here because "zfs unmount $mnt"
3297 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3298 # targets are not available at the time, the stat(2) on $MOUNT will
3301 do_facet $facet $ZFS set mountpoint=legacy $ds
3302 do_facet $facet mount -t zfs $ds $mnt
3303 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3304 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3309 local ds=$(facet_device $facet)
3310 local mnt=${2:-$(facet_mntpt $facet)}
3311 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3312 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3313 local mntpt=${!var_mntpt}
3314 local canmnt=${!var_canmnt}
3318 do_facet $facet umount $mnt
3319 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3320 do_facet $facet $ZFS set canmount=$canmnt $ds
3327 local fstype=$(facet_fstype $facet)
3329 mount_$fstype $facet $mnt
3335 local fstype=$(facet_fstype $facet)
3337 unmount_$fstype $facet $mnt
3344 # make sure we are using the primary server, so test-framework will
3345 # be able to clean up properly.
3346 activemds=`facet_active mds1`
3347 if [ $activemds != "mds1" ]; then
3351 local clients=$CLIENTS
3352 [ -z $clients ] && clients=$(hostname)
3354 zconf_umount_clients $clients $MOUNT "$*" || true
3355 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3357 [ -n "$CLIENTONLY" ] && return
3359 # The add fn does rm ${facet}active file, this would be enough
3360 # if we use do_facet <facet> only after the facet added, but
3361 # currently we use do_facet mds in local.sh
3362 for num in `seq $MDSCOUNT`; do
3364 rm -f ${TMP}/mds${num}active
3366 combined_mgs_mds && rm -f $TMP/mgsactive
3368 for num in `seq $OSTCOUNT`; do
3370 rm -f $TMP/ost${num}active
3373 if ! combined_mgs_mds ; then
3380 cleanup_echo_devs () {
3381 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3383 for dev in $devs; do
3384 $LCTL --device $dev cleanup
3385 $LCTL --device $dev detach
3390 nfs_client_mode && return
3391 cifs_client_mode && return
3400 combined_mgs_mds () {
3401 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3402 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3406 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3410 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3416 local fsname=${3:-"$FSNAME"}
3417 local type=$(facet_type $facet)
3418 local index=$(facet_index $facet)
3419 local fstype=$(facet_fstype $facet)
3420 local host=$(facet_host $facet)
3425 if [ $type == MGS ] || ( [ $type == MDS ] &&
3426 [ "$dev" == $(mgsdevname) ] &&
3427 [ "$host" == "$(facet_host mgs)" ] ); then
3430 opts="--mgsnode=$MGSNID"
3433 if [ $type != MGS ]; then
3434 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3438 var=${facet}failover_HOST
3439 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3440 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3443 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3444 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3446 if [ $type == MDS ]; then
3447 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3448 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3449 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3450 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3452 if [ $fstype == ldiskfs ]; then
3453 # Check for wide striping
3454 if [ $OSTCOUNT -gt 160 ]; then
3455 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3456 fs_mkfs_opts+="-O large_xattr"
3460 if [ -n "${!var}" ]; then
3461 fs_mkfs_opts+=" -J device=${!var}"
3463 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3465 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3469 if [ $type == OST ]; then
3470 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3472 if [ $fstype == ldiskfs ]; then
3474 if [ -n "${!var}" ]; then
3475 fs_mkfs_opts+=" -J device=${!var}"
3477 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3482 opts+=" --backfstype=$fstype"
3485 if [ -n "${!var}" ]; then
3486 opts+=" --device-size=${!var}"
3489 var=$(upper $fstype)_MKFS_OPTS
3490 fs_mkfs_opts+=${!var:+" ${!var}"}
3492 var=${type}_FS_MKFS_OPTS
3493 fs_mkfs_opts+=${!var:+" ${!var}"}
3495 if [ -n "${fs_mkfs_opts## }" ]; then
3496 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3500 opts+=${!var:+" ${!var}"}
3505 check_ost_indices() {
3506 local index_count=${#OST_INDICES[@]}
3507 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
3509 # OST count is greater than the index count in $OST_INDEX_LIST.
3510 # We need check whether there are duplicate indices.
3514 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
3515 index=$(facet_index ost$i)
3516 for j in $(seq 0 $((index_count - 1))); do
3517 [[ $index -ne ${OST_INDICES[j]} ]] ||
3518 error "ost$i has the same index $index as ost$((j+1))"
3529 echo "Format mgs: $(mgsdevname)"
3530 reformat_external_journal mgs
3531 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3532 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
3542 echo "Format mds$num: $(mdsdevname $num)"
3543 reformat_external_journal mds$num
3544 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3545 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3546 ${quiet:+>/dev/null} || exit 10
3555 echo "Format ost$num: $(ostdevname $num)"
3556 reformat_external_journal ost$num
3557 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3558 --reformat $(ostdevname $num) $(ostvdevname ${num}) \
3559 ${quiet:+>/dev/null} || exit 10
3564 # Set hostid for ZFS/SPL zpool import protection
3565 # (Assumes MDS version is also OSS version)
3566 if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ];
3568 do_rpc_nodes "$(comma_list $(remote_nodes_list))" set_hostid
3571 # We need ldiskfs here, may as well load them all
3573 [ -n "$CLIENTONLY" ] && return
3574 echo Formatting mgs, mds, osts
3575 if ! combined_mgs_mds ; then
3579 for num in $(seq $MDSCOUNT); do
3583 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
3585 for num in $(seq $OSTCOUNT); do
3591 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3595 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3599 # 0: success, the old identity set already.
3600 # 1: success, the old identity does not set.
3605 local j=`expr $num - 1`
3606 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3608 if [ -z "$MDT" ]; then
3612 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3615 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3617 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3620 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3622 if [ $old = "NONE" ]; then
3631 zconf_umount `hostname` $1 || error "umount failed"
3632 zconf_mount `hostname` $1 || error "mount failed"
3640 rm -f $TMP/${facet}active
3641 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3646 local mdt_count=${1:-$MDSCOUNT}
3647 local ost_count=${2:-$OSTCOUNT}
3650 for num in $(seq $mdt_count); do
3651 DEVNAME=$(mdsdevname $num)
3652 writeconf_facet mds$num $DEVNAME || rc=$?
3655 for num in $(seq $ost_count); do
3656 DEVNAME=$(ostdevname $num)
3657 writeconf_facet ost$num $DEVNAME || rc=$?
3663 nfs_client_mode && return
3664 cifs_client_mode && return
3666 sanity_mount_check || error "environments are insane!"
3670 if [ -z "$CLIENTONLY" ]; then
3671 echo Setup mgs, mdt, osts
3672 echo $WRITECONF | grep -q "writeconf" && writeconf_all
3673 if ! combined_mgs_mds ; then
3674 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3677 for num in `seq $MDSCOUNT`; do
3678 DEVNAME=$(mdsdevname $num)
3679 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3681 # We started mds, now we should set failover variables properly.
3682 # Set mds${num}failover_HOST if it is not set (the default failnode).
3683 local varname=mds${num}failover_HOST
3684 if [ -z "${!varname}" ]; then
3685 eval mds${num}failover_HOST=$(facet_host mds$num)
3688 if [ $IDENTITY_UPCALL != "default" ]; then
3689 switch_identity $num $IDENTITY_UPCALL
3692 for num in `seq $OSTCOUNT`; do
3693 DEVNAME=$(ostdevname $num)
3694 start ost$num $DEVNAME $OST_MOUNT_OPTS
3696 # We started ost$num, now we should set ost${num}failover variable properly.
3697 # Set ost${num}failover_HOST if it is not set (the default failnode).
3698 varname=ost${num}failover_HOST
3699 if [ -z "${!varname}" ]; then
3700 eval ost${num}failover_HOST=$(facet_host ost${num})
3708 # wait a while to allow sptlrpc configuration be propogated to targets,
3709 # only needed when mounting new target devices.
3714 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3716 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3719 if [ "$MOUNT_2" ]; then
3720 mount_client $MOUNT2
3721 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3726 # by remounting mdt before ost, initial connect from mdt to ost might
3727 # timeout because ost is not ready yet. wait some time to its fully
3728 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3729 # by a context negotiation rpc with $TIMEOUT.
3730 # FIXME better by monitoring import status.
3733 sleep $((TIMEOUT + 5))
3739 mounted_lustre_filesystems() {
3740 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3743 init_facet_vars () {
3744 [ -n "$CLIENTONLY" ] && return 0
3751 eval export ${facet}_dev=${device}
3752 eval export ${facet}_opt=\"$@\"
3754 local dev=${facet}_dev
3756 # We need to loop for the label
3757 # in case its not initialized yet.
3758 for wait_time in {0,1,3,5,10}; do
3760 if [ $wait_time -gt 0 ]; then
3761 echo "${!dev} not yet initialized,"\
3762 "waiting ${wait_time} seconds."
3766 local label=$(devicelabel ${facet} ${!dev})
3768 # Check to make sure the label does
3769 # not include ffff at the end of the label.
3770 # This indicates it has not been initialized yet.
3772 if [[ $label =~ [f|F]{4}$ ]]; then
3773 # label is not initialized, unset the result
3774 # and either try again or fail
3781 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3783 eval export ${facet}_svc=${label}
3785 local varname=${facet}failover_HOST
3786 if [ -z "${!varname}" ]; then
3787 eval export $varname=$(facet_host $facet)
3790 varname=${facet}_HOST
3791 if [ -z "${!varname}" ]; then
3792 eval export $varname=$(facet_host $facet)
3795 # ${facet}failover_dev is set in cfg file
3796 varname=${facet}failover_dev
3797 if [ -n "${!varname}" ] ; then
3798 eval export ${facet}failover_dev=${!varname}
3800 eval export ${facet}failover_dev=$device
3803 # get mount point of already mounted device
3804 # is facet_dev is already mounted then use the real
3805 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3806 # i.e. ${facet}_MOUNT if specified by user or default
3807 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3808 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3809 if [ -z $mntpt ]; then
3810 mntpt=$(facet_mntpt $facet)
3812 eval export ${facet}_MOUNT=$mntpt
3815 init_facets_vars () {
3818 if ! remote_mds_nodsh; then
3819 for num in $(seq $MDSCOUNT); do
3820 DEVNAME=`mdsdevname $num`
3821 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3825 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3827 if ! remote_ost_nodsh; then
3828 for num in $(seq $OSTCOUNT); do
3829 DEVNAME=$(ostdevname $num)
3830 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3835 osc_ensure_active () {
3840 while [ $period -lt $timeout ]; do
3841 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3842 if [ $count -eq 0 ]; then
3846 echo "There are $count OST are inactive, wait $period seconds, and try again"
3848 period=$((period+3))
3851 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3854 set_conf_param_and_check() {
3858 local ORIG=$(do_facet $myfacet "$TEST")
3859 if [ $# -gt 3 ]; then
3865 echo "Setting $PARAM from $ORIG to $FINAL"
3866 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3867 error "conf_param $PARAM failed"
3869 wait_update_facet $myfacet "$TEST" "$FINAL" ||
3870 error "check $PARAM failed!"
3873 init_param_vars () {
3874 TIMEOUT=$(lctl get_param -n timeout)
3875 TIMEOUT=${TIMEOUT:-20}
3877 remote_mds_nodsh && log "Using TIMEOUT=$TIMEOUT" && return 0
3879 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3880 log "Using TIMEOUT=$TIMEOUT"
3882 osc_ensure_active $SINGLEMDS $TIMEOUT
3883 osc_ensure_active client $TIMEOUT
3885 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
3886 local current_jobid_var=$($LCTL get_param -n jobid_var)
3888 if [ $JOBID_VAR = "existing" ]; then
3889 echo "keeping jobstats as $current_jobid_var"
3890 elif [ $current_jobid_var != $JOBID_VAR ]; then
3891 echo "seting jobstats to $JOBID_VAR"
3893 set_conf_param_and_check client \
3894 "$LCTL get_param -n jobid_var" \
3895 "$FSNAME.sys.jobid_var" $JOBID_VAR
3898 echo "jobstats not supported by server"
3901 if [ $QUOTA_AUTO -ne 0 ]; then
3902 if [ "$ENABLE_QUOTA" ]; then
3903 echo "enable quota as required"
3904 setup_quota $MOUNT || return 2
3906 echo "disable quota as required"
3907 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
3913 nfs_client_mode () {
3914 if [ "$NFSCLIENT" ]; then
3915 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
3916 local clients=$CLIENTS
3917 [ -z $clients ] && clients=$(hostname)
3919 # FIXME: remove hostname when 19215 fixed
3920 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
3921 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
3922 if [[ ${#nfsexport[@]} -eq 0 ]]; then
3923 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
3925 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
3931 cifs_client_mode () {
3932 [ x$CIFSCLIENT = xyes ] &&
3933 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
3936 check_config_client () {
3939 local mounted=$(mount | grep " $mntpt ")
3940 if [ -n "$CLIENTONLY" ]; then
3942 # CLIENTONLY should not depend on *_HOST settings
3943 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
3944 # in theory someone could create a new,
3945 # client-only config file that assumed lustre was already
3946 # configured and didn't set the MGSNID. If MGSNID is not set,
3947 # then we should use the mgs nid currently being used
3948 # as the default value. bug 18021
3949 [[ x$MGSNID = x ]] &&
3952 if [[ x$mgc != xMGC$MGSNID ]]; then
3953 if [ "$mgs_HOST" ]; then
3954 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
3955 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
3956 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
3962 local myMGS_host=$mgs_HOST
3963 if [ "$NETTYPE" = "ptl" ]; then
3964 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
3967 echo Checking config lustre mounted on $mntpt
3968 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
3969 mgshost=$(echo $mgshost | awk -F: '{print $1}')
3971 # if [ "$mgshost" != "$myMGS_host" ]; then
3972 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
3973 # Please use correct config or set mds_HOST correctly!"
3978 check_config_clients () {
3979 local clients=${CLIENTS:-$HOSTNAME}
3982 nfs_client_mode && return
3983 cifs_client_mode && return
3985 do_rpc_nodes "$clients" check_config_client $mntpt
3987 sanity_mount_check || error "environments are insane!"
3991 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3992 local cltimeout=$(lctl get_param -n timeout)
3993 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
3994 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
4001 [ -z $mntpt ] && return 1
4002 local mounted=$(mounted_lustre_filesystems)
4004 echo $mounted' ' | grep -w -q $mntpt' '
4008 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
4012 # empty lustre filesystem may have empty directories lost+found and .lustre
4014 # exclude .lustre & lost+found
4015 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
4016 -print | wc -l) = 1 ] || return 1
4017 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
4018 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
4019 # exclude .lustre/fid (LU-2780)
4020 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
4021 -print | wc -l) = 1 ] || return 1
4023 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
4028 check_and_setup_lustre() {
4030 nfs_client_mode && return
4031 cifs_client_mode && return
4033 local MOUNTED=$(mounted_lustre_filesystems)
4037 # both MOUNT and MOUNT2 are not mounted
4038 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
4039 [ "$REFORMAT" = "yes" ] && formatall
4040 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
4042 is_mounted $MOUNT || error "NAME=$NAME not mounted"
4043 export I_MOUNTED=yes
4047 elif is_mounted $MOUNT2; then
4049 # MOUNT2 is mounted, while MOUNT_2 is not set
4050 if ! [ "$MOUNT_2" ]; then
4051 cleanup_mount $MOUNT2
4052 export I_UMOUNTED2=yes
4055 # MOUNT2 is mounted, MOUNT_2 is set
4057 # FIXME: what to do if check_config failed?
4059 # 1) remote client has mounted other Lustre fs ?
4060 # 2) it has insane env ?
4061 # let's try umount MOUNT2 on all clients and mount it again:
4062 if ! check_config_clients $MOUNT2; then
4063 cleanup_mount $MOUNT2
4064 restore_mount $MOUNT2
4065 export I_MOUNTED2=yes
4070 # MOUNT is mounted MOUNT2 is not mounted
4071 elif [ "$MOUNT_2" ]; then
4072 restore_mount $MOUNT2
4073 export I_MOUNTED2=yes
4077 # FIXME: what to do if check_config failed?
4079 # 1) remote client has mounted other Lustre fs?
4080 # 2) lustre is mounted on remote_clients atall ?
4081 check_config_clients $MOUNT
4085 set_default_debug_nodes $(comma_list $(nodes_list))
4088 if [ -z "$CLIENTONLY" -a $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ]; then
4090 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
4091 facets="$(get_facets OST)"
4092 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
4093 facets="$facets,$(get_facets MDS)"
4094 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
4095 facets="$facets,mgs"
4096 local nodes="$(facets_hosts ${facets})"
4097 if [ -n "$nodes" ] ; then
4098 do_nodes $nodes "$LCTL set_param \
4099 osd-ldiskfs.track_declares_assert=1 || true"
4108 if [ -z "$CLIENTONLY" ]; then
4109 # Enable remote MDT create for testing
4110 for num in $(seq $MDSCOUNT); do
4112 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
4117 if [ "$ONLY" == "setup" ]; then
4123 local clients=${CLIENTS:-$HOSTNAME}
4126 zconf_mount_clients $clients $mntpt
4130 local clients=${CLIENTS:-$HOSTNAME}
4133 zconf_umount_clients $clients $mntpt
4136 cleanup_and_setup_lustre() {
4137 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
4138 lctl set_param debug=0 || true
4140 if [ "$ONLY" == "cleanup" ]; then
4144 check_and_setup_lustre
4147 # Get all of the server target devices from a given server node and type.
4154 if [ "$type" == ost ]; then
4155 devs=$(get_osd_param $node "" mntdev)
4157 devs=$(do_node $node $LCTL get_param -n osd-*.$FSNAME-M*.mntdev)
4159 for dev in $devs; do
4161 *loop*) do_node $node "losetup $dev" | \
4162 sed -e "s/.*(//" -e "s/).*//" ;;
4168 # Get all of the server target devices.
4173 # Master MDS parameters used by lfsck
4174 MDTNODE=$(facet_active_host $SINGLEMDS)
4175 MDTDEV=$(echo $(get_mnt_devs $MDTNODE mdt) | awk '{print $1}')
4179 for node in $(mdts_nodes); do
4180 MDTDEVS[i]=$(get_mnt_devs $node mdt)
4186 for node in $(osts_nodes); do
4187 OSTDEVS[i]=$(get_mnt_devs $node ost)
4192 # Run e2fsck on MDT or OST device.
4197 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
4198 local log=$TMP/e2fsck.log
4202 do_node $node $cmd 2>&1 | tee $log
4204 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
4206 if [ $MDSCOUNT -gt 1 ]; then
4207 skip "DNE mode isn't supported!"
4211 error "It's not DNE mode."
4216 [ $rc -le $FSCK_MAX_ERR ] ||
4217 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4223 # Run resize2fs on MDT or OST device.
4232 do_facet $facet "$RESIZE2FS $opts $device $size"
4235 # verify a directory is shared among nodes.
4236 check_shared_dir() {
4238 local list=${2:-$(comma_list $(nodes_list))}
4240 [ -z "$dir" ] && return 1
4241 do_rpc_nodes "$list" check_logdir $dir
4242 check_write_access $dir "$list" || return 1
4247 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
4248 $LCTL set_param printk=+lfsck
4249 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
4251 for k in $(seq $MDSCOUNT); do
4252 # wait up to 10+1 minutes for LFSCK to complete
4253 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4254 mdd.$(facet_svc mds${k}).lfsck_layout |
4255 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
4256 error "MDS${k} layout isn't the expected 'completed'"
4257 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
4258 mdd.$(facet_svc mds${k}).lfsck_namespace |
4259 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
4260 error "MDS${k} namespace isn't the expected 'completed'"
4262 local rep_mdt=$(do_nodes $(comma_list $(mdts_nodes)) \
4263 $LCTL get_param -n mdd.$FSNAME-*.lfsck_* |
4264 awk '/repaired/ { print $2 }' | calc_sum)
4265 local rep_ost=$(do_nodes $(comma_list $(osts_nodes)) \
4266 $LCTL get_param -n obdfilter.$FSNAME-*.lfsck_* |
4267 awk '/repaired/ { print $2 }' | calc_sum)
4268 local repaired=$((rep_mdt + rep_ost))
4269 [ $repaired -eq 0 ] ||
4270 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
4273 dump_file_contents() {
4279 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
4280 error_noexit false \
4281 "Invalid parameters for dump_file_contents()"
4284 for node in ${nodes}; do
4285 do_node $node "for i in \\\$(find $dir -type f); do
4286 echo ====\\\${i}=======================;
4288 done" >> ${logname}.${node}.log
4292 dump_command_output() {
4298 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
4299 error_noexit false \
4300 "Invalid parameters for dump_command_output()"
4304 for node in ${nodes}; do
4305 do_node $node "echo ====${cmd}=======================;
4306 $cmd" >> ${logname}.${node}.log
4313 # dump file contents from /proc/spl in case of zfs test
4314 if [ "$(facet_fstype ost1)" = "zfs" ]; then
4315 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
4316 dump_command_output \
4317 "$(osts_nodes)" "zpool events -v" "${logname}"
4320 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
4321 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
4322 dump_command_output \
4323 "$(mdts_nodes)" "zpool events -v" "${logname}"
4327 check_and_cleanup_lustre() {
4328 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "sanity-lfsck" -a \
4329 "$TESTSUITE" != "sanity-scrub" ]; then
4333 if is_mounted $MOUNT; then
4334 if $DO_CLEANUP; then
4335 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4336 error "remove sub-test dirs failed"
4340 [ "$ENABLE_QUOTA" ] && restore_quota || true
4343 if [ "$I_UMOUNTED2" = "yes" ]; then
4344 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4347 if [ "$I_MOUNTED2" = "yes" ]; then
4348 cleanup_mount $MOUNT2
4351 if [ "$I_MOUNTED" = "yes" ]; then
4352 cleanupall -f || error "cleanup failed"
4360 wait_for_function () {
4363 # suppress fn both stderr and stdout
4364 if [ "$1" = "--quiet" ]; then
4366 quiet=" > /dev/null 2>&1"
4378 eval $fn $quiet && return 0
4380 wait=$((wait + sleep))
4381 [ $wait -lt $max ] || return 1
4382 echo waiting $fn, $((max - wait)) secs left ...
4392 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4393 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4394 echo "Network not available!"
4398 echo `date +"%H:%M:%S (%s)"` network interface is UP
4406 # Convert a space-delimited list to a comma-delimited list. If the input is
4407 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4409 # echo is used to convert newlines to spaces, since it doesn't
4410 # introduce a trailing space as using "tr '\n' ' '" does
4411 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4417 echo $list | grep -qw $item
4420 # list, excluded are the comma separated lists
4421 exclude_items_from_list () {
4427 for item in ${excluded//,/ }; do
4428 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4430 echo $(comma_list $list)
4433 # list, expand are the comma separated lists
4435 local list=${1//,/ }
4436 local expand=${2//,/ }
4439 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4440 echo $(comma_list $expanded)
4443 testslist_filter () {
4444 local script=$LUSTRE/tests/${TESTSUITE}.sh
4446 [ -f $script ] || return 0
4448 local start_at=$START_AT
4449 local stop_at=$STOP_AT
4451 local var=${TESTSUITE//-/_}_START_AT
4452 [ x"${!var}" != x ] && start_at=${!var}
4453 var=${TESTSUITE//-/_}_STOP_AT
4454 [ x"${!var}" != x ] && stop_at=${!var}
4456 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4457 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4458 /^'${start_at}'$/ {flag = 0}
4459 {if (flag == 1) print $0}
4460 /^'${stop_at}'$/ { flag = 1 }'
4464 (cd `dirname $1`; echo $PWD/`basename $1`)
4468 local types=${1:-"OST MDS MGS"}
4472 for entry in $types; do
4473 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4474 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4477 MGS ) list="$list $name";;
4478 MDS|OST|AGT ) local count=${type}COUNT
4479 for ((i=1; i<=${!count}; i++)) do
4480 list="$list ${name}$i"
4482 * ) error "Invalid facet type"
4486 echo $(comma_list $list)
4489 ##################################
4490 # Adaptive Timeouts funcs
4493 # only check mds, we assume at_max is the same on all nodes
4494 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4495 if [ $at_max -eq 0 ]; then
4506 # suppose that all ost-s have the same $at value set
4507 [ $facet != "ost" ] || facet=ost1
4509 do_facet $facet "lctl get_param -n $at"
4527 if [ $facet == "ost" ]; then
4528 facet=$(get_facets OST)
4529 elif [ $facet == "mds" ]; then
4530 facet=$(get_facets MDS)
4532 hosts=$(expand_list $hosts $(facets_hosts $facet))
4535 do_nodes $hosts lctl set_param at_max=$at_max
4538 ##################################
4542 # OBD_FAIL_MDS_ALL_REQUEST_NET
4544 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4545 do_facet client "$1" || RC=$?
4546 do_facet $SINGLEMDS lctl set_param fail_loc=0
4551 # OBD_FAIL_MDS_ALL_REPLY_NET
4553 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
4555 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4559 drop_reint_reply() {
4560 # OBD_FAIL_MDS_REINT_NET_REP
4562 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
4564 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4568 drop_update_reply() {
4569 # OBD_FAIL_OUT_UPDATE_NET_REP
4573 do_facet mds${index} lctl set_param fail_loc=0x1701
4574 do_facet client "$@" || RC=$?
4575 do_facet mds${index} lctl set_param fail_loc=0
4580 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4583 local timeout=${2:-0}
4584 # default is (obd_timeout / 4) if unspecified
4585 echo "timeout is $timeout/$2"
4586 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
4587 do_facet client "$1" || RC=$?
4588 do_facet client "sync"
4589 do_facet ost1 lctl set_param fail_loc=0
4593 drop_ldlm_cancel() {
4594 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4596 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4597 do_nodes $list lctl set_param fail_loc=0x304
4599 do_facet client "$@" || RC=$?
4601 do_nodes $list lctl set_param fail_loc=0
4605 drop_bl_callback_once() {
4607 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4608 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4609 do_facet client lctl set_param fail_loc=0x80000305
4610 do_facet client "$@" || rc=$?
4611 do_facet client lctl set_param fail_loc=0
4612 do_facet client lctl set_param fail_val=0
4613 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4617 drop_bl_callback() {
4619 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4620 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4621 do_facet client lctl set_param fail_loc=0x305
4622 do_facet client "$@" || rc=$?
4623 do_facet client lctl set_param fail_loc=0
4624 do_facet client lctl set_param fail_val=0
4625 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4630 #define OBD_FAIL_LDLM_REPLY 0x30c
4632 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4633 do_nodes $list lctl set_param fail_loc=0x30c
4635 do_facet client "$@" || RC=$?
4637 do_nodes $list lctl set_param fail_loc=0
4641 drop_ldlm_reply_once() {
4642 #define OBD_FAIL_LDLM_REPLY 0x30c
4644 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4645 do_nodes $list lctl set_param fail_loc=0x8000030c
4647 do_facet client "$@" || RC=$?
4649 do_nodes $list lctl set_param fail_loc=0
4657 echo "clearing fail_loc on $facet"
4658 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4661 set_nodes_failloc () {
4663 do_nodes $(comma_list $1) lctl set_param fail_val=$fv fail_loc=$2
4666 cancel_lru_locks() {
4667 #$LCTL mark "cancel_lru_locks $1 start"
4668 $LCTL set_param -n ldlm.namespaces.*$1*.lru_size=clear
4669 $LCTL get_param ldlm.namespaces.*$1*.lock_unused_count | grep -v '=0'
4670 #$LCTL mark "cancel_lru_locks $1 stop"
4675 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4676 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4677 echo "$DEFAULT_LRU_SIZE"
4682 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4685 lru_resize_disable()
4687 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4693 [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] && RC=1
4699 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4700 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4701 echo there is still data in page cache $FILE ?
4702 lctl get_param -n $FILE
4710 DEBUGSAVE="$(lctl get_param -n debug)"
4711 DEBUGSAVE_SERVER=$(do_facet $SINGLEMDS "$LCTL get_param -n debug")
4715 [ -n "$DEBUGSAVE" ] &&
4716 do_nodes $CLIENTS "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\""||
4720 [ -n "DEBUGSAVE_SERVER" ] &&
4721 do_nodes $(comma_list $(all_server_nodes)) \
4722 "$LCTL set_param debug=\\\"${DEBUGSAVE_SERVER}\\\"" ||
4728 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4731 debug_size_restore() {
4732 [ -n "$DEBUG_SIZE_SAVED" ] && \
4733 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4737 start_full_debug_logging() {
4742 local DEBUG_SIZE=150
4744 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4745 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4748 stop_full_debug_logging() {
4753 # prints bash call stack
4754 print_stack_trace() {
4757 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4758 local src=${BASH_SOURCE[$i]}
4759 local lineno=${BASH_LINENO[$i-1]}
4760 local funcname=${FUNCNAME[$i]}
4761 echo " = $src:$lineno:$funcname()"
4766 local TYPE=${TYPE:-"FAIL"}
4769 # do not dump logs if $1=false
4770 if [ "x$1" = "xfalse" ]; then
4775 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4776 (print_stack_trace 2) >&2
4778 # We need to dump the logs on all nodes
4780 gather_logs $(comma_list $(nodes_list))
4784 [ "$TESTSUITELOG" ] &&
4785 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4786 if [ -z "$*" ]; then
4787 echo "error() without useful message, please fix" > $LOGDIR/err
4789 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4790 echo "$@" > $LOGDIR/ignore
4792 echo "$@" > $LOGDIR/err
4796 # cleanup the env for failed tests
4800 ##################################
4802 ##################################
4810 local log=$TESTSUITELOG
4812 [ -f "$log" ] && grep -q FAIL $log && status=1
4826 # use only if we are ignoring failures for this test, bugno required.
4827 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4828 # e.g. error_ignore bz5494 "your message" or
4829 # error_ignore LU-5494 "your message"
4831 local TYPE="IGNORE ($1)"
4836 error_and_remount() {
4838 remount_client $MOUNT
4843 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4848 log " SKIP: $TESTSUITE $TESTNAME $@"
4850 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4851 skip_logged $TESTNAME "$@"
4854 echo "$@" > $LOGDIR/skip
4857 [[ -n "$TESTSUITELOG" ]] &&
4858 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
4861 build_test_filter() {
4862 EXCEPT="$EXCEPT $(testslist_filter)"
4865 if [[ $O = [0-9]*-[0-9]* ]]; then
4866 for num in $(seq $(echo $O | tr '-' ' ')); do
4874 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
4875 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
4876 [ "$EXCEPT_SLOW" ] && \
4877 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
4878 for E in $EXCEPT; do
4879 eval EXCEPT_${E}=true
4881 for E in $ALWAYS_EXCEPT; do
4882 eval EXCEPT_ALWAYS_${E}=true
4884 for E in $EXCEPT_SLOW; do
4885 eval EXCEPT_SLOW_${E}=true
4887 for G in $GRANT_CHECK_LIST; do
4888 eval GCHECK_ONLY_${G}=true
4893 if [[ $1 = [a-z]* ]]; then
4900 # print a newline if the last test was skipped
4901 export LAST_SKIPPED=
4902 export ALWAYS_SKIPPED=
4904 # Main entry into test-framework. This is called with the name and
4905 # description of a test. The name is used to find the function to run
4906 # the test using "test_$name".
4908 # This supports a variety of methods of specifying specific test to
4909 # run or not run. These need to be documented...
4914 export base=$(basetest $1)
4915 if [ -n "$ONLY" ]; then
4917 if [ ${!testname}x != x ]; then
4918 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4919 run_one_logged $1 "$2"
4923 if [ ${!testname}x != x ]; then
4924 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4925 run_one_logged $1 "$2"
4935 if [ ${!testname}x != x ]; then
4936 TESTNAME=test_$1 skip "skipping excluded test $1"
4939 testname=EXCEPT_$base
4940 if [ ${!testname}x != x ]; then
4941 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
4944 testname=EXCEPT_ALWAYS_$1
4945 if [ ${!testname}x != x ]; then
4946 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
4949 testname=EXCEPT_ALWAYS_$base
4950 if [ ${!testname}x != x ]; then
4951 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
4954 testname=EXCEPT_SLOW_$1
4955 if [ ${!testname}x != x ]; then
4956 TESTNAME=test_$1 skip "skipping SLOW test $1"
4959 testname=EXCEPT_SLOW_$base
4960 if [ ${!testname}x != x ]; then
4961 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
4967 run_one_logged $1 "$2"
4974 load_module ../libcfs/libcfs/libcfs
4986 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
4991 strace -o $TMP/$1.strace -ttt $*
4993 log "FINISHED: $*: rc $RC"
5000 banner test complete, duration $duration sec
5001 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
5002 echo duration $duration >>$TESTSUITELOG
5006 # Set TEST_STATUS here. It will be used for logging the result.
5009 if [[ -f $LOGDIR/err ]]; then
5011 elif [[ -f $LOGDIR/skip ]]; then
5014 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
5018 local FFREE=$(do_node $SINGLEMDS \
5019 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
5020 local FTOTAL=$(do_node $SINGLEMDS \
5021 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
5023 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
5027 echo -n "Resetting fail_loc on all nodes..."
5028 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 \
5029 fail_val=0 2>/dev/null" || true
5035 # Log a message (on all nodes) padded with "=" before and after.
5036 # Also appends a timestamp and prepends the testsuite name.
5039 EQUALS="===================================================================================================="
5041 msg="== ${TESTSUITE} $*"
5043 [[ $last != "=" && $last != " " ]] && msg="$msg "
5044 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
5045 # always include at least == after the message
5046 log "$msg== $(date +"%H:%M:%S (%s)")"
5049 check_dmesg_for_errors() {
5051 local errors="VFS: Busy inodes after unmount of\|\
5052 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
5053 group descriptors corrupted"
5055 res=$(do_nodes $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
5056 [ -z "$res" ] && return 0
5057 echo "Kernel error detected: $res"
5062 # Run a single test function and cleanup after it.
5064 # This function should be run in a subshell so the test func can
5065 # exit() without stopping the whole script.
5070 export tfile=f${testnum}.${TESTSUITE}
5071 export tdir=d${testnum}.${TESTSUITE}
5072 export TESTNAME=test_$testnum
5073 local SAVE_UMASK=`umask`
5076 if ! grep -q $DIR /proc/mounts; then
5080 banner "test $testnum: $message"
5081 test_${testnum} || error "test_$testnum failed with $?"
5084 check_grant ${testnum} || error "check_grant $testnum failed with $?"
5085 check_catastrophe || error "LBUG/LASSERT detected"
5086 check_dmesg_for_errors || error "Error in dmesg detected"
5087 if [ "$PARALLEL" != "yes" ]; then
5088 ps auxww | grep -v grep | grep -q multiop &&
5089 error "multiop still running"
5100 # Wrapper around run_one to ensure:
5101 # - test runs in subshell
5102 # - output of test is saved to separate log file for error reporting
5103 # - test result is saved to data file
5106 local BEFORE=$(date +%s)
5108 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
5109 local test_log=$LOGDIR/$name
5110 local zfs_log_name=${TESTSUITE}.test_${1}.zfs_log
5111 local zfs_debug_log=$LOGDIR/$zfs_log_name
5113 rm -rf $LOGDIR/ignore
5115 local SAVE_UMASK=$(umask)
5119 log_sub_test_begin test_${1}
5120 (run_one $1 "$2") 2>&1 | tee -i $test_log
5121 local RC=${PIPESTATUS[0]}
5123 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
5124 echo "test_$1 returned $RC" | tee $LOGDIR/err
5126 duration=$(($(date +%s) - $BEFORE))
5127 pass "$1" "(${duration}s)"
5129 if [[ -f $LOGDIR/err ]]; then
5130 TEST_ERROR=$(cat $LOGDIR/err)
5131 elif [[ -f $LOGDIR/ignore ]]; then
5132 TEST_ERROR=$(cat $LOGDIR/ignore)
5133 elif [[ -f $LOGDIR/skip ]]; then
5134 TEST_ERROR=$(cat $LOGDIR/skip)
5136 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
5138 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
5142 if [ -f $LOGDIR/err ]; then
5143 log_zfs_info "$zfs_debug_log"
5144 $FAIL_ON_ERROR && exit $RC
5153 # Print information of skipped tests to result.yml
5156 log_sub_test_begin $1
5158 log_sub_test_end "SKIP" "0" "0" "$@"
5162 (cd $(dirname $1); echo $PWD/$(basename $1))
5167 export base=$(basetest $1)
5168 [ "$CHECK_GRANT" == "no" ] && return 0
5170 testname=GCHECK_ONLY_${base}
5171 [ ${!testname}x == x ] && return 0
5173 echo -n "checking grant......"
5175 local clients=$CLIENTS
5176 [ -z "$clients" ] && clients=$(hostname)
5178 # sync all the data and make sure no pending data on server
5179 do_nodes $clients sync
5182 client_grant=$(do_nodes $clients \
5183 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
5184 awk '{ total += $1 } END { printf("%0.0f", total) }')
5187 server_grant=$(do_nodes $(comma_list $(osts_nodes)) \
5188 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
5189 awk '{ total += $1 } END { printf("%0.0f", total) }')
5191 # check whether client grant == server grant
5192 if [[ $client_grant -ne $server_grant ]]; then
5193 echo "failed: client:${client_grant} server: ${server_grant}."
5194 do_nodes $(comma_list $(osts_nodes)) \
5195 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
5196 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
5199 echo "pass: client:${client_grant} server: ${server_grant}"
5203 ########################
5209 ost=`echo $1 | awk -F_ '{print $3}'`
5210 if [ -z $ost ]; then
5211 ost=`echo $1 | sed 's/-osc.*//'`
5216 ostuuid_from_index()
5218 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5221 ostname_from_index() {
5222 local uuid=$(ostuuid_from_index $1)
5226 index_from_ostuuid()
5228 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
5231 mdtuuid_from_index()
5233 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5237 # Return unique identifier for given hostname
5240 echo $host_name | md5sum | cut -d' ' -f1
5244 # Returns list of ip addresses for each interface
5246 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
5251 # Cache address list to avoid mutiple execution of local_addr_list
5252 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
5254 for i in $LOCAL_ADDR_LIST ; do
5255 [[ "$i" == "$addr" ]] && return 0
5262 local is_local="IS_LOCAL_$(host_id $host_name)"
5263 if [ -z "${!is_local-}" ] ; then
5265 local host_ip=$($LUSTRE/tests/resolveip $host_name)
5266 is_local_addr "$host_ip" && eval $is_local=1
5268 [[ "${!is_local}" == "1" ]]
5273 local_node $node && return 1
5280 for node in $(mdts_nodes); do
5281 remote_node $node && return 0
5288 [ -n "$CLIENTONLY" ] && return 0 || true
5289 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
5294 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" &&
5295 MSKIPPED=1 && return 1
5302 for node in $(osts_nodes) ; do
5303 remote_node $node && return 0
5310 [ -n "$CLIENTONLY" ] && return 0 || true
5311 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5316 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
5317 OSKIPPED=1 && return 1
5323 [ -n "$CLIENTONLY" ] && return 0 || true
5325 MGS=$(facet_host mgs)
5326 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5331 remote_mds_nodsh || remote_ost_nodsh || \
5332 $(single_local_node $(comma_list $(nodes_list)))
5336 remote_ost && remote_mds
5339 # Get the active nodes for facets.
5347 for facet in ${facets//,/ }; do
5348 nodes="$nodes $(facet_active_host $facet)"
5351 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5355 # Get all of the active MDS nodes.
5357 echo -n $(facets_nodes $(get_facets MDS))
5360 # Get all of the active OSS nodes.
5362 echo -n $(facets_nodes $(get_facets OST))
5365 # Get all of the active AGT (HSM agent) nodes.
5367 echo -n $(facets_nodes $(get_facets AGT))
5370 # Get all of the client nodes and active server nodes.
5372 local nodes=$HOSTNAME
5376 # CLIENTS (if specified) contains the local client
5377 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5379 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5380 nodes="$nodes $(facets_nodes $(get_facets))"
5383 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5387 # Get all of the remote client nodes and remote active server nodes.
5388 remote_nodes_list () {
5389 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5392 # Get all of the MDS nodes, including active and passive nodes.
5400 for i in $(seq $MDSCOUNT); do
5402 failover_host=mds${i}failover_HOST
5403 nodes="$nodes ${!host} ${!failover_host}"
5406 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5410 # Get all of the OSS nodes, including active and passive nodes.
5418 for i in $(seq $OSTCOUNT); do
5420 failover_host=ost${i}failover_HOST
5421 nodes="$nodes ${!host} ${!failover_host}"
5424 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5428 # Get all of the server nodes, including active and passive nodes.
5429 all_server_nodes () {
5434 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5436 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5440 # Get all of the client and server nodes, including active and passive nodes.
5442 local nodes=$HOSTNAME
5446 # CLIENTS (if specified) contains the local client
5447 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5449 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5450 nodes="$nodes $(all_server_nodes)"
5453 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5457 init_clients_lists () {
5458 # Sanity check: exclude the local client from RCLIENTS
5459 local clients=$(hostlist_expand "$RCLIENTS")
5460 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5462 # Sanity check: exclude the dup entries
5463 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5465 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5467 # Sanity check: exclude the dup entries from CLIENTS
5468 # for those configs which has SINGLCLIENT set to local client
5469 clients=$(for i in $clients; do echo $i; done | sort -u)
5471 CLIENTS=$(comma_list $clients)
5472 local -a remoteclients=($RCLIENTS)
5473 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5474 varname=CLIENT$((i + 2))
5475 eval $varname=${remoteclients[i]}
5478 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5481 get_random_entry () {
5484 rnodes=${rnodes//,/ }
5486 local -a nodes=($rnodes)
5487 local num=${#nodes[@]}
5488 local i=$((RANDOM * num * 2 / 65536))
5494 [ -n "$CLIENTONLY" ] || [ "x$CLIENTMODSONLY" = "xyes" ]
5498 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5499 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5504 echo $nodes | wc -w || true
5508 local nodes=$(osts_nodes)
5509 local osscount=$(get_node_count "$nodes")
5510 [ ! "$OSTCOUNT" = "$osscount" ]
5514 local nodes=$(mdts_nodes)
5515 local mdtcount=$(get_node_count "$nodes")
5516 [ ! "$MDSCOUNT" = "$mdtcount" ]
5519 generate_machine_file() {
5520 local nodes=${1//,/ }
5521 local machinefile=$2
5523 for node in $nodes; do
5524 echo $node >>$machinefile || \
5525 { echo "can not generate machinefile $machinefile" && return 1; }
5530 local file=$1/stripe
5533 $LFS getstripe -v $file || error "getstripe $file failed"
5537 setstripe_nfsserver () {
5540 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5541 { print $1 }' /proc/mounts | cut -f 1 -d : | head -n1)
5543 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5545 do_nodev $nfsserver lfs setstripe "$@"
5548 # Check and add a test group.
5554 local gid=$(getent group $group_name | cut -d: -f3)
5555 if [[ -n "$gid" ]]; then
5556 [[ "$gid" -eq "$group_id" ]] || {
5557 error_noexit "inconsistent group ID:" \
5558 "new: $group_id, old: $gid"
5562 groupadd -g $group_id $group_name
5569 # Check and add a test user.
5582 local uid=$(getent passwd $user_name | cut -d: -f3)
5583 if [[ -n "$uid" ]]; then
5584 if [[ "$uid" -eq "$user_id" ]]; then
5585 local dir=$(getent passwd $user_name | cut -d: -f6)
5586 if [[ "$dir" != "$home" ]]; then
5588 usermod -d $home $user_name
5592 error_noexit "inconsistent user ID:" \
5593 "new: $user_id, old: $uid"
5598 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5605 check_runas_id_ret() {
5607 local myRUNAS_UID=$1
5608 local myRUNAS_GID=$2
5611 if [ -z "$myRUNAS" ]; then
5612 error_exit "myRUNAS command must be specified for check_runas_id"
5615 $myRUNAS krb5_login.sh || \
5616 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5618 mkdir $DIR/d0_runas_test
5620 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5621 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5622 rm -rf $DIR/d0_runas_test
5627 local myRUNAS_UID=$1
5628 local myRUNAS_GID=$2
5631 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5632 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5633 Please set RUNAS_ID to some UID which exists on MDS and client or
5634 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5637 # obtain the UID/GID for MPI_USER
5641 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5642 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5644 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5645 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5648 # obtain and cache Kerberos ticket-granting ticket
5649 refresh_krb5_tgt() {
5650 local myRUNAS_UID=$1
5651 local myRUNAS_GID=$2
5654 if [ -z "$myRUNAS" ]; then
5655 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5658 CLIENTS=${CLIENTS:-$HOSTNAME}
5659 do_nodes $CLIENTS "set -x
5660 if ! $myRUNAS krb5_login.sh; then
5661 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5666 # Run multiop in the background, but wait for it to print
5667 # "PAUSING" to its stdout before returning from this function.
5668 multiop_bg_pause() {
5669 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5673 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5676 echo "$MULTIOP_PROG $FILE v$ARGS"
5677 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5679 echo "TMPPIPE=${TMPPIPE}"
5680 read -t 60 multiop_output < $TMPPIPE
5681 if [ $? -ne 0 ]; then
5686 if [ "$multiop_output" != "PAUSING" ]; then
5687 echo "Incorrect multiop output: $multiop_output"
5702 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5708 inodes_available () {
5709 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
5710 sort -un | head -n1) || return 1
5714 mdsrate_inodes_available () {
5715 local min_inodes=$(inodes_available)
5716 echo $((min_inodes * 99 / 100))
5719 # reset llite stat counters
5720 clear_llite_stats(){
5721 lctl set_param -n llite.*.stats 0
5724 # sum llite stat items
5725 calc_llite_stats() {
5726 local res=$(lctl get_param -n llite.*.stats |
5727 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5731 # reset osc stat counters
5733 lctl set_param -n osc.*.osc_stats 0
5736 # sum osc stat items
5738 local res=$(lctl get_param -n osc.*.osc_stats |
5739 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5744 awk '{sum += $1} END { printf("%0.0f", sum) }'
5747 calc_osc_kbytes () {
5748 df $MOUNT > /dev/null
5749 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5752 # save_lustre_params(comma separated facet list, parameter_mask)
5753 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5754 save_lustre_params() {
5760 for facet in ${facets//,/ }; do
5761 node=$(facet_active_host $facet)
5762 [[ *\ $node\ * = " $nodes " ]] && continue
5763 nodes="$nodes $node"
5765 do_node $node "$LCTL get_param $2 |
5766 while read s; do echo $facet \\\$s; done"
5770 # restore lustre parameters from input stream, produces by save_lustre_params
5771 restore_lustre_params() {
5776 while IFS=" =" read facet name val; do
5777 do_facet $facet "$LCTL set_param -n $name $val"
5781 check_catastrophe() {
5782 local nodes=${1:-$(comma_list $(nodes_list))}
5784 do_nodes $nodes "rc=0;
5785 val=\\\$($LCTL get_param -n catastrophe 2>&1);
5786 if [[ \\\$? -eq 0 && \\\$val -ne 0 ]]; then
5787 echo \\\$(hostname -s): \\\$val;
5793 mdsrate_cleanup () {
5795 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
5796 --nfiles $3 --dir $4 --filefmt $5 $6
5801 delayed_recovery_enabled () {
5802 local var=${SINGLEMDS}_svc
5803 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5806 ########################
5808 convert_facet2label() {
5811 if [ x$facet = xost ]; then
5815 local varsvc=${facet}_svc
5817 if [ -n ${!varsvc} ]; then
5820 error "No lablel for $facet!"
5824 get_clientosc_proc_path() {
5828 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5829 # used by MDT would not be changed.
5830 # mdt lov: fsname-mdtlov
5831 # mdt osc: fsname-OSTXXXX-osc
5832 mds_on_old_device() {
5833 local mds=${1:-"$SINGLEMDS"}
5835 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5836 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5837 > /dev/null 2>&1" && return 0
5842 get_mdtosc_proc_path() {
5844 local ost_label=${2:-"*OST*"}
5846 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5847 local mdt_label=$(convert_facet2label $mds_facet)
5848 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5850 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5851 mds_on_old_device $mds_facet; then
5852 echo "${ost_label}-osc"
5853 elif [[ $ost_label = *OST* ]]; then
5854 echo "${ost_label}-osc-${mdt_index}"
5856 echo "${ost_label}-osp-${mdt_index}"
5860 get_osc_import_name() {
5863 local label=$(convert_facet2label $ost)
5865 if [ "${facet:0:3}" = "mds" ]; then
5866 get_mdtosc_proc_path $facet $label
5870 get_clientosc_proc_path $label
5874 _wait_import_state () {
5877 local maxtime=${3:-$(max_recovery_time)}
5878 local error_on_failure=${4:-1}
5882 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5883 while [ "${CONN_STATE}" != "${expected}" ]; do
5884 if [ "${expected}" == "DISCONN" ]; then
5885 # for disconn we can check after proc entry is removed
5886 [ "x${CONN_STATE}" == "x" ] && return 0
5887 # with AT enabled, we can have connect request timeout near of
5888 # reconnect timeout and test can't see real disconnect
5889 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
5891 if [ $i -ge $maxtime ]; then
5892 [ $error_on_failure -ne 0 ] && \
5893 error "can't put import for $CONN_PROC into ${expected}" \
5894 "state after $i sec, have ${CONN_STATE}"
5898 # Add uniq for multi-mount case
5899 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5903 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
5907 wait_import_state() {
5910 local maxtime=${3:-$(max_recovery_time)}
5911 local error_on_failure=${4:-1}
5914 for param in ${params//,/ }; do
5915 _wait_import_state $state $param $maxtime $error_on_failure || return
5919 wait_import_state_mount() {
5920 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
5924 wait_import_state $*
5927 # One client request could be timed out because server was not ready
5928 # when request was sent by client.
5929 # The request timeout calculation details :
5931 # /* We give the server rq_timeout secs to process the req, and
5932 # add the network latency for our local timeout. */
5933 # request->rq_deadline = request->rq_sent + request->rq_timeout +
5934 # ptlrpc_at_get_net_latency(request) ;
5936 # ptlrpc_connect_import ()
5937 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5940 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
5941 # ptlrpc_at_get_net_latency(request) ->
5942 # at_get (max (iat_net_latency=0, at_min)) = at_min
5945 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
5946 # INITIAL_CONNECT_TIMEOUT + at_min
5948 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
5949 # because we can not get this value in runtime,
5950 # the value depends on configure options, and it is not stored in /proc.
5952 # #define CONNECTION_SWITCH_MIN 5U
5953 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5955 request_timeout () {
5958 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5959 local init_connect_timeout=$TIMEOUT
5960 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5962 local at_min=$(at_get $facet at_min)
5964 echo $(( init_connect_timeout + at_min ))
5967 _wait_osc_import_state() {
5971 local target=$(get_osc_import_name $facet $ost_facet)
5972 local param="osc.${target}.ost_server_uuid"
5976 # 1. wait the deadline of client 1st request (it could be skipped)
5977 # 2. wait the deadline of client 2nd request
5978 local maxtime=$(( 2 * $(request_timeout $facet)))
5980 if [[ $facet == client* ]]; then
5981 # During setup time, the osc might not be setup, it need wait
5982 # until list_param can return valid value. And also if there
5983 # are mulitple osc entries we should list all of them before
5985 params=$($LCTL list_param $param 2>/dev/null || true)
5986 while [ -z "$params" ]; do
5987 if [ $i -ge $maxtime ]; then
5988 echo "can't get $param in $maxtime secs"
5993 params=$($LCTL list_param $param 2>/dev/null || true)
5997 if [[ $ost_facet = mds* ]]; then
5998 # no OSP connection to itself
5999 if [[ $facet = $ost_facet ]]; then
6002 param="osp.${target}.mdt_server_uuid"
6006 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6007 wait_import_state $expected "$params" $maxtime; then
6008 error "import is not in ${expected} state"
6015 wait_osc_import_state() {
6021 if [[ $facet = mds ]]; then
6022 for num in $(seq $MDSCOUNT); do
6023 _wait_osc_import_state mds$num "$ost_facet" "$expected"
6026 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
6030 _wait_mgc_import_state() {
6033 local error_on_failure=${3:-1}
6034 local param="mgc.*.mgs_server_uuid"
6038 # 1. wait the deadline of client 1st request (it could be skipped)
6039 # 2. wait the deadline of client 2nd request
6040 local maxtime=$(( 2 * $(request_timeout $facet)))
6042 if [[ $facet == client* ]]; then
6043 # During setup time, the osc might not be setup, it need wait
6044 # until list_param can return valid value. And also if there
6045 # are mulitple osc entries we should list all of them before
6047 params=$($LCTL list_param $param 2>/dev/null || true)
6048 while [ -z "$params" ]; do
6049 if [ $i -ge $maxtime ]; then
6050 echo "can't get $param in $maxtime secs"
6055 params=$($LCTL list_param $param 2>/dev/null || true)
6058 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6059 wait_import_state $expected "$params" $maxtime \
6060 $error_on_failure; then
6061 if [ $error_on_failure -ne 0 ]; then
6062 error "import is not in ${expected} state"
6070 wait_mgc_import_state() {
6073 local error_on_failure=${3:-1}
6076 if [[ $facet = mds ]]; then
6077 for num in $(seq $MDSCOUNT); do
6078 _wait_mgc_import_state mds$num "$expected" \
6079 $error_on_failure || return
6082 _wait_mgc_import_state "$facet" "$expected"
6083 $error_on_failure || return
6087 wait_dne_interconnect() {
6090 if [ $MDSCOUNT -gt 1 ]; then
6091 for num in $(seq $MDSCOUNT); do
6092 wait_osc_import_state mds mds$num FULL
6097 get_clientmdc_proc_path() {
6101 get_clientmgc_proc_path() {
6109 [ -z "$list" ] && return 0
6111 # Add paths to lustre tests for 32 and 64 bit systems.
6112 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
6113 local TESTPATH="$RLUSTRE/tests:"
6114 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
6115 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
6118 wait_clients_import_state () {
6125 if [ "$FAILURE_MODE" = HARD ]; then
6126 facets=$(facets_on_host $(facet_active_host $facet))
6129 for facet in ${facets//,/ }; do
6130 local label=$(convert_facet2label $facet)
6133 ost* ) proc_path="osc.$(get_clientosc_proc_path \
6134 $label).ost_server_uuid" ;;
6135 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
6136 $label).mds_server_uuid" ;;
6137 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
6138 $label).mgs_server_uuid" ;;
6139 *) error "unknown facet!" ;;
6142 local params=$(expand_list $params $proc_path)
6145 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params;
6147 error "import is not in ${expected} state"
6157 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
6158 $LCTL get_param obdfilter.*.kbytesavail))
6159 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
6160 $LCTL get_param -n obdfilter.*.tot_granted))
6161 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
6162 $LCTL get_param -n obdfilter.*.kbytestotal))
6163 for ((i=0; i<${#AVAILA[@]}; i++)); do
6164 local -a AVAIL1=(${AVAILA[$i]//=/ })
6165 local -a TOTAL=(${TOTALA[$i]//=/ })
6166 GRANT=$((${GRANTA[$i]}/1024))
6167 # allow 1% of total space in bavail because of delayed
6168 # allocation with ZFS which might release some free space after
6169 # txg commit. For small devices, we set a mininum of 8MB
6170 local LIMIT=$((${TOTAL} / 100 + 8000))
6171 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
6172 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
6173 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
6174 echo " FULL" || echo
6180 do_facet mgs lctl pool_list $1
6184 local fsname=${1%%.*}
6185 local poolname=${1##$fsname.}
6187 do_facet mgs lctl pool_new $1
6189 # get param should return err unless pool is created
6190 [[ $RC -ne 0 ]] && return $RC
6192 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6193 2>/dev/null || echo foo" "" || RC=1
6194 if [[ $RC -eq 0 ]]; then
6197 error "pool_new failed $1"
6202 add_pool_to_list () {
6203 local fsname=${1%%.*}
6204 local poolname=${1##$fsname.}
6206 local listvar=${fsname}_CREATED_POOLS
6207 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
6211 remove_pool_from_list () {
6212 local fsname=${1%%.*}
6213 local poolname=${1##$fsname.}
6215 local listvar=${fsname}_CREATED_POOLS
6216 local temp=${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
6220 destroy_pool_int() {
6222 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
6223 awk '$1 !~ /^Pool:/ {print $1}')
6224 for ost in $OSTS; do
6225 do_facet mgs lctl pool_remove $1 $ost
6227 do_facet mgs lctl pool_destroy $1
6230 # <fsname>.<poolname> or <poolname>
6232 local fsname=${1%%.*}
6233 local poolname=${1##$fsname.}
6235 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
6239 pool_list $fsname.$poolname || return $?
6241 destroy_pool_int $fsname.$poolname
6243 [[ $RC -ne 0 ]] && return $RC
6245 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6246 2>/dev/null || echo foo" "foo" || RC=1
6248 if [[ $RC -eq 0 ]]; then
6249 remove_pool_from_list $fsname.$poolname
6251 error "destroy pool failed $1"
6257 local fsname=${1:-$FSNAME}
6259 local listvar=${fsname}_CREATED_POOLS
6263 [ x${!listvar} = x ] && return 0
6265 echo destroy the created pools: ${!listvar}
6266 for poolname in ${!listvar//,/ }; do
6267 destroy_pool $fsname.$poolname
6272 local fsname=${1:-$FSNAME}
6274 destroy_pools $fsname
6280 local ts=$(date +%s)
6283 if [[ ! -f "$YAML_LOG" ]]; then
6284 # init_logging is not performed before gather_logs,
6285 # so the $LOGDIR needs to be checked here
6286 check_shared_dir $LOGDIR && touch $LOGDIR/shared
6289 [ -f $LOGDIR/shared ] && docp=false
6291 # dump lustre logs, dmesg
6293 prefix="$TESTLOG_PREFIX.$TESTNAME"
6295 echo "Dumping lctl log to ${prefix}.*.${suffix}"
6297 if [ -n "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
6298 echo "Dumping logs only on local client."
6299 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
6300 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
6305 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
6306 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
6307 if [ ! -f $LOGDIR/shared ]; then
6308 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
6321 for i in $(seq 0 $num_mntpts); do
6322 cmd="ls -laf ${mntpt_root}$i/$dir"
6328 for pid in $pids; do
6335 # check_and_start_recovery_timer()
6336 # service_time = at_est2timeout(service_time);
6337 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
6338 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
6340 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
6341 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
6342 #define CONNECTION_SWITCH_MIN 5
6343 #define CONNECTION_SWITCH_INC 5
6344 max_recovery_time() {
6345 local init_connect_timeout=$((TIMEOUT / 20))
6346 ((init_connect_timeout >= 5)) || init_connect_timeout=5
6348 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
6349 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
6351 echo -n $service_time
6354 recovery_time_min() {
6355 local connection_switch_min=5
6356 local connection_switch_inc=5
6357 local connection_switch_max
6358 local reconnect_delay_max
6359 local initial_connect_timeout
6363 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
6364 (($connection_switch_min > $TIMEOUT)) &&
6365 max=$connection_switch_min || max=$TIMEOUT
6366 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
6368 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
6369 timeout_20=$((TIMEOUT/20))
6370 (($connection_switch_min > $timeout_20)) &&
6371 initial_connect_timeout=$connection_switch_min ||
6372 initial_connect_timeout=$timeout_20
6374 reconnect_delay_max=$((connection_switch_max + connection_switch_inc + \
6375 initial_connect_timeout))
6376 echo $((2 * reconnect_delay_max))
6379 get_clients_mount_count () {
6380 local clients=${CLIENTS:-`hostname`}
6382 # we need to take into account the clients mounts and
6383 # exclude mds/ost mounts if any;
6384 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
6388 PROC_CLI="srpc_info"
6396 if [ $M -lt $N ]; then
6400 while [ $N -lt $M ]; do
6410 calc_connection_cnt() {
6413 # MDT->MDT = 2 * C(M, 2)
6417 comb_m2=$(combination $MDSCOUNT 2)
6419 local num_clients=$(get_clients_mount_count)
6421 local cnt_mdt2mdt=$((comb_m2 * 2))
6422 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
6423 local cnt_cli2ost=$((num_clients * OSTCOUNT))
6424 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
6425 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
6426 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
6427 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
6441 local cmd="$tgt.srpc.flavor"
6443 if [ $net == "any" ]; then
6448 if [ $dir != "any" ]; then
6453 log "Setting sptlrpc rule: $cmd"
6454 do_facet mgs "$LCTL conf_param $cmd"
6463 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
6464 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
6466 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
6468 if [ "x$bulkspec" != "x" ]; then
6469 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
6471 if [ "x$algs" != "x" ]; then
6472 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
6474 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
6475 if [ $bulk == "bulkn" ]; then
6476 bulk_count=`echo "$output" | grep "bulk flavor" \
6477 | grep "null/null" | wc -l`
6478 elif [ $bulk == "bulki" ]; then
6479 bulk_count=`echo "$output" | grep "bulk flavor" \
6480 | grep "/null" | grep -v "null/" | wc -l`
6482 bulk_count=`echo "$output" | grep "bulk flavor" \
6483 | grep -v "/null" | grep -v "null/" | wc -l`
6487 [ $bulk_count -lt $count ] && count=$bulk_count
6498 local clients=${CLIENTS:-`hostname`}
6500 for c in ${clients//,/ }; do
6501 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
6502 tmpcnt=`count_flvr "$output" $flavor`
6503 cnt=$((cnt + tmpcnt))
6513 local clients=${CLIENTS:-`hostname`}
6515 for c in ${clients//,/ }; do
6516 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
6517 tmpcnt=`count_flvr "$output" $flavor`
6518 cnt=$((cnt + tmpcnt))
6528 if [ $MDSCOUNT -le 1 ]; then
6533 for num in `seq $MDSCOUNT`; do
6534 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
6535 tmpcnt=`count_flvr "$output" $flavor`
6536 cnt=$((cnt + tmpcnt))
6547 for num in `seq $MDSCOUNT`; do
6548 mdtosc=$(get_mdtosc_proc_path mds$num)
6549 mdtosc=${mdtosc/-MDT*/-MDT\*}
6550 output=$(do_facet mds$num lctl get_param -n \
6551 osc.$mdtosc.$PROC_CLI 2>/dev/null)
6552 tmpcnt=`count_flvr "$output" $flavor`
6553 cnt=$((cnt + tmpcnt))
6562 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
6563 count_flvr "$output" $flavor
6568 local dir=$1 # from to
6569 local flavor=$2 # flavor expected
6572 if [ $dir == "cli2mdt" ]; then
6573 res=`flvr_cnt_cli2mdt $flavor`
6574 elif [ $dir == "cli2ost" ]; then
6575 res=`flvr_cnt_cli2ost $flavor`
6576 elif [ $dir == "mdt2mdt" ]; then
6577 res=`flvr_cnt_mdt2mdt $flavor`
6578 elif [ $dir == "mdt2ost" ]; then
6579 res=`flvr_cnt_mdt2ost $flavor`
6580 elif [ $dir == "all2ost" ]; then
6581 res1=`flvr_cnt_mdt2ost $flavor`
6582 res2=`flvr_cnt_cli2ost $flavor`
6583 res=$((res1 + res2))
6584 elif [ $dir == "all2mdt" ]; then
6585 res1=`flvr_cnt_mdt2mdt $flavor`
6586 res2=`flvr_cnt_cli2mdt $flavor`
6587 res=$((res1 + res2))
6588 elif [ $dir == "all2all" ]; then
6589 res1=`flvr_cnt_mdt2ost $flavor`
6590 res2=`flvr_cnt_cli2ost $flavor`
6591 res3=`flvr_cnt_mdt2mdt $flavor`
6592 res4=`flvr_cnt_cli2mdt $flavor`
6593 res=$((res1 + res2 + res3 + res4))
6601 local dir=$1 # from to
6602 local flavor=$2 # flavor expected
6603 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6607 for ((i=0;i<20;i++)); do
6608 echo -n "checking $dir..."
6609 res=$(do_check_flavor $dir $flavor)
6610 echo "found $res/$expect $flavor connections"
6611 [ $res -ge $expect ] && return 0
6615 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6619 restore_to_default_flavor()
6621 local proc="mgs.MGS.live.$FSNAME"
6623 echo "restoring to default flavor..."
6625 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6627 # remove all existing rules if any
6628 if [ $nrule -ne 0 ]; then
6629 echo "$nrule existing rules"
6630 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6631 echo "remove rule: $rule"
6632 spec=`echo $rule | awk -F = '{print $1}'`
6633 do_facet mgs "$LCTL conf_param -d $spec"
6637 # verify no rules left
6638 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6639 [ $nrule -ne 0 ] && error "still $nrule rules left"
6641 # wait for default flavor to be applied
6642 # currently default flavor for all connections are 'null'
6643 wait_flavor all2all null
6644 echo "now at default flavor settings"
6649 local flavor=${1:-null}
6651 echo "setting all flavor to $flavor"
6653 # FIXME need parameter to this fn
6654 # and remove global vars
6655 local cnt_all2all=$(calc_connection_cnt all2all)
6657 local res=$(do_check_flavor all2all $flavor)
6658 if [ $res -eq $cnt_all2all ]; then
6659 echo "already have total $res $flavor connections"
6663 echo "found $res $flavor out of total $cnt_all2all connections"
6664 restore_to_default_flavor
6666 [[ $flavor = null ]] && return 0
6668 set_rule $FSNAME any any $flavor
6669 wait_flavor all2all $flavor
6675 # Checking for shared logdir
6676 if [ ! -d $dir ]; then
6677 # Not found. Create local logdir
6680 touch $dir/check_file.$(hostname -s)
6685 check_write_access() {
6687 local list=${2:-$(comma_list $(nodes_list))}
6691 for node in ${list//,/ }; do
6692 file=$dir/check_file.$(short_nodename $node)
6693 if [[ ! -f "$file" ]]; then
6694 # Logdir not accessible/writable from this node.
6697 rm -f $file || return 1
6703 [[ -n $YAML_LOG ]] && return
6704 local save_umask=$(umask)
6707 export YAML_LOG=${LOGDIR}/results.yml
6711 # If the yaml log already exists then we will just append to it
6712 if [ ! -f $YAML_LOG ]; then
6713 if check_shared_dir $LOGDIR; then
6714 touch $LOGDIR/shared
6715 echo "Logging to shared log directory: $LOGDIR"
6717 echo "Logging to local directory: $LOGDIR"
6720 yml_nodes_file $LOGDIR >> $YAML_LOG
6721 yml_results_file >> $YAML_LOG
6726 # If modules are not yet loaded then older "lctl lustre_build_version"
6727 # will fail. Use lctl build version instead.
6728 log "Client: $($LCTL lustre_build_version)"
6729 log "MDS: $(do_facet $SINGLEMDS $LCTL lustre_build_version 2>/dev/null||
6730 do_facet $SINGLEMDS $LCTL --version)"
6731 log "OSS: $(do_facet ost1 $LCTL lustre_build_version 2> /dev/null ||
6732 do_facet ost1 $LCTL --version)"
6736 yml_log_test $1 >> $YAML_LOG
6740 yml_log_test_status $@ >> $YAML_LOG
6743 log_sub_test_begin() {
6744 yml_log_sub_test_begin "$@" >> $YAML_LOG
6747 log_sub_test_end() {
6748 yml_log_sub_test_end "$@" >> $YAML_LOG
6754 local llverdev_opts=$2
6755 local devname=$(basename $1)
6756 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6757 # loop devices aren't in /proc/partitions
6758 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6760 size=$(($size / 1024 / 1024)) # Gb
6762 local partial_arg=""
6763 # Run in partial (fast) mode if the size
6764 # of a partition > 1 GB
6765 [ $size -gt 1 ] && partial_arg="-p"
6767 llverdev --force $partial_arg $llverdev_opts $dev
6773 local llverfs_opts=$2
6774 local use_partial_arg=$3
6775 local partial_arg=""
6776 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6778 # Run in partial (fast) mode if the size
6779 # of a partition > 1 GB
6780 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6782 llverfs $partial_arg $llverfs_opts $dir
6785 #Remove objects from OST
6786 remove_ost_objects() {
6792 local mntpt=$(facet_mntpt $facet)
6793 local opts=$OST_MOUNT_OPTS
6797 echo "removing objects from $ostdev on $facet: $objids"
6798 if ! test -b $ostdev; then
6799 opts=$(csa_add "$opts" -o loop)
6801 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
6804 for i in $objids; do
6805 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
6807 umount -f $mntpt || return $?
6811 #Remove files from MDT
6812 remove_mdt_files() {
6817 local mntpt=$(facet_mntpt $facet)
6818 local opts=$MDS_MOUNT_OPTS
6820 echo "removing files from $mdtdev on $facet: $files"
6821 if [ $(facet_fstype $facet) == ldiskfs ] &&
6822 ! do_facet $facet test -b $mdtdev; then
6823 opts=$(csa_add "$opts" -o loop)
6825 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6829 rm $mntpt/ROOT/$f || { rc=$?; break; }
6831 umount -f $mntpt || return $?
6835 duplicate_mdt_files() {
6840 local mntpt=$(facet_mntpt $facet)
6841 local opts=$MDS_MOUNT_OPTS
6843 echo "duplicating files on $mdtdev on $facet: $files"
6844 mkdir -p $mntpt || return $?
6845 if [ $(facet_fstype $facet) == ldiskfs ] &&
6846 ! do_facet $facet test -b $mdtdev; then
6847 opts=$(csa_add "$opts" -o loop)
6849 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6860 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
6861 pushd $mntpt/ROOT > /dev/null || return $?
6864 touch $f.bad || return $?
6865 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
6867 [ $rc -eq 0 ] || return $rc
6868 setfattr --restore $tmp || return $?
6874 local devs=${1//,/ }
6877 local rslt=$TMP/sgpdd_survey
6879 # sgpdd-survey cleanups ${rslt}.* files
6881 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
6887 # returns the canonical name for an ldiskfs device
6892 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
6893 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
6894 echo dm-\\\${foo##*:};
6896 echo \\\$(basename \\\$dv);
6900 is_sanity_benchmark() {
6901 local benchmarks="dbench bonnie iozone fsx"
6903 for b in $benchmarks; do
6904 if [ "$b" == "$suite" ]; then
6912 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
6916 # Get the available size (KB) of a given obd target.
6923 [[ $facet != client ]] || return 0
6925 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
6930 # Get the page size (bytes) on a given facet node.
6934 local size=$(getconf PAGE_SIZE 2>/dev/null)
6936 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet getconf PAGE_SIZE)
6937 echo -n ${size:-4096}
6941 # Get the block count of the filesystem.
6948 [ -z "$CLIENTONLY" ] && count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6949 awk '/^Block count:/ {print $3}')
6953 # Get the block size of the filesystem.
6959 [ -z "$CLIENTONLY" ] && size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6960 awk '/^Block size:/ {print $3}')
6964 # Check whether the "large_xattr" feature is enabled or not.
6965 large_xattr_enabled() {
6966 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
6968 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6970 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
6971 grep -E -q '(ea_inode|large_xattr)'"
6972 return ${PIPESTATUS[0]}
6975 # Get the maximum xattr size supported by the filesystem.
6979 if large_xattr_enabled; then
6980 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
6983 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6984 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
6986 # maximum xattr size = size of block - size of header -
6987 # size of 1 entry - 4 null bytes
6988 size=$((block_size - 32 - 32 - 4))
6994 # Dump the value of the named xattr from a file.
6999 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
7002 # Generate a string with size of $size bytes.
7004 local size=${1:-1024} # in bytes
7006 echo "$(head -c $size < /dev/zero | tr '\0' y)"
7009 reformat_external_journal() {
7014 if [ -n "${!var}" ]; then
7015 local rcmd="do_facet $facet"
7017 echo "reformat external journal on $facet:${!var}"
7018 ${rcmd} mke2fs -O journal_dev ${!var} || return 1
7022 # MDT file-level backup/restore
7023 mds_backup_restore() {
7026 local devname=$(mdsdevname $(facet_number $facet))
7027 local mntpt=$(facet_mntpt brpt)
7028 local rcmd="do_facet $facet"
7029 local metaea=${TMP}/backup_restore.ea
7030 local metadata=${TMP}/backup_restore.tgz
7031 local opts=${MDS_MOUNT_OPTS}
7032 local svc=${facet}_svc
7034 if ! ${rcmd} test -b ${devname}; then
7035 opts=$(csa_add "$opts" -o loop)
7038 echo "file-level backup/restore on $facet:${devname}"
7040 # step 1: build mount point
7041 ${rcmd} mkdir -p $mntpt
7042 # step 2: cleanup old backup
7043 ${rcmd} rm -f $metaea $metadata
7045 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7046 if [ ! -z $igif ]; then
7047 # step 3.5: rm .lustre
7048 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
7050 # step 4: backup metaea
7052 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
7054 # step 5: backup metadata
7056 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
7058 ${rcmd} $UMOUNT $mntpt || return 4
7059 # step 8: reformat dev
7060 echo "reformat new device"
7061 format_mdt $(facet_number $facet)
7063 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
7064 # step 10: restore metadata
7066 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
7067 # step 11: restore metaea
7069 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
7070 # step 12: remove recovery logs
7071 echo "remove recovery logs"
7072 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
7073 # step 13: umount dev
7074 ${rcmd} $UMOUNT $mntpt || return 10
7075 # step 14: cleanup tmp backup
7076 ${rcmd} rm -f $metaea $metadata
7077 # step 15: reset device label - it's not virgin on
7078 ${rcmd} e2label $devname ${!svc}
7085 local devname=$(mdsdevname $(facet_number $facet))
7086 local mntpt=$(facet_mntpt brpt)
7087 local rcmd="do_facet $facet"
7088 local opts=${MDS_MOUNT_OPTS}
7090 if ! ${rcmd} test -b ${devname}; then
7091 opts=$(csa_add "$opts" -o loop)
7094 echo "removing OI files on $facet: idx=${idx}"
7096 # step 1: build mount point
7097 ${rcmd} mkdir -p $mntpt
7099 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7100 if [ -z $idx ]; then
7101 # step 3: remove all OI files
7102 ${rcmd} rm -fv $mntpt/oi.16*
7103 elif [ $idx -lt 2 ]; then
7104 ${rcmd} rm -fv $mntpt/oi.16.${idx}
7108 # others, rm oi.16.[idx, idx * idx, idx ** ...]
7109 for ((i=${idx}; i<64; i=$((i * idx)))); do
7110 ${rcmd} rm -fv $mntpt/oi.16.${i}
7114 ${rcmd} $UMOUNT $mntpt || return 2
7115 # OI files will be recreated when mounted as lustre next time.
7118 # generate maloo upload-able log file name
7119 # \param logname specify unique part of file name
7120 generate_logname() {
7121 local logname=${1:-"default_logname"}
7123 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
7126 # make directory on different MDTs
7130 local stripe_count=2
7131 local stripe_index=-1
7134 while getopts "c:i:p" opt; do
7136 c) stripe_count=$OPTARG;;
7137 i) stripe_index=$OPTARG;;
7139 \?) error "only support -i -c -p";;
7143 shift $((OPTIND - 1))
7144 [ $# -eq 1 ] || error "Only creating single directory is supported"
7147 if [ "$p_option" == "-p" ]; then
7148 local parent=$(dirname $path)
7150 [ -d $path ] && return 0
7151 [ ! -d ${parent} ] && mkdir -p ${parent}
7154 if [ $MDSCOUNT -le 1 ]; then
7157 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
7160 if [ $stripe_index -eq -1 ]; then
7161 mdt_index=$((test_num % MDSCOUNT))
7163 mdt_index=$stripe_index
7165 echo "striped dir -i$mdt_index -c$stripe_count $path"
7166 $LFS setdirstripe -i$mdt_index -c$stripe_count $path
7170 # find the smallest and not in use file descriptor
7173 local max_fd=$(ulimit -n)
7175 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
7178 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
7182 check_mount_and_prep()
7184 is_mounted $MOUNT || setupall
7186 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
7187 mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
7188 for idx in $(seq $MDSCOUNT); do
7189 local name="MDT$(printf '%04x' $((idx - 1)))"
7190 rm -rf $MOUNT/.lustre/lost+found/$name/*
7194 # calcule how many ost-objects to be created.
7195 precreated_ost_obj_count()
7199 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
7200 local ost_name="OST$(printf '%04x' $ost_idx)"
7201 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
7202 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7203 osp.$proc_path.prealloc_last_id)
7204 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7205 osp.$proc_path.prealloc_next_id)
7206 echo $((last_id - next_id + 1))
7209 check_file_in_pool()
7214 local res=$($GETSTRIPE $file | grep 0x | cut -f2)
7217 for t in $tlist ; do
7218 [ "$i" -eq "$t" ] && continue 2
7221 echo "pool list: $tlist"
7222 echo "striping: $res"
7223 error_noexit "$file not allocated in $pool"
7230 echo "Creating new pool"
7233 create_pool $FSNAME.$pool ||
7234 { error_noexit "No pool created, result code $?"; return 1; }
7235 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
7236 { error_noexit "$pool not in lfs pool_list"; return 2; }
7239 pool_add_targets() {
7240 echo "Adding targets to pool"
7246 local list=$(seq $first $step $last)
7248 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
7249 do_facet mgs $LCTL pool_add \
7250 $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
7251 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
7252 | sort -u | tr '\n' ' ' " "$t" || {
7253 error_noexit "Add to pool failed"
7256 local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
7257 local addcount=$(((last - first) / step + 1))
7258 [ $lfscount -eq $addcount ] || {
7259 error_noexit "lfs pool_list bad ost count" \
7260 "$lfscount != $addcount"
7268 echo "Setting pool on directory $tdir"
7270 $SETSTRIPE -c 2 -p $pool $tdir && return 0
7272 error_noexit "Cannot set pool $pool to $tdir"
7279 echo "Checking pool on directory $tdir"
7281 local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
7282 [ "$res" = "$pool" ] && return 0
7284 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
7288 pool_dir_rel_path() {
7289 echo "Testing relative path works well"
7294 mkdir -p $root/$tdir/$tdir
7296 pool_set_dir $pool $tdir || return 1
7297 pool_set_dir $pool ./$tdir || return 2
7298 pool_set_dir $pool ../$tdir || return 3
7299 pool_set_dir $pool ../$tdir/$tdir || return 4
7300 rm -rf $tdir; cd - > /dev/null
7303 pool_alloc_files() {
7304 echo "Checking files allocation from directory pool"
7311 for i in $(seq -w 1 $count)
7313 local file=$tdir/file-$i
7315 check_file_in_pool $file $pool "$tlist" || \
7316 failed=$((failed + 1))
7318 [ "$failed" = 0 ] && return 0
7320 error_noexit "$failed files not allocated in $pool"
7324 pool_create_files() {
7325 echo "Creating files in pool"
7333 for i in $(seq -w 1 $count)
7335 local file=$tdir/spoo-$i
7336 $SETSTRIPE -p $pool $file
7337 check_file_in_pool $file $pool "$tlist" || \
7338 failed=$((failed + 1))
7340 [ "$failed" = 0 ] && return 0
7342 error_noexit "$failed files not allocated in $pool"
7347 echo "Checking 'lfs df' output"
7350 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
7352 local res=$($LFS df --pool $FSNAME.$pool |
7354 grep "$FSNAME-OST" |
7356 [ "$res" = "$t" ] && return 0
7358 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
7362 pool_file_rel_path() {
7363 echo "Creating files in a pool with relative pathname"
7368 { error_noexit "unable to create $tdir"; return 1 ; }
7369 local file="/..$tdir/$tfile-1"
7370 $SETSTRIPE -p $pool $file ||
7371 { error_noexit "unable to create $file" ; return 2 ; }
7374 $SETSTRIPE -p $pool $tfile-2 || {
7375 error_noexit "unable to create $tfile-2 in $tdir"
7380 pool_remove_first_target() {
7381 echo "Removing first target from a pool"
7384 local pname="lov.$FSNAME-*.pools.$pool"
7385 local t=$($LCTL get_param -n $pname | head -1)
7386 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7387 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
7388 error_noexit "$t not removed from $FSNAME.$pool"
7393 pool_remove_all_targets() {
7394 echo "Removing all targets from pool"
7397 local pname="lov.$FSNAME-*.pools.$pool"
7398 for t in $($LCTL get_param -n $pname | sort -u)
7400 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7402 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
7403 error_noexit "Pool $FSNAME.$pool cannot be drained"
7406 # striping on an empty/nonexistant pool should fall back
7407 # to "pool of everything"
7409 error_noexit "failed to use fallback striping for empty pool"
7412 # setstripe on an empty pool should fail
7413 $SETSTRIPE -p $pool $file 2>/dev/null && {
7414 error_noexit "expected failure when creating file" \
7422 echo "Destroying pool"
7426 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
7429 # striping on an empty/nonexistant pool should fall back
7430 # to "pool of everything"
7432 error_noexit "failed to use fallback striping for missing pool"
7435 # setstripe on an empty pool should fail
7436 $SETSTRIPE -p $pool $file 2>/dev/null && {
7437 error_noexit "expected failure when creating file" \
7442 # get param should return err once pool is gone
7443 if wait_update $HOSTNAME "lctl get_param -n \
7444 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
7446 remove_pool_from_list $FSNAME.$pool
7449 error_noexit "Pool $FSNAME.$pool is not destroyed"
7453 # Get and check the actual stripe count of one file.
7454 # Usage: check_stripe_count <file> <expected_stripe_count>
7455 check_stripe_count() {
7460 [[ -z "$file" || -z "$expected" ]] &&
7461 error "check_stripe_count: invalid argument"
7463 local cmd="$GETSTRIPE -c $file"
7464 actual=$($cmd) || error "$cmd failed"
7465 actual=${actual%% *}
7467 if [[ $actual -ne $expected ]]; then
7468 [[ $expected -eq -1 ]] ||
7469 error "$cmd wrong: found $actual, expected $expected"
7470 [[ $actual -eq $OSTCOUNT ]] ||
7471 error "$cmd wrong: found $actual, expected $OSTCOUNT"
7475 # Get and check the actual list of OST indices on one file.
7476 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
7482 [[ -z "$file" || -z "$expected" ]] &&
7483 error "check_obdidx: invalid argument!"
7485 obdidx=$(comma_list $($GETSTRIPE $file | grep -A $OSTCOUNT obdidx |
7486 grep -v obdidx | awk '{print $1}' | xargs))
7488 [[ $obdidx = $expected ]] ||
7489 error "list of OST indices on $file is $obdidx," \
7490 "should be $expected"
7493 # Get and check the actual OST index of the first stripe on one file.
7494 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
7495 check_start_ost_idx() {
7500 [[ -z "$file" || -z "$expected" ]] &&
7501 error "check_start_ost_idx: invalid argument!"
7503 start_ost_idx=$($GETSTRIPE $file | grep -A 1 obdidx | grep -v obdidx |
7506 [[ $start_ost_idx = $expected ]] ||
7507 error "OST index of the first stripe on $file is" \
7508 "$start_ost_idx, should be $expected"
7511 killall_process () {
7512 local clients=${1:-$(hostname)}
7517 do_nodes $clients "killall $signal $name"