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 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
81 local form="%-13s %-17s %-9s %s %s\n"
82 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
83 echo "------------------------------------------------------------------------------------"
84 for O in $DEFAULT_SUITES; do
85 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
86 [ "${!O}" = "no" ] && continue || true
87 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
88 local log=${TMP}/${o}.log
89 if is_sanity_benchmark $o; then
90 log=${TMP}/sanity-benchmark.log
95 local status=Unfinished
97 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
99 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
100 sort -nr -k 3 | head -n5 | awk '{ print $2":"$3"s" }')
101 total=$(grep duration $log | awk '{ print $2 }')
102 if [ "${!O}" = "done" ]; then
106 local durations=$(egrep "^PASS|^FAIL" $log |
107 tr -d "("| sed s/s\)$//g |
108 awk '{ print $2":"$3"|" }')
109 details=$(printf "%s\n%s %s %s\n" "$details" \
110 "DDETAILS" "$O" "$(echo $durations)")
113 printf "$form" $status "$O" "${total}" "E=$skipped"
114 printf "$form" "-" "-" "-" "S=$(echo $slow)"
117 for O in $DEFAULT_SUITES; do
118 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
119 if [ "${!O}" = "no" ]; then
120 printf "$form" "Skipped" "$O" ""
124 # print the detailed tests durations if DDETAILS=true
131 export LUSTRE=$(absolute_path $LUSTRE)
132 export TESTSUITE=$(basename $0 .sh)
133 export TEST_FAILED=false
134 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
135 export RPC_MODE=${RPC_MODE:-false}
137 export MKE2FS=$MKE2FS
138 if [ -z "$MKE2FS" ]; then
139 if which mkfs.ldiskfs >/dev/null 2>&1; then
140 export MKE2FS=mkfs.ldiskfs
146 export DEBUGFS=$DEBUGFS
147 if [ -z "$DEBUGFS" ]; then
148 if which debugfs.ldiskfs >/dev/null 2>&1; then
149 export DEBUGFS=debugfs.ldiskfs
151 export DEBUGFS=debugfs
155 export TUNE2FS=$TUNE2FS
156 if [ -z "$TUNE2FS" ]; then
157 if which tunefs.ldiskfs >/dev/null 2>&1; then
158 export TUNE2FS=tunefs.ldiskfs
160 export TUNE2FS=tune2fs
164 export E2LABEL=$E2LABEL
165 if [ -z "$E2LABEL" ]; then
166 if which label.ldiskfs >/dev/null 2>&1; then
167 export E2LABEL=label.ldiskfs
169 export E2LABEL=e2label
173 export DUMPE2FS=$DUMPE2FS
174 if [ -z "$DUMPE2FS" ]; then
175 if which dumpfs.ldiskfs >/dev/null 2>&1; then
176 export DUMPE2FS=dumpfs.ldiskfs
178 export DUMPE2FS=dumpe2fs
182 export E2FSCK=$E2FSCK
183 if [ -z "$E2FSCK" ]; then
184 if which fsck.ldiskfs >/dev/null 2>&1; then
185 export E2FSCK=fsck.ldiskfs
191 export RESIZE2FS=$RESIZE2FS
192 if [ -z "$RESIZE2FS" ]; then
193 if which resizefs.ldiskfs >/dev/null 2>&1; then
194 export RESIZE2FS=resizefs.ldiskfs
196 export RESIZE2FS=resize2fs
200 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
201 export FSCK_MAX_ERR=4 # File system errors left uncorrected
203 export ZFS=${ZFS:-zfs}
204 export ZPOOL=${ZPOOL:-zpool}
205 export ZDB=${ZDB:-zdb}
206 export PARTPROBE=${PARTPROBE:-partprobe}
208 #[ -d /r ] && export ROOT=${ROOT:-/r}
209 export TMP=${TMP:-$ROOT/tmp}
210 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
211 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
212 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
214 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
215 if ! echo $PATH | grep -q $LUSTRE/utils; then
216 export PATH=$LUSTRE/utils:$PATH
218 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
219 export PATH=$LUSTRE/utils/gss:$PATH
221 if ! echo $PATH | grep -q $LUSTRE/tests; then
222 export PATH=$LUSTRE/tests:$PATH
224 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
225 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
227 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
228 [ ! -f "$LST" ] && export LST=$(which lst)
229 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
230 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
231 export MCREATE=${MCREATE:-mcreate}
232 # Ubuntu, at least, has a truncate command in /usr/bin
233 # so fully path our truncate command.
234 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
235 export FSX=${FSX:-$LUSTRE/tests/fsx}
236 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
237 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
238 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
239 export PATH=$LUSTRE/tests/racer:$PATH:
241 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
242 export PATH=$LUSTRE/tests/mpi:$PATH
244 export RSYNC_RSH=${RSYNC_RSH:-rsh}
246 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
247 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
248 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
249 [ ! -f "$LFS" ] && export LFS=$(which lfs)
250 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
251 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
253 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
254 if [ ! -f "$L_GETIDENTITY" ]; then
255 if `which l_getidentity > /dev/null 2>&1`; then
256 export L_GETIDENTITY=$(which l_getidentity)
258 export L_GETIDENTITY=NONE
261 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
262 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
263 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
264 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
265 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
266 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
267 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
268 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
269 [ ! -f "$LUSTRE_RMMOD" ] &&
270 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
271 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
272 [ ! -f "$LFS_MIGRATE" ] &&
273 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
274 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
275 [ ! -f "$LR_READER" ] && export LR_READER=$(which lr_reader 2> /dev/null)
276 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
277 export NAME=${NAME:-local}
278 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
279 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
280 export LGSSD=$(which lgssd)
281 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
282 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
283 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
285 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
288 if [ "$ACCEPTOR_PORT" ]; then
289 export PORT_OPT="--port $ACCEPTOR_PORT"
294 echo "Using GSS/krb5 ptlrpc security flavor"
295 which lgss_keyring > /dev/null 2>&1 || \
296 error_exit "built with gss disabled! SEC=$SEC"
307 IDENTITY_UPCALL=false
311 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
313 # Paths on remote nodes, if different
314 export RLUSTRE=${RLUSTRE:-$LUSTRE}
315 export RPWD=${RPWD:-$PWD}
316 export I_MOUNTED=${I_MOUNTED:-"no"}
317 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
318 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
319 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
320 ! -f $LUSTRE/mdt/mdt.ko ]; then
321 export CLIENTMODSONLY=yes
324 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
325 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
329 while getopts "rvwf:" opt $*; do
332 r) REFORMAT=--reformat;;
334 w) WRITECONF=writeconf;;
339 shift $((OPTIND - 1))
342 # print the durations of each test if "true"
343 DDETAILS=${DDETAILS:-false}
344 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
349 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
356 ncpts=$(do_facet $facet "lctl get_param -n " \
357 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
359 if [ $ncpts -eq 0 ]; then
366 # Return a numeric version code based on a version string. The version
367 # code is useful for comparison two version strings to see which is newer.
369 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
370 eval set -- $(tr "[:punct:]" " " <<< $*)
372 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
375 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
376 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
378 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
380 # usage: lustre_build_version
382 # All Lustre versions support "lctl get_param" to report the version of the
383 # code running in the kernel (what our tests are interested in), but it
384 # doesn't work without modules loaded. If that fails, use "lctl version"
385 # instead, which is easy to parse and works without the kernel modules,
386 # but was only added in 2.6.50. If that also fails, fall back to calling
387 # "lctl lustre_build_version" which prints either (or both) the userspace
388 # and kernel build versions, but is deprecated and should eventually be
391 # output: prints version string to stdout in dotted-decimal format
392 lustre_build_version() {
393 local facet=${1:-client}
396 # kernel: patchless_client
397 # build: v2_6_92_0-gadb3ee4-2.6.32-431.29.2.el6_lustre.x86_64
398 local VER=$(do_facet $facet $LCTL get_param -n version 2> /dev/null |
399 awk '/lustre: / { print $2 }')
401 [ -z "$VER" ] && VER=$(do_facet $facet $LCTL --version 2>/dev/null |
403 # Lustre version: 2.5.3-gfcfd782-CHANGED-2.6.32.26-175.fc12.x86_64
404 # lctl version: 2.5.3-gfcfd782-CHANGED-2.6.32.26-175.fc12.x86_64
405 [ -z "$VER" ] && VER=$(do_facet $facet $LCTL lustre_build_version |
406 awk '/version:/ { print $3; exit; }')
407 sed -e 's/^v//' -e 's/-.*//' -e 's/_/./g' <<<$VER
410 # Report the Lustre numeric build version code for the supplied facet.
411 lustre_version_code() {
412 version_code $(lustre_build_version $1)
416 /sbin/lsmod | grep -q "^\<$1\>"
419 # Load a module on the system where this is running.
421 # usage: load_module module_name [module arguments for insmod/modprobe]
423 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
424 # will be used as the arguments. Otherwise arguments will be obtained from
425 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
432 BASE=$(basename $module $EXT)
434 module_loaded ${BASE} && return
436 # If no module arguments were passed, get them from $MODOPTS_<MODULE>,
437 # else from modprobe.conf
438 if [ $# -eq 0 ]; then
439 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
440 # Bash until 4.x, so we resort to eval.
441 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
442 eval set -- \$$optvar
443 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
444 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
446 opt=$(awk -v var="^options $BASE" '$0 ~ var \
447 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
448 set -- $(echo -n $opt)
450 # Ensure we have accept=all for lnet
451 if [ $(basename $module) = lnet ]; then
452 # OK, this is a bit wordy...
453 local arg accept_all_present=false
456 [ "$arg" = accept=all ] && \
457 accept_all_present=true
459 $accept_all_present || set -- "$@" accept=all
465 [ $# -gt 0 ] && echo "${module} options: '$*'"
467 # Note that insmod will ignore anything in modprobe.conf, which is why
468 # we're passing options on the command-line.
469 if [[ "$BASE" == "lnet_selftest" ]] &&
470 [[ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]]; then
471 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
472 elif [[ -f ${LUSTRE}/${module}${EXT} ]]; then
473 [[ "$BASE" != "ptlrpc_gss" ]] || modprobe sunrpc
474 insmod ${LUSTRE}/${module}${EXT} "$@"
476 # must be testing a "make install" or "rpm" installation
477 # note failed to load ptlrpc_gss is considered not fatal
478 if [[ "$BASE" == "ptlrpc_gss" ]]; then
479 modprobe $BASE "$@" 2>/dev/null ||
480 echo "gss/krb5 is not supported"
487 llite_lloop_enabled() {
488 local n1=$(uname -r | cut -d. -f1)
489 local n2=$(uname -r | cut -d. -f2)
490 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
492 # load the llite_lloop module for < 2.6.32 kernels
493 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
494 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
501 load_modules_local() {
502 if [ -n "$MODPROBE" ]; then
504 echo "Using modprobe to load modules"
508 echo Loading modules from $LUSTRE
512 if [ -f /sys/devices/system/cpu/online ]; then
513 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
514 echo "detected $ncpus online CPUs by sysfs"
516 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
518 if [ $rc -eq 0 ]; then
519 echo "detected $ncpus online CPUs by getconf"
521 echo "Can't detect number of CPUs"
526 # if there is only one CPU core, libcfs can only create one partition
527 # if there is more than 4 CPU cores, libcfs should create multiple CPU
528 # partitions. So we just force libcfs to create 2 partitions for
529 # system with 2 or 4 cores
530 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
531 # force to enable multiple CPU partitions
532 echo "Force libcfs to create 2 CPU partitions"
533 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
535 echo "libcfs will create CPU partition based on online CPUs"
538 load_module ../libcfs/libcfs/libcfs
540 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
541 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
542 load_module ../lnet/lnet/lnet
545 LNETLND="o2iblnd/ko2iblnd"
550 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
551 load_module ../lnet/klnds/$LNETLND
552 load_module obdclass/obdclass
553 load_module ptlrpc/ptlrpc
554 load_module ptlrpc/gss/ptlrpc_gss
562 load_module obdecho/obdecho
563 if ! client_only; then
564 SYMLIST=/proc/kallsyms
565 grep -q crc16 $SYMLIST || { modprobe crc16 2>/dev/null || true; }
566 grep -q -w jbd $SYMLIST || { modprobe jbd 2>/dev/null || true; }
567 grep -q -w jbd2 $SYMLIST || { modprobe jbd2 2>/dev/null || true; }
568 load_module lfsck/lfsck
569 [ "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
570 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
572 load_module osd-zfs/osd_zfs
574 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
575 grep -q exportfs_decode_fh $SYMLIST ||
576 { modprobe exportfs 2> /dev/null || true; }
577 load_module ../ldiskfs/ldiskfs
578 load_module osd-ldiskfs/osd_ldiskfs
590 load_module llite/lustre
591 llite_lloop_enabled && load_module llite/llite_lloop
592 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
594 rm -f $OGDB/ogdb-$HOSTNAME
595 $LCTL modules > $OGDB/ogdb-$HOSTNAME
597 # 'mount' doesn't look in $PATH, just sbin
598 local mount_lustre=$LUSTRE/utils/mount.lustre
599 if [ -f $mount_lustre ]; then
600 local sbin_mount=$(readlink -f /sbin)/mount.lustre
601 if grep -qw "$sbin_mount" /proc/mounts; then
602 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
604 if ! grep -qw "$sbin_mount" /proc/mounts; then
605 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
606 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
607 cat <<- EOF > "$sbin_mount"
610 echo "This $sbin_mount just a mountpoint." 1>&2
611 echo "It is never supposed to be run." 1>&2
612 logger -p emerg -- "using stub $sbin_mount $@"
615 chmod a+x $sbin_mount
617 mount --bind $mount_lustre $sbin_mount ||
618 error "can't bind $mount_lustre to $sbin_mount"
626 # load modules on remote nodes optionally
627 # lustre-tests have to be installed on these nodes
628 if $LOAD_MODULES_REMOTE; then
629 local list=$(comma_list $(remote_nodes_list))
630 if [ -n "$list" ]; then
631 echo "loading modules on: '$list'"
632 do_rpc_nodes "$list" load_modules_local
638 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
639 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
640 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
641 echo "$LEAK_LUSTRE" 1>&2
642 echo "$LEAK_PORTALS" 1>&2
643 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
644 echo "Memory leaks detected"
645 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
651 wait_exit_ST client # bug 12845
653 $LUSTRE_RMMOD ldiskfs || return 2
655 if $LOAD_MODULES_REMOTE; then
656 local list=$(comma_list $(remote_nodes_list))
657 if [ -n "$list" ]; then
658 echo "unloading modules on: '$list'"
659 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
660 do_rpc_nodes "$list" check_mem_leak
664 local sbin_mount=$(readlink -f /sbin)/mount.lustre
665 if grep -qe "$sbin_mount " /proc/mounts; then
666 umount $sbin_mount || true
667 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
671 check_mem_leak || return 254
673 echo "modules unloaded."
678 local facet=${1:-$SINGLEMDS}
679 local fstype=$(facet_fstype $facet)
682 ldiskfs) size=50;; # largest seen is 44, leave some headroom
683 zfs) size=400;; # largest seen is 384
689 check_gss_daemon_nodes() {
693 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
694 if [ \\\"\\\$num\\\" -ne 1 ]; then
695 echo \\\$num instance of $dname;
700 check_gss_daemon_facet() {
704 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
705 if [ $num -ne 1 ]; then
706 echo "$num instance of $dname on $facet"
715 echo Stopping $@ on $list
716 do_nodes $list "killall -2 $@ 2>/dev/null || true"
719 # start gss daemons on all nodes, or
720 # "daemon" on "list" if set
721 start_gss_daemons() {
725 if [ "$list" ] && [ "$daemon" ] ; then
726 echo "Starting gss daemon on nodes: $list"
727 do_nodes $list "$daemon" || return 8
731 local list=$(comma_list $(mdts_nodes))
732 echo "Starting gss daemon on mds: $list"
733 do_nodes $list "$LSVCGSSD -v" || return 1
735 do_nodes $list "$LGSSD -v" || return 2
738 list=$(comma_list $(osts_nodes))
739 echo "Starting gss daemon on ost: $list"
740 do_nodes $list "$LSVCGSSD -v" || return 3
741 # starting on clients
743 local clients=${CLIENTS:-`hostname`}
745 echo "Starting $LGSSD on clients $clients "
746 do_nodes $clients "$LGSSD -v" || return 4
749 # wait daemons entering "stable" status
753 # check daemons are running
755 list=$(comma_list $(mdts_nodes) $(osts_nodes))
756 check_gss_daemon_nodes $list lsvcgssd || return 5
758 list=$(comma_list $(mdts_nodes))
759 check_gss_daemon_nodes $list lgssd || return 6
762 check_gss_daemon_nodes $clients lgssd || return 7
767 local list=$(comma_list $(mdts_nodes))
769 send_sigint $list lsvcgssd lgssd
771 list=$(comma_list $(osts_nodes))
772 send_sigint $list lsvcgssd
774 list=${CLIENTS:-`hostname`}
775 send_sigint $list lgssd
780 if ! module_loaded ptlrpc_gss; then
781 load_module ptlrpc/gss/ptlrpc_gss
782 module_loaded ptlrpc_gss ||
783 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
786 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
789 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
791 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
799 # maybe cleanup credential cache?
805 local var=${facet}_svc
813 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
814 tr '[:lower:]' '[:upper:]'
820 if [ $facet == mgs ]; then
824 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
832 if [ -n "${!var}" ]; then
837 var=$(facet_type $facet)FSTYPE
838 if [ -n "${!var}" ]; then
843 if [ -n "$FSTYPE" ]; then
848 if [[ $facet == mgs ]] && combined_mgs_mds; then
860 local facets=$(get_facets)
863 for facet in ${facets//,/ }; do
864 if [ $node == $(facet_host $facet) ] ||
865 [ $node == "$(facet_failover_host $facet)" ]; then
866 fstype=$(facet_fstype $facet)
867 if [[ $fstypes != *$fstype* ]]; then
868 fstypes+="${fstypes:+,}$fstype"
877 local num=$(facet_number $facet)
880 if [[ $(facet_type $facet) = OST ]]; then
882 if [[ -n "${!index}" ]]; then
887 index=${OST_INDICES[num - 1]}
890 [[ -n "$index" ]] || index=$((num - 1))
898 local fstype=$(facet_fstype $facet)
902 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
904 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
905 ${dev} 2>/dev/null");;
907 error "unknown fstype!";;
915 local device=$(mdsdevname $num)
916 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
922 local device=$(ostdevname $num)
923 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
928 # Get the device of a facet.
935 mgs) device=$(mgsdevname) ;;
936 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
937 ost*) device=$(ostdevname $(facet_number $facet)) ;;
938 fs2mds) device=$(mdsdevname 1_2) ;;
939 fs2ost) device=$(ostdevname 1_2) ;;
940 fs3ost) device=$(ostdevname 2_2) ;;
948 # Get the virtual device of a facet.
955 mgs) device=$(mgsvdevname) ;;
956 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
957 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
958 fs2mds) device=$(mdsvdevname 1_2) ;;
959 fs2ost) device=$(ostvdevname 1_2) ;;
960 fs3ost) device=$(ostvdevname 2_2) ;;
968 # Re-read the partition table on failover partner host.
969 # After a ZFS storage pool is created on a shared device, the partition table
970 # on the device may change. However, the operating system on the failover
971 # host may not notice the change automatically. Without the up-to-date partition
972 # block devices, 'zpool import ..' cannot find the labels, whose positions are
973 # relative to partition rather than disk beginnings.
975 # This function performs partprobe on the failover host to make it re-read the
978 refresh_partition_table() {
983 host=$(facet_passive_host $facet)
984 if [[ -n "$host" ]]; then
985 do_node $host "$PARTPROBE $device"
990 # Get ZFS storage pool name.
997 device=$(facet_device $facet)
998 # poolname is string before "/"
999 poolname="${device%%/*}"
1005 # Create ZFS storage pool.
1012 local opts=${@:-"-o cachefile=none"}
1014 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
1015 $ZPOOL create -f $opts $poolname $vdev"
1019 # Create ZFS file system.
1025 local opts=${@:-"-o mountpoint=legacy"}
1027 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1028 $ZFS create $opts $dataset"
1032 # Export ZFS storage pool.
1033 # Before exporting the pool, all datasets within the pool should be unmounted.
1041 poolname=$(zpool_name $facet)
1043 if [[ -n "$poolname" ]]; then
1044 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1045 grep -q ^$poolname/ /proc/mounts ||
1046 $ZPOOL export $opts $poolname"
1051 # Destroy ZFS storage pool.
1052 # Destroy the given pool and free up any devices for other use. This command
1053 # tries to unmount any active datasets before destroying the pool.
1054 # -f Force any active datasets contained within the pool to be unmounted.
1058 local poolname=${2:-$(zpool_name $facet)}
1060 if [[ -n "$poolname" ]]; then
1061 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1062 $ZPOOL destroy -f $poolname"
1067 # Import ZFS storage pool.
1068 # Force importing, even if the pool appears to be potentially active.
1073 local opts=${@:-"-o cachefile=none"}
1076 poolname=$(zpool_name $facet)
1078 if [[ -n "$poolname" ]]; then
1079 opts+=" -d $(dirname $(facet_vdevice $facet))"
1080 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
1081 $ZPOOL import -f $opts $poolname"
1086 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1087 # is not automatically imported on system startup.
1089 # In a failover environment, this will provide resource level fencing which
1090 # will ensure that the same ZFS storage pool will not be imported concurrently
1091 # on different nodes.
1093 disable_zpool_cache() {
1097 poolname=$(zpool_name $facet)
1099 if [[ -n "$poolname" ]]; then
1100 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1105 # This and set_osd_param() shall be used to access OSD parameters
1106 # once existed under "obdfilter":
1111 # writethrough_cache_enable
1115 local device=${2:-$FSNAME-OST*}
1118 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1119 osd-*.$device.$name 2>&1" | grep -v 'Found no match'
1124 local device=${2:-$FSNAME-OST*}
1128 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1129 osd-*.$device.$name=$value 2>&1" | grep -v 'Found no match'
1133 local dz=${1:-$DEBUG_SIZE}
1135 if [ -f /sys/devices/system/cpu/possible ]; then
1136 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1138 local cpus=$(getconf _NPROCESSORS_CONF)
1141 # bug 19944, adjust size to be -gt num_possible_cpus()
1142 # promise 2MB for every cpu at least
1143 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1146 lctl set_param debug_mb=$dz
1149 set_default_debug () {
1150 local debug=${1:-"$PTLDEBUG"}
1151 local subsys=${2:-"$SUBSYSTEM"}
1152 local debug_size=${3:-$DEBUG_SIZE}
1154 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1155 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1157 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1160 set_default_debug_nodes () {
1163 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1164 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1168 do_rpc_nodes "$nodes" set_default_debug \
1169 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1172 set_default_debug_facet () {
1174 local node=$(facet_active_host $facet)
1175 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1177 set_default_debug_nodes $node
1182 local facets=${1:-$(get_facets)}
1185 for facet in ${facets//,/ }; do
1188 [ $RC -eq 0 ] && continue
1190 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1191 skip "Restart of $facet failed!." && touch $LU482_FAILED
1193 error "Restart of $facet failed!"
1200 # Add argument "arg" (e.g., "loop") to the comma-separated list
1201 # of arguments for option "opt" (e.g., "-o") on command
1202 # line "opts" (e.g., "-o flock").
1208 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1210 if echo "$opts" | grep -q $opt_pattern; then
1211 opts=$(echo "$opts" | sed -e \
1212 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1214 opts+="${opts:+ }$opt $arg"
1222 local dev=$(facet_active $facet)_dev
1223 local opt=${facet}_opt
1224 local mntpt=$(facet_mntpt $facet)
1225 local opts="${!opt} $@"
1227 module_loaded lustre || load_modules
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 # get mdt quota type
1387 local varsvc=${SINGLEMDS}_svc
1388 do_facet $SINGLEMDS $LCTL get_param -n \
1389 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1392 # get ost quota type
1394 # All OSTs should have same quota type
1395 local varsvc=ost1_svc
1396 do_facet ost1 $LCTL get_param -n \
1397 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1400 # restore old quota type settings
1402 if [ "$old_MDT_QUOTA_TYPE" ]; then
1403 do_facet mgs $LCTL conf_param \
1404 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1406 if [ "$old_OST_QUOTA_TYPE" ]; then
1407 do_facet mgs $LCTL conf_param \
1408 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1412 # Handle the case when there is a space in the lfs df
1413 # "filesystem summary" line the same as when there is no space.
1414 # This will allow fixing the "lfs df" summary line in the future.
1416 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1419 # Get free inodes on the MDT specified by mdt index, free indoes on
1420 # the whole filesystem will be returned when index == -1.
1426 if [ $index -eq -1 ]; then
1429 mdt_uuid=$(mdtuuid_from_index $index)
1432 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1439 # save old quota type & set new quota type
1440 local mdt_qtype=$(mdt_quota_type)
1441 local ost_qtype=$(ost_quota_type)
1443 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1444 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1446 export old_MDT_QUOTA_TYPE=$mdt_qtype
1447 export old_OST_QUOTA_TYPE=$ost_qtype
1449 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1450 error "set mdt quota type failed"
1451 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1452 error "set ost quota type failed"
1454 local quota_usrs=$QUOTA_USERS
1456 # get_filesystem_size
1457 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1458 local blk_soft=$((disksz + 1024))
1459 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1461 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1462 local i_soft=$inodes
1463 local i_hard=$((i_soft + i_soft / 20))
1465 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1466 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1467 "inode-hardlimit: $i_hard"
1470 for usr in $quota_usrs; do
1471 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1473 cmd="$LFS setquota -$type $usr -b $blk_soft"
1474 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1476 eval $cmd || error "$cmd FAILED!"
1478 # display the quota status
1479 echo "Quota settings for $usr : "
1480 $LFS quota -v -u $usr $mntpt || true
1487 local opts=${3:-$MOUNT_OPTS}
1488 opts=${opts:+-o $opts}
1489 local flags=${4:-$MOUNT_FLAGS}
1491 local device=$MGSNID:/$FSNAME
1492 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1493 echo Bad zconf mount command: opt=$flags $opts dev=$device mnt=$mnt
1497 echo "Starting client: $client: $flags $opts $device $mnt"
1498 do_node $client mkdir -p $mnt
1499 do_node $client $MOUNT_CMD $flags $opts $device $mnt || return 1
1501 set_default_debug_nodes $client
1513 [ "$3" ] && force=-f
1514 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1515 if [ $running -ne 0 ]; then
1516 echo "Stopping client $client $mnt (opts:$force)"
1517 do_node $client lsof -t $mnt || need_kill=no
1518 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1519 pids=$(do_node $client lsof -t $mnt | sort -u);
1520 if [ -n $pids ]; then
1521 do_node $client kill -9 $pids || true
1525 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1526 if [ $busy -ne 0 ] ; then
1527 echo "$mnt is still busy, wait one second" && sleep 1
1528 do_node $client umount $force $mnt
1533 # nodes is comma list
1534 sanity_mount_check_nodes () {
1540 # FIXME: assume that all cluster nodes run the same os
1541 [ "$(uname)" = Linux ] || return 0
1544 for mnt in $mnts ; do
1545 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1546 mpts=\\\$(mount | grep -c $mnt' ');
1547 if [ \\\$running -ne \\\$mpts ]; then
1548 echo \\\$(hostname) env are INSANE!;
1551 [ $? -eq 0 ] || rc=1
1556 sanity_mount_check_servers () {
1557 [ "$CLIENTONLY" ] &&
1558 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1559 echo Checking servers environments
1561 # FIXME: modify get_facets to display all facets wo params
1562 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1566 for facet in ${facets//,/ }; do
1567 node=$(facet_host ${facet})
1568 mntpt=$(facet_mntpt $facet)
1569 sanity_mount_check_nodes $node $mntpt ||
1570 { error "server $node environments are insane!"; return 1; }
1574 sanity_mount_check_clients () {
1575 local clients=${1:-$CLIENTS}
1576 local mntpt=${2:-$MOUNT}
1577 local mntpt2=${3:-$MOUNT2}
1579 [ -z $clients ] && clients=$(hostname)
1580 echo Checking clients $clients environments
1582 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1583 error "clients environments are insane!"
1586 sanity_mount_check () {
1587 sanity_mount_check_servers || return 1
1588 sanity_mount_check_clients || return 2
1591 # mount clients if not mouted
1592 zconf_mount_clients() {
1595 local opts=${3:-$MOUNT_OPTS}
1596 opts=${opts:+-o $opts}
1597 local flags=${4:-$MOUNT_FLAGS}
1599 local device=$MGSNID:/$FSNAME
1600 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1601 echo Bad zconf mount command: opt=$flags $opts dev=$device mnt=$mnt
1605 echo "Starting client $clients: $flags $opts $device $mnt"
1608 running=\\\$(mount | grep -c $mnt' ');
1610 if [ \\\$running -eq 0 ] ; then
1612 $MOUNT_CMD $flags $opts $device $mnt;
1615 exit \\\$rc" || return ${PIPESTATUS[0]}
1617 echo "Started clients $clients: "
1618 do_nodes $clients "mount | grep $mnt' '"
1620 set_default_debug_nodes $clients
1625 zconf_umount_clients() {
1630 [ "$3" ] && force=-f
1632 echo "Stopping clients: $clients $mnt (opts:$force)"
1633 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1634 if [ \\\$running -ne 0 ] ; then
1635 echo Stopping client \\\$(hostname) $mnt opts:$force;
1636 lsof $mnt || need_kill=no;
1637 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1638 pids=\\\$(lsof -t $mnt | sort -u);
1639 if [ -n \\\"\\\$pids\\\" ]; then
1643 while umount $force $mnt 2>&1 | grep -q "busy"; do
1644 echo "$mnt is still busy, wait one second" && sleep 1;
1651 echo + $POWER_DOWN $node
1655 shutdown_node_hard () {
1657 local attempts=$SHUTDOWN_ATTEMPTS
1659 for i in $(seq $attempts) ; do
1662 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1663 echo "waiting for $host to fail attempts=$attempts"
1664 [ $i -lt $attempts ] || \
1665 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1671 local mnt=${2:-$MOUNT}
1674 if [ "$FAILURE_MODE" = HARD ]; then
1675 shutdown_node_hard $client
1677 zconf_umount_clients $client $mnt -f
1683 local facets="$(get_facets OST),$(get_facets MDS)"
1686 combined_mgs_mds || facets="$facets,mgs"
1688 for facet in ${facets//,/ }; do
1689 if [ $(facet_active_host $facet) == $host ]; then
1690 affected="$affected $facet"
1694 echo $(comma_list $affected)
1699 local host=${2:-$(facet_host $facet)}
1701 local label=$(convert_facet2label $facet)
1702 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
1705 facets_up_on_host () {
1707 local facets=$(facets_on_host $host)
1710 for facet in ${facets//,/ }; do
1711 if $(facet_up $facet $host); then
1712 affected_up="$affected_up $facet"
1716 echo $(comma_list $affected_up)
1722 if [ "$FAILURE_MODE" = HARD ]; then
1723 shutdown_node_hard $(facet_active_host $facet)
1731 echo + $POWER_UP $node
1744 if [ "$FAILURE_MODE" = HARD ]; then
1745 reboot_node $(facet_active_host $facet)
1753 if [ "$FAILURE_MODE" = HARD ]; then
1763 for facet in ${facets//,/ }; do
1764 hosts=$(expand_list $hosts $(facet_host $facet) )
1770 _check_progs_installed () {
1774 for prog in $progs; do
1775 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1776 echo $prog missing on $(hostname)
1783 check_progs_installed () {
1787 do_rpc_nodes "$nodes" _check_progs_installed $@
1790 # recovery-scale functions
1792 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1795 start_client_load() {
1798 local var=$(node_var_name $client)_load
1799 eval export ${var}=$load
1801 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1802 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1803 END_RUN_FILE=$END_RUN_FILE \
1804 LOAD_PID_FILE=$LOAD_PID_FILE \
1805 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1806 TESTNAME=$TESTNAME \
1807 DBENCH_LIB=$DBENCH_LIB \
1808 DBENCH_SRC=$DBENCH_SRC \
1809 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1813 log "Started client load: ${load} on $client"
1815 # get the children process IDs
1816 local pids=$(ps --ppid $ppid -o pid= | xargs)
1817 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1821 start_client_loads () {
1822 local -a clients=(${1//,/ })
1823 local numloads=${#CLIENT_LOADS[@]}
1826 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1827 testnum=$((nodenum % numloads))
1828 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1830 # bug 22169: wait the background threads to start
1834 # only for remote client
1835 check_client_load () {
1837 local var=$(node_var_name $client)_load
1838 local TESTLOAD=run_${!var}.sh
1840 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1842 # bug 18914: try to connect several times not only when
1843 # check ps, but while check_catastrophe also
1846 while [ $RC = 254 -a $tries -gt 0 ]; do
1850 if ! check_catastrophe $client; then
1852 if [ $RC -eq 254 ]; then
1853 # FIXME: not sure how long we shuold sleep here
1857 echo "check catastrophe failed: RC=$RC "
1861 # We can continue try to connect if RC=254
1862 # Just print the warning about this
1863 if [ $RC = 254 ]; then
1864 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1867 # see if the load is still on the client
1870 while [ $RC = 254 -a $tries -gt 0 ]; do
1874 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1879 if [ $RC = 254 ]; then
1880 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1881 # see if we can diagnose a bit why this is
1886 check_client_loads () {
1887 local clients=${1//,/ }
1891 for client in $clients; do
1892 check_client_load $client
1894 if [ "$rc" != 0 ]; then
1895 log "Client load failed on node $client, rc=$rc"
1901 restart_client_loads () {
1902 local clients=${1//,/ }
1903 local expectedfail=${2:-""}
1907 for client in $clients; do
1908 check_client_load $client
1910 if [ "$rc" != 0 -a "$expectedfail" ]; then
1911 local var=$(node_var_name $client)_load
1912 start_client_load $client ${!var}
1913 echo "Restarted client load ${!var}: on $client. Checking ..."
1914 check_client_load $client
1916 if [ "$rc" != 0 ]; then
1917 log "Client load failed to restart on node $client, rc=$rc"
1918 # failure one client load means test fail
1919 # we do not need to check other
1928 # Start vmstat and save its process ID in a file.
1933 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1936 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1937 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1940 # Display the nodes on which client loads failed.
1941 print_end_run_file() {
1945 [ -s $file ] || return 0
1947 echo "Found the END_RUN_FILE file: $file"
1950 # A client load will stop if it finds the END_RUN_FILE file.
1951 # That does not mean the client load actually failed though.
1952 # The first node in END_RUN_FILE is the one we are interested in.
1955 if [ -n "$node" ]; then
1956 local var=$(node_var_name $node)_load
1958 local prefix=$TESTLOG_PREFIX
1959 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
1960 local stdout_log=$prefix.run_${!var}_stdout.$node.log
1961 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
1963 echo "Client load ${!var} failed on node $node:"
1969 # Stop the process which had its PID saved in a file.
1974 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1976 do_nodes $nodes "test -f $pid_file &&
1977 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
1980 # Stop all client loads.
1981 stop_client_loads() {
1982 local nodes=${1:-$CLIENTS}
1985 # stop the client loads
1986 stop_process $nodes $pid_file
1988 # clean up the processes that started them
1989 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
1991 # End recovery-scale functions
1993 # verify that lustre actually cleaned up properly
1995 VAR=$(lctl get_param -n catastrophe 2>&1)
1996 if [ $? = 0 ] ; then
1997 if [ $VAR != 0 ]; then
1998 error "LBUG/LASSERT detected"
2001 BUSY=$(dmesg | grep -i destruct || true)
2002 if [ -n "$BUSY" ]; then
2004 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
2008 check_mem_leak || exit 204
2010 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
2011 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2014 if module_loaded lnet || module_loaded libcfs; then
2015 echo "$TESTSUITE: modules still loaded..." 1>&2
2024 if [[ "$1" == "--verbose" ]]; then
2039 PREV_RESULT=$(do_node $node "$TEST")
2041 RESULT=$(do_node $node "$TEST")
2042 if [[ "$RESULT" == "$FINAL" ]]; then
2043 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2044 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2048 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2049 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2053 [[ $WAIT -ge $MAX ]] && break
2054 [[ $((WAIT % print)) -eq 0 ]] &&
2055 echo "Waiting $((MAX - WAIT)) secs for update"
2056 WAIT=$((WAIT + sleep))
2059 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2063 wait_update_facet() {
2065 [ "$1" = "--verbose" ] && verbose="$1" && shift
2069 wait_update $verbose $(facet_active_host $facet) "$@"
2073 do_nodes $(comma_list $(mdts_nodes)) \
2074 "lctl set_param -n osd*.*MDT*.force_sync=1"
2075 do_nodes $(comma_list $(osts_nodes)) \
2076 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
2077 grep -v 'Found no match'
2080 wait_delete_completed_mds() {
2081 local MAX_WAIT=${1:-20}
2082 # for ZFS, waiting more time for DMUs to be committed
2083 local ZFS_WAIT=${2:-5}
2085 local stime=$(date +%s)
2090 # find MDS with pending deletions
2091 for node in $(mdts_nodes); do
2092 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2093 2>/dev/null | calc_sum)
2094 if [[ $changes -eq 0 ]]; then
2097 mds2sync="$mds2sync $node"
2099 if [ -z "$mds2sync" ]; then
2102 mds2sync=$(comma_list $mds2sync)
2104 # sync MDS transactions
2105 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2107 # wait till all changes are sent and commmitted by OSTs
2108 # for ldiskfs space is released upon execution, but DMU
2109 # do this upon commit
2112 while [[ $WAIT -ne $MAX_WAIT ]]; do
2113 changes=$(do_nodes $mds2sync \
2114 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2115 #echo "$node: $changes changes on all"
2116 if [[ $changes -eq 0 ]]; then
2118 #echo "delete took $((etime - stime)) seconds"
2120 # the occupied disk space will be released
2121 # only after DMUs are committed
2122 if [[ $(facet_fstype $SINGLEMDS) == zfs ]]; then
2123 echo "sleep $ZFS_WAIT for ZFS OSD"
2134 echo "Delete is not completed in $((etime - stime)) seconds"
2135 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2141 # we can use "for" here because we are waiting the slowest
2142 for host in ${hostlist//,/ }; do
2143 check_network "$host" 900
2145 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2152 for facet in ${facetlist//,/ }; do
2153 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2155 wait_for_host $hostlist
2158 _wait_recovery_complete () {
2161 # Use default policy if $2 is not passed by caller.
2162 local MAX=${2:-$(max_recovery_time)}
2167 while [ $WAIT -lt $MAX ]; do
2168 STATUS=$(lctl get_param -n $param | grep status)
2170 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2173 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2175 echo "$param recovery not done in $MAX sec. $STATUS"
2179 wait_recovery_complete () {
2182 # with an assumption that at_max is the same on all nodes
2183 local MAX=${2:-$(max_recovery_time)}
2186 if [ "$FAILURE_MODE" = HARD ]; then
2187 facets=$(facets_on_host $(facet_active_host $facet))
2189 echo affected facets: $facets
2191 # we can use "for" here because we are waiting the slowest
2192 for facet in ${facets//,/ }; do
2193 local var_svc=${facet}_svc
2194 local param="*.${!var_svc}.recovery_status"
2196 local host=$(facet_active_host $facet)
2197 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2201 wait_mds_ost_sync () {
2202 # just because recovery is done doesn't mean we've finished
2203 # orphan cleanup. Wait for llogs to get synchronized.
2204 echo "Waiting for orphan cleanup..."
2205 # MAX value includes time needed for MDS-OST reconnection
2206 local MAX=$(( TIMEOUT * 2 ))
2207 local WAIT_TIMEOUT=${1:-$MAX}
2210 local list=$(comma_list $(mdts_nodes))
2211 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2212 if ! do_facet $SINGLEMDS \
2213 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2215 # old way, use mds_sync
2217 list=$(comma_list $(osts_nodes))
2218 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2221 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2222 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2223 local -a sync=($(do_nodes $list "$cmd"))
2226 for ((i=0; i<${#sync[@]}; i++)); do
2228 [ ${sync[$i]} -eq 1 ] && continue
2230 [ ${sync[$i]} -eq 0 ] && continue
2232 # there is a not finished MDS-OST synchronization
2236 sleep 2 # increase waiting time and cover statfs cache
2237 [ ${con} -eq 1 ] && return 0
2238 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2242 # show which nodes are not finished.
2243 do_nodes $list "$cmd"
2244 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2248 wait_destroy_complete () {
2249 echo "Waiting for local destroys to complete"
2250 # MAX value shouldn't be big as this mean server responsiveness
2251 # never increase this just to make test pass but investigate
2252 # why it takes so long time
2255 while [ $WAIT -lt $MAX ]; do
2256 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2260 for ((i=0; i<${#RPCs[@]}; i++)); do
2261 [ ${RPCs[$i]} -eq 0 ] && continue
2262 # there are still some destroy RPCs in flight
2267 [ ${con} -eq 1 ] && return 0 # done waiting
2268 echo "Waiting ${WAIT}s for local destroys to complete"
2271 echo "Local destroys weren't done in $MAX sec."
2275 wait_delete_completed() {
2276 wait_delete_completed_mds $1 || return $?
2277 wait_destroy_complete
2286 # conf-sanity 31 takes a long time cleanup
2287 while [ $WAIT -lt 300 ]; do
2288 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2289 [ -z "${running}" ] && return 0
2290 echo "waited $WAIT for${running}"
2291 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2293 WAIT=$((WAIT + INTERVAL))
2295 echo "service didn't stop after $WAIT seconds. Still running:"
2300 wait_remote_prog () {
2306 [ "$PDSH" = "no_dsh" ] && return 0
2308 while [ $WAIT -lt $2 ]; do
2309 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2310 [ -z "${running}" ] && return 0 || true
2311 echo "waited $WAIT for: "
2313 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2315 WAIT=$((WAIT + INTERVAL))
2317 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2318 [ -z "$pids" ] && return 0
2319 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2320 # FIXME: not portable
2321 for pid in $pids; do
2322 cat /proc/${pid}/status || true
2323 cat /proc/${pid}/wchan || true
2325 kill -9 $pid || true
2334 # not every config has many clients
2336 if [ ! -z "$CLIENTS" ]; then
2337 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
2339 stat -f $MOUNT > /dev/null
2345 # usually checked on particular client or locally
2347 if [ ! -z "$client" ]; then
2348 $PDSH $client "stat -f $MOUNT" > /dev/null
2350 stat -f $MOUNT > /dev/null
2358 client_reconnect_try() {
2359 uname -n >> $MOUNT/recon
2360 if [ -z "$CLIENTS" ]; then
2361 df $MOUNT; uname -n >> $MOUNT/recon
2363 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
2365 echo Connected clients:
2367 ls -l $MOUNT/recon > /dev/null
2371 client_reconnect() {
2372 # one client_reconnect_try call does not always do the job...
2374 client_reconnect_try && break
2379 affected_facets () {
2382 local host=$(facet_active_host $facet)
2383 local affected=$facet
2385 if [ "$FAILURE_MODE" = HARD ]; then
2386 affected=$(facets_up_on_host $host)
2392 local E2FSCK_ON_MDT0=false
2393 if [ "$1" == "--fsck" ]; then
2395 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2407 #Because it will only get up facets, we need get affected
2408 #facets before shutdown
2409 #For HARD Failure mode, it needs make sure facets on the same
2410 #HOST will only be shutdown and reboot once
2411 for facet in ${facets//,/ }; do
2412 local affected_facet
2414 #check whether facet has been included in other affected facets
2415 for ((index=0; index<$total; index++)); do
2416 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2419 if [ $skip -eq 0 ]; then
2420 affecteds[$total]=$(affected_facets $facet)
2425 for ((index=0; index<$total; index++)); do
2426 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2427 local host=$(facet_active_host $facet)
2428 echo "Failing ${affecteds[index]} on $host"
2429 shutdown_facet $facet
2432 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
2433 $(mdsdevname 1) "-n" || error "Running e2fsck")
2435 for ((index=0; index<$total; index++)); do
2436 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2437 echo reboot facets: ${affecteds[index]}
2441 change_active ${affecteds[index]}
2443 wait_for_facet ${affecteds[index]}
2444 # start mgs first if it is affected
2445 if ! combined_mgs_mds &&
2446 list_member ${affecteds[index]} mgs; then
2447 mount_facet mgs || error "Restart of mgs failed"
2449 # FIXME; has to be changed to mount all facets concurrently
2450 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2451 echo mount facets: ${affecteds[index]}
2452 mount_facets ${affecteds[index]}
2462 do_facet $facet "sync; sync; sync"
2465 # make sure there will be no seq change
2466 local clients=${CLIENTS:-$HOSTNAME}
2467 local f=fsa-\\\$\(hostname\)
2468 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2469 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2471 local svc=${facet}_svc
2472 do_facet $facet $LCTL --device ${!svc} notransno
2474 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2475 # in-memory state has to be cleared by either rebooting the host or
2476 # exporting and reimporting the pool.
2478 # Although the uberblocks are not updated when a pool is freezed,
2479 # transactions are still written to the disks. Modified blocks may be
2480 # cached in memory when tests try reading them back. The
2481 # export-and-reimport process also evicts any cached pool data from
2482 # memory to provide the correct "data loss" semantics.
2484 # In the test framework, the exporting and importing operations are
2485 # handled by stop() and mount_facet() separately, which are used
2486 # inside fail() and fail_abort().
2488 do_facet $facet $LCTL --device ${!svc} readonly
2489 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2490 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2493 replay_barrier_nodf() {
2494 local facet=$1 echo running=${running}
2495 do_facet $facet "sync; sync; sync"
2496 local svc=${facet}_svc
2497 echo Replay barrier on ${!svc}
2498 do_facet $facet $LCTL --device ${!svc} notransno
2499 do_facet $facet $LCTL --device ${!svc} readonly
2500 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2501 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2504 replay_barrier_nosync() {
2505 local facet=$1 echo running=${running}
2506 local svc=${facet}_svc
2507 echo Replay barrier on ${!svc}
2508 do_facet $facet $LCTL --device ${!svc} notransno
2509 do_facet $facet $LCTL --device ${!svc} readonly
2510 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2511 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2515 # Get Lustre client uuid for a given Lustre mount point.
2518 local mntpnt=${1:-$MOUNT}
2520 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2521 local uuid=$($LCTL get_param -n llite.$name.uuid)
2526 mds_evict_client() {
2527 local mntpnt=${1:-$MOUNT}
2528 local uuid=$(get_client_uuid $mntpnt)
2530 do_facet $SINGLEMDS \
2531 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2534 ost_evict_client() {
2535 local mntpnt=${1:-$MOUNT}
2536 local uuid=$(get_client_uuid $mntpnt)
2539 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2544 local clients=${CLIENTS:-$HOSTNAME}
2546 facet_failover $* || error "failover: $?"
2547 wait_clients_import_state "$clients" "$facets" FULL
2548 clients_up || error "post-failover df: $?"
2553 facet_failover $facet
2559 change_active $facet
2560 wait_for_facet $facet
2561 mount_facet $facet -o abort_recovery
2562 clients_up || echo "first df failed: $?"
2563 clients_up || error "post-failover df: $?"
2567 echo There is no lmc. This is mountconf, baby.
2571 host_nids_address() {
2575 if [ -n "$kind" ]; then
2576 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2578 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2584 if [ "$1" = "'*'" ]; then echo \'*\'; else
2590 if [ "$1" = "'*'" ]; then echo \'*\'; else
2591 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2593 if [ -z "$ID" ]; then
2594 echo "Could not get a ptl id for $1..."
2603 h2name_or_ip "$1" "tcp"
2608 if [ "$1" = "'*'" ]; then echo \'*\'; else
2609 if type __h2elan >/dev/null 2>&1; then
2612 ID=`echo $1 | sed 's/[^0-9]*//g'`
2620 h2name_or_ip "$1" "o2ib"
2624 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2625 # expressions format. As a bonus we can then just pass in those variables
2626 # to pdsh. What this function does is take a HOSTLIST type string and
2627 # expand it into a space deliminated list for us.
2635 [ -z "$hostlist" ] && return
2637 # Translate the case of [..],..,[..] to [..] .. [..]
2638 list="${hostlist/],/] }"
2640 [[ "$front" == *,* ]] && {
2643 list=${list/${old}/${new}}
2646 for item in $list; do
2647 # Test if we have any []'s at all
2648 if [ "$item" != "${item/\[/}" ]; then {
2649 # Expand the [*] into list
2653 if [ "$name" != "$item" ]; then
2654 group=${item#$name[*}
2657 for range in ${group//,/ }; do
2661 # Number of leading zeros
2664 end=$(echo $end | sed 's/0*//')
2665 [[ -z "$end" ]] && end=0
2666 [[ $padlen2 -gt $padlen ]] && {
2667 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2670 begin=$(echo $begin | sed 's/0*//')
2671 [ -z $begin ] && begin=0
2673 for num in $(seq -f "%0${padlen}g" $begin $end); do
2674 value="${name#*,}${num}${back}"
2675 [ "$value" != "${value/\[/}" ] && {
2676 value=$(hostlist_expand "$value")
2678 myList="$myList $value"
2683 myList="$myList $item"
2686 myList=${myList//,/ }
2687 myList=${myList:1} # Remove first character which is a space
2689 # Filter any duplicates without sorting
2691 myList="${list%% *}"
2693 while [[ "$list" != ${myList##* } ]]; do
2694 list=${list//${list%% *} /}
2695 myList="$myList ${list%% *}"
2697 myList="${myList%* }";
2699 # We can select an object at an offset in the list
2702 for item in $myList; do
2704 [ $cnt -eq $offset ] && {
2708 [ $(get_node_count $myList) -ne 1 ] && myList=""
2717 [ "$facet" == client ] && echo -n $HOSTNAME && return
2718 varname=${facet}_HOST
2719 if [ -z "${!varname}" ]; then
2720 if [ "${facet:0:3}" == "ost" ]; then
2721 local fh=${facet%failover}_HOST
2722 eval export ${facet}_HOST=${!fh}
2723 if [ -z "${!varname}" ]; then
2724 eval export ${facet}_HOST=${ost_HOST}
2726 elif [ "${facet:0:3}" == "mdt" -o \
2727 "${facet:0:3}" == "mds" -o \
2728 "${facet:0:3}" == "mgs" ]; then
2729 eval export ${facet}_HOST=${mds_HOST}
2735 facet_failover_host() {
2739 var=${facet}failover_HOST
2740 if [ -n "${!var}" ]; then
2745 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2746 "${facet:0:3}" == "mgs" ]; then
2748 eval export ${facet}failover_host=${mds_HOST}
2753 if [[ $facet == ost* ]]; then
2754 eval export ${facet}failover_host=${ost_HOST}
2762 local activevar=${facet}active
2764 if [ -f $TMP/${facet}active ] ; then
2765 source $TMP/${facet}active
2768 active=${!activevar}
2769 if [ -z "$active" ] ; then
2776 facet_active_host() {
2777 facet_host $(facet_active $1)
2780 # Get the passive failover partner host of facet.
2781 facet_passive_host() {
2783 [[ $facet = client ]] && return
2785 local host=${facet}_HOST
2786 local failover_host=${facet}failover_HOST
2787 local active_host=$(facet_active_host $facet)
2789 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2791 if [[ $active_host = ${!host} ]]; then
2792 echo -n ${!failover_host}
2802 facetlist=$(exclude_items_from_list $facetlist mgs)
2804 for facet in ${facetlist//,/ }; do
2805 local failover=${facet}failover
2806 local host=`facet_host $failover`
2807 [ -z "$host" ] && return
2809 local curactive=`facet_active $facet`
2810 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2811 eval export ${facet}active=$facet
2813 eval export ${facet}active=$failover
2815 # save the active host for this facet
2816 local activevar=${facet}active
2817 echo "$activevar=${!activevar}" > $TMP/$activevar
2818 [[ $facet = mds1 ]] && combined_mgs_mds && \
2819 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2820 local TO=`facet_active_host $facet`
2821 echo "Failover $facet to $TO"
2827 # do not stripe off hostname if verbose, bug 19215
2828 if [ x$1 = x--verbose ]; then
2836 if [ "$HOST" = "$HOSTNAME" ]; then
2838 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2839 echo "cannot run remote command on $HOST with $myPDSH"
2843 echo "CMD: $HOST $@" >&2
2844 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2847 if [ "$myPDSH" = "rsh" ]; then
2848 # we need this because rsh does not return exit code of an executed command
2849 local command_status="$TMP/cs"
2850 rsh $HOST ":> $command_status"
2851 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2852 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2853 echo command failed >$command_status"
2854 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2859 # print HOSTNAME for myPDSH="no_dsh"
2860 if [[ $myPDSH = no_dsh ]]; then
2861 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2863 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2866 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2868 return ${PIPESTATUS[0]}
2872 do_node --verbose "$@"
2875 single_local_node () {
2876 [ "$1" = "$HOSTNAME" ]
2879 # Outputs environment variable assignments that should be passed to remote nodes
2883 local facets=$(get_facets)
2886 for var in ${!MODOPTS_*}; do
2887 value=${!var//\"/\\\"}
2888 echo -n " ${var}=\"$value\""
2891 for facet in ${facets//,/ }; do
2893 if [ -n "${!var}" ]; then
2894 echo -n " $var=${!var}"
2898 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2899 if [ -n "${!var}" ]; then
2900 echo -n " $var=${!var}"
2904 for var in VERBOSE; do
2905 if [ -n "${!var}" ]; then
2906 echo -n " $var=${!var}"
2910 if [ -n "$FSTYPE" ]; then
2911 echo -n " FSTYPE=$FSTYPE"
2914 for var in LNETLND NETTYPE; do
2915 if [ -n "${!var}" ]; then
2916 echo -n " $var=${!var}"
2923 # do not stripe off hostname if verbose, bug 19215
2924 if [ x$1 = x--verbose ]; then
2932 if single_local_node $rnodes; then
2934 do_nodev $rnodes "$@"
2936 do_node $rnodes "$@"
2941 # This is part from do_node
2944 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2945 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2947 export FANOUT=$(get_node_count "${rnodes//,/ }")
2949 echo "CMD: $rnodes $@" >&2
2950 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2953 # do not replace anything from pdsh output if -N is used
2954 # -N Disable hostname: prefix on lines of output.
2955 if $verbose || [[ $myPDSH = *-N* ]]; then
2956 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2958 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2960 return ${PIPESTATUS[0]}
2964 # Execute commands on a single service's host
2966 # The \a facet (service) may be on a local or remote node, which is
2967 # determined at the time the command is run.
2969 # usage: do_facet $facet command [arg ...]
2973 local HOST=$(facet_active_host $facet)
2974 [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
2978 # Function: do_facet_random_file $FACET $FILE $SIZE
2979 # Creates FILE with random content on the given FACET of given SIZE
2981 do_facet_random_file() {
2985 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
2986 do_facet $facet "$cmd 2>/dev/null"
2989 do_facet_create_file() {
2993 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
2994 do_facet $facet "$cmd 2>/dev/null"
2998 do_nodes --verbose "$@"
3004 # make sure its not already running
3006 rm -f $TMP/${facet}active
3007 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
3008 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
3010 if [[ $(facet_fstype $facet) == zfs ]]; then
3012 # After formatting a ZFS target, "cachefile=none" property will
3013 # be set on the ZFS storage pool so that the pool is not
3014 # automatically imported on system startup. And then the pool
3015 # will be exported so as to leave the importing and exporting
3016 # operations handled by mount_facet() and stop() separately.
3018 refresh_partition_table $facet $(facet_vdevice $facet)
3019 disable_zpool_cache $facet
3024 # Device formatted as ost
3027 local DEVNAME=OSTDEV$num
3029 local fstype=$(facet_fstype ost$num)
3033 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
3034 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3036 #try $OSTZFSDEVn - independent of vdev
3037 DEVNAME=OSTZFSDEV$num
3038 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
3040 error "unknown fstype!";;
3046 # Physical device location of data
3052 local fstype=$(facet_fstype ost$num)
3056 # vdevs are not supported by ldiskfs
3059 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3060 # Device formatted by zfs
3062 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3064 error "unknown fstype!";;
3070 # Logical device formatted for lustre
3073 local DEVNAME=MDSDEV$num
3075 local fstype=$(facet_fstype mds$num)
3079 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3080 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3082 # try $MDSZFSDEVn - independent of vdev
3083 DEVNAME=MDSZFSDEV$num
3084 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3086 error "unknown fstype!";;
3092 # Physical location of data
3096 local fstype=$(facet_fstype mds$num)
3100 # vdevs are not supported by ldiskfs
3103 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3104 # Device formatted by ZFS
3105 local DEVNAME=MDSDEV$num
3106 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3108 error "unknown fstype!";;
3116 local fstype=$(facet_fstype mgs)
3120 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3121 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3122 DEVPTR=$(mdsdevname 1)
3127 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3128 ( [ -z "$MGSZFSDEV" ] &&
3129 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3130 DEVPTR=$(mdsdevname 1)
3132 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3135 error "unknown fstype!";;
3144 local fstype=$(facet_fstype mgs)
3148 # vdevs are not supported by ldiskfs
3151 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3152 ( [ -z "$MGSDEV" ] &&
3153 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3154 VDEVPTR=$(mdsvdevname 1)
3155 elif [ -n "$MGSDEV" ]; then
3159 error "unknown fstype!";;
3167 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3169 local var=${facet}_MOUNT
3170 eval mntpt=${!var:-${MOUNT%/*}/$facet}
3177 local dev=$(facet_device $facet)
3178 local mnt=$(facet_mntpt $facet)
3181 if ! do_facet $facet test -b $dev; then
3184 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3189 local dev=$(facet_device $facet)
3190 local mnt=$(facet_mntpt $facet)
3192 do_facet $facet $UMOUNT $mnt
3196 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3201 local ds=$(facet_device $facet)
3202 local mnt=$(facet_mntpt $facet)
3207 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3208 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3209 do_facet $facet $ZFS set canmount=noauto $ds
3211 # The "legacy" mount method is used here because "zfs unmount $mnt"
3212 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3213 # targets are not available at the time, the stat(2) on $MOUNT will
3216 do_facet $facet $ZFS set mountpoint=legacy $ds
3217 do_facet $facet mount -t zfs $ds $mnt
3218 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3219 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3224 local ds=$(facet_device $facet)
3225 local mnt=$(facet_mntpt $facet)
3226 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3227 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3228 local mntpt=${!var_mntpt}
3229 local canmnt=${!var_canmnt}
3233 do_facet $facet umount $mnt
3234 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3235 do_facet $facet $ZFS set canmount=$canmnt $ds
3241 local fstype=$(facet_fstype $facet)
3243 mount_$fstype $facet
3248 local fstype=$(facet_fstype $facet)
3250 unmount_$fstype $facet
3257 # make sure we are using the primary server, so test-framework will
3258 # be able to clean up properly.
3259 activemds=`facet_active mds1`
3260 if [ $activemds != "mds1" ]; then
3264 local clients=$CLIENTS
3265 [ -z $clients ] && clients=$(hostname)
3267 zconf_umount_clients $clients $MOUNT "$*" || true
3268 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3270 [ "$CLIENTONLY" ] && return
3271 # The add fn does rm ${facet}active file, this would be enough
3272 # if we use do_facet <facet> only after the facet added, but
3273 # currently we use do_facet mds in local.sh
3274 for num in `seq $MDSCOUNT`; do
3276 rm -f ${TMP}/mds${num}active
3278 combined_mgs_mds && rm -f $TMP/mgsactive
3280 for num in `seq $OSTCOUNT`; do
3282 rm -f $TMP/ost${num}active
3285 if ! combined_mgs_mds ; then
3292 cleanup_echo_devs () {
3293 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3295 for dev in $devs; do
3296 $LCTL --device $dev cleanup
3297 $LCTL --device $dev detach
3302 nfs_client_mode && return
3303 cifs_client_mode && return
3312 combined_mgs_mds () {
3313 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3314 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3318 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3322 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3328 local fsname=${3:-"$FSNAME"}
3329 local type=$(facet_type $facet)
3330 local index=$(facet_index $facet)
3331 local fstype=$(facet_fstype $facet)
3332 local host=$(facet_host $facet)
3337 if [ $type == MGS ] || ( [ $type == MDS ] &&
3338 [ "$dev" == $(mgsdevname) ] &&
3339 [ "$host" == "$(facet_host mgs)" ] ); then
3342 opts="--mgsnode=$MGSNID"
3345 if [ $type != MGS ]; then
3346 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3350 var=${facet}failover_HOST
3351 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3352 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3355 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3356 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3358 if [ $type == MDS ]; then
3359 opts+=${SECLEVEL:+" --param=mdt.sec_level"}
3360 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3361 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3362 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3363 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3365 if [ $fstype == ldiskfs ]; then
3366 # Check for wide striping
3367 if [ $OSTCOUNT -gt 160 ]; then
3368 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3369 fs_mkfs_opts+="-O large_xattr"
3373 if [ -n "${!var}" ]; then
3374 fs_mkfs_opts+=" -J device=${!var}"
3376 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3378 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3382 if [ $type == OST ]; then
3383 opts+=${SECLEVEL:+" --param=ost.sec_level"}
3384 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3386 if [ $fstype == ldiskfs ]; then
3388 if [ -n "${!var}" ]; then
3389 fs_mkfs_opts+=" -J device=${!var}"
3391 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3396 opts+=" --backfstype=$fstype"
3399 if [ -n "${!var}" ]; then
3400 opts+=" --device-size=${!var}"
3403 var=$(upper $fstype)_MKFS_OPTS
3404 fs_mkfs_opts+=${!var:+" ${!var}"}
3406 var=${type}_FS_MKFS_OPTS
3407 fs_mkfs_opts+=${!var:+" ${!var}"}
3409 if [ -n "${fs_mkfs_opts## }" ]; then
3410 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3414 opts+=${!var:+" ${!var}"}
3419 check_ost_indices() {
3420 local index_count=${#OST_INDICES[@]}
3421 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
3423 # OST count is greater than the index count in $OST_INDEX_LIST.
3424 # We need check whether there are duplicate indices.
3428 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
3429 index=$(facet_index ost$i)
3430 for j in $(seq 0 $((index_count - 1))); do
3431 [[ $index -ne ${OST_INDICES[j]} ]] ||
3432 error "ost$i has the same index $index as ost$((j+1))"
3443 echo "Format mgs: $(mgsdevname)"
3444 reformat_external_journal mgs
3445 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3446 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
3456 echo "Format mds$num: $(mdsdevname $num)"
3457 reformat_external_journal mds$num
3458 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3459 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3460 ${quiet:+>/dev/null} || exit 10
3469 echo "Format ost$num: $(ostdevname $num)"
3470 reformat_external_journal ost$num
3471 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3472 --reformat $(ostdevname $num) $(ostvdevname ${num}) \
3473 ${quiet:+>/dev/null} || exit 10
3478 # We need ldiskfs here, may as well load them all
3480 [ "$CLIENTONLY" ] && return
3481 echo Formatting mgs, mds, osts
3482 if ! combined_mgs_mds ; then
3486 for num in $(seq $MDSCOUNT); do
3490 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
3492 for num in $(seq $OSTCOUNT); do
3498 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3502 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3506 # 0: success, the old identity set already.
3507 # 1: success, the old identity does not set.
3512 local j=`expr $num - 1`
3513 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3515 if [ -z "$MDT" ]; then
3519 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3522 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3524 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3527 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3529 if [ $old = "NONE" ]; then
3538 zconf_umount `hostname` $1 || error "umount failed"
3539 zconf_mount `hostname` $1 || error "mount failed"
3547 rm -f $TMP/${facet}active
3548 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3553 local mdt_count=${1:-$MDSCOUNT}
3554 local ost_count=${2:-$OSTCOUNT}
3557 for num in $(seq $mdt_count); do
3558 DEVNAME=$(mdsdevname $num)
3559 writeconf_facet mds$num $DEVNAME || rc=$?
3562 for num in $(seq $ost_count); do
3563 DEVNAME=$(ostdevname $num)
3564 writeconf_facet ost$num $DEVNAME || rc=$?
3570 nfs_client_mode && return
3571 cifs_client_mode && return
3573 sanity_mount_check ||
3574 error "environments are insane!"
3578 if [ -z "$CLIENTONLY" ]; then
3579 echo Setup mgs, mdt, osts
3580 echo $WRITECONF | grep -q "writeconf" && \
3582 if ! combined_mgs_mds ; then
3583 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3586 for num in `seq $MDSCOUNT`; do
3587 DEVNAME=$(mdsdevname $num)
3588 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3590 # We started mds, now we should set failover variables properly.
3591 # Set mds${num}failover_HOST if it is not set (the default failnode).
3592 local varname=mds${num}failover_HOST
3593 if [ -z "${!varname}" ]; then
3594 eval mds${num}failover_HOST=$(facet_host mds$num)
3597 if [ $IDENTITY_UPCALL != "default" ]; then
3598 switch_identity $num $IDENTITY_UPCALL
3601 for num in `seq $OSTCOUNT`; do
3602 DEVNAME=$(ostdevname $num)
3603 start ost$num $DEVNAME $OST_MOUNT_OPTS
3605 # We started ost$num, now we should set ost${num}failover variable properly.
3606 # Set ost${num}failover_HOST if it is not set (the default failnode).
3607 varname=ost${num}failover_HOST
3608 if [ -z "${!varname}" ]; then
3609 eval ost${num}failover_HOST=$(facet_host ost${num})
3617 # wait a while to allow sptlrpc configuration be propogated to targets,
3618 # only needed when mounting new target devices.
3623 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3625 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3628 if [ "$MOUNT_2" ]; then
3629 mount_client $MOUNT2
3630 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3635 # by remounting mdt before ost, initial connect from mdt to ost might
3636 # timeout because ost is not ready yet. wait some time to its fully
3637 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3638 # by a context negotiation rpc with $TIMEOUT.
3639 # FIXME better by monitoring import status.
3642 sleep $((TIMEOUT + 5))
3648 mounted_lustre_filesystems() {
3649 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3652 init_facet_vars () {
3653 [ "$CLIENTONLY" ] && return 0
3660 eval export ${facet}_dev=${device}
3661 eval export ${facet}_opt=\"$@\"
3663 local dev=${facet}_dev
3665 # We need to loop for the label
3666 # in case its not initialized yet.
3667 for wait_time in {0,1,3,5,10}; do
3669 if [ $wait_time -gt 0 ]; then
3670 echo "${!dev} not yet initialized,"\
3671 "waiting ${wait_time} seconds."
3675 local label=$(devicelabel ${facet} ${!dev})
3677 # Check to make sure the label does
3678 # not include ffff at the end of the label.
3679 # This indicates it has not been initialized yet.
3681 if [[ $label =~ [f|F]{4}$ ]]; then
3682 # label is not initialized, unset the result
3683 # and either try again or fail
3690 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3692 eval export ${facet}_svc=${label}
3694 local varname=${facet}failover_HOST
3695 if [ -z "${!varname}" ]; then
3696 eval export $varname=$(facet_host $facet)
3699 varname=${facet}_HOST
3700 if [ -z "${!varname}" ]; then
3701 eval export $varname=$(facet_host $facet)
3704 # ${facet}failover_dev is set in cfg file
3705 varname=${facet}failover_dev
3706 if [ -n "${!varname}" ] ; then
3707 eval export ${facet}failover_dev=${!varname}
3709 eval export ${facet}failover_dev=$device
3712 # get mount point of already mounted device
3713 # is facet_dev is already mounted then use the real
3714 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3715 # i.e. ${facet}_MOUNT if specified by user or default
3716 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3717 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3718 if [ -z $mntpt ]; then
3719 mntpt=$(facet_mntpt $facet)
3721 eval export ${facet}_MOUNT=$mntpt
3724 init_facets_vars () {
3727 if ! remote_mds_nodsh; then
3728 for num in $(seq $MDSCOUNT); do
3729 DEVNAME=`mdsdevname $num`
3730 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3734 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3736 if ! remote_ost_nodsh; then
3737 for num in $(seq $OSTCOUNT); do
3738 DEVNAME=$(ostdevname $num)
3739 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3744 osc_ensure_active () {
3749 while [ $period -lt $timeout ]; do
3750 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3751 if [ $count -eq 0 ]; then
3755 echo "There are $count OST are inactive, wait $period seconds, and try again"
3757 period=$((period+3))
3760 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3763 set_conf_param_and_check() {
3767 local ORIG=$(do_facet $myfacet "$TEST")
3768 if [ $# -gt 3 ]; then
3774 echo "Setting $PARAM from $ORIG to $FINAL"
3775 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3776 error "conf_param $PARAM failed"
3778 wait_update $(facet_host $myfacet) "$TEST" "$FINAL" ||
3779 error "check $PARAM failed!"
3782 init_param_vars () {
3784 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3786 log "Using TIMEOUT=$TIMEOUT"
3788 osc_ensure_active $SINGLEMDS $TIMEOUT
3789 osc_ensure_active client $TIMEOUT
3791 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
3792 local current_jobid_var=$($LCTL get_param -n jobid_var)
3794 if [ $JOBID_VAR = "existing" ]; then
3795 echo "keeping jobstats as $current_jobid_var"
3796 elif [ $current_jobid_var != $JOBID_VAR ]; then
3797 echo "seting jobstats to $JOBID_VAR"
3799 set_conf_param_and_check client \
3800 "$LCTL get_param -n jobid_var" \
3801 "$FSNAME.sys.jobid_var" $JOBID_VAR
3804 echo "jobstats not supported by server"
3807 if [ $QUOTA_AUTO -ne 0 ]; then
3808 if [ "$ENABLE_QUOTA" ]; then
3809 echo "enable quota as required"
3810 setup_quota $MOUNT || return 2
3812 echo "disable quota as required"
3813 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
3819 nfs_client_mode () {
3820 if [ "$NFSCLIENT" ]; then
3821 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
3822 local clients=$CLIENTS
3823 [ -z $clients ] && clients=$(hostname)
3825 # FIXME: remove hostname when 19215 fixed
3826 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
3827 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
3828 if [[ ${#nfsexport[@]} -eq 0 ]]; then
3829 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
3831 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
3837 cifs_client_mode () {
3838 [ x$CIFSCLIENT = xyes ] &&
3839 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
3842 check_config_client () {
3845 local mounted=$(mount | grep " $mntpt ")
3846 if [ "$CLIENTONLY" ]; then
3848 # CLIENTONLY should not depend on *_HOST settings
3849 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
3850 # in theory someone could create a new,
3851 # client-only config file that assumed lustre was already
3852 # configured and didn't set the MGSNID. If MGSNID is not set,
3853 # then we should use the mgs nid currently being used
3854 # as the default value. bug 18021
3855 [[ x$MGSNID = x ]] &&
3858 if [[ x$mgc != xMGC$MGSNID ]]; then
3859 if [ "$mgs_HOST" ]; then
3860 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
3861 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
3862 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
3868 local myMGS_host=$mgs_HOST
3869 if [ "$NETTYPE" = "ptl" ]; then
3870 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
3873 echo Checking config lustre mounted on $mntpt
3874 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
3875 mgshost=$(echo $mgshost | awk -F: '{print $1}')
3877 # if [ "$mgshost" != "$myMGS_host" ]; then
3878 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
3879 # Please use correct config or set mds_HOST correctly!"
3884 check_config_clients () {
3885 local clients=${CLIENTS:-$HOSTNAME}
3888 nfs_client_mode && return
3889 cifs_client_mode && return
3891 do_rpc_nodes "$clients" check_config_client $mntpt
3893 sanity_mount_check || error "environments are insane!"
3897 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3898 local cltimeout=$(lctl get_param -n timeout)
3899 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
3900 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
3907 [ -z $mntpt ] && return 1
3908 local mounted=$(mounted_lustre_filesystems)
3910 echo $mounted' ' | grep -w -q $mntpt' '
3914 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
3918 # empty lustre filesystem may have empty directories lost+found and .lustre
3920 # exclude .lustre & lost+found
3921 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
3922 -print | wc -l) = 1 ] || return 1
3923 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
3924 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
3925 # exclude .lustre/fid (LU-2780)
3926 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
3927 -print | wc -l) = 1 ] || return 1
3929 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
3934 check_and_setup_lustre() {
3935 nfs_client_mode && return
3936 cifs_client_mode && return
3938 local MOUNTED=$(mounted_lustre_filesystems)
3942 # both MOUNT and MOUNT2 are not mounted
3943 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
3944 [ "$REFORMAT" ] && formatall
3945 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
3947 is_mounted $MOUNT || error "NAME=$NAME not mounted"
3948 export I_MOUNTED=yes
3952 elif is_mounted $MOUNT2; then
3954 # MOUNT2 is mounted, while MOUNT_2 is not set
3955 if ! [ "$MOUNT_2" ]; then
3956 cleanup_mount $MOUNT2
3957 export I_UMOUNTED2=yes
3960 # MOUNT2 is mounted, MOUNT_2 is set
3962 # FIXME: what to do if check_config failed?
3964 # 1) remote client has mounted other Lustre fs ?
3965 # 2) it has insane env ?
3966 # let's try umount MOUNT2 on all clients and mount it again:
3967 if ! check_config_clients $MOUNT2; then
3968 cleanup_mount $MOUNT2
3969 restore_mount $MOUNT2
3970 export I_MOUNTED2=yes
3975 # MOUNT is mounted MOUNT2 is not mounted
3976 elif [ "$MOUNT_2" ]; then
3977 restore_mount $MOUNT2
3978 export I_MOUNTED2=yes
3982 # FIXME: what to do if check_config failed?
3984 # 1) remote client has mounted other Lustre fs?