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
59 [[ $DIR/ = $MOUNT/* ]] || \
60 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
61 [[ $DIR1/ = $MOUNT1/* ]] || \
62 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
63 [[ $DIR2/ = $MOUNT2/* ]] || \
64 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
66 [ -n "$failed" ] && exit 99 || true
70 echo "usage: $0 [-r] [-f cfgfile]"
78 [ -z "$DEFAULT_SUITES"] && return 0
79 [ "$TESTSUITE" == "lfsck" ] && return 0
80 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
82 local form="%-13s %-17s %-9s %s %s\n"
83 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
84 echo "------------------------------------------------------------------------------------"
85 for O in $DEFAULT_SUITES; do
86 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
87 [ "${!O}" = "no" ] && continue || true
88 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
89 local log=${TMP}/${o}.log
90 if is_sanity_benchmark $o; then
91 log=${TMP}/sanity-benchmark.log
96 local status=Unfinished
98 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
100 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
101 sort -nr -k 3 | head -n5 | awk '{ print $2":"$3"s" }')
102 total=$(grep duration $log | awk '{ print $2 }')
103 if [ "${!O}" = "done" ]; then
107 local durations=$(egrep "^PASS|^FAIL" $log |
108 tr -d "("| sed s/s\)$//g |
109 awk '{ print $2":"$3"|" }')
110 details=$(printf "%s\n%s %s %s\n" "$details" \
111 "DDETAILS" "$O" "$(echo $durations)")
114 printf "$form" $status "$O" "${total}" "E=$skipped"
115 printf "$form" "-" "-" "-" "S=$(echo $slow)"
118 for O in $DEFAULT_SUITES; do
119 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
120 if [ "${!O}" = "no" ]; then
121 printf "$form" "Skipped" "$O" ""
125 # print the detailed tests durations if DDETAILS=true
132 export LUSTRE=$(absolute_path $LUSTRE)
133 export TESTSUITE=$(basename $0 .sh)
134 export TEST_FAILED=false
135 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
136 export RPC_MODE=${RPC_MODE:-false}
138 export MKE2FS=$MKE2FS
139 if [ -z "$MKE2FS" ]; then
140 if which mkfs.ldiskfs >/dev/null 2>&1; then
141 export MKE2FS=mkfs.ldiskfs
147 export DEBUGFS=$DEBUGFS
148 if [ -z "$DEBUGFS" ]; then
149 if which debugfs.ldiskfs >/dev/null 2>&1; then
150 export DEBUGFS=debugfs.ldiskfs
152 export DEBUGFS=debugfs
156 export TUNE2FS=$TUNE2FS
157 if [ -z "$TUNE2FS" ]; then
158 if which tunefs.ldiskfs >/dev/null 2>&1; then
159 export TUNE2FS=tunefs.ldiskfs
161 export TUNE2FS=tune2fs
165 export E2LABEL=$E2LABEL
166 if [ -z "$E2LABEL" ]; then
167 if which label.ldiskfs >/dev/null 2>&1; then
168 export E2LABEL=label.ldiskfs
170 export E2LABEL=e2label
174 export DUMPE2FS=$DUMPE2FS
175 if [ -z "$DUMPE2FS" ]; then
176 if which dumpfs.ldiskfs >/dev/null 2>&1; then
177 export DUMPE2FS=dumpfs.ldiskfs
179 export DUMPE2FS=dumpe2fs
183 export E2FSCK=$E2FSCK
184 if [ -z "$E2FSCK" ]; then
185 if which fsck.ldiskfs >/dev/null 2>&1; then
186 export E2FSCK=fsck.ldiskfs
192 export RESIZE2FS=$RESIZE2FS
193 if [ -z "$RESIZE2FS" ]; then
194 if which resizefs.ldiskfs >/dev/null 2>&1; then
195 export RESIZE2FS=resizefs.ldiskfs
197 export RESIZE2FS=resize2fs
201 export LFSCK_BIN=${LFSCK_BIN:-lfsck}
202 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after each test suite
203 export FSCK_MAX_ERR=4 # File system errors left uncorrected
205 export ZFS=${ZFS:-zfs}
206 export ZPOOL=${ZPOOL:-zpool}
207 export ZDB=${ZDB:-zdb}
208 export PARTPROBE=${PARTPROBE:-partprobe}
210 #[ -d /r ] && export ROOT=${ROOT:-/r}
211 export TMP=${TMP:-$ROOT/tmp}
212 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
213 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
214 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
216 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
217 if ! echo $PATH | grep -q $LUSTRE/utils; then
218 export PATH=$LUSTRE/utils:$PATH
220 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
221 export PATH=$LUSTRE/utils/gss:$PATH
223 if ! echo $PATH | grep -q $LUSTRE/tests; then
224 export PATH=$LUSTRE/tests:$PATH
226 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
227 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
229 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
230 [ ! -f "$LST" ] && export LST=$(which lst)
231 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
232 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
233 export MCREATE=${MCREATE:-mcreate}
234 # Ubuntu, at least, has a truncate command in /usr/bin
235 # so fully path our truncate command.
236 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
237 export FSX=${FSX:-$LUSTRE/tests/fsx}
238 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
239 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
240 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
241 export PATH=$LUSTRE/tests/racer:$PATH:
243 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
244 export PATH=$LUSTRE/tests/mpi:$PATH
246 export RSYNC_RSH=${RSYNC_RSH:-rsh}
248 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
249 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
250 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
251 [ ! -f "$LFS" ] && export LFS=$(which lfs)
252 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
253 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
255 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
256 if [ ! -f "$L_GETIDENTITY" ]; then
257 if `which l_getidentity > /dev/null 2>&1`; then
258 export L_GETIDENTITY=$(which l_getidentity)
260 export L_GETIDENTITY=NONE
263 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
264 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
265 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
266 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
267 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
268 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
269 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
270 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
271 [ ! -f "$LUSTRE_RMMOD" ] &&
272 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
273 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
274 [ ! -f "$LFS_MIGRATE" ] &&
275 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
276 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
277 [ ! -f "$LR_READER" ] && export LR_READER=$(which lr_reader 2> /dev/null)
278 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
279 export NAME=${NAME:-local}
280 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
281 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
282 export LGSSD=$(which lgssd)
283 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
284 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
285 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
287 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
290 if [ "$ACCEPTOR_PORT" ]; then
291 export PORT_OPT="--port $ACCEPTOR_PORT"
296 echo "Using GSS/krb5 ptlrpc security flavor"
297 which lgss_keyring > /dev/null 2>&1 || \
298 error_exit "built with gss disabled! SEC=$SEC"
309 IDENTITY_UPCALL=false
313 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
315 # Paths on remote nodes, if different
316 export RLUSTRE=${RLUSTRE:-$LUSTRE}
317 export RPWD=${RPWD:-$PWD}
318 export I_MOUNTED=${I_MOUNTED:-"no"}
319 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
320 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
321 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
322 ! -f $LUSTRE/mdt/mdt.ko ]; then
323 export CLIENTMODSONLY=yes
326 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
327 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
331 while getopts "rvwf:" opt $*; do
334 r) REFORMAT=--reformat;;
336 w) WRITECONF=writeconf;;
341 shift $((OPTIND - 1))
344 # print the durations of each test if "true"
345 DDETAILS=${DDETAILS:-false}
346 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
351 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
358 ncpts=$(do_facet $facet "lctl get_param -n " \
359 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
361 if [ $ncpts -eq 0 ]; then
368 # Return a numeric version code based on a version string. The version
369 # code is useful for comparison two version strings to see which is newer.
371 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
372 eval set -- $(tr "[:punct:]" " " <<< $*)
374 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
377 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
378 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
380 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
382 # usage: lustre_build_version
384 # All Lustre versions support "lctl get_param" to report the version of the
385 # code running in the kernel (what our tests are interested in), but it
386 # doesn't work without modules loaded. If that fails, use "lctl version"
387 # instead, which is easy to parse and works without the kernel modules,
388 # but was only added in 2.6.50. If that also fails, fall back to calling
389 # "lctl lustre_build_version" which prints either (or both) the userspace
390 # and kernel build versions, but is deprecated and should eventually be
393 # output: prints version string to stdout in dotted-decimal format
394 lustre_build_version() {
395 local facet=${1:-client}
398 # kernel: patchless_client
399 # build: v2_6_92_0-gadb3ee4-2.6.32-431.29.2.el6_lustre.x86_64
400 local VER=$(do_facet $facet $LCTL get_param -n version 2> /dev/null |
401 awk '/lustre: / { print $2 }')
403 [ -z "$VER" ] && VER=$(do_facet $facet $LCTL --version 2>/dev/null |
405 # Lustre version: 2.5.3-gfcfd782-CHANGED-2.6.32.26-175.fc12.x86_64
406 # lctl version: 2.5.3-gfcfd782-CHANGED-2.6.32.26-175.fc12.x86_64
407 [ -z "$VER" ] && VER=$(do_facet $facet $LCTL lustre_build_version |
408 awk '/version:/ { print $3; exit; }')
409 sed -e 's/^v//' -e 's/-.*//' -e 's/_/./g' <<<$VER
412 # Report the Lustre numeric build version code for the supplied facet.
413 lustre_version_code() {
414 version_code $(lustre_build_version $1)
418 /sbin/lsmod | grep -q "^\<$1\>"
421 # Load a module on the system where this is running.
423 # usage: load_module module_name [module arguments for insmod/modprobe]
425 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
426 # will be used as the arguments. Otherwise arguments will be obtained from
427 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
434 BASE=$(basename $module $EXT)
436 module_loaded ${BASE} && return
438 # If no module arguments were passed, get them from $MODOPTS_<MODULE>,
439 # else from modprobe.conf
440 if [ $# -eq 0 ]; then
441 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
442 # Bash until 4.x, so we resort to eval.
443 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
444 eval set -- \$$optvar
445 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
446 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
448 opt=$(awk -v var="^options $BASE" '$0 ~ var \
449 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
450 set -- $(echo -n $opt)
452 # Ensure we have accept=all for lnet
453 if [ $(basename $module) = lnet ]; then
454 # OK, this is a bit wordy...
455 local arg accept_all_present=false
458 [ "$arg" = accept=all ] && \
459 accept_all_present=true
461 $accept_all_present || set -- "$@" accept=all
467 [ $# -gt 0 ] && echo "${module} options: '$*'"
469 # Note that insmod will ignore anything in modprobe.conf, which is why
470 # we're passing options on the command-line.
471 if [[ "$BASE" == "lnet_selftest" ]] &&
472 [[ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]]; then
473 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
474 elif [[ -f ${LUSTRE}/${module}${EXT} ]]; then
475 [[ "$BASE" != "ptlrpc_gss" ]] || modprobe sunrpc
476 insmod ${LUSTRE}/${module}${EXT} "$@"
478 # must be testing a "make install" or "rpm" installation
479 # note failed to load ptlrpc_gss is considered not fatal
480 if [[ "$BASE" == "ptlrpc_gss" ]]; then
481 modprobe $BASE "$@" 2>/dev/null ||
482 echo "gss/krb5 is not supported"
489 llite_lloop_enabled() {
490 local n1=$(uname -r | cut -d. -f1)
491 local n2=$(uname -r | cut -d. -f2)
492 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
494 # load the llite_lloop module for < 2.6.32 kernels
495 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
496 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
503 load_modules_local() {
504 if [ -n "$MODPROBE" ]; then
506 echo "Using modprobe to load modules"
510 echo Loading modules from $LUSTRE
514 if [ -f /sys/devices/system/cpu/online ]; then
515 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
516 echo "detected $ncpus online CPUs by sysfs"
518 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
520 if [ $rc -eq 0 ]; then
521 echo "detected $ncpus online CPUs by getconf"
523 echo "Can't detect number of CPUs"
528 # if there is only one CPU core, libcfs can only create one partition
529 # if there is more than 4 CPU cores, libcfs should create multiple CPU
530 # partitions. So we just force libcfs to create 2 partitions for
531 # system with 2 or 4 cores
532 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
533 # force to enable multiple CPU partitions
534 echo "Force libcfs to create 2 CPU partitions"
535 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
537 echo "libcfs will create CPU partition based on online CPUs"
540 load_module ../libcfs/libcfs/libcfs
542 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
543 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
544 load_module ../lnet/lnet/lnet
547 LNETLND="o2iblnd/ko2iblnd"
552 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
553 load_module ../lnet/klnds/$LNETLND
554 load_module obdclass/obdclass
555 load_module ptlrpc/ptlrpc
556 load_module ptlrpc/gss/ptlrpc_gss
564 load_module obdecho/obdecho
565 if ! client_only; then
566 SYMLIST=/proc/kallsyms
567 grep -q crc16 $SYMLIST || { modprobe crc16 2>/dev/null || true; }
568 grep -q -w jbd $SYMLIST || { modprobe jbd 2>/dev/null || true; }
569 grep -q -w jbd2 $SYMLIST || { modprobe jbd2 2>/dev/null || true; }
570 load_module lfsck/lfsck
571 [ "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
572 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
574 load_module osd-zfs/osd_zfs
576 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
577 grep -q exportfs_decode_fh $SYMLIST ||
578 { modprobe exportfs 2> /dev/null || true; }
579 load_module ../ldiskfs/ldiskfs
580 load_module osd-ldiskfs/osd_ldiskfs
592 load_module llite/lustre
593 llite_lloop_enabled && load_module llite/llite_lloop
594 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
596 rm -f $OGDB/ogdb-$HOSTNAME
597 $LCTL modules > $OGDB/ogdb-$HOSTNAME
599 # 'mount' doesn't look in $PATH, just sbin
600 local mount_lustre=$LUSTRE/utils/mount.lustre
601 if [ -f $mount_lustre ]; then
602 local sbin_mount=$(readlink -f /sbin)/mount.lustre
603 if grep -qw "$sbin_mount" /proc/mounts; then
604 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
606 if ! grep -qw "$sbin_mount" /proc/mounts; then
607 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
608 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
609 cat <<- EOF > "$sbin_mount"
612 echo "This $sbin_mount just a mountpoint." 1>&2
613 echo "It is never supposed to be run." 1>&2
614 logger -p emerg -- "using stub $sbin_mount $@"
617 chmod a+x $sbin_mount
619 mount --bind $mount_lustre $sbin_mount ||
620 error "can't bind $mount_lustre to $sbin_mount"
628 # load modules on remote nodes optionally
629 # lustre-tests have to be installed on these nodes
630 if $LOAD_MODULES_REMOTE; then
631 local list=$(comma_list $(remote_nodes_list))
632 if [ -n "$list" ]; then
633 echo "loading modules on: '$list'"
634 do_rpc_nodes "$list" load_modules_local
640 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
641 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
642 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
643 echo "$LEAK_LUSTRE" 1>&2
644 echo "$LEAK_PORTALS" 1>&2
645 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
646 echo "Memory leaks detected"
647 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
653 wait_exit_ST client # bug 12845
655 $LUSTRE_RMMOD ldiskfs || return 2
657 if $LOAD_MODULES_REMOTE; then
658 local list=$(comma_list $(remote_nodes_list))
659 if [ -n "$list" ]; then
660 echo "unloading modules on: '$list'"
661 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
662 do_rpc_nodes "$list" check_mem_leak
666 local sbin_mount=$(readlink -f /sbin)/mount.lustre
667 if grep -qe "$sbin_mount " /proc/mounts; then
668 umount $sbin_mount || true
669 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
673 check_mem_leak || return 254
675 echo "modules unloaded."
680 local facet=${1:-$SINGLEMDS}
681 local fstype=$(facet_fstype $facet)
684 ldiskfs) size=50;; # largest seen is 44, leave some headroom
685 zfs) size=400;; # largest seen is 384
691 check_gss_daemon_nodes() {
695 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
696 if [ \\\"\\\$num\\\" -ne 1 ]; then
697 echo \\\$num instance of $dname;
702 check_gss_daemon_facet() {
706 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
707 if [ $num -ne 1 ]; then
708 echo "$num instance of $dname on $facet"
717 echo Stopping $@ on $list
718 do_nodes $list "killall -2 $@ 2>/dev/null || true"
721 # start gss daemons on all nodes, or
722 # "daemon" on "list" if set
723 start_gss_daemons() {
727 if [ "$list" ] && [ "$daemon" ] ; then
728 echo "Starting gss daemon on nodes: $list"
729 do_nodes $list "$daemon" || return 8
733 local list=$(comma_list $(mdts_nodes))
734 echo "Starting gss daemon on mds: $list"
735 do_nodes $list "$LSVCGSSD -v" || return 1
737 do_nodes $list "$LGSSD -v" || return 2
740 list=$(comma_list $(osts_nodes))
741 echo "Starting gss daemon on ost: $list"
742 do_nodes $list "$LSVCGSSD -v" || return 3
743 # starting on clients
745 local clients=${CLIENTS:-`hostname`}
747 echo "Starting $LGSSD on clients $clients "
748 do_nodes $clients "$LGSSD -v" || return 4
751 # wait daemons entering "stable" status
755 # check daemons are running
757 list=$(comma_list $(mdts_nodes) $(osts_nodes))
758 check_gss_daemon_nodes $list lsvcgssd || return 5
760 list=$(comma_list $(mdts_nodes))
761 check_gss_daemon_nodes $list lgssd || return 6
764 check_gss_daemon_nodes $clients lgssd || return 7
769 local list=$(comma_list $(mdts_nodes))
771 send_sigint $list lsvcgssd lgssd
773 list=$(comma_list $(osts_nodes))
774 send_sigint $list lsvcgssd
776 list=${CLIENTS:-`hostname`}
777 send_sigint $list lgssd
782 if ! module_loaded ptlrpc_gss; then
783 load_module ptlrpc/gss/ptlrpc_gss
784 module_loaded ptlrpc_gss ||
785 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
788 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
791 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
793 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
801 # maybe cleanup credential cache?
807 local var=${facet}_svc
815 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
816 tr '[:lower:]' '[:upper:]'
822 if [ $facet == mgs ]; then
826 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
834 if [ -n "${!var}" ]; then
839 var=$(facet_type $facet)FSTYPE
840 if [ -n "${!var}" ]; then
845 if [ -n "$FSTYPE" ]; then
850 if [[ $facet == mgs ]] && combined_mgs_mds; then
862 local facets=$(get_facets)
865 for facet in ${facets//,/ }; do
866 if [ $node == $(facet_host $facet) ] ||
867 [ $node == "$(facet_failover_host $facet)" ]; then
868 fstype=$(facet_fstype $facet)
869 if [[ $fstypes != *$fstype* ]]; then
870 fstypes+="${fstypes:+,}$fstype"
879 local num=$(facet_number $facet)
882 if [[ $(facet_type $facet) = OST ]]; then
884 if [[ -n "${!index}" ]]; then
889 index=${OST_INDICES[num - 1]}
892 [[ -n "$index" ]] || index=$((num - 1))
900 local fstype=$(facet_fstype $facet)
904 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
906 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
907 ${dev} 2>/dev/null");;
909 error "unknown fstype!";;
917 local device=$(mdsdevname $num)
918 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
924 local device=$(ostdevname $num)
925 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
930 # Get the device of a facet.
937 mgs) device=$(mgsdevname) ;;
938 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
939 ost*) device=$(ostdevname $(facet_number $facet)) ;;
940 fs2mds) device=$(mdsdevname 1_2) ;;
941 fs2ost) device=$(ostdevname 1_2) ;;
942 fs3ost) device=$(ostdevname 2_2) ;;
950 # Get the virtual device of a facet.
957 mgs) device=$(mgsvdevname) ;;
958 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
959 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
960 fs2mds) device=$(mdsvdevname 1_2) ;;
961 fs2ost) device=$(ostvdevname 1_2) ;;
962 fs3ost) device=$(ostvdevname 2_2) ;;
970 # Re-read the partition table on failover partner host.
971 # After a ZFS storage pool is created on a shared device, the partition table
972 # on the device may change. However, the operating system on the failover
973 # host may not notice the change automatically. Without the up-to-date partition
974 # block devices, 'zpool import ..' cannot find the labels, whose positions are
975 # relative to partition rather than disk beginnings.
977 # This function performs partprobe on the failover host to make it re-read the
980 refresh_partition_table() {
985 host=$(facet_passive_host $facet)
986 if [[ -n "$host" ]]; then
987 do_node $host "$PARTPROBE $device"
992 # Get ZFS storage pool name.
999 device=$(facet_device $facet)
1000 # poolname is string before "/"
1001 poolname="${device%%/*}"
1007 # Create ZFS storage pool.
1014 local opts=${@:-"-o cachefile=none"}
1016 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
1017 $ZPOOL create -f $opts $poolname $vdev"
1021 # Create ZFS file system.
1027 local opts=${@:-"-o mountpoint=legacy"}
1029 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1030 $ZFS create $opts $dataset"
1034 # Export ZFS storage pool.
1035 # Before exporting the pool, all datasets within the pool should be unmounted.
1043 poolname=$(zpool_name $facet)
1045 if [[ -n "$poolname" ]]; then
1046 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1047 grep -q ^$poolname/ /proc/mounts ||
1048 $ZPOOL export $opts $poolname"
1053 # Destroy ZFS storage pool.
1054 # Destroy the given pool and free up any devices for other use. This command
1055 # tries to unmount any active datasets before destroying the pool.
1056 # -f Force any active datasets contained within the pool to be unmounted.
1060 local poolname=${2:-$(zpool_name $facet)}
1062 if [[ -n "$poolname" ]]; then
1063 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1064 $ZPOOL destroy -f $poolname"
1069 # Import ZFS storage pool.
1070 # Force importing, even if the pool appears to be potentially active.
1075 local opts=${@:-"-o cachefile=none"}
1078 poolname=$(zpool_name $facet)
1080 if [[ -n "$poolname" ]]; then
1081 opts+=" -d $(dirname $(facet_vdevice $facet))"
1082 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
1083 $ZPOOL import -f $opts $poolname"
1088 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1089 # is not automatically imported on system startup.
1091 # In a failover environment, this will provide resource level fencing which
1092 # will ensure that the same ZFS storage pool will not be imported concurrently
1093 # on different nodes.
1095 disable_zpool_cache() {
1099 poolname=$(zpool_name $facet)
1101 if [[ -n "$poolname" ]]; then
1102 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1107 # This and set_osd_param() shall be used to access OSD parameters
1108 # once existed under "obdfilter":
1113 # writethrough_cache_enable
1117 local device=${2:-$FSNAME-OST*}
1120 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1121 osd-*.$device.$name 2>&1" | grep -v 'Found no match'
1126 local device=${2:-$FSNAME-OST*}
1130 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1131 osd-*.$device.$name=$value 2>&1" | grep -v 'Found no match'
1135 local dz=${1:-$DEBUG_SIZE}
1137 if [ -f /sys/devices/system/cpu/possible ]; then
1138 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1140 local cpus=$(getconf _NPROCESSORS_CONF)
1143 # bug 19944, adjust size to be -gt num_possible_cpus()
1144 # promise 2MB for every cpu at least
1145 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1148 lctl set_param debug_mb=$dz
1151 set_default_debug () {
1152 local debug=${1:-"$PTLDEBUG"}
1153 local subsys=${2:-"$SUBSYSTEM"}
1154 local debug_size=${3:-$DEBUG_SIZE}
1156 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1157 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1159 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1162 set_default_debug_nodes () {
1165 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1166 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1170 do_rpc_nodes "$nodes" set_default_debug \
1171 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1174 set_default_debug_facet () {
1176 local node=$(facet_active_host $facet)
1177 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1179 set_default_debug_nodes $node
1184 local facets=${1:-$(get_facets)}
1187 for facet in ${facets//,/ }; do
1190 [ $RC -eq 0 ] && continue
1192 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1193 skip "Restart of $facet failed!." && touch $LU482_FAILED
1195 error "Restart of $facet failed!"
1202 # Add argument "arg" (e.g., "loop") to the comma-separated list
1203 # of arguments for option "opt" (e.g., "-o") on command
1204 # line "opts" (e.g., "-o flock").
1210 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1212 if echo "$opts" | grep -q $opt_pattern; then
1213 opts=$(echo "$opts" | sed -e \
1214 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1216 opts+="${opts:+ }$opt $arg"
1224 local dev=$(facet_active $facet)_dev
1225 local opt=${facet}_opt
1226 local mntpt=$(facet_mntpt $facet)
1227 local opts="${!opt} $@"
1229 if [ $(facet_fstype $facet) == ldiskfs ] &&
1230 ! do_facet $facet test -b ${!dev}; then
1231 opts=$(csa_add "$opts" -o loop)
1234 if [[ $(facet_fstype $facet) == zfs ]]; then
1235 # import ZFS storage pool
1236 import_zpool $facet || return ${PIPESTATUS[0]}
1239 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1240 # for testing LU-482 error handling in mount_facets() and test_0a()
1241 if [ -f $TMP/test-lu482-trigger ]; then
1244 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1249 if [ $RC -ne 0 ]; then
1250 echo "Start of ${!dev} on ${facet} failed ${RC}"
1254 set_default_debug_facet $facet
1256 if [[ $facet == mds* ]]; then
1258 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 2>/dev/null
1261 if [[ $opts =~ .*nosvc.* ]]; then
1262 echo "Start ${!dev} without service"
1264 local fstype=$(facet_fstype $facet)
1268 wait_update_facet ${facet} "$E2LABEL ${!dev} \
1269 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
1270 "" || error "${!dev} failed to initialize!";;
1272 wait_update_facet ${facet} "$ZFS get -H -o value \
1273 lustre:svname ${!dev} 2>/dev/null | \
1274 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
1275 error "${!dev} failed to initialize!";;
1278 error "unknown fstype!";;
1282 label=$(devicelabel ${facet} ${!dev})
1283 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1284 eval export ${facet}_svc=${label}
1285 echo Started ${label}
1290 # start facet device options
1296 eval export ${facet}_dev=${device}
1297 eval export ${facet}_opt=\"$@\"
1299 local varname=${facet}failover_dev
1300 if [ -n "${!varname}" ] ; then
1301 eval export ${facet}failover_dev=${!varname}
1303 eval export ${facet}failover_dev=$device
1306 local mntpt=$(facet_mntpt $facet)
1307 do_facet ${facet} mkdir -p $mntpt
1308 eval export ${facet}_MOUNT=$mntpt
1309 mount_facet ${facet}
1312 if [[ $facet == mds* ]]; then
1314 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1325 local HOST=`facet_active_host $facet`
1326 [ -z $HOST ] && echo stop: no host for $facet && return 0
1328 local mntpt=$(facet_mntpt $facet)
1329 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1330 if [ ${running} -ne 0 ]; then
1331 echo "Stopping $mntpt (opts:$@) on $HOST"
1332 do_facet ${facet} $UMOUNT $@ $mntpt
1335 # umount should block, but we should wait for unrelated obd's
1336 # like the MGS or MGC to also stop.
1337 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1339 if [[ $(facet_fstype $facet) == zfs ]]; then
1340 # export ZFS storage pool
1345 # save quota version (both administrative and operational quotas)
1346 # add an additional parameter if mountpoint is ever different from $MOUNT
1348 # XXX This function is kept for interoperability with old server (< 2.3.50),
1349 # it should be removed whenever we drop the interoperability for such
1351 quota_save_version() {
1352 local fsname=${2:-$FSNAME}
1354 local ver=$(tr -c -d "123" <<< $spec)
1355 local type=$(tr -c -d "ug" <<< $spec)
1357 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1359 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1361 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1363 local osts=$(get_facets OST)
1364 for ost in ${osts//,/ }; do
1366 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1370 # client could mount several lustre
1372 # XXX This function is kept for interoperability with old server (< 2.3.50),
1373 # it should be removed whenever we drop the interoperability for such
1376 local fsname=${1:-$FSNAME}
1378 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1380 do_nodes $(comma_list $(osts_nodes)) \
1381 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1385 # XXX This function is kept for interoperability with old server (< 2.3.50),
1386 # it should be removed whenever we drop the interoperability for such
1388 restore_quota_old() {
1389 local mntpt=${1:-$MOUNT}
1390 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
1391 if [ ! "$old_QUOTA_TYPE" ] ||
1392 [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
1395 quota_save_version $old_QUOTA_TYPE
1398 # XXX This function is kept for interoperability with old server (< 2.3.50),
1399 # it should be removed whenever we drop the interoperability for such
1404 # no quota enforcement for now and accounting works out of the box
1407 # We need save the original quota_type params, and restore them after testing
1409 # Suppose that quota type the same on mds and ost
1410 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
1411 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
1412 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
1413 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
1414 export old_QUOTA_TYPE=$quota_type
1415 quota_save_version $QUOTA_TYPE
1417 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
1418 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
1421 local quota_usrs=$QUOTA_USERS
1423 # get_filesystem_size
1424 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1425 local blk_soft=$((disksz + 1024))
1426 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1428 local Inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1429 local i_soft=$Inodes
1430 local i_hard=$((i_soft + i_soft / 20))
1432 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
1433 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
1436 for usr in $quota_usrs; do
1437 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1439 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1441 eval $cmd || error "$cmd FAILED!"
1443 # display the quota status
1444 echo "Quota settings for $usr : "
1445 $LFS quota -v -u $usr $mntpt || true
1449 # get mdt quota type
1451 local varsvc=${SINGLEMDS}_svc
1452 do_facet $SINGLEMDS $LCTL get_param -n \
1453 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1456 # get ost quota type
1458 # All OSTs should have same quota type
1459 local varsvc=ost1_svc
1460 do_facet ost1 $LCTL get_param -n \
1461 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1464 # restore old quota type settings
1466 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1471 if [ "$old_MDT_QUOTA_TYPE" ]; then
1472 do_facet mgs $LCTL conf_param \
1473 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1475 if [ "$old_OST_QUOTA_TYPE" ]; then
1476 do_facet mgs $LCTL conf_param \
1477 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1481 # Handle the case when there is a space in the lfs df
1482 # "filesystem summary" line the same as when there is no space.
1483 # This will allow fixing the "lfs df" summary line in the future.
1485 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1488 # Get free inodes on the MDT specified by mdt index, free indoes on
1489 # the whole filesystem will be returned when index == -1.
1495 if [ $index -eq -1 ]; then
1498 mdt_uuid=$(mdtuuid_from_index $index)
1501 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1506 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1513 # save old quota type & set new quota type
1514 local mdt_qtype=$(mdt_quota_type)
1515 local ost_qtype=$(ost_quota_type)
1517 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1518 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1520 export old_MDT_QUOTA_TYPE=$mdt_qtype
1521 export old_OST_QUOTA_TYPE=$ost_qtype
1523 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1524 error "set mdt quota type failed"
1525 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1526 error "set ost quota type failed"
1528 local quota_usrs=$QUOTA_USERS
1530 # get_filesystem_size
1531 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1532 local blk_soft=$((disksz + 1024))
1533 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1535 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1536 local i_soft=$inodes
1537 local i_hard=$((i_soft + i_soft / 20))
1539 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1540 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1541 "inode-hardlimit: $i_hard"
1544 for usr in $quota_usrs; do
1545 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1547 cmd="$LFS setquota -$type $usr -b $blk_soft"
1548 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1550 eval $cmd || error "$cmd FAILED!"
1552 # display the quota status
1553 echo "Quota settings for $usr : "
1554 $LFS quota -v -u $usr $mntpt || true
1561 local opts=${3:-$MOUNT_OPTS}
1562 opts=${opts:+-o $opts}
1563 local flags=${4:-$MOUNT_FLAGS}
1565 local device=$MGSNID:/$FSNAME
1566 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1567 echo Bad zconf mount command: opt=$flags $opts dev=$device mnt=$mnt
1571 echo "Starting client: $client: $flags $opts $device $mnt"
1572 do_node $client mkdir -p $mnt
1573 do_node $client $MOUNT_CMD $flags $opts $device $mnt || return 1
1575 set_default_debug_nodes $client
1587 [ "$3" ] && force=-f
1588 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1589 if [ $running -ne 0 ]; then
1590 echo "Stopping client $client $mnt (opts:$force)"
1591 do_node $client lsof -t $mnt || need_kill=no
1592 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1593 pids=$(do_node $client lsof -t $mnt | sort -u);
1594 if [ -n $pids ]; then
1595 do_node $client kill -9 $pids || true
1599 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1600 if [ $busy -ne 0 ] ; then
1601 echo "$mnt is still busy, wait one second" && sleep 1
1602 do_node $client umount $force $mnt
1607 # nodes is comma list
1608 sanity_mount_check_nodes () {
1614 # FIXME: assume that all cluster nodes run the same os
1615 [ "$(uname)" = Linux ] || return 0
1618 for mnt in $mnts ; do
1619 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1620 mpts=\\\$(mount | grep -c $mnt' ');
1621 if [ \\\$running -ne \\\$mpts ]; then
1622 echo \\\$(hostname) env are INSANE!;
1625 [ $? -eq 0 ] || rc=1
1630 sanity_mount_check_servers () {
1631 [ "$CLIENTONLY" ] &&
1632 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1633 echo Checking servers environments
1635 # FIXME: modify get_facets to display all facets wo params
1636 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1640 for facet in ${facets//,/ }; do
1641 node=$(facet_host ${facet})
1642 mntpt=$(facet_mntpt $facet)
1643 sanity_mount_check_nodes $node $mntpt ||
1644 { error "server $node environments are insane!"; return 1; }
1648 sanity_mount_check_clients () {
1649 local clients=${1:-$CLIENTS}
1650 local mntpt=${2:-$MOUNT}
1651 local mntpt2=${3:-$MOUNT2}
1653 [ -z $clients ] && clients=$(hostname)
1654 echo Checking clients $clients environments
1656 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1657 error "clients environments are insane!"
1660 sanity_mount_check () {
1661 sanity_mount_check_servers || return 1
1662 sanity_mount_check_clients || return 2
1665 # mount clients if not mouted
1666 zconf_mount_clients() {
1669 local opts=${3:-$MOUNT_OPTS}
1670 opts=${opts:+-o $opts}
1671 local flags=${4:-$MOUNT_FLAGS}
1673 local device=$MGSNID:/$FSNAME
1674 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1675 echo Bad zconf mount command: opt=$flags $opts dev=$device mnt=$mnt
1679 echo "Starting client $clients: $flags $opts $device $mnt"
1682 running=\\\$(mount | grep -c $mnt' ');
1684 if [ \\\$running -eq 0 ] ; then
1686 $MOUNT_CMD $flags $opts $device $mnt;
1689 exit \\\$rc" || return ${PIPESTATUS[0]}
1691 echo "Started clients $clients: "
1692 do_nodes $clients "mount | grep $mnt' '"
1694 set_default_debug_nodes $clients
1699 zconf_umount_clients() {
1704 [ "$3" ] && force=-f
1706 echo "Stopping clients: $clients $mnt (opts:$force)"
1707 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1708 if [ \\\$running -ne 0 ] ; then
1709 echo Stopping client \\\$(hostname) $mnt opts:$force;
1710 lsof $mnt || need_kill=no;
1711 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1712 pids=\\\$(lsof -t $mnt | sort -u);
1713 if [ -n \\\"\\\$pids\\\" ]; then
1717 while umount $force $mnt 2>&1 | grep -q "busy"; do
1718 echo "$mnt is still busy, wait one second" && sleep 1;
1725 echo + $POWER_DOWN $node
1729 shutdown_node_hard () {
1731 local attempts=$SHUTDOWN_ATTEMPTS
1733 for i in $(seq $attempts) ; do
1736 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1737 echo "waiting for $host to fail attempts=$attempts"
1738 [ $i -lt $attempts ] || \
1739 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1745 local mnt=${2:-$MOUNT}
1748 if [ "$FAILURE_MODE" = HARD ]; then
1749 shutdown_node_hard $client
1751 zconf_umount_clients $client $mnt -f
1757 local facets="$(get_facets OST),$(get_facets MDS)"
1760 combined_mgs_mds || facets="$facets,mgs"
1762 for facet in ${facets//,/ }; do
1763 if [ $(facet_active_host $facet) == $host ]; then
1764 affected="$affected $facet"
1768 echo $(comma_list $affected)
1773 local host=${2:-$(facet_host $facet)}
1775 local label=$(convert_facet2label $facet)
1776 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
1779 facets_up_on_host () {
1781 local facets=$(facets_on_host $host)
1784 for facet in ${facets//,/ }; do
1785 if $(facet_up $facet $host); then
1786 affected_up="$affected_up $facet"
1790 echo $(comma_list $affected_up)
1796 if [ "$FAILURE_MODE" = HARD ]; then
1797 shutdown_node_hard $(facet_active_host $facet)
1805 echo + $POWER_UP $node
1818 if [ "$FAILURE_MODE" = HARD ]; then
1819 reboot_node $(facet_active_host $facet)
1827 if [ "$FAILURE_MODE" = HARD ]; then
1837 for facet in ${facets//,/ }; do
1838 hosts=$(expand_list $hosts $(facet_host $facet) )
1844 _check_progs_installed () {
1848 for prog in $progs; do
1849 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1850 echo $prog missing on $(hostname)
1857 check_progs_installed () {
1861 do_rpc_nodes "$nodes" _check_progs_installed $@
1864 # recovery-scale functions
1866 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1869 start_client_load() {
1872 local var=$(node_var_name $client)_load
1873 eval export ${var}=$load
1875 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1876 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1877 END_RUN_FILE=$END_RUN_FILE \
1878 LOAD_PID_FILE=$LOAD_PID_FILE \
1879 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1880 TESTNAME=$TESTNAME \
1881 DBENCH_LIB=$DBENCH_LIB \
1882 DBENCH_SRC=$DBENCH_SRC \
1883 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1887 log "Started client load: ${load} on $client"
1889 # get the children process IDs
1890 local pids=$(ps --ppid $ppid -o pid= | xargs)
1891 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1895 start_client_loads () {
1896 local -a clients=(${1//,/ })
1897 local numloads=${#CLIENT_LOADS[@]}
1900 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1901 testnum=$((nodenum % numloads))
1902 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1904 # bug 22169: wait the background threads to start
1908 # only for remote client
1909 check_client_load () {
1911 local var=$(node_var_name $client)_load
1912 local TESTLOAD=run_${!var}.sh
1914 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1916 # bug 18914: try to connect several times not only when
1917 # check ps, but while check_catastrophe also
1920 while [ $RC = 254 -a $tries -gt 0 ]; do
1924 if ! check_catastrophe $client; then
1926 if [ $RC -eq 254 ]; then
1927 # FIXME: not sure how long we shuold sleep here
1931 echo "check catastrophe failed: RC=$RC "
1935 # We can continue try to connect if RC=254
1936 # Just print the warning about this
1937 if [ $RC = 254 ]; then
1938 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1941 # see if the load is still on the client
1944 while [ $RC = 254 -a $tries -gt 0 ]; do
1948 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1953 if [ $RC = 254 ]; then
1954 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1955 # see if we can diagnose a bit why this is
1960 check_client_loads () {
1961 local clients=${1//,/ }
1965 for client in $clients; do
1966 check_client_load $client
1968 if [ "$rc" != 0 ]; then
1969 log "Client load failed on node $client, rc=$rc"
1975 restart_client_loads () {
1976 local clients=${1//,/ }
1977 local expectedfail=${2:-""}
1981 for client in $clients; do
1982 check_client_load $client
1984 if [ "$rc" != 0 -a "$expectedfail" ]; then
1985 local var=$(node_var_name $client)_load
1986 start_client_load $client ${!var}
1987 echo "Restarted client load ${!var}: on $client. Checking ..."
1988 check_client_load $client
1990 if [ "$rc" != 0 ]; then
1991 log "Client load failed to restart on node $client, rc=$rc"
1992 # failure one client load means test fail
1993 # we do not need to check other
2002 # Start vmstat and save its process ID in a file.
2007 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2010 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
2011 2>/dev/null </dev/null & echo \\\$! > $pid_file"
2014 # Display the nodes on which client loads failed.
2015 print_end_run_file() {
2019 [ -s $file ] || return 0
2021 echo "Found the END_RUN_FILE file: $file"
2024 # A client load will stop if it finds the END_RUN_FILE file.
2025 # That does not mean the client load actually failed though.
2026 # The first node in END_RUN_FILE is the one we are interested in.
2029 if [ -n "$node" ]; then
2030 local var=$(node_var_name $node)_load
2032 local prefix=$TESTLOG_PREFIX
2033 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2034 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2035 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2037 echo "Client load ${!var} failed on node $node:"
2043 # Stop the process which had its PID saved in a file.
2048 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2050 do_nodes $nodes "test -f $pid_file &&
2051 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2054 # Stop all client loads.
2055 stop_client_loads() {
2056 local nodes=${1:-$CLIENTS}
2059 # stop the client loads
2060 stop_process $nodes $pid_file
2062 # clean up the processes that started them
2063 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
2065 # End recovery-scale functions
2067 # verify that lustre actually cleaned up properly
2069 VAR=$(lctl get_param -n catastrophe 2>&1)
2070 if [ $? = 0 ] ; then
2071 if [ $VAR != 0 ]; then
2072 error "LBUG/LASSERT detected"
2075 BUSY=$(dmesg | grep -i destruct || true)
2076 if [ -n "$BUSY" ]; then
2078 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2082 check_mem_leak || exit 204
2084 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2085 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2088 if module_loaded lnet || module_loaded libcfs; then
2089 echo "$TESTSUITE: modules still loaded..." 1>&2
2098 if [[ "$1" == "--verbose" ]]; then
2113 PREV_RESULT=$(do_node $node "$TEST")
2115 RESULT=$(do_node $node "$TEST")
2116 if [[ "$RESULT" == "$FINAL" ]]; then
2117 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2118 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2122 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2123 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2127 [[ $WAIT -ge $MAX ]] && break
2128 [[ $((WAIT % print)) -eq 0 ]] &&
2129 echo "Waiting $((MAX - WAIT)) secs for update"
2130 WAIT=$((WAIT + sleep))
2133 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2137 wait_update_facet() {
2140 wait_update $(facet_active_host $facet) "$@"
2144 do_nodes $(comma_list $(mdts_nodes)) \
2145 "lctl set_param -n osd*.*MDT*.force_sync 1"
2146 do_nodes $(comma_list $(osts_nodes)) \
2147 "lctl set_param -n osd*.*OS*.force_sync 1" 2>&1 |
2148 grep -v 'Found no match'
2151 wait_delete_completed_mds() {
2152 local MAX_WAIT=${1:-20}
2153 # for ZFS, waiting more time for DMUs to be committed
2154 local ZFS_WAIT=${2:-5}
2156 local stime=$(date +%s)
2161 # find MDS with pending deletions
2162 for node in $(mdts_nodes); do
2163 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2164 2>/dev/null | calc_sum)
2165 if [[ $changes -eq 0 ]]; then
2168 mds2sync="$mds2sync $node"
2170 if [ -z "$mds2sync" ]; then
2173 mds2sync=$(comma_list $mds2sync)
2175 # sync MDS transactions
2176 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2178 # wait till all changes are sent and commmitted by OSTs
2179 # for ldiskfs space is released upon execution, but DMU
2180 # do this upon commit
2183 while [[ $WAIT -ne $MAX_WAIT ]]; do
2184 changes=$(do_nodes $mds2sync \
2185 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2186 #echo "$node: $changes changes on all"
2187 if [[ $changes -eq 0 ]]; then
2189 #echo "delete took $((etime - stime)) seconds"
2191 # the occupied disk space will be released
2192 # only after DMUs are committed
2193 if [[ $(facet_fstype $SINGLEMDS) == zfs ]]; then
2194 echo "sleep $ZFS_WAIT for ZFS OSD"
2205 echo "Delete is not completed in $((etime - stime)) seconds"
2206 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2212 # we can use "for" here because we are waiting the slowest
2213 for host in ${hostlist//,/ }; do
2214 check_network "$host" 900
2216 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2223 for facet in ${facetlist//,/ }; do
2224 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2226 wait_for_host $hostlist
2229 _wait_recovery_complete () {
2232 # Use default policy if $2 is not passed by caller.
2233 local MAX=${2:-$(max_recovery_time)}
2238 while [ $WAIT -lt $MAX ]; do
2239 STATUS=$(lctl get_param -n $param | grep status)
2241 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2244 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2246 echo "$param recovery not done in $MAX sec. $STATUS"
2250 wait_recovery_complete () {
2253 # with an assumption that at_max is the same on all nodes
2254 local MAX=${2:-$(max_recovery_time)}
2257 if [ "$FAILURE_MODE" = HARD ]; then
2258 facets=$(facets_on_host $(facet_active_host $facet))
2260 echo affected facets: $facets
2262 # we can use "for" here because we are waiting the slowest
2263 for facet in ${facets//,/ }; do
2264 local var_svc=${facet}_svc
2265 local param="*.${!var_svc}.recovery_status"
2267 local host=$(facet_active_host $facet)
2268 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2272 wait_mds_ost_sync () {
2273 # just because recovery is done doesn't mean we've finished
2274 # orphan cleanup. Wait for llogs to get synchronized.
2275 echo "Waiting for orphan cleanup..."
2276 # MAX value includes time needed for MDS-OST reconnection
2277 local MAX=$(( TIMEOUT * 2 ))
2278 local WAIT_TIMEOUT=${1:-$MAX}
2281 local list=$(comma_list $(mdts_nodes))
2282 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2283 if ! do_facet $SINGLEMDS \
2284 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2286 # old way, use mds_sync
2288 list=$(comma_list $(osts_nodes))
2289 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2292 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2293 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2294 local -a sync=($(do_nodes $list "$cmd"))
2297 for ((i=0; i<${#sync[@]}; i++)); do
2299 [ ${sync[$i]} -eq 1 ] && continue
2301 [ ${sync[$i]} -eq 0 ] && continue
2303 # there is a not finished MDS-OST synchronization
2307 sleep 2 # increase waiting time and cover statfs cache
2308 [ ${con} -eq 1 ] && return 0
2309 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2313 # show which nodes are not finished.
2314 do_nodes $list "$cmd"
2315 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2319 wait_destroy_complete () {
2320 echo "Waiting for local destroys to complete"
2321 # MAX value shouldn't be big as this mean server responsiveness
2322 # never increase this just to make test pass but investigate
2323 # why it takes so long time
2326 while [ $WAIT -lt $MAX ]; do
2327 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2331 for ((i=0; i<${#RPCs[@]}; i++)); do
2332 [ ${RPCs[$i]} -eq 0 ] && continue
2333 # there are still some destroy RPCs in flight
2338 [ ${con} -eq 1 ] && return 0 # done waiting
2339 echo "Waiting ${WAIT}s for local destroys to complete"
2342 echo "Local destroys weren't done in $MAX sec."
2346 wait_delete_completed() {
2347 wait_delete_completed_mds $1 || return $?
2348 wait_destroy_complete
2357 # conf-sanity 31 takes a long time cleanup
2358 while [ $WAIT -lt 300 ]; do
2359 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2360 [ -z "${running}" ] && return 0
2361 echo "waited $WAIT for${running}"
2362 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2364 WAIT=$((WAIT + INTERVAL))
2366 echo "service didn't stop after $WAIT seconds. Still running:"
2371 wait_remote_prog () {
2377 [ "$PDSH" = "no_dsh" ] && return 0
2379 while [ $WAIT -lt $2 ]; do
2380 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2381 [ -z "${running}" ] && return 0 || true
2382 echo "waited $WAIT for: "
2384 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2386 WAIT=$((WAIT + INTERVAL))
2388 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2389 [ -z "$pids" ] && return 0
2390 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2391 # FIXME: not portable
2392 for pid in $pids; do
2393 cat /proc/${pid}/status || true
2394 cat /proc/${pid}/wchan || true
2396 kill -9 $pid || true
2405 # not every config has many clients
2407 if [ ! -z "$CLIENTS" ]; then
2408 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
2410 stat -f $MOUNT > /dev/null
2416 # usually checked on particular client or locally
2418 if [ ! -z "$client" ]; then
2419 $PDSH $client "stat -f $MOUNT" > /dev/null
2421 stat -f $MOUNT > /dev/null
2429 client_reconnect_try() {
2430 uname -n >> $MOUNT/recon
2431 if [ -z "$CLIENTS" ]; then
2432 df $MOUNT; uname -n >> $MOUNT/recon
2434 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
2436 echo Connected clients:
2438 ls -l $MOUNT/recon > /dev/null
2442 client_reconnect() {
2443 # one client_reconnect_try call does not always do the job...
2445 client_reconnect_try && break
2450 affected_facets () {
2453 local host=$(facet_active_host $facet)
2454 local affected=$facet
2456 if [ "$FAILURE_MODE" = HARD ]; then
2457 affected=$(facets_up_on_host $host)
2471 #Because it will only get up facets, we need get affected
2472 #facets before shutdown
2473 #For HARD Failure mode, it needs make sure facets on the same
2474 #HOST will only be shutdown and reboot once
2475 for facet in ${facets//,/ }; do
2476 local affected_facet
2478 #check whether facet has been included in other affected facets
2479 for ((index=0; index<$total; index++)); do
2480 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2483 if [ $skip -eq 0 ]; then
2484 affecteds[$total]=$(affected_facets $facet)
2489 for ((index=0; index<$total; index++)); do
2490 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2491 local host=$(facet_active_host $facet)
2492 echo "Failing ${affecteds[index]} on $host"
2493 shutdown_facet $facet
2496 for ((index=0; index<$total; index++)); do
2497 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2498 echo reboot facets: ${affecteds[index]}
2502 change_active ${affecteds[index]}
2504 wait_for_facet ${affecteds[index]}
2505 # start mgs first if it is affected
2506 if ! combined_mgs_mds &&
2507 list_member ${affecteds[index]} mgs; then
2508 mount_facet mgs || error "Restart of mgs failed"
2510 # FIXME; has to be changed to mount all facets concurrently
2511 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2512 echo mount facets: ${affecteds[index]}
2513 mount_facets ${affecteds[index]}
2523 do_facet $facet "sync; sync; sync"
2526 # make sure there will be no seq change
2527 local clients=${CLIENTS:-$HOSTNAME}
2528 local f=fsa-\\\$\(hostname\)
2529 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2530 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2532 local svc=${facet}_svc
2533 do_facet $facet $LCTL --device ${!svc} notransno
2535 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2536 # in-memory state has to be cleared by either rebooting the host or
2537 # exporting and reimporting the pool.
2539 # Although the uberblocks are not updated when a pool is freezed,
2540 # transactions are still written to the disks. Modified blocks may be
2541 # cached in memory when tests try reading them back. The
2542 # export-and-reimport process also evicts any cached pool data from
2543 # memory to provide the correct "data loss" semantics.
2545 # In the test framework, the exporting and importing operations are
2546 # handled by stop() and mount_facet() separately, which are used
2547 # inside fail() and fail_abort().
2549 do_facet $facet $LCTL --device ${!svc} readonly
2550 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2551 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2554 replay_barrier_nodf() {
2555 local facet=$1 echo running=${running}
2556 do_facet $facet "sync; sync; sync"
2557 local svc=${facet}_svc
2558 echo Replay barrier on ${!svc}
2559 do_facet $facet $LCTL --device ${!svc} notransno
2560 do_facet $facet $LCTL --device ${!svc} readonly
2561 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2562 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2565 replay_barrier_nosync() {
2566 local facet=$1 echo running=${running}
2567 local svc=${facet}_svc
2568 echo Replay barrier on ${!svc}
2569 do_facet $facet $LCTL --device ${!svc} notransno
2570 do_facet $facet $LCTL --device ${!svc} readonly
2571 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2572 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2576 # Get Lustre client uuid for a given Lustre mount point.
2579 local mntpnt=${1:-$MOUNT}
2581 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2582 local uuid=$($LCTL get_param -n llite.$name.uuid)
2587 mds_evict_client() {
2588 local mntpnt=${1:-$MOUNT}
2589 local uuid=$(get_client_uuid $mntpnt)
2591 do_facet $SINGLEMDS \
2592 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2595 ost_evict_client() {
2596 local mntpnt=${1:-$MOUNT}
2597 local uuid=$(get_client_uuid $mntpnt)
2600 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2605 local clients=${CLIENTS:-$HOSTNAME}
2607 facet_failover $* || error "failover: $?"
2608 wait_clients_import_state "$clients" "$facets" FULL
2609 clients_up || error "post-failover df: $?"
2614 facet_failover $facet
2620 change_active $facet
2621 wait_for_facet $facet
2622 mount_facet $facet -o abort_recovery
2623 clients_up || echo "first df failed: $?"
2624 clients_up || error "post-failover df: $?"
2628 echo There is no lmc. This is mountconf, baby.
2632 host_nids_address() {
2636 if [ -n "$kind" ]; then
2637 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2639 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2645 if [ "$1" = "'*'" ]; then echo \'*\'; else
2651 if [ "$1" = "'*'" ]; then echo \'*\'; else
2652 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2654 if [ -z "$ID" ]; then
2655 echo "Could not get a ptl id for $1..."
2664 h2name_or_ip "$1" "tcp"
2669 if [ "$1" = "'*'" ]; then echo \'*\'; else
2670 if type __h2elan >/dev/null 2>&1; then
2673 ID=`echo $1 | sed 's/[^0-9]*//g'`
2681 h2name_or_ip "$1" "o2ib"
2685 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2686 # expressions format. As a bonus we can then just pass in those variables
2687 # to pdsh. What this function does is take a HOSTLIST type string and
2688 # expand it into a space deliminated list for us.
2696 [ -z "$hostlist" ] && return
2698 # Translate the case of [..],..,[..] to [..] .. [..]
2699 list="${hostlist/],/] }"
2701 [[ "$front" == *,* ]] && {
2704 list=${list/${old}/${new}}
2707 for item in $list; do
2708 # Test if we have any []'s at all
2709 if [ "$item" != "${item/\[/}" ]; then {
2710 # Expand the [*] into list
2714 if [ "$name" != "$item" ]; then
2715 group=${item#$name[*}
2718 for range in ${group//,/ }; do
2722 # Number of leading zeros
2725 end=$(echo $end | sed 's/0*//')
2726 [[ -z "$end" ]] && end=0
2727 [[ $padlen2 -gt $padlen ]] && {
2728 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2731 begin=$(echo $begin | sed 's/0*//')
2732 [ -z $begin ] && begin=0
2734 for num in $(seq -f "%0${padlen}g" $begin $end); do
2735 value="${name#*,}${num}${back}"
2736 [ "$value" != "${value/\[/}" ] && {
2737 value=$(hostlist_expand "$value")
2739 myList="$myList $value"
2744 myList="$myList $item"
2747 myList=${myList//,/ }
2748 myList=${myList:1} # Remove first character which is a space
2750 # Filter any duplicates without sorting
2752 myList="${list%% *}"
2754 while [[ "$list" != ${myList##* } ]]; do
2755 list=${list//${list%% *} /}
2756 myList="$myList ${list%% *}"
2758 myList="${myList%* }";
2760 # We can select an object at an offset in the list
2763 for item in $myList; do
2765 [ $cnt -eq $offset ] && {
2769 [ $(get_node_count $myList) -ne 1 ] && myList=""
2778 [ "$facet" == client ] && echo -n $HOSTNAME && return
2779 varname=${facet}_HOST
2780 if [ -z "${!varname}" ]; then
2781 if [ "${facet:0:3}" == "ost" ]; then
2782 local fh=${facet%failover}_HOST
2783 eval export ${facet}_HOST=${!fh}
2784 if [ -z "${!varname}" ]; then
2785 eval export ${facet}_HOST=${ost_HOST}
2787 elif [ "${facet:0:3}" == "mdt" -o \
2788 "${facet:0:3}" == "mds" -o \
2789 "${facet:0:3}" == "mgs" ]; then
2790 eval export ${facet}_HOST=${mds_HOST}
2796 facet_failover_host() {
2800 var=${facet}failover_HOST
2801 if [ -n "${!var}" ]; then
2806 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2807 "${facet:0:3}" == "mgs" ]; then
2809 eval export ${facet}failover_host=${mds_HOST}
2814 if [[ $facet == ost* ]]; then
2815 eval export ${facet}failover_host=${ost_HOST}
2823 local activevar=${facet}active
2825 if [ -f $TMP/${facet}active ] ; then
2826 source $TMP/${facet}active
2829 active=${!activevar}
2830 if [ -z "$active" ] ; then
2837 facet_active_host() {
2838 facet_host $(facet_active $1)
2841 # Get the passive failover partner host of facet.
2842 facet_passive_host() {
2844 [[ $facet = client ]] && return
2846 local host=${facet}_HOST
2847 local failover_host=${facet}failover_HOST
2848 local active_host=$(facet_active_host $facet)
2850 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2852 if [[ $active_host = ${!host} ]]; then
2853 echo -n ${!failover_host}
2863 facetlist=$(exclude_items_from_list $facetlist mgs)
2865 for facet in ${facetlist//,/ }; do
2866 local failover=${facet}failover
2867 local host=`facet_host $failover`
2868 [ -z "$host" ] && return
2870 local curactive=`facet_active $facet`
2871 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2872 eval export ${facet}active=$facet
2874 eval export ${facet}active=$failover
2876 # save the active host for this facet
2877 local activevar=${facet}active
2878 echo "$activevar=${!activevar}" > $TMP/$activevar
2879 [[ $facet = mds1 ]] && combined_mgs_mds && \
2880 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2881 local TO=`facet_active_host $facet`
2882 echo "Failover $facet to $TO"
2888 # do not stripe off hostname if verbose, bug 19215
2889 if [ x$1 = x--verbose ]; then
2897 if [ "$HOST" = "$HOSTNAME" ]; then
2899 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2900 echo "cannot run remote command on $HOST with $myPDSH"
2904 echo "CMD: $HOST $@" >&2
2905 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2908 if [ "$myPDSH" = "rsh" ]; then
2909 # we need this because rsh does not return exit code of an executed command
2910 local command_status="$TMP/cs"
2911 rsh $HOST ":> $command_status"
2912 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2913 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2914 echo command failed >$command_status"
2915 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2920 # print HOSTNAME for myPDSH="no_dsh"
2921 if [[ $myPDSH = no_dsh ]]; then
2922 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2924 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2927 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2929 return ${PIPESTATUS[0]}
2933 do_node --verbose "$@"
2936 single_local_node () {
2937 [ "$1" = "$HOSTNAME" ]
2940 # Outputs environment variable assignments that should be passed to remote nodes
2944 local facets=$(get_facets)
2947 for var in ${!MODOPTS_*}; do
2948 value=${!var//\"/\\\"}
2949 echo -n " ${var}=\"$value\""
2952 for facet in ${facets//,/ }; do
2954 if [ -n "${!var}" ]; then
2955 echo -n " $var=${!var}"
2959 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2960 if [ -n "${!var}" ]; then
2961 echo -n " $var=${!var}"
2965 for var in VERBOSE; do
2966 if [ -n "${!var}" ]; then
2967 echo -n " $var=${!var}"
2971 if [ -n "$FSTYPE" ]; then
2972 echo -n " FSTYPE=$FSTYPE"
2975 for var in LNETLND NETTYPE; do
2976 if [ -n "${!var}" ]; then
2977 echo -n " $var=${!var}"
2984 # do not stripe off hostname if verbose, bug 19215
2985 if [ x$1 = x--verbose ]; then
2993 if single_local_node $rnodes; then
2995 do_nodev $rnodes "$@"
2997 do_node $rnodes "$@"
3002 # This is part from do_node
3005 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
3006 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
3008 export FANOUT=$(get_node_count "${rnodes//,/ }")
3010 echo "CMD: $rnodes $@" >&2
3011 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
3014 # do not replace anything from pdsh output if -N is used
3015 # -N Disable hostname: prefix on lines of output.
3016 if $verbose || [[ $myPDSH = *-N* ]]; then
3017 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
3019 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
3021 return ${PIPESTATUS[0]}
3025 # Execute commands on a single service's host
3027 # The \a facet (service) may be on a local or remote node, which is
3028 # determined at the time the command is run.
3030 # usage: do_facet $facet command [arg ...]
3034 local HOST=$(facet_active_host $facet)
3035 [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
3039 # Function: do_facet_random_file $FACET $FILE $SIZE
3040 # Creates FILE with random content on the given FACET of given SIZE
3042 do_facet_random_file() {
3046 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
3047 do_facet $facet "$cmd 2>/dev/null"
3050 do_facet_create_file() {
3054 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
3055 do_facet $facet "$cmd 2>/dev/null"
3059 do_nodes --verbose "$@"
3065 # make sure its not already running
3067 rm -f $TMP/${facet}active
3068 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
3069 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
3071 if [[ $(facet_fstype $facet) == zfs ]]; then
3073 # After formatting a ZFS target, "cachefile=none" property will
3074 # be set on the ZFS storage pool so that the pool is not
3075 # automatically imported on system startup. And then the pool
3076 # will be exported so as to leave the importing and exporting
3077 # operations handled by mount_facet() and stop() separately.
3079 refresh_partition_table $facet $(facet_vdevice $facet)
3080 disable_zpool_cache $facet
3085 # Device formatted as ost
3088 local DEVNAME=OSTDEV$num
3090 local fstype=$(facet_fstype ost$num)
3094 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
3095 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3097 #try $OSTZFSDEVn - independent of vdev
3098 DEVNAME=OSTZFSDEV$num
3099 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
3101 error "unknown fstype!";;
3107 # Physical device location of data
3113 local fstype=$(facet_fstype ost$num)
3117 # vdevs are not supported by ldiskfs
3120 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3121 # Device formatted by zfs
3123 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3125 error "unknown fstype!";;
3131 # Logical device formatted for lustre
3134 local DEVNAME=MDSDEV$num
3136 local fstype=$(facet_fstype mds$num)
3140 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3141 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3143 # try $MDSZFSDEVn - independent of vdev
3144 DEVNAME=MDSZFSDEV$num
3145 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3147 error "unknown fstype!";;
3153 # Physical location of data
3157 local fstype=$(facet_fstype mds$num)
3161 # vdevs are not supported by ldiskfs
3164 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3165 # Device formatted by ZFS
3166 local DEVNAME=MDSDEV$num
3167 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3169 error "unknown fstype!";;
3177 local fstype=$(facet_fstype mgs)
3181 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3182 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3183 DEVPTR=$(mdsdevname 1)
3188 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3189 ( [ -z "$MGSZFSDEV" ] &&
3190 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3191 DEVPTR=$(mdsdevname 1)
3193 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3196 error "unknown fstype!";;
3205 local fstype=$(facet_fstype mgs)
3209 # vdevs are not supported by ldiskfs
3212 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3213 ( [ -z "$MGSDEV" ] &&
3214 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3215 VDEVPTR=$(mdsvdevname 1)
3216 elif [ -n "$MGSDEV" ]; then
3220 error "unknown fstype!";;
3228 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3230 local var=${facet}_MOUNT
3231 eval mntpt=${!var:-${MOUNT%/*}/$facet}
3238 local dev=$(facet_device $facet)
3239 local mnt=$(facet_mntpt $facet)
3242 if ! do_facet $facet test -b $dev; then
3245 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3250 local dev=$(facet_device $facet)
3251 local mnt=$(facet_mntpt $facet)
3253 do_facet $facet $UMOUNT $mnt
3257 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3262 local ds=$(facet_device $facet)
3263 local mnt=$(facet_mntpt $facet)
3268 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3269 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3270 do_facet $facet $ZFS set canmount=noauto $ds
3272 # The "legacy" mount method is used here because "zfs unmount $mnt"
3273 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3274 # targets are not available at the time, the stat(2) on $MOUNT will
3277 do_facet $facet $ZFS set mountpoint=legacy $ds
3278 do_facet $facet mount -t zfs $ds $mnt
3279 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3280 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3285 local ds=$(facet_device $facet)
3286 local mnt=$(facet_mntpt $facet)
3287 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3288 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3289 local mntpt=${!var_mntpt}
3290 local canmnt=${!var_canmnt}
3294 do_facet $facet umount $mnt
3295 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3296 do_facet $facet $ZFS set canmount=$canmnt $ds
3302 local fstype=$(facet_fstype $facet)
3304 mount_$fstype $facet
3309 local fstype=$(facet_fstype $facet)
3311 unmount_$fstype $facet
3318 # make sure we are using the primary server, so test-framework will
3319 # be able to clean up properly.
3320 activemds=`facet_active mds1`
3321 if [ $activemds != "mds1" ]; then
3325 local clients=$CLIENTS
3326 [ -z $clients ] && clients=$(hostname)
3328 zconf_umount_clients $clients $MOUNT "$*" || true
3329 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3331 [ "$CLIENTONLY" ] && return
3332 # The add fn does rm ${facet}active file, this would be enough
3333 # if we use do_facet <facet> only after the facet added, but
3334 # currently we use do_facet mds in local.sh
3335 for num in `seq $MDSCOUNT`; do
3337 rm -f ${TMP}/mds${num}active
3339 combined_mgs_mds && rm -f $TMP/mgsactive
3341 for num in `seq $OSTCOUNT`; do
3343 rm -f $TMP/ost${num}active
3346 if ! combined_mgs_mds ; then
3353 cleanup_echo_devs () {
3354 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3356 for dev in $devs; do
3357 $LCTL --device $dev cleanup
3358 $LCTL --device $dev detach
3363 nfs_client_mode && return
3364 cifs_client_mode && return
3373 combined_mgs_mds () {
3374 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3375 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3379 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3383 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3389 local fsname=${3:-"$FSNAME"}
3390 local type=$(facet_type $facet)
3391 local index=$(facet_index $facet)
3392 local fstype=$(facet_fstype $facet)
3393 local host=$(facet_host $facet)
3398 if [ $type == MGS ] || ( [ $type == MDS ] &&
3399 [ "$dev" == $(mgsdevname) ] &&
3400 [ "$host" == "$(facet_host mgs)" ] ); then
3403 opts="--mgsnode=$MGSNID"
3406 if [ $type != MGS ]; then
3407 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3411 var=${facet}failover_HOST
3412 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3413 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3416 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3417 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3419 if [ $type == MDS ]; then
3420 opts+=${SECLEVEL:+" --param=mdt.sec_level"}
3421 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3422 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3423 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3424 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3426 if [ $fstype == ldiskfs ]; then
3427 # Check for wide striping
3428 if [ $OSTCOUNT -gt 160 ]; then
3429 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3430 fs_mkfs_opts+="-O large_xattr"
3434 if [ -n "${!var}" ]; then
3435 fs_mkfs_opts+=" -J device=${!var}"
3437 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3439 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3443 if [ $type == OST ]; then
3444 opts+=${SECLEVEL:+" --param=ost.sec_level"}
3445 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3447 if [ $fstype == ldiskfs ]; then
3449 if [ -n "${!var}" ]; then
3450 fs_mkfs_opts+=" -J device=${!var}"
3452 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3457 opts+=" --backfstype=$fstype"
3460 if [ -n "${!var}" ]; then
3461 opts+=" --device-size=${!var}"
3464 var=$(upper $fstype)_MKFS_OPTS
3465 fs_mkfs_opts+=${!var:+" ${!var}"}
3467 var=${type}_FS_MKFS_OPTS
3468 fs_mkfs_opts+=${!var:+" ${!var}"}
3470 if [ -n "${fs_mkfs_opts## }" ]; then
3471 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3475 opts+=${!var:+" ${!var}"}
3480 check_ost_indices() {
3481 local index_count=${#OST_INDICES[@]}
3482 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
3484 # OST count is greater than the index count in $OST_INDEX_LIST.
3485 # We need check whether there are duplicate indices.
3489 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
3490 index=$(facet_index ost$i)
3491 for j in $(seq 0 $((index_count - 1))); do
3492 [[ $index -ne ${OST_INDICES[j]} ]] ||
3493 error "ost$i has the same index $index as ost$((j+1))"
3504 echo "Format mgs: $(mgsdevname)"
3505 reformat_external_journal mgs
3506 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3507 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
3517 echo "Format mds$num: $(mdsdevname $num)"
3518 reformat_external_journal mds$num
3519 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3520 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3521 ${quiet:+>/dev/null} || exit 10
3530 echo "Format ost$num: $(ostdevname $num)"
3531 reformat_external_journal ost$num
3532 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3533 --reformat $(ostdevname $num) $(ostvdevname ${num}) \
3534 ${quiet:+>/dev/null} || exit 10
3539 # We need ldiskfs here, may as well load them all
3541 [ "$CLIENTONLY" ] && return
3542 echo Formatting mgs, mds, osts
3543 if ! combined_mgs_mds ; then
3547 for num in $(seq $MDSCOUNT); do
3551 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
3553 for num in $(seq $OSTCOUNT); do
3559 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3563 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3567 # 0: success, the old identity set already.
3568 # 1: success, the old identity does not set.
3573 local j=`expr $num - 1`
3574 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3576 if [ -z "$MDT" ]; then
3580 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3583 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3585 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3588 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3590 if [ $old = "NONE" ]; then
3599 zconf_umount `hostname` $1 || error "umount failed"
3600 zconf_mount `hostname` $1 || error "mount failed"
3608 rm -f $TMP/${facet}active
3609 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3614 local mdt_count=${1:-$MDSCOUNT}
3615 local ost_count=${2:-$OSTCOUNT}
3618 for num in $(seq $mdt_count); do
3619 DEVNAME=$(mdsdevname $num)
3620 writeconf_facet mds$num $DEVNAME || rc=$?
3623 for num in $(seq $ost_count); do
3624 DEVNAME=$(ostdevname $num)
3625 writeconf_facet ost$num $DEVNAME || rc=$?
3631 nfs_client_mode && return
3632 cifs_client_mode && return
3634 sanity_mount_check ||
3635 error "environments are insane!"
3639 if [ -z "$CLIENTONLY" ]; then
3640 echo Setup mgs, mdt, osts
3641 echo $WRITECONF | grep -q "writeconf" && \
3643 if ! combined_mgs_mds ; then
3644 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3647 for num in `seq $MDSCOUNT`; do
3648 DEVNAME=$(mdsdevname $num)
3649 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3651 # We started mds, now we should set failover variables properly.
3652 # Set mds${num}failover_HOST if it is not set (the default failnode).
3653 local varname=mds${num}failover_HOST
3654 if [ -z "${!varname}" ]; then
3655 eval mds${num}failover_HOST=$(facet_host mds$num)
3658 if [ $IDENTITY_UPCALL != "default" ]; then
3659 switch_identity $num $IDENTITY_UPCALL
3662 for num in `seq $OSTCOUNT`; do
3663 DEVNAME=$(ostdevname $num)
3664 start ost$num $DEVNAME $OST_MOUNT_OPTS
3666 # We started ost$num, now we should set ost${num}failover variable properly.
3667 # Set ost${num}failover_HOST if it is not set (the default failnode).
3668 varname=ost${num}failover_HOST
3669 if [ -z "${!varname}" ]; then
3670 eval ost${num}failover_HOST=$(facet_host ost${num})
3678 # wait a while to allow sptlrpc configuration be propogated to targets,
3679 # only needed when mounting new target devices.
3684 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3686 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3689 if [ "$MOUNT_2" ]; then
3690 mount_client $MOUNT2
3691 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3696 # by remounting mdt before ost, initial connect from mdt to ost might
3697 # timeout because ost is not ready yet. wait some time to its fully
3698 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3699 # by a context negotiation rpc with $TIMEOUT.
3700 # FIXME better by monitoring import status.
3703 sleep $((TIMEOUT + 5))
3709 mounted_lustre_filesystems() {
3710 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3713 init_facet_vars () {
3714 [ "$CLIENTONLY" ] && return 0
3721 eval export ${facet}_dev=${device}
3722 eval export ${facet}_opt=\"$@\"
3724 local dev=${facet}_dev
3726 # We need to loop for the label
3727 # in case its not initialized yet.
3728 for wait_time in {0,1,3,5,10}; do
3730 if [ $wait_time -gt 0 ]; then
3731 echo "${!dev} not yet initialized,"\
3732 "waiting ${wait_time} seconds."
3736 local label=$(devicelabel ${facet} ${!dev})
3738 # Check to make sure the label does
3739 # not include ffff at the end of the label.
3740 # This indicates it has not been initialized yet.
3742 if [[ $label =~ [f|F]{4}$ ]]; then
3743 # label is not initialized, unset the result
3744 # and either try again or fail
3751 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3753 eval export ${facet}_svc=${label}
3755 local varname=${facet}failover_HOST
3756 if [ -z "${!varname}" ]; then
3757 eval export $varname=$(facet_host $facet)
3760 varname=${facet}_HOST
3761 if [ -z "${!varname}" ]; then
3762 eval export $varname=$(facet_host $facet)
3765 # ${facet}failover_dev is set in cfg file
3766 varname=${facet}failover_dev
3767 if [ -n "${!varname}" ] ; then
3768 eval export ${facet}failover_dev=${!varname}
3770 eval export ${facet}failover_dev=$device
3773 # get mount point of already mounted device
3774 # is facet_dev is already mounted then use the real
3775 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3776 # i.e. ${facet}_MOUNT if specified by user or default
3777 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3778 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3779 if [ -z $mntpt ]; then
3780 mntpt=$(facet_mntpt $facet)
3782 eval export ${facet}_MOUNT=$mntpt
3785 init_facets_vars () {
3788 if ! remote_mds_nodsh; then
3789 for num in $(seq $MDSCOUNT); do
3790 DEVNAME=`mdsdevname $num`
3791 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3795 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3797 if ! remote_ost_nodsh; then
3798 for num in $(seq $OSTCOUNT); do
3799 DEVNAME=$(ostdevname $num)
3800 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3805 osc_ensure_active () {
3810 while [ $period -lt $timeout ]; do
3811 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3812 if [ $count -eq 0 ]; then
3816 echo "There are $count OST are inactive, wait $period seconds, and try again"
3818 period=$((period+3))
3821 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3824 set_conf_param_and_check() {
3828 local ORIG=$(do_facet $myfacet "$TEST")
3829 if [ $# -gt 3 ]; then
3835 echo "Setting $PARAM from $ORIG to $FINAL"
3836 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3837 error "conf_param $PARAM failed"
3839 wait_update $(facet_host $myfacet) "$TEST" "$FINAL" ||
3840 error "check $PARAM failed!"
3843 init_param_vars () {
3845 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3847 log "Using TIMEOUT=$TIMEOUT"
3849 osc_ensure_active $SINGLEMDS $TIMEOUT
3850 osc_ensure_active client $TIMEOUT
3852 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
3853 local current_jobid_var=$($LCTL get_param -n jobid_var)
3855 if [ $JOBID_VAR = "existing" ]; then
3856 echo "keeping jobstats as $current_jobid_var"
3857 elif [ $current_jobid_var != $JOBID_VAR ]; then
3858 echo "seting jobstats to $JOBID_VAR"
3860 set_conf_param_and_check client \
3861 "$LCTL get_param -n jobid_var" \
3862 "$FSNAME.sys.jobid_var" $JOBID_VAR
3865 echo "jobstats not supported by server"
3868 if [ $QUOTA_AUTO -ne 0 ]; then
3869 if [ "$ENABLE_QUOTA" ]; then
3870 echo "enable quota as required"
3871 setup_quota $MOUNT || return 2
3873 echo "disable quota as required"
3874 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
3880 nfs_client_mode () {
3881 if [ "$NFSCLIENT" ]; then
3882 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
3883 local clients=$CLIENTS
3884 [ -z $clients ] && clients=$(hostname)
3886 # FIXME: remove hostname when 19215 fixed
3887 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
3888 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
3889 if [[ ${#nfsexport[@]} -eq 0 ]]; then
3890 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
3892 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
3898 cifs_client_mode () {
3899 [ x$CIFSCLIENT = xyes ] &&
3900 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
3903 check_config_client () {
3906 local mounted=$(mount | grep " $mntpt ")
3907 if [ "$CLIENTONLY" ]; then
3909 # CLIENTONLY should not depend on *_HOST settings
3910 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
3911 # in theory someone could create a new,
3912 # client-only config file that assumed lustre was already
3913 # configured and didn't set the MGSNID. If MGSNID is not set,
3914 # then we should use the mgs nid currently being used
3915 # as the default value. bug 18021
3916 [[ x$MGSNID = x ]] &&
3919 if [[ x$mgc != xMGC$MGSNID ]]; then
3920 if [ "$mgs_HOST" ]; then
3921 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
3922 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
3923 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
3929 local myMGS_host=$mgs_HOST
3930 if [ "$NETTYPE" = "ptl" ]; then
3931 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
3934 echo Checking config lustre mounted on $mntpt
3935 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
3936 mgshost=$(echo $mgshost | awk -F: '{print $1}')
3938 # if [ "$mgshost" != "$myMGS_host" ]; then
3939 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
3940 # Please use correct config or set mds_HOST correctly!"
3945 check_config_clients () {
3946 local clients=${CLIENTS:-$HOSTNAME}
3949 nfs_client_mode && return
3950 cifs_client_mode && return
3952 do_rpc_nodes "$clients" check_config_client $mntpt
3954 sanity_mount_check || error "environments are insane!"
3958 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3959 local cltimeout=$(lctl get_param -n timeout)
3960 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
3961 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
3968 [ -z $mntpt ] && return 1
3969 local mounted=$(mounted_lustre_filesystems)
3971 echo $mounted' ' | grep -w -q $mntpt' '
3975 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
3979 # empty lustre filesystem may have empty directories lost+found and .lustre
3981 # exclude .lustre & lost+found
3982 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
3983 -print | wc -l) = 1 ] || return 1
3984 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
3985 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
3986 # exclude .lustre/fid (LU-2780)
3987 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
3988 -print | wc -l) = 1 ] || return 1
3990 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
3995 check_and_setup_lustre() {
3996 nfs_client_mode && return
3997 cifs_client_mode && return
3999 local MOUNTED=$(mounted_lustre_filesystems)
4003 # both MOUNT and MOUNT2 are not mounted
4004 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
4005 [ "$REFORMAT" ] && formatall
4006 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
4008 is_mounted $MOUNT || error "NAME=$NAME not mounted"
4009 export I_MOUNTED=yes
4013 elif is_mounted $MOUNT2; then
4015 # MOUNT2 is mounted, while MOUNT_2 is not set
4016 if ! [ "$MOUNT_2" ]; then
4017 cleanup_mount $MOUNT2
4018 export I_UMOUNTED2=yes
4021 # MOUNT2 is mounted, MOUNT_2 is set
4023 # FIXME: what to do if check_config failed?
4025 # 1) remote client has mounted other Lustre fs ?
4026 # 2) it has insane env ?
4027 # let's try umount MOUNT2 on all clients and mount it again:
4028 if ! check_config_clients $MOUNT2; then
4029 cleanup_mount $MOUNT2
4030 restore_mount $MOUNT2
4031 export I_MOUNTED2=yes
4036 # MOUNT is mounted MOUNT2 is not mounted
4037 elif [ "$MOUNT_2" ]; then
4038 restore_mount $MOUNT2
4039 export I_MOUNTED2=yes
4043 # FIXME: what to do if check_config failed?
4045 # 1) remote client has mounted other Lustre fs?
4046 # 2) lustre is mounted on remote_clients atall ?
4047 check_config_clients $MOUNT
4051 set_default_debug_nodes $(comma_list $(nodes_list))
4054 if [ $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ] ; then
4056 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
4057 facets="$(get_facets OST)"
4058 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
4059 facets="$facets,$(get_facets MDS)"
4060 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
4061 facets="$facets,mgs"
4062 local nodes="$(facets_hosts ${facets})"
4063 if [ -n "$nodes" ] ; then
4064 do_nodes $nodes "$LCTL set_param \
4065 osd-ldiskfs.track_declares_assert=1 || true"
4074 #Enable remote MDT create for testing
4075 for num in $(seq $MDSCOUNT); do
4077 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
4081 if [ "$ONLY" == "setup" ]; then
4087 local clients=${CLIENTS:-$HOSTNAME}
4090 zconf_mount_clients $clients $mntpt
4094 local clients=${CLIENTS:-$HOSTNAME}
4097 zconf_umount_clients $clients $mntpt
4100 cleanup_and_setup_lustre() {
4101 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
4102 lctl set_param debug=0 || true
4104 if [ "$ONLY" == "cleanup" ]; then
4108 check_and_setup_lustre
4111 # Get all of the server target devices from a given server node and type.
4118 if [ "$type" == ost ]; then
4119 devs=$(get_osd_param $node "" mntdev)
4121 devs=$(do_node $node $LCTL get_param -n osd-*.$FSNAME-M*.mntdev)
4123 for dev in $devs; do
4125 *loop*) do_node $node "losetup $dev" | \
4126 sed -e "s/.*(//" -e "s/).*//" ;;
4132 # Get all of the server target devices.
4137 # Master MDS parameters used by lfsck
4138 MDTNODE=$(facet_active_host $SINGLEMDS)
4139 MDTDEV=$(echo $(get_mnt_devs $MDTNODE mdt) | awk '{print $1}')
4143 for node in $(mdts_nodes); do
4144 MDTDEVS[i]=$(get_mnt_devs $node mdt)
4150 for node in $(osts_nodes); do
4151 OSTDEVS[i]=$(get_mnt_devs $node ost)
4156 # Run e2fsck on MDT or OST device.
4161 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
4162 local log=$TMP/e2fsck.log
4166 do_node $node $cmd 2>&1 | tee $log
4168 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
4170 if [ $MDSCOUNT -gt 1 ]; then
4171 skip "DNE mode isn't supported!"
4175 error "It's not DNE mode."
4180 [ $rc -le $FSCK_MAX_ERR ] ||
4181 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4187 # Run resize2fs on MDT or OST device.
4196 do_facet $facet "$RESIZE2FS $opts $device $size"
4199 # verify a directory is shared among nodes.
4200 check_shared_dir() {
4202 local list=${2:-$(comma_list $(nodes_list))}
4204 [ -z "$dir" ] && return 1
4205 do_rpc_nodes "$list" check_logdir $dir
4206 check_write_access $dir "$list" || return 1
4210 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
4217 [[ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]] ||
4218 { skip "Lustre 2.2.0 lacks the patch for LU-1255"; exit 0; }
4220 check_shared_dir $SHARED_DIRECTORY ||
4221 error "$SHARED_DIRECTORY isn't a shared directory"
4223 export MDSDB=$SHARED_DIRECTORY/mdsdb
4224 export OSTDB=$SHARED_DIRECTORY/ostdb
4226 # DNE is not supported, so when running e2fsck on a DNE filesystem,
4227 # we only pass master MDS parameters.
4228 run_e2fsck $MDTNODE $MDTDEV "-n --mdsdb $MDSDB"
4233 for node in $(osts_nodes); do
4234 for dev in ${OSTDEVS[i]}; do
4235 run_e2fsck $node $dev "-n --mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
4236 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
4237 ostidx=$((ostidx + 1))
4243 # Run lfsck on server node if lfsck can't be found on client (LU-2571)
4244 run_lfsck_remote() {
4245 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
4250 #Check if lustre is already mounted
4251 do_rpc_nodes $client is_mounted $MOUNT || mounted=false
4253 zconf_mount $client $MOUNT ||
4254 error "failed to mount Lustre on $client"
4258 do_node $client $cmd || rc=$?
4259 #Umount if necessary
4261 zconf_umount $client $MOUNT ||
4262 error "failed to unmount Lustre on $client"
4265 [ $rc -le $FSCK_MAX_ERR ] ||
4266 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4267 echo "lfsck finished with rc=$rc"
4273 local facets="client $SINGLEMDS"
4279 for facet in $facets; do
4280 node=$(facet_active_host $facet)
4281 if check_progs_installed $node $LFSCK_BIN; then
4286 ! $found && error "None of \"$facets\" supports lfsck"
4288 run_lfsck_remote $node || rc=$?
4290 rm -rvf $MDSDB* $OSTDB* || true
4294 dump_file_contents() {
4300 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
4301 error_noexit false \
4302 "Invalid parameters for dump_file_contents()"
4305 for node in ${nodes}; do
4306 do_node $node "for i in \\\$(find $dir -type f); do
4307 echo ====\\\${i}=======================;
4309 done" >> ${logname}.${node}.log
4313 dump_command_output() {
4319 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
4320 error_noexit false \
4321 "Invalid parameters for dump_command_output()"
4325 for node in ${nodes}; do
4326 do_node $node "echo ====${cmd}=======================;
4327 $cmd" >> ${logname}.${node}.log
4334 # dump file contents from /proc/spl in case of zfs test
4335 if [ "$(facet_fstype ost1)" = "zfs" ]; then
4336 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
4337 dump_command_output \
4338 "$(osts_nodes)" "zpool events -v" "${logname}"
4341 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
4342 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
4343 dump_command_output \
4344 "$(mdts_nodes)" "zpool events -v" "${logname}"
4348 check_and_cleanup_lustre() {
4349 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
4355 if is_mounted $MOUNT; then
4356 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4357 error "remove sub-test dirs failed"
4358 [ "$ENABLE_QUOTA" ] && restore_quota || true
4361 if [ "$I_UMOUNTED2" = "yes" ]; then
4362 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4365 if [ "$I_MOUNTED2" = "yes" ]; then
4366 cleanup_mount $MOUNT2
4369 if [ "$I_MOUNTED" = "yes" ]; then
4370 cleanupall -f || error "cleanup failed"
4378 wait_for_function () {
4381 # suppress fn both stderr and stdout
4382 if [ "$1" = "--quiet" ]; then
4384 quiet=" > /dev/null 2>&1"
4396 eval $fn $quiet && return 0
4398 wait=$((wait + sleep))
4399 [ $wait -lt $max ] || return 1
4400 echo waiting $fn, $((max - wait)) secs left ...
4410 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4411 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4412 echo "Network not available!"
4416 echo `date +"%H:%M:%S (%s)"` network interface is UP
4424 # Convert a space-delimited list to a comma-delimited list. If the input is
4425 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4427 # echo is used to convert newlines to spaces, since it doesn't
4428 # introduce a trailing space as using "tr '\n' ' '" does
4429 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4435 echo $list | grep -qw $item
4438 # list, excluded are the comma separated lists
4439 exclude_items_from_list () {
4445 for item in ${excluded//,/ }; do
4446 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4448 echo $(comma_list $list)
4451 # list, expand are the comma separated lists
4453 local list=${1//,/ }
4454 local expand=${2//,/ }
4457 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4458 echo $(comma_list $expanded)
4461 testslist_filter () {
4462 local script=$LUSTRE/tests/${TESTSUITE}.sh
4464 [ -f $script ] || return 0
4466 local start_at=$START_AT
4467 local stop_at=$STOP_AT
4469 local var=${TESTSUITE//-/_}_START_AT
4470 [ x"${!var}" != x ] && start_at=${!var}
4471 var=${TESTSUITE//-/_}_STOP_AT
4472 [ x"${!var}" != x ] && stop_at=${!var}
4474 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4475 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4476 /^'${start_at}'$/ {flag = 0}
4477 {if (flag == 1) print $0}
4478 /^'${stop_at}'$/ { flag = 1 }'
4482 (cd `dirname $1`; echo $PWD/`basename $1`)
4486 local types=${1:-"OST MDS MGS"}
4490 for entry in $types; do
4491 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4492 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4495 MGS ) list="$list $name";;
4496 MDS|OST|AGT ) local count=${type}COUNT
4497 for ((i=1; i<=${!count}; i++)) do
4498 list="$list ${name}$i"
4500 * ) error "Invalid facet type"
4504 echo $(comma_list $list)
4507 ##################################
4508 # Adaptive Timeouts funcs
4511 # only check mds, we assume at_max is the same on all nodes
4512 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4513 if [ $at_max -eq 0 ]; then
4524 # suppose that all ost-s have the same $at value set
4525 [ $facet != "ost" ] || facet=ost1
4527 do_facet $facet "lctl get_param -n $at"
4545 if [ $facet == "ost" ]; then
4546 facet=$(get_facets OST)
4547 elif [ $facet == "mds" ]; then
4548 facet=$(get_facets MDS)
4550 hosts=$(expand_list $hosts $(facets_hosts $facet))
4553 do_nodes $hosts lctl set_param at_max=$at_max
4556 ##################################
4560 # OBD_FAIL_MDS_ALL_REQUEST_NET
4562 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4563 do_facet client "$1" || RC=$?
4564 do_facet $SINGLEMDS lctl set_param fail_loc=0
4569 # OBD_FAIL_MDS_ALL_REPLY_NET
4571 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
4573 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4577 drop_reint_reply() {
4578 # OBD_FAIL_MDS_REINT_NET_REP
4580 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
4582 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4586 drop_update_reply() {
4587 # OBD_FAIL_OUT_UPDATE_NET_REP
4591 do_facet mds${index} lctl set_param fail_loc=0x1701
4592 do_facet client "$@" || RC=$?
4593 do_facet mds${index} lctl set_param fail_loc=0
4598 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4601 local timeout=${2:-0}
4602 # default is (obd_timeout / 4) if unspecified
4603 echo "timeout is $timeout/$2"
4604 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
4605 do_facet client "$1" || RC=$?
4606 do_facet client "sync"
4607 do_facet ost1 lctl set_param fail_loc=0
4611 drop_ldlm_cancel() {
4612 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4614 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4615 do_nodes $list lctl set_param fail_loc=0x304
4617 do_facet client "$@" || RC=$?
4619 do_nodes $list lctl set_param fail_loc=0
4623 drop_bl_callback_once() {
4625 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4626 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4627 do_facet client lctl set_param fail_loc=0x80000305
4628 do_facet client "$@" || rc=$?
4629 do_facet client lctl set_param fail_loc=0
4630 do_facet client lctl set_param fail_val=0
4631 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4635 drop_bl_callback() {
4637 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4638 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4639 do_facet client lctl set_param fail_loc=0x305
4640 do_facet client "$@" || rc=$?
4641 do_facet client lctl set_param fail_loc=0
4642 do_facet client lctl set_param fail_val=0
4643 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4648 #define OBD_FAIL_LDLM_REPLY 0x30c
4650 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4651 do_nodes $list lctl set_param fail_loc=0x30c
4653 do_facet client "$@" || RC=$?
4655 do_nodes $list lctl set_param fail_loc=0
4659 drop_ldlm_reply_once() {
4660 #define OBD_FAIL_LDLM_REPLY 0x30c
4662 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4663 do_nodes $list lctl set_param fail_loc=0x8000030c
4665 do_facet client "$@" || RC=$?
4667 do_nodes $list lctl set_param fail_loc=0
4675 echo "clearing fail_loc on $facet"
4676 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4679 set_nodes_failloc () {
4680 do_nodes $(comma_list $1) lctl set_param fail_val=0 fail_loc=$2
4683 cancel_lru_locks() {
4684 $LCTL mark "cancel_lru_locks $1 start"
4686 if [ $1 != "MGC" ]; then
4687 for d in $(lctl get_param -N ldlm.namespaces.*.lru_size |
4689 $LCTL set_param -n $d=clear
4691 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 |
4695 /{proc,sys}/fs/lustre/ldlm/namespaces/*$1*/lru_size \
4701 /{proc,sys}/fs/lustre/ldlm/namespaces/*$1*/lock_unused_count \
4703 if [ $(cat $d) != 0 ]; then
4704 echo "ldlm.namespaces.$(echo "$d" |
4705 cut -f 7 -d'/').lock_unused_count=$(cat $d)"
4710 $LCTL mark "cancel_lru_locks $1 stop"
4715 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4716 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4717 echo "$DEFAULT_LRU_SIZE"
4722 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4725 lru_resize_disable()
4727 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4733 [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] && RC=1
4739 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4740 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4741 echo there is still data in page cache $FILE ?
4742 lctl get_param -n $FILE
4750 DEBUGSAVE="$(lctl get_param -n debug)"
4754 [ -n "$DEBUGSAVE" ] && \
4755 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
4760 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4763 debug_size_restore() {
4764 [ -n "$DEBUG_SIZE_SAVED" ] && \
4765 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4769 start_full_debug_logging() {
4774 local DEBUG_SIZE=150
4776 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4777 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4780 stop_full_debug_logging() {
4785 # prints bash call stack
4786 print_stack_trace() {
4788 for (( i=1; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4789 local s=${BASH_SOURCE[$i]}
4790 local l=${BASH_LINENO[$i-1]}
4791 local f=${FUNCNAME[$i]}
4792 echo " = $s:$l:$f()"
4796 ##################################
4798 ##################################
4801 local TYPE=${TYPE:-"FAIL"}
4804 # do not dump logs if $1=false
4805 if [ "x$1" = "xfalse" ]; then
4811 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4812 print_stack_trace >&2
4815 # We need to dump the logs on all nodes
4817 gather_logs $(comma_list $(nodes_list))
4821 [ "$TESTSUITELOG" ] &&
4822 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4823 if [ -z "$*" ]; then
4824 echo "error() without useful message, please fix" > $LOGDIR/err
4826 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4827 echo "$@" > $LOGDIR/ignore
4829 echo "$@" > $LOGDIR/err
4836 local log=$TESTSUITELOG
4838 [ -f "$log" ] && grep -q FAIL $log && status=1
4851 # use only if we are ignoring failures for this test, bugno required.
4852 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4853 # e.g. error_ignore bz5494 "your message" or
4854 # error_ignore LU-5494 "your message"
4856 local TYPE="IGNORE ($1)"
4861 error_and_remount() {
4863 remount_client $MOUNT
4868 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4873 log " SKIP: $TESTSUITE $TESTNAME $@"
4875 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4876 skip_logged $TESTNAME "$@"
4879 echo "$@" > $LOGDIR/skip
4882 [[ -n "$TESTSUITELOG" ]] &&
4883 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
4886 build_test_filter() {
4887 EXCEPT="$EXCEPT $(testslist_filter)"
4890 if [[ $O = [0-9]*-[0-9]* ]]; then
4891 for num in $(seq $(echo $O | tr '-' ' ')); do
4899 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
4900 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
4901 [ "$EXCEPT_SLOW" ] && \
4902 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
4903 for E in $EXCEPT; do
4904 eval EXCEPT_${E}=true
4906 for E in $ALWAYS_EXCEPT; do
4907 eval EXCEPT_ALWAYS_${E}=true
4909 for E in $EXCEPT_SLOW; do
4910 eval EXCEPT_SLOW_${E}=true
4912 for G in $GRANT_CHECK_LIST; do
4913 eval GCHECK_ONLY_${G}=true
4918 if [[ $1 = [a-z]* ]]; then
4925 # print a newline if the last test was skipped
4926 export LAST_SKIPPED=
4927 export ALWAYS_SKIPPED=
4929 # Main entry into test-framework. This is called with the name and
4930 # description of a test. The name is used to find the function to run
4931 # the test using "test_$name".
4933 # This supports a variety of methods of specifying specific test to
4934 # run or not run. These need to be documented...
4939 export base=$(basetest $1)
4940 if [ -n "$ONLY" ]; then
4942 if [ ${!testname}x != x ]; then
4943 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4944 run_one_logged $1 "$2"
4948 if [ ${!testname}x != x ]; then
4949 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4950 run_one_logged $1 "$2"
4960 if [ ${!testname}x != x ]; then
4961 TESTNAME=test_$1 skip "skipping excluded test $1"
4964 testname=EXCEPT_$base
4965 if [ ${!testname}x != x ]; then
4966 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
4969 testname=EXCEPT_ALWAYS_$1
4970 if [ ${!testname}x != x ]; then
4971 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
4974 testname=EXCEPT_ALWAYS_$base
4975 if [ ${!testname}x != x ]; then
4976 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
4979 testname=EXCEPT_SLOW_$1
4980 if [ ${!testname}x != x ]; then
4981 TESTNAME=test_$1 skip "skipping SLOW test $1"
4984 testname=EXCEPT_SLOW_$base
4985 if [ ${!testname}x != x ]; then
4986 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
4992 run_one_logged $1 "$2"
4999 load_module ../libcfs/libcfs/libcfs
5011 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
5016 strace -o $TMP/$1.strace -ttt $*
5018 log "FINISHED: $*: rc $RC"
5025 banner test complete, duration $duration sec
5026 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
5027 echo duration $duration >>$TESTSUITELOG
5031 # Set TEST_STATUS here. It will be used for logging the result.
5034 if [[ -f $LOGDIR/err ]]; then
5036 elif [[ -f $LOGDIR/skip ]]; then
5039 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
5043 local FFREE=$(do_node $SINGLEMDS \
5044 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
5045 local FTOTAL=$(do_node $SINGLEMDS \
5046 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
5048 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
5052 echo -n "Resetting fail_loc on all nodes..."
5053 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 \
5054 fail_val=0 2>/dev/null || true"
5060 # Log a message (on all nodes) padded with "=" before and after.
5061 # Also appends a timestamp and prepends the testsuite name.
5064 EQUALS="===================================================================================================="
5066 msg="== ${TESTSUITE} $*"
5068 [[ $last != "=" && $last != " " ]] && msg="$msg "
5069 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
5070 # always include at least == after the message
5071 log "$msg== $(date +"%H:%M:%S (%s)")"
5075 # Run a single test function and cleanup after it.
5077 # This function should be run in a subshell so the test func can
5078 # exit() without stopping the whole script.
5083 export tfile=f${testnum}.${TESTSUITE}
5084 export tdir=d${testnum}.${TESTSUITE}
5085 export TESTNAME=test_$testnum
5086 local SAVE_UMASK=`umask`
5089 banner "test $testnum: $message"
5090 test_${testnum} || error "test_$testnum failed with $?"
5093 check_grant ${testnum} || error "check_grant $testnum failed with $?"
5094 check_catastrophe || error "LBUG/LASSERT detected"
5095 if [ "$PARALLEL" != "yes" ]; then
5096 ps auxww | grep -v grep | grep -q multiop &&
5097 error "multiop still running"
5107 # Wrapper around run_one to ensure:
5108 # - test runs in subshell
5109 # - output of test is saved to separate log file for error reporting
5110 # - test result is saved to data file
5113 local BEFORE=$(date +%s)
5115 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
5116 local test_log=$LOGDIR/$name
5117 local zfs_log_name=${TESTSUITE}.test_${1}.zfs_log
5118 local zfs_debug_log=$LOGDIR/$zfs_log_name
5120 rm -rf $LOGDIR/ignore
5122 local SAVE_UMASK=$(umask)
5126 log_sub_test_begin test_${1}
5127 (run_one $1 "$2") 2>&1 | tee -i $test_log
5128 local RC=${PIPESTATUS[0]}
5130 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
5131 echo "test_$1 returned $RC" | tee $LOGDIR/err
5133 duration=$(($(date +%s) - $BEFORE))
5134 pass "$1" "(${duration}s)"
5136 if [[ -f $LOGDIR/err ]]; then
5137 TEST_ERROR=$(cat $LOGDIR/err)
5138 elif [[ -f $LOGDIR/ignore ]]; then
5139 TEST_ERROR=$(cat $LOGDIR/ignore)
5140 elif [[ -f $LOGDIR/skip ]]; then
5141 TEST_ERROR=$(cat $LOGDIR/skip)
5143 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
5145 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
5149 if [ -f $LOGDIR/err ]; then
5150 log_zfs_info "$zfs_debug_log"
5151 $FAIL_ON_ERROR && exit $RC
5160 # Print information of skipped tests to result.yml
5163 log_sub_test_begin $1
5165 log_sub_test_end "SKIP" "0" "0" "$@"
5169 (cd $(dirname $1); echo $PWD/$(basename $1))
5174 export base=$(basetest $1)
5175 [ "$CHECK_GRANT" == "no" ] && return 0
5177 testname=GCHECK_ONLY_${base}
5178 [ ${!testname}x == x ] && return 0
5180 echo -n "checking grant......"
5182 local clients=$CLIENTS
5183 [ -z "$clients" ] && clients=$(hostname)
5185 # sync all the data and make sure no pending data on server
5186 do_nodes $clients sync
5189 client_grant=$(do_nodes $clients \
5190 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
5191 awk '{ total += $1 } END { printf("%0.0f", total) }')
5194 server_grant=$(do_nodes $(comma_list $(osts_nodes)) \
5195 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
5196 awk '{ total += $1 } END { printf("%0.0f", total) }')
5198 # check whether client grant == server grant
5199 if [[ $client_grant -ne $server_grant ]]; then
5200 echo "failed: client:${client_grant} server: ${server_grant}."
5201 do_nodes $(comma_list $(osts_nodes)) \
5202 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
5203 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
5206 echo "pass: client:${client_grant} server: ${server_grant}"
5210 ########################
5216 ost=`echo $1 | awk -F_ '{print $3}'`
5217 if [ -z $ost ]; then
5218 ost=`echo $1 | sed 's/-osc.*//'`
5223 ostuuid_from_index()
5225 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5228 ostname_from_index() {
5229 local uuid=$(ostuuid_from_index $1)
5233 index_from_ostuuid()
5235 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
5238 mdtuuid_from_index()
5240 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5244 # Return unique identifier for given hostname
5247 echo $host_name | md5sum | cut -d' ' -f1
5251 # Returns list of ip addresses for each interface
5253 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
5258 # Cache address list to avoid mutiple execution of local_addr_list
5259 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
5261 for i in $LOCAL_ADDR_LIST ; do
5262 [[ "$i" == "$addr" ]] && return 0
5269 local is_local="IS_LOCAL_$(host_id $host_name)"
5270 if [ -z "${!is_local-}" ] ; then
5272 local host_ip=$($LUSTRE/tests/resolveip $host_name)
5273 is_local_addr "$host_ip" && eval $is_local=1
5275 [[ "${!is_local}" == "1" ]]
5280 local_node $node && return 1
5287 for node in $(mdts_nodes); do
5288 remote_node $node && return 0
5295 [ "$CLIENTONLY" ] && return 0 || true
5296 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
5301 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
5302 MSKIPPED=1 && return 1
5309 for node in $(osts_nodes) ; do
5310 remote_node $node && return 0
5317 [ "$CLIENTONLY" ] && return 0 || true
5318 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5323 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
5324 OSKIPPED=1 && return 1
5330 [ "$CLIENTONLY" ] && return 0 || true
5332 MGS=$(facet_host mgs)
5333 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5338 remote_mds_nodsh || remote_ost_nodsh || \
5339 $(single_local_node $(comma_list $(nodes_list)))
5343 remote_ost && remote_mds
5346 # Get the active nodes for facets.
5354 for facet in ${facets//,/ }; do
5355 nodes="$nodes $(facet_active_host $facet)"
5358 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5362 # Get all of the active MDS nodes.
5364 echo -n $(facets_nodes $(get_facets MDS))
5367 # Get all of the active OSS nodes.
5369 echo -n $(facets_nodes $(get_facets OST))
5372 # Get all of the active AGT (HSM agent) nodes.
5374 echo -n $(facets_nodes $(get_facets AGT))
5377 # Get all of the client nodes and active server nodes.
5379 local nodes=$HOSTNAME
5383 # CLIENTS (if specified) contains the local client
5384 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5386 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5387 nodes="$nodes $(facets_nodes $(get_facets))"
5390 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5394 # Get all of the remote client nodes and remote active server nodes.
5395 remote_nodes_list () {
5396 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5399 # Get all of the MDS nodes, including active and passive nodes.
5407 for i in $(seq $MDSCOUNT); do
5409 failover_host=mds${i}failover_HOST
5410 nodes="$nodes ${!host} ${!failover_host}"
5413 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5417 # Get all of the OSS nodes, including active and passive nodes.
5425 for i in $(seq $OSTCOUNT); do
5427 failover_host=ost${i}failover_HOST
5428 nodes="$nodes ${!host} ${!failover_host}"
5431 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5435 # Get all of the server nodes, including active and passive nodes.
5436 all_server_nodes () {
5441 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5443 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5447 # Get all of the client and server nodes, including active and passive nodes.
5449 local nodes=$HOSTNAME
5453 # CLIENTS (if specified) contains the local client
5454 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5456 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5457 nodes="$nodes $(all_server_nodes)"
5460 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5464 init_clients_lists () {
5465 # Sanity check: exclude the local client from RCLIENTS
5466 local clients=$(hostlist_expand "$RCLIENTS")
5467 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5469 # Sanity check: exclude the dup entries
5470 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5472 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5474 # Sanity check: exclude the dup entries from CLIENTS
5475 # for those configs which has SINGLCLIENT set to local client
5476 clients=$(for i in $clients; do echo $i; done | sort -u)
5478 CLIENTS=$(comma_list $clients)
5479 local -a remoteclients=($RCLIENTS)
5480 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5481 varname=CLIENT$((i + 2))
5482 eval $varname=${remoteclients[i]}
5485 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5488 get_random_entry () {
5491 rnodes=${rnodes//,/ }
5493 local -a nodes=($rnodes)
5494 local num=${#nodes[@]}
5495 local i=$((RANDOM * num * 2 / 65536))
5501 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
5506 lctl get_param version | grep -q patchless
5510 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5511 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5516 echo $nodes | wc -w || true
5520 local nodes=$(osts_nodes)
5521 local osscount=$(get_node_count "$nodes")
5522 [ ! "$OSTCOUNT" = "$osscount" ]
5526 local nodes=$(mdts_nodes)
5527 local mdtcount=$(get_node_count "$nodes")
5528 [ ! "$MDSCOUNT" = "$mdtcount" ]
5531 generate_machine_file() {
5532 local nodes=${1//,/ }
5533 local machinefile=$2
5535 for node in $nodes; do
5536 echo $node >>$machinefile || \
5537 { echo "can not generate machinefile $machinefile" && return 1; }
5542 local file=$1/stripe
5545 $LFS getstripe -v $file || error "getstripe $file failed"
5549 setstripe_nfsserver () {
5552 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5553 { print $1 }' /proc/mounts | cut -f 1 -d : | head -n1)
5555 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5557 do_nodev $nfsserver lfs setstripe "$@"
5560 # Check and add a test group.
5566 local gid=$(getent group $group_name | cut -d: -f3)
5567 if [[ -n "$gid" ]]; then
5568 [[ "$gid" -eq "$group_id" ]] || {
5569 error_noexit "inconsistent group ID:" \
5570 "new: $group_id, old: $gid"
5574 groupadd -g $group_id $group_name
5581 # Check and add a test user.
5594 local uid=$(getent passwd $user_name | cut -d: -f3)
5595 if [[ -n "$uid" ]]; then
5596 if [[ "$uid" -eq "$user_id" ]]; then
5597 local dir=$(getent passwd $user_name | cut -d: -f6)
5598 if [[ "$dir" != "$home" ]]; then
5600 usermod -d $home $user_name
5604 error_noexit "inconsistent user ID:" \
5605 "new: $user_id, old: $uid"
5610 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5617 check_runas_id_ret() {
5619 local myRUNAS_UID=$1
5620 local myRUNAS_GID=$2
5623 if [ -z "$myRUNAS" ]; then
5624 error_exit "myRUNAS command must be specified for check_runas_id"
5627 $myRUNAS krb5_login.sh || \
5628 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5630 mkdir $DIR/d0_runas_test
5632 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5633 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5634 rm -rf $DIR/d0_runas_test
5639 local myRUNAS_UID=$1
5640 local myRUNAS_GID=$2
5643 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5644 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5645 Please set RUNAS_ID to some UID which exists on MDS and client or
5646 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5649 # obtain the UID/GID for MPI_USER
5653 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5654 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5656 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5657 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5660 # obtain and cache Kerberos ticket-granting ticket
5661 refresh_krb5_tgt() {
5662 local myRUNAS_UID=$1
5663 local myRUNAS_GID=$2
5666 if [ -z "$myRUNAS" ]; then
5667 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5670 CLIENTS=${CLIENTS:-$HOSTNAME}
5671 do_nodes $CLIENTS "set -x
5672 if ! $myRUNAS krb5_login.sh; then
5673 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5678 # Run multiop in the background, but wait for it to print
5679 # "PAUSING" to its stdout before returning from this function.
5680 multiop_bg_pause() {
5681 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5685 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5688 echo "$MULTIOP_PROG $FILE v$ARGS"
5689 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5691 echo "TMPPIPE=${TMPPIPE}"
5692 read -t 60 multiop_output < $TMPPIPE
5693 if [ $? -ne 0 ]; then
5698 if [ "$multiop_output" != "PAUSING" ]; then
5699 echo "Incorrect multiop output: $multiop_output"
5714 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5720 inodes_available () {
5721 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
5722 sort -un | head -n1) || return 1
5726 mdsrate_inodes_available () {
5727 local min_inodes=$(inodes_available)
5728 echo $((min_inodes * 99 / 100))
5731 # reset llite stat counters
5732 clear_llite_stats(){
5733 lctl set_param -n llite.*.stats 0
5736 # sum llite stat items
5737 calc_llite_stats() {
5738 local res=$(lctl get_param -n llite.*.stats |
5739 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5743 # reset osc stat counters
5745 lctl set_param -n osc.*.osc_stats 0
5748 # sum osc stat items
5750 local res=$(lctl get_param -n osc.*.osc_stats |
5751 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5756 awk '{sum += $1} END { printf("%0.0f", sum) }'
5759 calc_osc_kbytes () {
5760 df $MOUNT > /dev/null
5761 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5764 # save_lustre_params(comma separated facet list, parameter_mask)
5765 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5766 save_lustre_params() {
5772 for facet in ${facets//,/ }; do
5773 node=$(facet_active_host $facet)
5774 [[ *\ $node\ * = " $nodes " ]] && continue
5775 nodes="$nodes $node"
5777 do_node $node "$LCTL get_param $2 |
5778 while read s; do echo $facet \\\$s; done"
5782 # restore lustre parameters from input stream, produces by save_lustre_params
5783 restore_lustre_params() {
5788 while IFS=" =" read facet name val; do
5789 do_facet $facet "$LCTL set_param -n $name $val"
5793 check_catastrophe() {
5794 local nodes=${1:-$(comma_list $(nodes_list))}
5796 do_nodes $nodes "rc=0;
5797 val=\\\$($LCTL get_param -n catastrophe 2>&1);
5798 if [[ \\\$? -eq 0 && \\\$val -ne 0 ]]; then
5799 echo \\\$(hostname -s): \\\$val;
5805 mdsrate_cleanup () {
5807 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
5808 --nfiles $3 --dir $4 --filefmt $5 $6
5813 delayed_recovery_enabled () {
5814 local var=${SINGLEMDS}_svc
5815 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5818 ########################
5820 convert_facet2label() {
5823 if [ x$facet = xost ]; then
5827 local varsvc=${facet}_svc
5829 if [ -n ${!varsvc} ]; then
5832 error "No lablel for $facet!"
5836 get_clientosc_proc_path() {
5840 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5841 # used by MDT would not be changed.
5842 # mdt lov: fsname-mdtlov
5843 # mdt osc: fsname-OSTXXXX-osc
5844 mds_on_old_device() {
5845 local mds=${1:-"$SINGLEMDS"}
5847 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5848 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5849 > /dev/null 2>&1" && return 0
5854 get_mdtosc_proc_path() {
5856 local ost_label=${2:-"*OST*"}
5858 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5859 local mdt_label=$(convert_facet2label $mds_facet)
5860 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5862 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5863 mds_on_old_device $mds_facet; then
5864 echo "${ost_label}-osc"
5865 elif [[ $ost_label = *OST* ]]; then
5866 echo "${ost_label}-osc-${mdt_index}"
5868 echo "${ost_label}-osp-${mdt_index}"
5872 get_osc_import_name() {
5875 local label=$(convert_facet2label $ost)
5877 if [ "${facet:0:3}" = "mds" ]; then
5878 get_mdtosc_proc_path $facet $label
5882 get_clientosc_proc_path $label
5886 _wait_import_state () {
5889 local maxtime=${3:-$(max_recovery_time)}
5890 local error_on_failure=${4:-1}
5894 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5895 while [ "${CONN_STATE}" != "${expected}" ]; do
5896 if [ "${expected}" == "DISCONN" ]; then
5897 # for disconn we can check after proc entry is removed
5898 [ "x${CONN_STATE}" == "x" ] && return 0
5899 # with AT enabled, we can have connect request timeout near of
5900 # reconnect timeout and test can't see real disconnect
5901 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
5903 if [ $i -ge $maxtime ]; then
5904 [ $error_on_failure -ne 0 ] && \
5905 error "can't put import for $CONN_PROC into ${expected}" \
5906 "state after $i sec, have ${CONN_STATE}"
5910 # Add uniq for multi-mount case
5911 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5915 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
5919 wait_import_state() {
5922 local maxtime=${3:-$(max_recovery_time)}
5923 local error_on_failure=${4:-1}
5926 for param in ${params//,/ }; do
5927 _wait_import_state $state $param $maxtime $error_on_failure || return
5931 wait_import_state_mount() {
5932 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
5936 wait_import_state $*
5939 # One client request could be timed out because server was not ready
5940 # when request was sent by client.
5941 # The request timeout calculation details :
5943 # /* We give the server rq_timeout secs to process the req, and
5944 # add the network latency for our local timeout. */
5945 # request->rq_deadline = request->rq_sent + request->rq_timeout +
5946 # ptlrpc_at_get_net_latency(request) ;
5948 # ptlrpc_connect_import ()
5949 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5952 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
5953 # ptlrpc_at_get_net_latency(request) ->
5954 # at_get (max (iat_net_latency=0, at_min)) = at_min
5957 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
5958 # INITIAL_CONNECT_TIMEOUT + at_min
5960 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
5961 # because we can not get this value in runtime,
5962 # the value depends on configure options, and it is not stored in /proc.
5964 # #define CONNECTION_SWITCH_MIN 5U
5965 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5967 request_timeout () {
5970 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5971 local init_connect_timeout=$TIMEOUT
5972 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5974 local at_min=$(at_get $facet at_min)
5976 echo $(( init_connect_timeout + at_min ))
5979 _wait_osc_import_state() {
5983 local target=$(get_osc_import_name $facet $ost_facet)
5984 local param="osc.${target}.ost_server_uuid"
5988 # 1. wait the deadline of client 1st request (it could be skipped)
5989 # 2. wait the deadline of client 2nd request
5990 local maxtime=$(( 2 * $(request_timeout $facet)))
5992 if [[ $facet == client* ]]; then
5993 # During setup time, the osc might not be setup, it need wait
5994 # until list_param can return valid value. And also if there
5995 # are mulitple osc entries we should list all of them before
5997 params=$($LCTL list_param $param 2>/dev/null || true)
5998 while [ -z "$params" ]; do
5999 if [ $i -ge $maxtime ]; then
6000 echo "can't get $param in $maxtime secs"
6005 params=$($LCTL list_param $param 2>/dev/null || true)
6009 if [[ $ost_facet = mds* ]]; then
6010 # no OSP connection to itself
6011 if [[ $facet = $ost_facet ]]; then
6014 param="osp.${target}.mdt_server_uuid"
6018 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6019 wait_import_state $expected "$params" $maxtime; then
6020 error "import is not in ${expected} state"
6027 wait_osc_import_state() {
6033 if [[ $facet = mds ]]; then
6034 for num in $(seq $MDSCOUNT); do
6035 _wait_osc_import_state mds$num "$ost_facet" "$expected"
6038 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
6042 _wait_mgc_import_state() {
6045 local error_on_failure=${3:-1}
6046 local param="mgc.*.mgs_server_uuid"
6050 # 1. wait the deadline of client 1st request (it could be skipped)
6051 # 2. wait the deadline of client 2nd request
6052 local maxtime=$(( 2 * $(request_timeout $facet)))
6054 if [[ $facet == client* ]]; then
6055 # During setup time, the osc might not be setup, it need wait
6056 # until list_param can return valid value. And also if there
6057 # are mulitple osc entries we should list all of them before
6059 params=$($LCTL list_param $param 2>/dev/null || true)
6060 while [ -z "$params" ]; do
6061 if [ $i -ge $maxtime ]; then
6062 echo "can't get $param in $maxtime secs"
6067 params=$($LCTL list_param $param 2>/dev/null || true)
6070 if ! do_rpc_nodes "$(facet_active_host $facet)" \
6071 wait_import_state $expected "$params" $maxtime \
6072 $error_on_failure; then
6073 if [ $error_on_failure -ne 0 ]; then
6074 error "import is not in ${expected} state"
6082 wait_mgc_import_state() {
6085 local error_on_failure=${3:-1}
6088 if [[ $facet = mds ]]; then
6089 for num in $(seq $MDSCOUNT); do
6090 _wait_mgc_import_state mds$num "$expected" \
6091 $error_on_failure || return
6094 _wait_mgc_import_state "$facet" "$expected"
6095 $error_on_failure || return
6099 wait_dne_interconnect() {
6102 if [ $MDSCOUNT -gt 1 ]; then
6103 for num in $(seq $MDSCOUNT); do
6104 wait_osc_import_state mds mds$num FULL
6109 get_clientmdc_proc_path() {
6113 get_clientmgc_proc_path() {
6121 [ -z "$list" ] && return 0
6123 # Add paths to lustre tests for 32 and 64 bit systems.
6124 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
6125 local TESTPATH="$RLUSTRE/tests:"
6126 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
6127 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
6130 wait_clients_import_state () {
6137 if [ "$FAILURE_MODE" = HARD ]; then
6138 facets=$(facets_on_host $(facet_active_host $facet))
6141 for facet in ${facets//,/ }; do
6142 local label=$(convert_facet2label $facet)
6145 ost* ) proc_path="osc.$(get_clientosc_proc_path \
6146 $label).ost_server_uuid" ;;
6147 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
6148 $label).mds_server_uuid" ;;
6149 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
6150 $label).mgs_server_uuid" ;;
6151 *) error "unknown facet!" ;;
6154 local params=$(expand_list $params $proc_path)
6157 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params;
6159 error "import is not in ${expected} state"
6169 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
6170 $LCTL get_param obdfilter.*.kbytesavail))
6171 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
6172 $LCTL get_param -n obdfilter.*.tot_granted))
6173 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
6174 $LCTL get_param -n obdfilter.*.kbytestotal))
6175 for ((i=0; i<${#AVAILA[@]}; i++)); do
6176 local -a AVAIL1=(${AVAILA[$i]//=/ })
6177 local -a TOTAL=(${TOTALA[$i]//=/ })
6178 GRANT=$((${GRANTA[$i]}/1024))
6179 # allow 1% of total space in bavail because of delayed
6180 # allocation with ZFS which might release some free space after
6181 # txg commit. For small devices, we set a mininum of 8MB
6182 local LIMIT=$((${TOTAL} / 100 + 8000))
6183 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
6184 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
6185 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
6186 echo " FULL" || echo
6192 do_facet mgs lctl pool_list $1
6196 local fsname=${1%%.*}
6197 local poolname=${1##$fsname.}
6199 do_facet mgs lctl pool_new $1
6201 # get param should return err unless pool is created
6202 [[ $RC -ne 0 ]] && return $RC
6204 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6205 2>/dev/null || echo foo" "" || RC=1
6206 if [[ $RC -eq 0 ]]; then
6209 error "pool_new failed $1"
6214 add_pool_to_list () {
6215 local fsname=${1%%.*}
6216 local poolname=${1##$fsname.}
6218 local listvar=${fsname}_CREATED_POOLS
6219 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
6222 remove_pool_from_list () {
6223 local fsname=${1%%.*}
6224 local poolname=${1##$fsname.}
6226 local listvar=${fsname}_CREATED_POOLS
6227 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
6230 destroy_pool_int() {
6232 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
6233 awk '$1 !~ /^Pool:/ {print $1}')
6234 for ost in $OSTS; do
6235 do_facet mgs lctl pool_remove $1 $ost
6237 do_facet mgs lctl pool_destroy $1
6240 # <fsname>.<poolname> or <poolname>
6242 local fsname=${1%%.*}
6243 local poolname=${1##$fsname.}
6245 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
6249 pool_list $fsname.$poolname || return $?
6251 destroy_pool_int $fsname.$poolname
6253 [[ $RC -ne 0 ]] && return $RC
6255 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
6256 2>/dev/null || echo foo" "foo" || RC=1
6258 if [[ $RC -eq 0 ]]; then
6259 remove_pool_from_list $fsname.$poolname
6261 error "destroy pool failed $1"
6267 local fsname=${1:-$FSNAME}
6269 local listvar=${fsname}_CREATED_POOLS
6273 [ x${!listvar} = x ] && return 0
6275 echo destroy the created pools: ${!listvar}
6276 for poolname in ${!listvar//,/ }; do
6277 destroy_pool $fsname.$poolname
6282 local fsname=${1:-$FSNAME}
6284 destroy_pools $fsname
6290 local ts=$(date +%s)
6293 if [[ ! -f "$YAML_LOG" ]]; then
6294 # init_logging is not performed before gather_logs,
6295 # so the $LOGDIR needs to be checked here
6296 check_shared_dir $LOGDIR && touch $LOGDIR/shared
6299 [ -f $LOGDIR/shared ] && docp=false
6301 # dump lustre logs, dmesg
6303 prefix="$TESTLOG_PREFIX.$TESTNAME"
6305 echo "Dumping lctl log to ${prefix}.*.${suffix}"
6307 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
6308 echo "Dumping logs only on local client."
6309 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
6310 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
6315 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
6316 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
6317 if [ ! -f $LOGDIR/shared ]; then
6318 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
6331 for i in $(seq 0 $num_mntpts); do
6332 cmd="ls -laf ${mntpt_root}$i/$dir"
6338 for pid in $pids; do
6345 # check_and_start_recovery_timer()
6346 # service_time = at_est2timeout(service_time);
6347 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
6348 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
6350 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
6351 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
6352 #define CONNECTION_SWITCH_MIN 5
6353 #define CONNECTION_SWITCH_INC 5
6354 max_recovery_time() {
6355 local init_connect_timeout=$((TIMEOUT / 20))
6356 ((init_connect_timeout >= 5)) || init_connect_timeout=5
6358 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
6359 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
6361 echo -n $service_time
6364 get_clients_mount_count () {
6365 local clients=${CLIENTS:-`hostname`}
6367 # we need to take into account the clients mounts and
6368 # exclude mds/ost mounts if any;
6369 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
6373 PROC_CLI="srpc_info"
6381 if [ $M -lt $N ]; then
6385 while [ $N -lt $M ]; do
6395 calc_connection_cnt() {
6398 # MDT->MDT = 2 * C(M, 2)
6402 comb_m2=$(combination $MDSCOUNT 2)
6404 local num_clients=$(get_clients_mount_count)
6406 local cnt_mdt2mdt=$((comb_m2 * 2))
6407 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
6408 local cnt_cli2ost=$((num_clients * OSTCOUNT))
6409 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
6410 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
6411 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
6412 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
6426 local cmd="$tgt.srpc.flavor"
6428 if [ $net == "any" ]; then
6433 if [ $dir != "any" ]; then
6438 log "Setting sptlrpc rule: $cmd"
6439 do_facet mgs "$LCTL conf_param $cmd"
6448 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
6449 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
6451 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
6453 if [ "x$bulkspec" != "x" ]; then
6454 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
6456 if [ "x$algs" != "x" ]; then
6457 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
6459 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
6460 if [ $bulk == "bulkn" ]; then
6461 bulk_count=`echo "$output" | grep "bulk flavor" \
6462 | grep "null/null" | wc -l`
6463 elif [ $bulk == "bulki" ]; then
6464 bulk_count=`echo "$output" | grep "bulk flavor" \
6465 | grep "/null" | grep -v "null/" | wc -l`
6467 bulk_count=`echo "$output" | grep "bulk flavor" \
6468 | grep -v "/null" | grep -v "null/" | wc -l`
6472 [ $bulk_count -lt $count ] && count=$bulk_count
6483 local clients=${CLIENTS:-`hostname`}
6485 for c in ${clients//,/ }; do
6486 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
6487 tmpcnt=`count_flvr "$output" $flavor`
6488 cnt=$((cnt + tmpcnt))
6498 local clients=${CLIENTS:-`hostname`}
6500 for c in ${clients//,/ }; do
6501 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
6502 tmpcnt=`count_flvr "$output" $flavor`
6503 cnt=$((cnt + tmpcnt))
6513 if [ $MDSCOUNT -le 1 ]; then
6518 for num in `seq $MDSCOUNT`; do
6519 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
6520 tmpcnt=`count_flvr "$output" $flavor`
6521 cnt=$((cnt + tmpcnt))
6532 for num in `seq $MDSCOUNT`; do
6533 mdtosc=$(get_mdtosc_proc_path mds$num)
6534 mdtosc=${mdtosc/-MDT*/-MDT\*}
6535 output=$(do_facet mds$num lctl get_param -n \
6536 osc.$mdtosc.$PROC_CLI 2>/dev/null)
6537 tmpcnt=`count_flvr "$output" $flavor`
6538 cnt=$((cnt + tmpcnt))
6547 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
6548 count_flvr "$output" $flavor
6553 local dir=$1 # from to
6554 local flavor=$2 # flavor expected
6557 if [ $dir == "cli2mdt" ]; then
6558 res=`flvr_cnt_cli2mdt $flavor`
6559 elif [ $dir == "cli2ost" ]; then
6560 res=`flvr_cnt_cli2ost $flavor`
6561 elif [ $dir == "mdt2mdt" ]; then
6562 res=`flvr_cnt_mdt2mdt $flavor`
6563 elif [ $dir == "mdt2ost" ]; then
6564 res=`flvr_cnt_mdt2ost $flavor`
6565 elif [ $dir == "all2ost" ]; then
6566 res1=`flvr_cnt_mdt2ost $flavor`
6567 res2=`flvr_cnt_cli2ost $flavor`
6568 res=$((res1 + res2))
6569 elif [ $dir == "all2mdt" ]; then
6570 res1=`flvr_cnt_mdt2mdt $flavor`
6571 res2=`flvr_cnt_cli2mdt $flavor`
6572 res=$((res1 + res2))
6573 elif [ $dir == "all2all" ]; then
6574 res1=`flvr_cnt_mdt2ost $flavor`
6575 res2=`flvr_cnt_cli2ost $flavor`
6576 res3=`flvr_cnt_mdt2mdt $flavor`
6577 res4=`flvr_cnt_cli2mdt $flavor`
6578 res=$((res1 + res2 + res3 + res4))
6586 local dir=$1 # from to
6587 local flavor=$2 # flavor expected
6588 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6592 for ((i=0;i<20;i++)); do
6593 echo -n "checking $dir..."
6594 res=$(do_check_flavor $dir $flavor)
6595 echo "found $res/$expect $flavor connections"
6596 [ $res -ge $expect ] && return 0
6600 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6604 restore_to_default_flavor()
6606 local proc="mgs.MGS.live.$FSNAME"
6608 echo "restoring to default flavor..."
6610 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6612 # remove all existing rules if any
6613 if [ $nrule -ne 0 ]; then
6614 echo "$nrule existing rules"
6615 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6616 echo "remove rule: $rule"
6617 spec=`echo $rule | awk -F = '{print $1}'`
6618 do_facet mgs "$LCTL conf_param -d $spec"
6622 # verify no rules left
6623 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6624 [ $nrule -ne 0 ] && error "still $nrule rules left"
6626 # wait for default flavor to be applied
6627 # currently default flavor for all connections are 'null'
6628 wait_flavor all2all null
6629 echo "now at default flavor settings"
6634 local flavor=${1:-null}
6636 echo "setting all flavor to $flavor"
6638 # FIXME need parameter to this fn
6639 # and remove global vars
6640 local cnt_all2all=$(calc_connection_cnt all2all)
6642 local res=$(do_check_flavor all2all $flavor)
6643 if [ $res -eq $cnt_all2all ]; then
6644 echo "already have total $res $flavor connections"
6648 echo "found $res $flavor out of total $cnt_all2all connections"
6649 restore_to_default_flavor
6651 [[ $flavor = null ]] && return 0
6653 set_rule $FSNAME any any $flavor
6654 wait_flavor all2all $flavor
6660 # Checking for shared logdir
6661 if [ ! -d $dir ]; then
6662 # Not found. Create local logdir
6665 touch $dir/check_file.$(hostname -s)
6670 check_write_access() {
6672 local list=${2:-$(comma_list $(nodes_list))}
6676 for node in ${list//,/ }; do
6677 file=$dir/check_file.$(short_nodename $node)
6678 if [[ ! -f "$file" ]]; then
6679 # Logdir not accessible/writable from this node.
6682 rm -f $file || return 1
6688 if [[ -n $YAML_LOG ]]; then
6691 local SAVE_UMASK=`umask`
6694 export YAML_LOG=${LOGDIR}/results.yml
6698 if [ ! -f $YAML_LOG ]; then # If the yaml log already exists then we will just append to it
6699 if check_shared_dir $LOGDIR; then
6700 touch $LOGDIR/shared
6701 echo "Logging to shared log directory: $LOGDIR"
6703 echo "Logging to local directory: $LOGDIR"
6706 yml_nodes_file $LOGDIR >> $YAML_LOG
6707 yml_results_file >> $YAML_LOG
6714 yml_log_test $1 >> $YAML_LOG
6718 yml_log_test_status $@ >> $YAML_LOG
6721 log_sub_test_begin() {
6722 yml_log_sub_test_begin "$@" >> $YAML_LOG
6725 log_sub_test_end() {
6726 yml_log_sub_test_end "$@" >> $YAML_LOG
6732 local llverdev_opts=$2
6733 local devname=$(basename $1)
6734 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6735 # loop devices aren't in /proc/partitions
6736 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6738 size=$(($size / 1024 / 1024)) # Gb
6740 local partial_arg=""
6741 # Run in partial (fast) mode if the size
6742 # of a partition > 1 GB
6743 [ $size -gt 1 ] && partial_arg="-p"
6745 llverdev --force $partial_arg $llverdev_opts $dev
6751 local llverfs_opts=$2
6752 local use_partial_arg=$3
6753 local partial_arg=""
6754 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6756 # Run in partial (fast) mode if the size
6757 # of a partition > 1 GB
6758 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6760 llverfs $partial_arg $llverfs_opts $dir
6763 #Remove objects from OST
6764 remove_ost_objects() {
6770 local mntpt=$(facet_mntpt $facet)
6771 local opts=$OST_MOUNT_OPTS
6775 echo "removing objects from $ostdev on $facet: $objids"
6776 if ! test -b $ostdev; then
6777 opts=$(csa_add "$opts" -o loop)
6779 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
6782 for i in $objids; do
6783 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
6785 umount -f $mntpt || return $?
6789 #Remove files from MDT
6790 remove_mdt_files() {
6795 local mntpt=$(facet_mntpt $facet)
6796 local opts=$MDS_MOUNT_OPTS
6798 echo "removing files from $mdtdev on $facet: $files"
6799 if [ $(facet_fstype $facet) == ldiskfs ] &&
6800 ! do_facet $facet test -b $mdtdev; then
6801 opts=$(csa_add "$opts" -o loop)
6803 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6807 rm $mntpt/ROOT/$f || { rc=$?; break; }
6809 umount -f $mntpt || return $?
6813 duplicate_mdt_files() {
6818 local mntpt=$(facet_mntpt $facet)
6819 local opts=$MDS_MOUNT_OPTS
6821 echo "duplicating files on $mdtdev on $facet: $files"
6822 mkdir -p $mntpt || return $?
6823 if [ $(facet_fstype $facet) == ldiskfs ] &&
6824 ! do_facet $facet test -b $mdtdev; then
6825 opts=$(csa_add "$opts" -o loop)
6827 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6838 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
6839 pushd $mntpt/ROOT > /dev/null || return $?
6842 touch $f.bad || return $?
6843 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
6845 [ $rc -eq 0 ] || return $rc
6846 setfattr --restore $tmp || return $?
6852 local devs=${1//,/ }
6855 local rslt=$TMP/sgpdd_survey
6857 # sgpdd-survey cleanups ${rslt}.* files
6859 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
6865 # returns the canonical name for an ldiskfs device
6870 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
6871 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
6872 echo dm-\\\${foo##*:};
6874 echo \\\$(basename \\\$dv);
6878 is_sanity_benchmark() {
6879 local benchmarks="dbench bonnie iozone fsx"
6881 for b in $benchmarks; do
6882 if [ "$b" == "$suite" ]; then
6890 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
6894 # Get the available size (KB) of a given obd target.
6901 [[ $facet != client ]] || return 0
6903 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
6908 # Get the page size (bytes) on a given facet node.
6914 size=$(do_facet $facet getconf PAGE_SIZE)
6915 [[ ${PIPESTATUS[0]} = 0 && -n "$size" ]] || size=4096
6920 # Get the block count of the filesystem.
6927 count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6928 awk '/^Block count:/ {print $3}')
6932 # Get the block size of the filesystem.
6938 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6939 awk '/^Block size:/ {print $3}')
6943 # Check whether the "large_xattr" feature is enabled or not.
6944 large_xattr_enabled() {
6945 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
6947 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6949 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
6950 grep -E -q '(ea_inode|large_xattr)'"
6951 return ${PIPESTATUS[0]}
6954 # Get the maximum xattr size supported by the filesystem.
6958 if large_xattr_enabled; then
6959 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
6962 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6963 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
6965 # maximum xattr size = size of block - size of header -
6966 # size of 1 entry - 4 null bytes
6967 size=$((block_size - 32 - 32 - 4))
6973 # Dump the value of the named xattr from a file.
6978 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
6981 # Generate a string with size of $size bytes.
6983 local size=${1:-1024} # in bytes
6985 echo "$(head -c $size < /dev/zero | tr '\0' y)"
6988 reformat_external_journal() {
6993 if [ -n "${!var}" ]; then
6994 local rcmd="do_facet $facet"
6996 echo "reformat external journal on $facet:${!var}"
6997 ${rcmd} mke2fs -O journal_dev ${!var} || return 1
7001 # MDT file-level backup/restore
7002 mds_backup_restore() {
7005 local devname=$(mdsdevname $(facet_number $facet))
7006 local mntpt=$(facet_mntpt brpt)
7007 local rcmd="do_facet $facet"
7008 local metaea=${TMP}/backup_restore.ea
7009 local metadata=${TMP}/backup_restore.tgz
7010 local opts=${MDS_MOUNT_OPTS}
7011 local svc=${facet}_svc
7013 if ! ${rcmd} test -b ${devname}; then
7014 opts=$(csa_add "$opts" -o loop)
7017 echo "file-level backup/restore on $facet:${devname}"
7019 # step 1: build mount point
7020 ${rcmd} mkdir -p $mntpt
7021 # step 2: cleanup old backup
7022 ${rcmd} rm -f $metaea $metadata
7024 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7025 if [ ! -z $igif ]; then
7026 # step 3.5: rm .lustre
7027 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
7029 # step 4: backup metaea
7031 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
7033 # step 5: backup metadata
7035 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
7037 ${rcmd} $UMOUNT $mntpt || return 4
7038 # step 8: reformat dev
7039 echo "reformat new device"
7040 format_mdt $(facet_number $facet)
7042 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
7043 # step 10: restore metadata
7045 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
7046 # step 11: restore metaea
7048 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
7049 # step 12: remove recovery logs
7050 echo "remove recovery logs"
7051 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
7052 # step 13: umount dev
7053 ${rcmd} $UMOUNT $mntpt || return 10
7054 # step 14: cleanup tmp backup
7055 ${rcmd} rm -f $metaea $metadata
7056 # step 15: reset device label - it's not virgin on
7057 ${rcmd} e2label $devname ${!svc}
7064 local devname=$(mdsdevname $(facet_number $facet))
7065 local mntpt=$(facet_mntpt brpt)
7066 local rcmd="do_facet $facet"
7067 local opts=${MDS_MOUNT_OPTS}
7069 if ! ${rcmd} test -b ${devname}; then
7070 opts=$(csa_add "$opts" -o loop)
7073 echo "removing OI files on $facet: idx=${idx}"
7075 # step 1: build mount point
7076 ${rcmd} mkdir -p $mntpt
7078 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
7079 if [ -z $idx ]; then
7080 # step 3: remove all OI files
7081 ${rcmd} rm -fv $mntpt/oi.16*
7082 elif [ $idx -lt 2 ]; then
7083 ${rcmd} rm -fv $mntpt/oi.16.${idx}
7087 # others, rm oi.16.[idx, idx * idx, idx ** ...]
7088 for ((i=${idx}; i<64; i=$((i * idx)))); do
7089 ${rcmd} rm -fv $mntpt/oi.16.${i}
7093 ${rcmd} $UMOUNT $mntpt || return 2
7094 # OI files will be recreated when mounted as lustre next time.
7097 # generate maloo upload-able log file name
7098 # \param logname specify unique part of file name
7099 generate_logname() {
7100 local logname=${1:-"default_logname"}
7102 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
7105 # make directory on different MDTs
7109 local stripe_count=2
7110 local stripe_index=-1
7113 while getopts "c:i:p" opt; do
7115 c) stripe_count=$OPTARG;;
7116 i) stripe_index=$OPTARG;;
7118 \?) error "only support -i -c -p";;
7122 shift $((OPTIND - 1))
7123 [ $# -eq 1 ] || error "Only creating single directory is supported"
7126 if [ "$p_option" == "-p" ]; then
7127 local parent=$(dirname $path)
7129 [ -d $path ] && return 0
7130 [ ! -d ${parent} ] && mkdir -p ${parent}
7133 if [ $MDSCOUNT -le 1 ]; then
7136 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
7139 if [ $stripe_index -eq -1 ]; then
7140 mdt_index=$((test_num % MDSCOUNT))
7142 mdt_index=$stripe_index
7144 echo "striped dir -i$mdt_index -c$stripe_count $path"
7145 $LFS setdirstripe -i$mdt_index -c$stripe_count $path
7149 # find the smallest and not in use file descriptor
7152 local max_fd=$(ulimit -n)
7154 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
7157 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
7161 check_mount_and_prep()
7163 is_mounted $MOUNT || setupall
7165 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
7166 mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
7167 for idx in $(seq $MDSCOUNT); do
7168 local name="MDT$(printf '%04x' $((idx - 1)))"
7169 rm -rf $MOUNT/.lustre/lost+found/$name/*
7173 # calcule how many ost-objects to be created.
7174 precreated_ost_obj_count()
7178 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
7179 local ost_name="OST$(printf '%04x' $ost_idx)"
7180 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
7181 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7182 osp.$proc_path.prealloc_last_id)
7183 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
7184 osp.$proc_path.prealloc_next_id)
7185 echo $((last_id - next_id + 1))
7188 check_file_in_pool()
7193 local res=$($GETSTRIPE $file | grep 0x | cut -f2)
7196 for t in $tlist ; do
7197 [ "$i" -eq "$t" ] && continue 2
7200 echo "pool list: $tlist"
7201 echo "striping: $res"
7202 error_noexit "$file not allocated in $pool"
7209 echo "Creating new pool"
7212 create_pool $FSNAME.$pool ||
7213 { error_noexit "No pool created, result code $?"; return 1; }
7214 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
7215 { error_noexit "$pool not in lfs pool_list"; return 2; }
7218 pool_add_targets() {
7219 echo "Adding targets to pool"
7225 local list=$(seq $first $step $last)
7227 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
7228 do_facet mgs $LCTL pool_add \
7229 $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
7230 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
7231 | sort -u | tr '\n' ' ' " "$t" || {
7232 error_noexit "Add to pool failed"
7235 local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
7236 local addcount=$(((last - first) / step + 1))
7237 [ $lfscount -eq $addcount ] || {
7238 error_noexit "lfs pool_list bad ost count" \
7239 "$lfscount != $addcount"
7247 echo "Setting pool on directory $tdir"
7249 $SETSTRIPE -c 2 -p $pool $tdir && return 0
7251 error_noexit "Cannot set pool $pool to $tdir"
7258 echo "Checking pool on directory $tdir"
7260 local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
7261 [ "$res" = "$pool" ] && return 0
7263 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
7267 pool_dir_rel_path() {
7268 echo "Testing relative path works well"
7273 mkdir -p $root/$tdir/$tdir
7275 pool_set_dir $pool $tdir || return 1
7276 pool_set_dir $pool ./$tdir || return 2
7277 pool_set_dir $pool ../$tdir || return 3
7278 pool_set_dir $pool ../$tdir/$tdir || return 4
7279 rm -rf $tdir; cd - > /dev/null
7282 pool_alloc_files() {
7283 echo "Checking files allocation from directory pool"
7290 for i in $(seq -w 1 $count)
7292 local file=$tdir/file-$i
7294 check_file_in_pool $file $pool "$tlist" || \
7295 failed=$((failed + 1))
7297 [ "$failed" = 0 ] && return 0
7299 error_noexit "$failed files not allocated in $pool"
7303 pool_create_files() {
7304 echo "Creating files in pool"
7312 for i in $(seq -w 1 $count)
7314 local file=$tdir/spoo-$i
7315 $SETSTRIPE -p $pool $file
7316 check_file_in_pool $file $pool "$tlist" || \
7317 failed=$((failed + 1))
7319 [ "$failed" = 0 ] && return 0
7321 error_noexit "$failed files not allocated in $pool"
7326 echo "Checking 'lfs df' output"
7329 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
7331 local res=$($LFS df --pool $FSNAME.$pool |
7333 grep "$FSNAME-OST" |
7335 [ "$res" = "$t" ] && return 0
7337 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
7341 pool_file_rel_path() {
7342 echo "Creating files in a pool with relative pathname"
7347 { error_noexit "unable to create $tdir"; return 1 ; }
7348 local file="/..$tdir/$tfile-1"
7349 $SETSTRIPE -p $pool $file ||
7350 { error_noexit "unable to create $file" ; return 2 ; }
7353 $SETSTRIPE -p $pool $tfile-2 || {
7354 error_noexit "unable to create $tfile-2 in $tdir"
7359 pool_remove_first_target() {
7360 echo "Removing first target from a pool"
7363 local pname="lov.$FSNAME-*.pools.$pool"
7364 local t=$($LCTL get_param -n $pname | head -1)
7365 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7366 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
7367 error_noexit "$t not removed from $FSNAME.$pool"
7372 pool_remove_all_targets() {
7373 echo "Removing all targets from pool"
7376 local pname="lov.$FSNAME-*.pools.$pool"
7377 for t in $($LCTL get_param -n $pname | sort -u)
7379 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7381 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
7382 error_noexit "Pool $FSNAME.$pool cannot be drained"
7385 # striping on an empty/nonexistant pool should fall back
7386 # to "pool of everything"
7388 error_noexit "failed to use fallback striping for empty pool"
7391 # setstripe on an empty pool should fail
7392 $SETSTRIPE -p $pool $file 2>/dev/null && {
7393 error_noexit "expected failure when creating file" \
7401 echo "Destroying pool"
7405 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
7408 # striping on an empty/nonexistant pool should fall back
7409 # to "pool of everything"
7411 error_noexit "failed to use fallback striping for missing pool"
7414 # setstripe on an empty pool should fail
7415 $SETSTRIPE -p $pool $file 2>/dev/null && {
7416 error_noexit "expected failure when creating file" \
7421 # get param should return err once pool is gone
7422 if wait_update $HOSTNAME "lctl get_param -n \
7423 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
7425 remove_pool_from_list $FSNAME.$pool
7428 error_noexit "Pool $FSNAME.$pool is not destroyed"
7432 # Get and check the actual stripe count of one file.
7433 # Usage: check_stripe_count <file> <expected_stripe_count>
7434 check_stripe_count() {
7439 [[ -z "$file" || -z "$expected" ]] &&
7440 error "check_stripe_count: invalid argument"
7442 local cmd="$GETSTRIPE -c $file"
7443 actual=$($cmd) || error "$cmd failed"
7444 actual=${actual%% *}
7446 if [[ $actual -ne $expected ]]; then
7447 [[ $expected -eq -1 ]] ||
7448 error "$cmd wrong: found $actual, expected $expected"
7449 [[ $actual -eq $OSTCOUNT ]] ||
7450 error "$cmd wrong: found $actual, expected $OSTCOUNT"
7454 # Get and check the actual list of OST indices on one file.
7455 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
7461 [[ -z "$file" || -z "$expected" ]] &&
7462 error "check_obdidx: invalid argument!"
7464 obdidx=$(comma_list $($GETSTRIPE $file | grep -A $OSTCOUNT obdidx |
7465 grep -v obdidx | awk '{print $1}' | xargs))
7467 [[ $obdidx = $expected ]] ||
7468 error "list of OST indices on $file is $obdidx," \
7469 "should be $expected"
7472 # Get and check the actual OST index of the first stripe on one file.
7473 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
7474 check_start_ost_idx() {
7479 [[ -z "$file" || -z "$expected" ]] &&
7480 error "check_start_ost_idx: invalid argument!"
7482 start_ost_idx=$($GETSTRIPE $file | grep -A 1 obdidx | grep -v obdidx |
7485 [[ $start_ost_idx = $expected ]] ||
7486 error "OST index of the first stripe on $file is" \
7487 "$start_ost_idx, should be $expected"
7490 killall_process () {
7491 local clients=${1:-$(hostname)}
7496 do_nodes $clients "killall $signal $name"