3 trap 'print_summary && touch $TF_FAIL && \
4 echo "test-framework exiting on error"' ERR
9 export EJOURNAL=${EJOURNAL:-""}
10 export REFORMAT=${REFORMAT:-""}
11 export WRITECONF=${WRITECONF:-""}
12 export VERBOSE=${VERBOSE:-false}
15 export GSS_PIPEFS=false
16 export IDENTITY_UPCALL=default
18 # specify environment variable containing batch job name for server statistics
19 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
21 # LOAD_LLOOP: LU-409: only load llite_lloop module if kernel < 2.6.32 or
22 # LOAD_LLOOP is true. LOAD_LLOOP is false by default.
23 export LOAD_LLOOP=${LOAD_LLOOP:-false}
25 #export PDSH="pdsh -S -Rssh -w"
26 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
28 # function used by scripts run on remote nodes
29 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
30 . $LUSTRE/tests/functions.sh
31 . $LUSTRE/tests/yaml.sh
33 export LD_LIBRARY_PATH=${LUSTRE}/utils:${LD_LIBRARY_PATH}
35 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
37 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
39 if [ -f "$EXCEPT_LIST_FILE" ]; then
40 echo "Reading test skip list from $EXCEPT_LIST_FILE"
45 # check config files for options in decreasing order of preference
46 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
47 MODPROBECONF=/etc/modprobe.d/lustre.conf
48 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
49 MODPROBECONF=/etc/modprobe.d/Lustre
50 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
51 MODPROBECONF=/etc/modprobe.conf
55 [[ $DIR/ = $MOUNT/* ]] || \
56 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
57 [[ $DIR1/ = $MOUNT1/* ]] || \
58 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
59 [[ $DIR2/ = $MOUNT2/* ]] || \
60 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
62 [ -n "$failed" ] && exit 99 || true
66 echo "usage: $0 [-r] [-f cfgfile]"
74 [ "$TESTSUITE" == "lfsck" ] && return 0
75 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
77 local form="%-13s %-17s %-9s %s %s\n"
78 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
79 echo "------------------------------------------------------------------------------------"
80 for O in $DEFAULT_SUITES; do
81 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
82 [ "${!O}" = "no" ] && continue || true
83 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
84 local log=${TMP}/${o}.log
85 if is_sanity_benchmark $o; then
86 log=${TMP}/sanity-benchmark.log
91 local status=Unfinished
93 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
95 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
96 sort -nr -k 3 | head -n5 | awk '{ print $2":"$3"s" }')
97 total=$(grep duration $log | awk '{ print $2 }')
98 if [ "${!O}" = "done" ]; then
102 local durations=$(egrep "^PASS|^FAIL" $log |
103 tr -d "("| sed s/s\)$//g |
104 awk '{ print $2":"$3"|" }')
105 details=$(printf "%s\n%s %s %s\n" "$details" \
106 "DDETAILS" "$O" "$(echo $durations)")
109 printf "$form" $status "$O" "${total}" "E=$skipped"
110 printf "$form" "-" "-" "-" "S=$(echo $slow)"
113 for O in $DEFAULT_SUITES; do
114 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
115 if [ "${!O}" = "no" ]; then
116 printf "$form" "Skipped" "$O" ""
120 # print the detailed tests durations if DDETAILS=true
127 export LUSTRE=$(absolute_path $LUSTRE)
128 export TESTSUITE=$(basename $0 .sh)
129 export TEST_FAILED=false
130 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
131 export RPC_MODE=${RPC_MODE:-false}
133 export MKE2FS=$MKE2FS
134 if [ -z "$MKE2FS" ]; then
135 if which mkfs.ldiskfs >/dev/null 2>&1; then
136 export MKE2FS=mkfs.ldiskfs
142 export DEBUGFS=$DEBUGFS
143 if [ -z "$DEBUGFS" ]; then
144 if which debugfs.ldiskfs >/dev/null 2>&1; then
145 export DEBUGFS=debugfs.ldiskfs
147 export DEBUGFS=debugfs
151 export TUNE2FS=$TUNE2FS
152 if [ -z "$TUNE2FS" ]; then
153 if which tunefs.ldiskfs >/dev/null 2>&1; then
154 export TUNE2FS=tunefs.ldiskfs
156 export TUNE2FS=tune2fs
160 export E2LABEL=$E2LABEL
161 if [ -z "$E2LABEL" ]; then
162 if which label.ldiskfs >/dev/null 2>&1; then
163 export E2LABEL=label.ldiskfs
165 export E2LABEL=e2label
169 export DUMPE2FS=$DUMPE2FS
170 if [ -z "$DUMPE2FS" ]; then
171 if which dumpfs.ldiskfs >/dev/null 2>&1; then
172 export DUMPE2FS=dumpfs.ldiskfs
174 export DUMPE2FS=dumpe2fs
178 export E2FSCK=$E2FSCK
179 if [ -z "$E2FSCK" ]; then
180 if which fsck.ldiskfs >/dev/null 2>&1; then
181 export E2FSCK=fsck.ldiskfs
187 export RESIZE2FS=$RESIZE2FS
188 if [ -z "$RESIZE2FS" ]; then
189 if which resizefs.ldiskfs >/dev/null 2>&1; then
190 export RESIZE2FS=resizefs.ldiskfs
192 export RESIZE2FS=resize2fs
196 export LFSCK_BIN=${LFSCK_BIN:-lfsck}
197 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after each test suite
198 export FSCK_MAX_ERR=4 # File system errors left uncorrected
200 export ZFS=${ZFS:-zfs}
201 export ZPOOL=${ZPOOL:-zpool}
202 export ZDB=${ZDB:-zdb}
203 export PARTPROBE=${PARTPROBE:-partprobe}
205 #[ -d /r ] && export ROOT=${ROOT:-/r}
206 export TMP=${TMP:-$ROOT/tmp}
207 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
208 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
209 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
211 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
212 if ! echo $PATH | grep -q $LUSTRE/utils; then
213 export PATH=$LUSTRE/utils:$PATH
215 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
216 export PATH=$LUSTRE/utils/gss:$PATH
218 if ! echo $PATH | grep -q $LUSTRE/tests; then
219 export PATH=$LUSTRE/tests:$PATH
221 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
222 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
224 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
225 [ ! -f "$LST" ] && export LST=$(which lst)
226 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
227 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
228 export MCREATE=${MCREATE:-mcreate}
229 # Ubuntu, at least, has a truncate command in /usr/bin
230 # so fully path our truncate command.
231 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
232 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
233 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
234 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
235 export PATH=$LUSTRE/tests/racer:$PATH:
237 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
238 export PATH=$LUSTRE/tests/mpi:$PATH
240 export RSYNC_RSH=${RSYNC_RSH:-rsh}
242 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
243 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
244 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
245 [ ! -f "$LFS" ] && export LFS=$(which lfs)
246 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
247 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
249 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
250 if [ ! -f "$L_GETIDENTITY" ]; then
251 if `which l_getidentity > /dev/null 2>&1`; then
252 export L_GETIDENTITY=$(which l_getidentity)
254 export L_GETIDENTITY=NONE
257 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
258 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
259 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
260 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
261 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
262 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
263 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
264 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
265 [ ! -f "$LUSTRE_RMMOD" ] &&
266 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
267 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
268 [ ! -f "$LFS_MIGRATE" ] &&
269 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
270 export NAME=${NAME:-local}
271 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
272 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
273 export LGSSD=$(which lgssd)
274 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
275 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
276 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
278 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
281 if [ "$ACCEPTOR_PORT" ]; then
282 export PORT_OPT="--port $ACCEPTOR_PORT"
287 echo "Using GSS/krb5 ptlrpc security flavor"
288 which lgss_keyring > /dev/null 2>&1 || \
289 error_exit "built with gss disabled! SEC=$SEC"
300 IDENTITY_UPCALL=false
304 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
306 # Paths on remote nodes, if different
307 export RLUSTRE=${RLUSTRE:-$LUSTRE}
308 export RPWD=${RPWD:-$PWD}
309 export I_MOUNTED=${I_MOUNTED:-"no"}
310 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
311 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
312 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
313 ! -f $LUSTRE/mdt/mdt.ko ]; then
314 export CLIENTMODSONLY=yes
317 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
318 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
322 while getopts "rvwf:" opt $*; do
325 r) REFORMAT=--reformat;;
327 w) WRITECONF=writeconf;;
332 shift $((OPTIND - 1))
335 # print the durations of each test if "true"
336 DDETAILS=${DDETAILS:-false}
337 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
347 ncpts=$(do_facet $facet "lctl get_param -n " \
348 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
350 if [ $ncpts -eq 0 ]; then
358 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
359 eval set -- $(tr "[:punct:]" " " <<< $*)
361 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
364 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
365 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
368 /sbin/lsmod | grep -q "^\<$1\>"
371 # Load a module on the system where this is running.
373 # Synopsis: load_module module_name [module arguments for insmod/modprobe]
375 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
376 # will be used as the arguments. Otherwise arguments will be obtained from
377 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
384 BASE=`basename $module $EXT`
386 module_loaded ${BASE} && return
388 # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
390 if [ $# -eq 0 ]; then
391 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
392 # Bash until 4.x, so we resort to eval.
393 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
394 eval set -- \$$optvar
395 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
396 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
398 opt=$(awk -v var="^options $BASE" '$0 ~ var \
399 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
400 set -- $(echo -n $opt)
402 # Ensure we have accept=all for lnet
403 if [ $(basename $module) = lnet ]; then
404 # OK, this is a bit wordy...
405 local arg accept_all_present=false
408 [ "$arg" = accept=all ] && \
409 accept_all_present=true
411 $accept_all_present || set -- "$@" accept=all
417 [ $# -gt 0 ] && echo "${module} options: '$*'"
419 # Note that insmod will ignore anything in modprobe.conf, which is why we're
420 # passing options on the command-line.
421 if [ "$BASE" == "lnet_selftest" ] && \
422 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
423 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
424 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
425 insmod ${LUSTRE}/${module}${EXT} "$@"
427 # must be testing a "make install" or "rpm" installation
428 # note failed to load ptlrpc_gss is considered not fatal
429 if [ "$BASE" == "ptlrpc_gss" ]; then
430 modprobe $BASE "$@" 2>/dev/null || echo "gss/krb5 is not supported"
437 llite_lloop_enabled() {
438 local n1=$(uname -r | cut -d. -f1)
439 local n2=$(uname -r | cut -d. -f2)
440 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
442 # load the llite_lloop module for < 2.6.32 kernels
443 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
444 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
451 load_modules_local() {
452 if [ -n "$MODPROBE" ]; then
454 echo "Using modprobe to load modules"
458 echo Loading modules from $LUSTRE
462 if [ -f /sys/devices/system/cpu/online ]; then
463 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
464 echo "detected $ncpus online CPUs by sysfs"
466 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
468 if [ $rc -eq 0 ]; then
469 echo "detected $ncpus online CPUs by getconf"
471 echo "Can't detect number of CPUs"
476 # if there is only one CPU core, libcfs can only create one partition
477 # if there is more than 4 CPU cores, libcfs should create multiple CPU
478 # partitions. So we just force libcfs to create 2 partitions for
479 # system with 2 or 4 cores
480 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
481 # force to enable multiple CPU partitions
482 echo "Force libcfs to create 2 CPU partitions"
483 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
485 echo "libcfs will create CPU partition based on online CPUs"
488 load_module ../libcfs/libcfs/libcfs
490 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
491 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
492 load_module ../lnet/lnet/lnet
493 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
494 load_module ../lnet/klnds/$LNETLND
495 load_module obdclass/obdclass
496 load_module ptlrpc/ptlrpc
497 load_module ptlrpc/gss/ptlrpc_gss
505 load_module obdecho/obdecho
506 if ! client_only; then
507 SYMLIST=/proc/kallsyms
508 grep -q crc16 $SYMLIST || { modprobe crc16 2>/dev/null || true; }
509 grep -q -w jbd $SYMLIST || { modprobe jbd 2>/dev/null || true; }
510 grep -q -w jbd2 $SYMLIST || { modprobe jbd2 2>/dev/null || true; }
511 load_module lfsck/lfsck
512 [ "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
513 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
515 load_module osd-zfs/osd_zfs
517 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
518 grep -q exportfs_decode_fh $SYMLIST ||
519 { modprobe exportfs 2> /dev/null || true; }
520 load_module ../ldiskfs/ldiskfs
521 load_module osd-ldiskfs/osd_ldiskfs
523 load_module nodemap/nodemap
534 load_module llite/lustre
535 llite_lloop_enabled && load_module llite/llite_lloop
536 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
538 rm -f $OGDB/ogdb-$HOSTNAME
539 $LCTL modules > $OGDB/ogdb-$HOSTNAME
541 # 'mount' doesn't look in $PATH, just sbin
542 local mount_lustre=$LUSTRE/utils/mount.lustre
543 if [ -f $mount_lustre ]; then
544 local sbin_mount=/sbin/mount.lustre
545 if grep -qe "$sbin_mount " /proc/mounts; then
546 cmp $mount_lustre $sbin_mount || umount $sbin_mount
548 if ! grep -qe "$sbin_mount " /proc/mounts; then
549 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
550 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
551 cat <<- EOF > "$sbin_mount"
554 echo "This $sbin_mount just a mountpoint." 1>&2
555 echo "It is never supposed to be run." 1>&2
556 logger -p emerg -- "using stub $sbin_mount $@"
559 chmod a+x $sbin_mount
561 mount --bind $mount_lustre $sbin_mount ||
562 error "can't bind $mount_lustre to $sbin_mount"
570 # load modules on remote nodes optionally
571 # lustre-tests have to be installed on these nodes
572 if $LOAD_MODULES_REMOTE; then
573 local list=$(comma_list $(remote_nodes_list))
574 if [ -n "$list" ]; then
575 echo "loading modules on: '$list'"
576 do_rpc_nodes "$list" load_modules_local
582 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
583 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
584 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
585 echo "$LEAK_LUSTRE" 1>&2
586 echo "$LEAK_PORTALS" 1>&2
587 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
588 echo "Memory leaks detected"
589 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
595 wait_exit_ST client # bug 12845
597 $LUSTRE_RMMOD ldiskfs || return 2
599 if $LOAD_MODULES_REMOTE; then
600 local list=$(comma_list $(remote_nodes_list))
601 if [ -n "$list" ]; then
602 echo "unloading modules on: '$list'"
603 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
604 do_rpc_nodes "$list" check_mem_leak
608 local sbin_mount=/sbin/mount.lustre
609 if grep -qe "$sbin_mount " /proc/mounts; then
610 umount $sbin_mount || true
611 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
615 check_mem_leak || return 254
617 echo "modules unloaded."
622 local facet=${1:-$SINGLEMDS}
623 local fstype=$(facet_fstype $facet)
626 ldiskfs) size=50;; # largest seen is 44, leave some headroom
627 zfs) size=400;; # largest seen is 384
633 check_gss_daemon_nodes() {
637 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
638 if [ \\\"\\\$num\\\" -ne 1 ]; then
639 echo \\\$num instance of $dname;
644 check_gss_daemon_facet() {
648 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
649 if [ $num -ne 1 ]; then
650 echo "$num instance of $dname on $facet"
659 echo Stopping $@ on $list
660 do_nodes $list "killall -2 $@ 2>/dev/null || true"
663 # start gss daemons on all nodes, or
664 # "daemon" on "list" if set
665 start_gss_daemons() {
669 if [ "$list" ] && [ "$daemon" ] ; then
670 echo "Starting gss daemon on nodes: $list"
671 do_nodes $list "$daemon" || return 8
675 local list=$(comma_list $(mdts_nodes))
676 echo "Starting gss daemon on mds: $list"
677 do_nodes $list "$LSVCGSSD -v" || return 1
679 do_nodes $list "$LGSSD -v" || return 2
682 list=$(comma_list $(osts_nodes))
683 echo "Starting gss daemon on ost: $list"
684 do_nodes $list "$LSVCGSSD -v" || return 3
685 # starting on clients
687 local clients=${CLIENTS:-`hostname`}
689 echo "Starting $LGSSD on clients $clients "
690 do_nodes $clients "$LGSSD -v" || return 4
693 # wait daemons entering "stable" status
697 # check daemons are running
699 list=$(comma_list $(mdts_nodes) $(osts_nodes))
700 check_gss_daemon_nodes $list lsvcgssd || return 5
702 list=$(comma_list $(mdts_nodes))
703 check_gss_daemon_nodes $list lgssd || return 6
706 check_gss_daemon_nodes $clients lgssd || return 7
711 local list=$(comma_list $(mdts_nodes))
713 send_sigint $list lsvcgssd lgssd
715 list=$(comma_list $(osts_nodes))
716 send_sigint $list lsvcgssd
718 list=${CLIENTS:-`hostname`}
719 send_sigint $list lgssd
724 if ! module_loaded ptlrpc_gss; then
725 load_module ptlrpc/gss/ptlrpc_gss
726 module_loaded ptlrpc_gss ||
727 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
730 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
733 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
735 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
743 # maybe cleanup credential cache?
749 local var=${facet}_svc
757 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
758 tr '[:lower:]' '[:upper:]'
764 if [ $facet == mgs ]; then
768 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
776 if [ -n "${!var}" ]; then
781 var=$(facet_type $facet)FSTYPE
782 if [ -n "${!var}" ]; then
787 if [ -n "$FSTYPE" ]; then
792 if [[ $facet == mgs ]] && combined_mgs_mds; then
804 local facets=$(get_facets)
807 for facet in ${facets//,/ }; do
808 if [ $node == $(facet_host $facet) ] ||
809 [ $node == "$(facet_failover_host $facet)" ]; then
810 fstype=$(facet_fstype $facet)
811 if [[ $fstypes != *$fstype* ]]; then
812 fstypes+="${fstypes:+,}$fstype"
821 local num=$(facet_number $facet)
824 if [[ $(facet_type $facet) = OST ]]; then
826 if [[ -n "${!index}" ]]; then
831 index=${OST_INDICES[num - 1]}
834 [[ -n "$index" ]] || index=$((num - 1))
842 local fstype=$(facet_fstype $facet)
846 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
848 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
849 ${dev} 2>/dev/null");;
851 error "unknown fstype!";;
859 local device=$(mdsdevname $num)
860 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
866 local device=$(ostdevname $num)
867 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
872 # Get the device of a facet.
879 mgs) device=$(mgsdevname) ;;
880 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
881 ost*) device=$(ostdevname $(facet_number $facet)) ;;
882 fs2mds) device=$(mdsdevname 1_2) ;;
883 fs2ost) device=$(ostdevname 1_2) ;;
884 fs3ost) device=$(ostdevname 2_2) ;;
892 # Get the virtual device of a facet.
899 mgs) device=$(mgsvdevname) ;;
900 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
901 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
902 fs2mds) device=$(mdsvdevname 1_2) ;;
903 fs2ost) device=$(ostvdevname 1_2) ;;
904 fs3ost) device=$(ostvdevname 2_2) ;;
912 # Re-read the partition table on failover partner host.
913 # After a ZFS storage pool is created on a shared device, the partition table
914 # on the device may change. However, the operating system on the failover
915 # host may not notice the change automatically. Without the up-to-date partition
916 # block devices, 'zpool import ..' cannot find the labels, whose positions are
917 # relative to partition rather than disk beginnings.
919 # This function performs partprobe on the failover host to make it re-read the
922 refresh_partition_table() {
927 host=$(facet_passive_host $facet)
928 if [[ -n "$host" ]]; then
929 do_node $host "$PARTPROBE $device"
934 # Get ZFS storage pool name.
941 device=$(facet_device $facet)
942 # poolname is string before "/"
943 poolname="${device%%/*}"
949 # Create ZFS storage pool.
956 local opts=${@:-"-o cachefile=none"}
958 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
959 $ZPOOL create -f $opts $poolname $vdev"
963 # Create ZFS file system.
969 local opts=${@:-"-o mountpoint=legacy"}
971 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
972 $ZFS create $opts $dataset"
976 # Export ZFS storage pool.
977 # Before exporting the pool, all datasets within the pool should be unmounted.
985 poolname=$(zpool_name $facet)
987 if [[ -n "$poolname" ]]; then
988 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
989 grep -q ^$poolname/ /proc/mounts ||
990 $ZPOOL export $opts $poolname"
995 # Destroy ZFS storage pool.
996 # Destroy the given pool and free up any devices for other use. This command
997 # tries to unmount any active datasets before destroying the pool.
998 # -f Force any active datasets contained within the pool to be unmounted.
1002 local poolname=${2:-$(zpool_name $facet)}
1004 if [[ -n "$poolname" ]]; then
1005 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1006 $ZPOOL destroy -f $poolname"
1011 # Import ZFS storage pool.
1012 # Force importing, even if the pool appears to be potentially active.
1017 local opts=${@:-"-o cachefile=none"}
1020 poolname=$(zpool_name $facet)
1022 if [[ -n "$poolname" ]]; then
1023 opts+=" -d $(dirname $(facet_vdevice $facet))"
1024 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
1025 $ZPOOL import -f $opts $poolname"
1030 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1031 # is not automatically imported on system startup.
1033 # In a failover environment, this will provide resource level fencing which
1034 # will ensure that the same ZFS storage pool will not be imported concurrently
1035 # on different nodes.
1037 disable_zpool_cache() {
1041 poolname=$(zpool_name $facet)
1043 if [[ -n "$poolname" ]]; then
1044 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1049 # This and set_osd_param() shall be used to access OSD parameters
1050 # once existed under "obdfilter":
1055 # writethrough_cache_enable
1059 local device=${2:-$FSNAME-OST*}
1062 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1063 osd-*.$device.$name 2>&1" | grep -v 'Found no match'
1068 local device=${2:-$FSNAME-OST*}
1072 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1073 osd-*.$device.$name=$value 2>&1" | grep -v 'Found no match'
1077 local dz=${1:-$DEBUG_SIZE}
1079 if [ -f /sys/devices/system/cpu/possible ]; then
1080 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1082 local cpus=$(getconf _NPROCESSORS_CONF)
1085 # bug 19944, adjust size to be -gt num_possible_cpus()
1086 # promise 2MB for every cpu at least
1087 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1090 lctl set_param debug_mb=$dz
1093 set_default_debug () {
1094 local debug=${1:-"$PTLDEBUG"}
1095 local subsys=${2:-"$SUBSYSTEM"}
1096 local debug_size=${3:-$DEBUG_SIZE}
1098 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1099 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1101 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1104 set_default_debug_nodes () {
1107 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1108 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1112 do_rpc_nodes "$nodes" set_default_debug \
1113 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1116 set_default_debug_facet () {
1118 local node=$(facet_active_host $facet)
1119 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1121 set_default_debug_nodes $node
1126 local facets=${1:-$(get_facets)}
1129 for facet in ${facets//,/ }; do
1132 [ $RC -eq 0 ] && continue
1134 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1135 skip "Restart of $facet failed!." && touch $LU482_FAILED
1137 error "Restart of $facet failed!"
1144 # Add argument "arg" (e.g., "loop") to the comma-separated list
1145 # of arguments for option "opt" (e.g., "-o") on command
1146 # line "opts" (e.g., "-o flock").
1152 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1154 if echo "$opts" | grep -q $opt_pattern; then
1155 opts=$(echo "$opts" | sed -e \
1156 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1158 opts+="${opts:+ }$opt $arg"
1166 local dev=$(facet_active $facet)_dev
1167 local opt=${facet}_opt
1168 local mntpt=$(facet_mntpt $facet)
1169 local opts="${!opt} $@"
1171 if [ $(facet_fstype $facet) == ldiskfs ] &&
1172 ! do_facet $facet test -b ${!dev}; then
1173 opts=$(csa_add "$opts" -o loop)
1176 if [[ $(facet_fstype $facet) == zfs ]]; then
1177 # import ZFS storage pool
1178 import_zpool $facet || return ${PIPESTATUS[0]}
1181 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1182 # for testing LU-482 error handling in mount_facets() and test_0a()
1183 if [ -f $TMP/test-lu482-trigger ]; then
1186 do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
1190 if [ $RC -ne 0 ]; then
1191 echo "Start of ${!dev} on ${facet} failed ${RC}"
1193 set_default_debug_facet $facet
1195 label=$(devicelabel ${facet} ${!dev})
1196 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1197 eval export ${facet}_svc=${label}
1198 echo Started ${label}
1203 # start facet device options
1209 eval export ${facet}_dev=${device}
1210 eval export ${facet}_opt=\"$@\"
1212 local varname=${facet}failover_dev
1213 if [ -n "${!varname}" ] ; then
1214 eval export ${facet}failover_dev=${!varname}
1216 eval export ${facet}failover_dev=$device
1219 local mntpt=$(facet_mntpt $facet)
1220 do_facet ${facet} mkdir -p $mntpt
1221 eval export ${facet}_MOUNT=$mntpt
1222 mount_facet ${facet}
1225 if [[ $facet == mds* ]]; then
1227 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1238 local HOST=`facet_active_host $facet`
1239 [ -z $HOST ] && echo stop: no host for $facet && return 0
1241 local mntpt=$(facet_mntpt $facet)
1242 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1243 if [ ${running} -ne 0 ]; then
1244 echo "Stopping $mntpt (opts:$@) on $HOST"
1245 do_facet ${facet} umount -d $@ $mntpt
1248 # umount should block, but we should wait for unrelated obd's
1249 # like the MGS or MGC to also stop.
1250 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1252 if [[ $(facet_fstype $facet) == zfs ]]; then
1253 # export ZFS storage pool
1258 # save quota version (both administrative and operational quotas)
1259 # add an additional parameter if mountpoint is ever different from $MOUNT
1261 # XXX This function is kept for interoperability with old server (< 2.3.50),
1262 # it should be removed whenever we drop the interoperability for such
1264 quota_save_version() {
1265 local fsname=${2:-$FSNAME}
1267 local ver=$(tr -c -d "123" <<< $spec)
1268 local type=$(tr -c -d "ug" <<< $spec)
1270 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1272 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1274 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1276 local osts=$(get_facets OST)
1277 for ost in ${osts//,/ }; do
1279 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1283 # client could mount several lustre
1285 # XXX This function is kept for interoperability with old server (< 2.3.50),
1286 # it should be removed whenever we drop the interoperability for such
1289 local fsname=${1:-$FSNAME}
1291 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1293 do_nodes $(comma_list $(osts_nodes)) \
1294 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1298 # XXX This function is kept for interoperability with old server (< 2.3.50),
1299 # it should be removed whenever we drop the interoperability for such
1301 restore_quota_old() {
1302 local mntpt=${1:-$MOUNT}
1303 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
1304 if [ ! "$old_QUOTA_TYPE" ] ||
1305 [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
1308 quota_save_version $old_QUOTA_TYPE
1311 # XXX This function is kept for interoperability with old server (< 2.3.50),
1312 # it should be removed whenever we drop the interoperability for such
1317 # no quota enforcement for now and accounting works out of the box
1320 # We need save the original quota_type params, and restore them after testing
1322 # Suppose that quota type the same on mds and ost
1323 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
1324 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
1325 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
1326 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
1327 export old_QUOTA_TYPE=$quota_type
1328 quota_save_version $QUOTA_TYPE
1330 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
1331 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
1334 local quota_usrs=$QUOTA_USERS
1336 # get_filesystem_size
1337 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1338 local blk_soft=$((disksz + 1024))
1339 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1341 local Inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1342 local i_soft=$Inodes
1343 local i_hard=$((i_soft + i_soft / 20))
1345 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
1346 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
1349 for usr in $quota_usrs; do
1350 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1352 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1354 eval $cmd || error "$cmd FAILED!"
1356 # display the quota status
1357 echo "Quota settings for $usr : "
1358 $LFS quota -v -u $usr $mntpt || true
1362 # get mdt quota type
1364 local varsvc=${SINGLEMDS}_svc
1365 do_facet $SINGLEMDS $LCTL get_param -n \
1366 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1369 # get ost quota type
1371 # All OSTs should have same quota type
1372 local varsvc=ost1_svc
1373 do_facet ost1 $LCTL get_param -n \
1374 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1377 # restore old quota type settings
1379 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1384 if [ "$old_MDT_QUOTA_TYPE" ]; then
1385 do_facet mgs $LCTL conf_param \
1386 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1388 if [ "$old_OST_QUOTA_TYPE" ]; then
1389 do_facet mgs $LCTL conf_param \
1390 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1394 # Handle the case when there is a space in the lfs df
1395 # "filesystem summary" line the same as when there is no space.
1396 # This will allow fixing the "lfs df" summary line in the future.
1398 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1401 # Get free inodes on the MDT specified by mdt index, free indoes on
1402 # the whole filesystem will be returned when index == -1.
1408 if [ $index -eq -1 ]; then
1411 mdt_uuid=$(mdtuuid_from_index $index)
1414 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1419 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1426 # save old quota type & set new quota type
1427 local mdt_qtype=$(mdt_quota_type)
1428 local ost_qtype=$(ost_quota_type)
1430 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1431 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1433 export old_MDT_QUOTA_TYPE=$mdt_qtype
1434 export old_OST_QUOTA_TYPE=$ost_qtype
1436 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1437 error "set mdt quota type failed"
1438 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1439 error "set ost quota type failed"
1441 local quota_usrs=$QUOTA_USERS
1443 # get_filesystem_size
1444 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1445 local blk_soft=$((disksz + 1024))
1446 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1448 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1449 local i_soft=$inodes
1450 local i_hard=$((i_soft + i_soft / 20))
1452 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1453 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1454 "inode-hardlimit: $i_hard"
1457 for usr in $quota_usrs; do
1458 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1460 cmd="$LFS setquota -$type $usr -b $blk_soft"
1461 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1463 eval $cmd || error "$cmd FAILED!"
1465 # display the quota status
1466 echo "Quota settings for $usr : "
1467 $LFS quota -v -u $usr $mntpt || true
1474 local opts=${3:-$MOUNT_OPTS}
1475 opts=${opts:+-o $opts}
1476 local flags=${4:-$MOUNT_FLAGS}
1478 local device=$MGSNID:/$FSNAME
1479 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1480 echo Bad zconf mount command: opt=$flags $opts dev=$device mnt=$mnt
1484 echo "Starting client: $client: $flags $opts $device $mnt"
1485 do_node $client mkdir -p $mnt
1486 do_node $client $MOUNT_CMD $flags $opts $device $mnt || return 1
1488 set_default_debug_nodes $client
1500 [ "$3" ] && force=-f
1501 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1502 if [ $running -ne 0 ]; then
1503 echo "Stopping client $client $mnt (opts:$force)"
1504 do_node $client lsof -t $mnt || need_kill=no
1505 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1506 pids=$(do_node $client lsof -t $mnt | sort -u);
1507 if [ -n $pids ]; then
1508 do_node $client kill -9 $pids || true
1512 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1513 if [ $busy -ne 0 ] ; then
1514 echo "$mnt is still busy, wait one second" && sleep 1
1515 do_node $client umount $force $mnt
1520 # nodes is comma list
1521 sanity_mount_check_nodes () {
1527 # FIXME: assume that all cluster nodes run the same os
1528 [ "$(uname)" = Linux ] || return 0
1531 for mnt in $mnts ; do
1532 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1533 mpts=\\\$(mount | grep -c $mnt' ');
1534 if [ \\\$running -ne \\\$mpts ]; then
1535 echo \\\$(hostname) env are INSANE!;
1538 [ $? -eq 0 ] || rc=1
1543 sanity_mount_check_servers () {
1544 [ "$CLIENTONLY" ] &&
1545 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1546 echo Checking servers environments
1548 # FIXME: modify get_facets to display all facets wo params
1549 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1553 for facet in ${facets//,/ }; do
1554 node=$(facet_host ${facet})
1555 mntpt=$(facet_mntpt $facet)
1556 sanity_mount_check_nodes $node $mntpt ||
1557 { error "server $node environments are insane!"; return 1; }
1561 sanity_mount_check_clients () {
1562 local clients=${1:-$CLIENTS}
1563 local mntpt=${2:-$MOUNT}
1564 local mntpt2=${3:-$MOUNT2}
1566 [ -z $clients ] && clients=$(hostname)
1567 echo Checking clients $clients environments
1569 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1570 error "clients environments are insane!"
1573 sanity_mount_check () {
1574 sanity_mount_check_servers || return 1
1575 sanity_mount_check_clients || return 2
1578 # mount clients if not mouted
1579 zconf_mount_clients() {
1582 local opts=${3:-$MOUNT_OPTS}
1583 opts=${opts:+-o $opts}
1584 local flags=${4:-$MOUNT_FLAGS}
1586 local device=$MGSNID:/$FSNAME
1587 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1588 echo Bad zconf mount command: opt=$flags $opts dev=$device mnt=$mnt
1592 echo "Starting client $clients: $flags $opts $device $mnt"
1595 running=\\\$(mount | grep -c $mnt' ');
1597 if [ \\\$running -eq 0 ] ; then
1599 $MOUNT_CMD $flags $opts $device $mnt;
1602 exit \\\$rc" || return ${PIPESTATUS[0]}
1604 echo "Started clients $clients: "
1605 do_nodes $clients "mount | grep $mnt' '"
1607 set_default_debug_nodes $clients
1612 zconf_umount_clients() {
1617 [ "$3" ] && force=-f
1619 echo "Stopping clients: $clients $mnt (opts:$force)"
1620 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1621 if [ \\\$running -ne 0 ] ; then
1622 echo Stopping client \\\$(hostname) $mnt opts:$force;
1623 lsof $mnt || need_kill=no;
1624 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1625 pids=\\\$(lsof -t $mnt | sort -u);
1626 if [ -n \\\"\\\$pids\\\" ]; then
1630 while umount $force $mnt 2>&1 | grep -q "busy"; do
1631 echo "$mnt is still busy, wait one second" && sleep 1;
1638 echo + $POWER_DOWN $node
1642 shutdown_node_hard () {
1644 local attempts=$SHUTDOWN_ATTEMPTS
1646 for i in $(seq $attempts) ; do
1649 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1650 echo "waiting for $host to fail attempts=$attempts"
1651 [ $i -lt $attempts ] || \
1652 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1658 local mnt=${2:-$MOUNT}
1661 if [ "$FAILURE_MODE" = HARD ]; then
1662 shutdown_node_hard $client
1664 zconf_umount_clients $client $mnt -f
1670 local facets="$(get_facets OST),$(get_facets MDS)"
1673 combined_mgs_mds || facets="$facets,mgs"
1675 for facet in ${facets//,/ }; do
1676 if [ $(facet_active_host $facet) == $host ]; then
1677 affected="$affected $facet"
1681 echo $(comma_list $affected)
1686 local host=${2:-$(facet_host $facet)}
1688 local label=$(convert_facet2label $facet)
1689 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
1692 facets_up_on_host () {
1694 local facets=$(facets_on_host $host)
1697 for facet in ${facets//,/ }; do
1698 if $(facet_up $facet $host); then
1699 affected_up="$affected_up $facet"
1703 echo $(comma_list $affected_up)
1709 if [ "$FAILURE_MODE" = HARD ]; then
1710 shutdown_node_hard $(facet_active_host $facet)
1718 echo + $POWER_UP $node
1731 if [ "$FAILURE_MODE" = HARD ]; then
1732 reboot_node $(facet_active_host $facet)
1740 if [ "$FAILURE_MODE" = HARD ]; then
1750 for facet in ${facets//,/ }; do
1751 hosts=$(expand_list $hosts $(facet_host $facet) )
1757 _check_progs_installed () {
1761 for prog in $progs; do
1762 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1763 echo $prog missing on $(hostname)
1770 check_progs_installed () {
1774 do_rpc_nodes "$nodes" _check_progs_installed $@
1777 # recovery-scale functions
1779 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1782 start_client_load() {
1785 local var=$(node_var_name $client)_load
1786 eval export ${var}=$load
1788 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1789 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1790 END_RUN_FILE=$END_RUN_FILE \
1791 LOAD_PID_FILE=$LOAD_PID_FILE \
1792 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1793 TESTNAME=$TESTNAME \
1794 DBENCH_LIB=$DBENCH_LIB \
1795 DBENCH_SRC=$DBENCH_SRC \
1796 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1800 log "Started client load: ${load} on $client"
1802 # get the children process IDs
1803 local pids=$(ps --ppid $ppid -o pid= | xargs)
1804 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1808 start_client_loads () {
1809 local -a clients=(${1//,/ })
1810 local numloads=${#CLIENT_LOADS[@]}
1813 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1814 testnum=$((nodenum % numloads))
1815 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1817 # bug 22169: wait the background threads to start
1821 # only for remote client
1822 check_client_load () {
1824 local var=$(node_var_name $client)_load
1825 local TESTLOAD=run_${!var}.sh
1827 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1829 # bug 18914: try to connect several times not only when
1830 # check ps, but while check_catastrophe also
1833 while [ $RC = 254 -a $tries -gt 0 ]; do
1837 if ! check_catastrophe $client; then
1839 if [ $RC -eq 254 ]; then
1840 # FIXME: not sure how long we shuold sleep here
1844 echo "check catastrophe failed: RC=$RC "
1848 # We can continue try to connect if RC=254
1849 # Just print the warning about this
1850 if [ $RC = 254 ]; then
1851 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1854 # see if the load is still on the client
1857 while [ $RC = 254 -a $tries -gt 0 ]; do
1861 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1866 if [ $RC = 254 ]; then
1867 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1868 # see if we can diagnose a bit why this is
1873 check_client_loads () {
1874 local clients=${1//,/ }
1878 for client in $clients; do
1879 check_client_load $client
1881 if [ "$rc" != 0 ]; then
1882 log "Client load failed on node $client, rc=$rc"
1888 restart_client_loads () {
1889 local clients=${1//,/ }
1890 local expectedfail=${2:-""}
1894 for client in $clients; do
1895 check_client_load $client
1897 if [ "$rc" != 0 -a "$expectedfail" ]; then
1898 local var=$(node_var_name $client)_load
1899 start_client_load $client ${!var}
1900 echo "Restarted client load ${!var}: on $client. Checking ..."
1901 check_client_load $client
1903 if [ "$rc" != 0 ]; then
1904 log "Client load failed to restart on node $client, rc=$rc"
1905 # failure one client load means test fail
1906 # we do not need to check other
1915 # Start vmstat and save its process ID in a file.
1920 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1923 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1924 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1927 # Display the nodes on which client loads failed.
1928 print_end_run_file() {
1932 [ -s $file ] || return 0
1934 echo "Found the END_RUN_FILE file: $file"
1937 # A client load will stop if it finds the END_RUN_FILE file.
1938 # That does not mean the client load actually failed though.
1939 # The first node in END_RUN_FILE is the one we are interested in.
1942 if [ -n "$node" ]; then
1943 local var=$(node_var_name $node)_load
1945 local prefix=$TESTLOG_PREFIX
1946 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
1947 local stdout_log=$prefix.run_${!var}_stdout.$node.log
1948 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
1950 echo "Client load ${!var} failed on node $node:"
1956 # Stop the process which had its PID saved in a file.
1961 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1963 do_nodes $nodes "test -f $pid_file &&
1964 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
1967 # Stop all client loads.
1968 stop_client_loads() {
1969 local nodes=${1:-$CLIENTS}
1972 # stop the client loads
1973 stop_process $nodes $pid_file
1975 # clean up the processes that started them
1976 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
1978 # End recovery-scale functions
1980 # verify that lustre actually cleaned up properly
1982 VAR=$(lctl get_param -n catastrophe 2>&1)
1983 if [ $? = 0 ] ; then
1984 if [ $VAR != 0 ]; then
1985 error "LBUG/LASSERT detected"
1988 BUSY=$(dmesg | grep -i destruct || true)
1989 if [ -n "$BUSY" ]; then
1991 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
1995 check_mem_leak || exit 204
1997 [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
1998 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
2001 if module_loaded lnet || module_loaded libcfs; then
2002 echo "$TESTSUITE: modules still loaded..." 1>&2
2011 if [[ "$1" == "--verbose" ]]; then
2026 PREV_RESULT=$(do_node $node "$TEST")
2028 RESULT=$(do_node $node "$TEST")
2029 if [[ "$RESULT" == "$FINAL" ]]; then
2030 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
2031 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
2035 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
2036 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
2040 [[ $WAIT -ge $MAX ]] && break
2041 [[ $((WAIT % print)) -eq 0 ]] &&
2042 echo "Waiting $((MAX - WAIT)) secs for update"
2043 WAIT=$((WAIT + sleep))
2046 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
2050 wait_update_facet() {
2053 wait_update $(facet_active_host $facet) "$@"
2057 do_nodes $(comma_list $(mdts_nodes)) \
2058 "lctl set_param -n osd*.*MDT*.force_sync 1"
2059 do_nodes $(comma_list $(osts_nodes)) \
2060 "lctl set_param -n osd*.*OS*.force_sync 1" 2>&1 |
2061 grep -v 'Found no match'
2064 wait_delete_completed_mds() {
2065 local MAX_WAIT=${1:-20}
2067 local stime=$(date +%s)
2072 # find MDS with pending deletions
2073 for node in $(mdts_nodes); do
2074 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
2075 2>/dev/null | calc_sum)
2076 if [[ $changes -eq 0 ]]; then
2079 mds2sync="$mds2sync $node"
2081 if [ -z "$mds2sync" ]; then
2084 mds2sync=$(comma_list $mds2sync)
2086 # sync MDS transactions
2087 do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
2089 # wait till all changes are sent and commmitted by OSTs
2090 # for ldiskfs space is released upon execution, but DMU
2091 # do this upon commit
2094 while [[ $WAIT -ne $MAX_WAIT ]]; do
2095 changes=$(do_nodes $mds2sync \
2096 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
2097 #echo "$node: $changes changes on all"
2098 if [[ $changes -eq 0 ]]; then
2100 #echo "delete took $((etime - stime)) seconds"
2108 echo "Delete is not completed in $((etime - stime)) seconds"
2109 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
2115 # we can use "for" here because we are waiting the slowest
2116 for host in ${hostlist//,/ }; do
2117 check_network "$host" 900
2119 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2126 for facet in ${facetlist//,/ }; do
2127 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2129 wait_for_host $hostlist
2132 _wait_recovery_complete () {
2135 # Use default policy if $2 is not passed by caller.
2136 local MAX=${2:-$(max_recovery_time)}
2141 while [ $WAIT -lt $MAX ]; do
2142 STATUS=$(lctl get_param -n $param | grep status)
2144 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2147 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2149 echo "$param recovery not done in $MAX sec. $STATUS"
2153 wait_recovery_complete () {
2156 # with an assumption that at_max is the same on all nodes
2157 local MAX=${2:-$(max_recovery_time)}
2160 if [ "$FAILURE_MODE" = HARD ]; then
2161 facets=$(facets_on_host $(facet_active_host $facet))
2163 echo affected facets: $facets
2165 # we can use "for" here because we are waiting the slowest
2166 for facet in ${facets//,/ }; do
2167 local var_svc=${facet}_svc
2168 local param="*.${!var_svc}.recovery_status"
2170 local host=$(facet_active_host $facet)
2171 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2175 wait_mds_ost_sync () {
2176 # just because recovery is done doesn't mean we've finished
2177 # orphan cleanup. Wait for llogs to get synchronized.
2178 echo "Waiting for orphan cleanup..."
2179 # MAX value includes time needed for MDS-OST reconnection
2180 local MAX=$(( TIMEOUT * 2 ))
2181 local WAIT_TIMEOUT=${1:-$MAX}
2184 local list=$(comma_list $(mdts_nodes))
2185 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2186 if ! do_facet $SINGLEMDS \
2187 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2189 # old way, use mds_sync
2191 list=$(comma_list $(osts_nodes))
2192 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2195 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2196 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2197 local -a sync=($(do_nodes $list "$cmd"))
2200 for ((i=0; i<${#sync[@]}; i++)); do
2202 [ ${sync[$i]} -eq 1 ] && continue
2204 [ ${sync[$i]} -eq 0 ] && continue
2206 # there is a not finished MDS-OST synchronization
2210 sleep 2 # increase waiting time and cover statfs cache
2211 [ ${con} -eq 1 ] && return 0
2212 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2216 # show which nodes are not finished.
2217 do_nodes $list "$cmd"
2218 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2222 wait_destroy_complete () {
2223 echo "Waiting for local destroys to complete"
2224 # MAX value shouldn't be big as this mean server responsiveness
2225 # never increase this just to make test pass but investigate
2226 # why it takes so long time
2229 while [ $WAIT -lt $MAX ]; do
2230 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2234 for ((i=0; i<${#RPCs[@]}; i++)); do
2235 [ ${RPCs[$i]} -eq 0 ] && continue
2236 # there are still some destroy RPCs in flight
2241 [ ${con} -eq 1 ] && return 0 # done waiting
2242 echo "Waiting ${WAIT}s for local destroys to complete"
2245 echo "Local destroys weren't done in $MAX sec."
2249 wait_delete_completed() {
2250 wait_delete_completed_mds $1 || return $?
2251 wait_destroy_complete
2260 # conf-sanity 31 takes a long time cleanup
2261 while [ $WAIT -lt 300 ]; do
2262 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2263 [ -z "${running}" ] && return 0
2264 echo "waited $WAIT for${running}"
2265 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2267 WAIT=$((WAIT + INTERVAL))
2269 echo "service didn't stop after $WAIT seconds. Still running:"
2274 wait_remote_prog () {
2280 [ "$PDSH" = "no_dsh" ] && return 0
2282 while [ $WAIT -lt $2 ]; do
2283 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2284 [ -z "${running}" ] && return 0 || true
2285 echo "waited $WAIT for: "
2287 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2289 WAIT=$((WAIT + INTERVAL))
2291 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2292 [ -z "$pids" ] && return 0
2293 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2294 # FIXME: not portable
2295 for pid in $pids; do
2296 cat /proc/${pid}/status || true
2297 cat /proc/${pid}/wchan || true
2299 kill -9 $pid || true
2308 # not every config has many clients
2310 if [ ! -z "$CLIENTS" ]; then
2311 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
2313 stat -f $MOUNT > /dev/null
2319 # usually checked on particular client or locally
2321 if [ ! -z "$client" ]; then
2322 $PDSH $client "stat -f $MOUNT" > /dev/null
2324 stat -f $MOUNT > /dev/null
2332 client_reconnect_try() {
2333 uname -n >> $MOUNT/recon
2334 if [ -z "$CLIENTS" ]; then
2335 df $MOUNT; uname -n >> $MOUNT/recon
2337 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
2339 echo Connected clients:
2341 ls -l $MOUNT/recon > /dev/null
2345 client_reconnect() {
2346 # one client_reconnect_try call does not always do the job...
2348 client_reconnect_try && break
2353 affected_facets () {
2356 local host=$(facet_active_host $facet)
2357 local affected=$facet
2359 if [ "$FAILURE_MODE" = HARD ]; then
2360 affected=$(facets_up_on_host $host)
2374 #Because it will only get up facets, we need get affected
2375 #facets before shutdown
2376 #For HARD Failure mode, it needs make sure facets on the same
2377 #HOST will only be shutdown and reboot once
2378 for facet in ${facets//,/ }; do
2379 local affected_facet
2381 #check whether facet has been included in other affected facets
2382 for ((index=0; index<$total; index++)); do
2383 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2386 if [ $skip -eq 0 ]; then
2387 affecteds[$total]=$(affected_facets $facet)
2392 for ((index=0; index<$total; index++)); do
2393 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2394 local host=$(facet_active_host $facet)
2395 echo "Failing ${affecteds[index]} on $host"
2396 shutdown_facet $facet
2399 for ((index=0; index<$total; index++)); do
2400 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2401 echo reboot facets: ${affecteds[index]}
2405 change_active ${affecteds[index]}
2407 wait_for_facet ${affecteds[index]}
2408 # start mgs first if it is affected
2409 if ! combined_mgs_mds &&
2410 list_member ${affecteds[index]} mgs; then
2411 mount_facet mgs || error "Restart of mgs failed"
2413 # FIXME; has to be changed to mount all facets concurrently
2414 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2415 echo mount facets: ${affecteds[index]}
2416 mount_facets ${affecteds[index]}
2426 do_facet $facet "sync; sync; sync"
2429 # make sure there will be no seq change
2430 local clients=${CLIENTS:-$HOSTNAME}
2431 local f=fsa-\\\$\(hostname\)
2432 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2433 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2435 local svc=${facet}_svc
2436 do_facet $facet $LCTL --device ${!svc} notransno
2438 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2439 # in-memory state has to be cleared by either rebooting the host or
2440 # exporting and reimporting the pool.
2442 # Although the uberblocks are not updated when a pool is freezed,
2443 # transactions are still written to the disks. Modified blocks may be
2444 # cached in memory when tests try reading them back. The
2445 # export-and-reimport process also evicts any cached pool data from
2446 # memory to provide the correct "data loss" semantics.
2448 # In the test framework, the exporting and importing operations are
2449 # handled by stop() and mount_facet() separately, which are used
2450 # inside fail() and fail_abort().
2452 do_facet $facet $LCTL --device ${!svc} readonly
2453 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2454 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2457 replay_barrier_nodf() {
2458 local facet=$1 echo running=${running}
2459 do_facet $facet "sync; sync; sync"
2460 local svc=${facet}_svc
2461 echo Replay barrier on ${!svc}
2462 do_facet $facet $LCTL --device ${!svc} notransno
2463 do_facet $facet $LCTL --device ${!svc} readonly
2464 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2465 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2468 replay_barrier_nosync() {
2469 local facet=$1 echo running=${running}
2470 local svc=${facet}_svc
2471 echo Replay barrier on ${!svc}
2472 do_facet $facet $LCTL --device ${!svc} notransno
2473 do_facet $facet $LCTL --device ${!svc} readonly
2474 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2475 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2479 # Get Lustre client uuid for a given Lustre mount point.
2482 local mntpnt=${1:-$MOUNT}
2484 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2485 local uuid=$($LCTL get_param -n llite.$name.uuid)
2490 mds_evict_client() {
2491 local mntpnt=${1:-$MOUNT}
2492 local uuid=$(get_client_uuid $mntpnt)
2494 do_facet $SINGLEMDS \
2495 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2498 ost_evict_client() {
2499 local mntpnt=${1:-$MOUNT}
2500 local uuid=$(get_client_uuid $mntpnt)
2503 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2508 local clients=${CLIENTS:-$HOSTNAME}
2510 facet_failover $* || error "failover: $?"
2511 wait_clients_import_state "$clients" "$facets" FULL
2512 clients_up || error "post-failover df: $?"
2517 facet_failover $facet
2523 change_active $facet
2524 wait_for_facet $facet
2525 mount_facet $facet -o abort_recovery
2526 clients_up || echo "first df failed: $?"
2527 clients_up || error "post-failover df: $?"
2531 echo There is no lmc. This is mountconf, baby.
2535 host_nids_address() {
2539 if [ -n "$kind" ]; then
2540 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2542 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2548 if [ "$1" = "'*'" ]; then echo \'*\'; else
2554 if [ "$1" = "'*'" ]; then echo \'*\'; else
2555 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2557 if [ -z "$ID" ]; then
2558 echo "Could not get a ptl id for $1..."
2567 h2name_or_ip "$1" "tcp"
2572 if [ "$1" = "'*'" ]; then echo \'*\'; else
2573 if type __h2elan >/dev/null 2>&1; then
2576 ID=`echo $1 | sed 's/[^0-9]*//g'`
2584 h2name_or_ip "$1" "o2ib"
2588 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2589 # expressions format. As a bonus we can then just pass in those variables
2590 # to pdsh. What this function does is take a HOSTLIST type string and
2591 # expand it into a space deliminated list for us.
2599 [ -z "$hostlist" ] && return
2601 # Translate the case of [..],..,[..] to [..] .. [..]
2602 list="${hostlist/],/] }"
2604 [[ "$front" == *,* ]] && {
2607 list=${list/${old}/${new}}
2610 for item in $list; do
2611 # Test if we have any []'s at all
2612 if [ "$item" != "${item/\[/}" ]; then {
2613 # Expand the [*] into list
2617 if [ "$name" != "$item" ]; then
2618 group=${item#$name[*}
2621 for range in ${group//,/ }; do
2625 # Number of leading zeros
2628 end=$(echo $end | sed 's/0*//')
2629 [[ -z "$end" ]] && end=0
2630 [[ $padlen2 -gt $padlen ]] && {
2631 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2634 begin=$(echo $begin | sed 's/0*//')
2635 [ -z $begin ] && begin=0
2637 for num in $(seq -f "%0${padlen}g" $begin $end); do
2638 value="${name#*,}${num}${back}"
2639 [ "$value" != "${value/\[/}" ] && {
2640 value=$(hostlist_expand "$value")
2642 myList="$myList $value"
2647 myList="$myList $item"
2650 myList=${myList//,/ }
2651 myList=${myList:1} # Remove first character which is a space
2653 # Filter any duplicates without sorting
2655 myList="${list%% *}"
2657 while [[ "$list" != ${myList##* } ]]; do
2658 list=${list//${list%% *} /}
2659 myList="$myList ${list%% *}"
2661 myList="${myList%* }";
2663 # We can select an object at a offset in the list
2666 for item in $myList; do
2668 [ $cnt -eq $offset ] && {
2672 [ $(get_node_count $myList) -ne 1 ] && myList=""
2681 [ "$facet" == client ] && echo -n $HOSTNAME && return
2682 varname=${facet}_HOST
2683 if [ -z "${!varname}" ]; then
2684 if [ "${facet:0:3}" == "ost" ]; then
2685 local fh=${facet%failover}_HOST
2686 eval export ${facet}_HOST=${!fh}
2687 if [ -z "${!varname}" ]; then
2688 eval export ${facet}_HOST=${ost_HOST}
2690 elif [ "${facet:0:3}" == "mdt" -o \
2691 "${facet:0:3}" == "mds" -o \
2692 "${facet:0:3}" == "mgs" ]; then
2693 eval export ${facet}_HOST=${mds_HOST}
2699 facet_failover_host() {
2703 var=${facet}failover_HOST
2704 if [ -n "${!var}" ]; then
2709 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2710 "${facet:0:3}" == "mgs" ]; then
2712 eval export ${facet}failover_host=${mds_HOST}
2717 if [[ $facet == ost* ]]; then
2718 eval export ${facet}failover_host=${ost_HOST}
2726 local activevar=${facet}active
2728 if [ -f $TMP/${facet}active ] ; then
2729 source $TMP/${facet}active
2732 active=${!activevar}
2733 if [ -z "$active" ] ; then
2740 facet_active_host() {
2742 local active=`facet_active $facet`
2743 if [ "$facet" == client ]; then
2746 echo `facet_host $active`
2750 # Get the passive failover partner host of facet.
2751 facet_passive_host() {
2753 [[ $facet = client ]] && return
2755 local host=${facet}_HOST
2756 local failover_host=${facet}failover_HOST
2757 local active_host=$(facet_active_host $facet)
2759 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2761 if [[ $active_host = ${!host} ]]; then
2762 echo -n ${!failover_host}
2772 facetlist=$(exclude_items_from_list $facetlist mgs)
2774 for facet in ${facetlist//,/ }; do
2775 local failover=${facet}failover
2776 local host=`facet_host $failover`
2777 [ -z "$host" ] && return
2779 local curactive=`facet_active $facet`
2780 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2781 eval export ${facet}active=$facet
2783 eval export ${facet}active=$failover
2785 # save the active host for this facet
2786 local activevar=${facet}active
2787 echo "$activevar=${!activevar}" > $TMP/$activevar
2788 [[ $facet = mds1 ]] && combined_mgs_mds && \
2789 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2790 local TO=`facet_active_host $facet`
2791 echo "Failover $facet to $TO"
2797 # do not stripe off hostname if verbose, bug 19215
2798 if [ x$1 = x--verbose ]; then
2806 if [ "$HOST" = "$HOSTNAME" ]; then
2808 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2809 echo "cannot run remote command on $HOST with $myPDSH"
2813 echo "CMD: $HOST $@" >&2
2814 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2817 if [ "$myPDSH" = "rsh" ]; then
2818 # we need this because rsh does not return exit code of an executed command
2819 local command_status="$TMP/cs"
2820 rsh $HOST ":> $command_status"
2821 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2822 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2823 echo command failed >$command_status"
2824 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2829 # print HOSTNAME for myPDSH="no_dsh"
2830 if [[ $myPDSH = no_dsh ]]; then
2831 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2833 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2836 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2838 return ${PIPESTATUS[0]}
2842 do_node --verbose "$@"
2845 single_local_node () {
2846 [ "$1" = "$HOSTNAME" ]
2849 # Outputs environment variable assignments that should be passed to remote nodes
2853 local facets=$(get_facets)
2856 for var in ${!MODOPTS_*}; do
2857 value=${!var//\"/\\\"}
2858 echo -n " ${var}=\"$value\""
2861 for facet in ${facets//,/ }; do
2863 if [ -n "${!var}" ]; then
2864 echo -n " $var=${!var}"
2868 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2869 if [ -n "${!var}" ]; then
2870 echo -n " $var=${!var}"
2874 if [ -n "$FSTYPE" ]; then
2875 echo -n " FSTYPE=$FSTYPE"
2881 # do not stripe off hostname if verbose, bug 19215
2882 if [ x$1 = x--verbose ]; then
2890 if single_local_node $rnodes; then
2892 do_nodev $rnodes "$@"
2894 do_node $rnodes "$@"
2899 # This is part from do_node
2902 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2903 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2905 export FANOUT=$(get_node_count "${rnodes//,/ }")
2907 echo "CMD: $rnodes $@" >&2
2908 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2911 # do not replace anything from pdsh output if -N is used
2912 # -N Disable hostname: prefix on lines of output.
2913 if $verbose || [[ $myPDSH = *-N* ]]; then
2914 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2916 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2918 return ${PIPESTATUS[0]}
2924 local HOST=`facet_active_host $facet`
2925 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
2929 # Function: do_facet_random_file $FACET $FILE $SIZE
2930 # Creates FILE with random content on the given FACET of given SIZE
2932 do_facet_random_file() {
2936 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
2937 do_facet $facet "$cmd 2>/dev/null"
2940 do_facet_create_file() {
2944 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
2945 do_facet $facet "$cmd 2>/dev/null"
2949 do_nodes --verbose "$@"
2955 # make sure its not already running
2957 rm -f $TMP/${facet}active
2958 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
2959 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
2961 if [[ $(facet_fstype $facet) == zfs ]]; then
2963 # After formatting a ZFS target, "cachefile=none" property will
2964 # be set on the ZFS storage pool so that the pool is not
2965 # automatically imported on system startup. And then the pool
2966 # will be exported so as to leave the importing and exporting
2967 # operations handled by mount_facet() and stop() separately.
2969 refresh_partition_table $facet $(facet_vdevice $facet)
2970 disable_zpool_cache $facet
2975 # Device formatted as ost
2978 local DEVNAME=OSTDEV$num
2980 local fstype=$(facet_fstype ost$num)
2984 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2985 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2987 #try $OSTZFSDEVn - independent of vdev
2988 DEVNAME=OSTZFSDEV$num
2989 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
2991 error "unknown fstype!";;
2997 # Physical device location of data
3003 local fstype=$(facet_fstype ost$num)
3007 # vdevs are not supported by ldiskfs
3010 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
3011 # Device formated by zfs
3013 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
3015 error "unknown fstype!";;
3021 # Logical device formated for lustre
3024 local DEVNAME=MDSDEV$num
3026 local fstype=$(facet_fstype mds$num)
3030 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3031 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3033 # try $MDSZFSDEVn - independent of vdev
3034 DEVNAME=MDSZFSDEV$num
3035 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
3037 error "unknown fstype!";;
3043 # Physical location of data
3047 local fstype=$(facet_fstype mds$num)
3051 # vdevs are not supported by ldiskfs
3054 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
3055 # Device formated by ZFS
3056 local DEVNAME=MDSDEV$num
3057 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
3059 error "unknown fstype!";;
3067 local fstype=$(facet_fstype mgs)
3071 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3072 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3073 DEVPTR=$(mdsdevname 1)
3078 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3079 ( [ -z "$MGSZFSDEV" ] &&
3080 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3081 DEVPTR=$(mdsdevname 1)
3083 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3086 error "unknown fstype!";;
3095 local fstype=$(facet_fstype mgs)
3099 # vdevs are not supported by ldiskfs
3102 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3103 ( [ -z "$MGSDEV" ] &&
3104 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3105 VDEVPTR=$(mdsvdevname 1)
3106 elif [ -n "$MGSDEV" ]; then
3110 error "unknown fstype!";;
3118 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3120 local var=${facet}_MOUNT
3121 eval mntpt=${!var:-${MOUNT%/*}/$facet}
3128 local dev=$(facet_device $facet)
3129 local mnt=$(facet_mntpt $facet)
3132 if ! do_facet $facet test -b $dev; then
3135 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3140 local dev=$(facet_device $facet)
3141 local mnt=$(facet_mntpt $facet)
3143 do_facet $facet umount -d $mnt
3147 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3152 local ds=$(facet_device $facet)
3153 local mnt=$(facet_mntpt $facet)
3158 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3159 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3160 do_facet $facet $ZFS set canmount=noauto $ds
3162 # The "legacy" mount method is used here because "zfs unmount $mnt"
3163 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3164 # targets are not available at the time, the stat(2) on $MOUNT will
3167 do_facet $facet $ZFS set mountpoint=legacy $ds
3168 do_facet $facet mount -t zfs $ds $mnt
3169 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3170 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3175 local ds=$(facet_device $facet)
3176 local mnt=$(facet_mntpt $facet)
3177 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3178 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3179 local mntpt=${!var_mntpt}
3180 local canmnt=${!var_canmnt}
3184 do_facet $facet umount $mnt
3185 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3186 do_facet $facet $ZFS set canmount=$canmnt $ds
3192 local fstype=$(facet_fstype $facet)
3194 mount_$fstype $facet
3199 local fstype=$(facet_fstype $facet)
3201 unmount_$fstype $facet
3208 # make sure we are using the primary server, so test-framework will
3209 # be able to clean up properly.
3210 activemds=`facet_active mds1`
3211 if [ $activemds != "mds1" ]; then
3215 local clients=$CLIENTS
3216 [ -z $clients ] && clients=$(hostname)
3218 zconf_umount_clients $clients $MOUNT "$*" || true
3219 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3221 [ "$CLIENTONLY" ] && return
3222 # The add fn does rm ${facet}active file, this would be enough
3223 # if we use do_facet <facet> only after the facet added, but
3224 # currently we use do_facet mds in local.sh
3225 for num in `seq $MDSCOUNT`; do
3227 rm -f ${TMP}/mds${num}active
3229 combined_mgs_mds && rm -f $TMP/mgsactive
3231 for num in `seq $OSTCOUNT`; do
3233 rm -f $TMP/ost${num}active
3236 if ! combined_mgs_mds ; then
3243 cleanup_echo_devs () {
3244 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3246 for dev in $devs; do
3247 $LCTL --device $dev cleanup
3248 $LCTL --device $dev detach
3253 nfs_client_mode && return
3262 combined_mgs_mds () {
3263 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3264 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3268 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3272 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3278 local fsname=${3:-"$FSNAME"}
3279 local type=$(facet_type $facet)
3280 local index=$(facet_index $facet)
3281 local fstype=$(facet_fstype $facet)
3282 local host=$(facet_host $facet)
3287 if [ $type == MGS ] && combined_mgs_mds; then
3291 if [ $type == MGS ] || ( [ $type == MDS ] &&
3292 [ "$dev" == $(mgsdevname) ] &&
3293 [ "$host" == "$(facet_host mgs)" ] ); then
3296 opts="--mgsnode=$MGSNID"
3299 if [ $type != MGS ]; then
3300 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3304 var=${facet}failover_HOST
3305 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3306 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3309 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3310 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3312 if [ $type == MDS ]; then
3313 opts+=${SECLEVEL:+" --param=mdt.sec_level"}
3314 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3315 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3316 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3317 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3319 if [ $fstype == ldiskfs ]; then
3320 # Check for wide striping
3321 if [ $OSTCOUNT -gt 160 ]; then
3322 MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
3323 fs_mkfs_opts+="-O large_xattr"
3326 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3327 if [ ! -z $EJOURNAL ]; then
3328 fs_mkfs_opts+=${MDSJOURNALSIZE:+" device=$EJOURNAL"}
3330 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3334 if [ $type == OST ]; then
3335 opts+=${SECLEVEL:+" --param=ost.sec_level"}
3336 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3338 if [ $fstype == ldiskfs ]; then
3339 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3343 opts+=" --backfstype=$fstype"
3346 if [ -n "${!var}" ]; then
3347 opts+=" --device-size=${!var}"
3350 var=$(upper $fstype)_MKFS_OPTS
3351 fs_mkfs_opts+=${!var:+" ${!var}"}
3353 var=${type}_FS_MKFS_OPTS
3354 fs_mkfs_opts+=${!var:+" ${!var}"}
3356 if [ -n "${fs_mkfs_opts## }" ]; then
3357 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3361 opts+=${!var:+" ${!var}"}
3366 check_ost_indices() {
3367 local index_count=${#OST_INDICES[@]}
3368 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
3370 # OST count is greater than the index count in $OST_INDEX_LIST.
3371 # We need check whether there are duplicate indices.
3375 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
3376 index=$(facet_index ost$i)
3377 for j in $(seq 0 $((index_count - 1))); do
3378 [[ $index -ne ${OST_INDICES[j]} ]] ||
3379 error "ost$i has the same index $index as ost$((j+1))"
3392 # We need ldiskfs here, may as well load them all
3394 [ "$CLIENTONLY" ] && return
3395 echo Formatting mgs, mds, osts
3396 if ! combined_mgs_mds ; then
3397 echo "Format mgs: $(mgsdevname)"
3398 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3399 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} ||
3403 for num in $(seq $MDSCOUNT); do
3404 echo "Format mds$num: $(mdsdevname $num)"
3405 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3406 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3407 ${quiet:+>/dev/null} || exit 10
3410 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
3412 for num in $(seq $OSTCOUNT); do
3413 echo "Format ost$num: $(ostdevname $num)"
3414 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3415 --reformat $(ostdevname $num) $(ostvdevname ${num}) \
3416 ${quiet:+>/dev/null} || exit 10
3421 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3425 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3429 # 0: success, the old identity set already.
3430 # 1: success, the old identity does not set.
3435 local j=`expr $num - 1`
3436 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3438 if [ -z "$MDT" ]; then
3442 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3445 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3447 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3450 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3452 if [ $old = "NONE" ]; then
3461 zconf_umount `hostname` $1 || error "umount failed"
3462 zconf_mount `hostname` $1 || error "mount failed"
3470 rm -f $TMP/${facet}active
3471 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3476 local mdt_count=${1:-$MDSCOUNT}
3477 local ost_count=${2:-$OSTCOUNT}
3480 for num in $(seq $mdt_count); do
3481 DEVNAME=$(mdsdevname $num)
3482 writeconf_facet mds$num $DEVNAME || rc=$?
3485 for num in $(seq $ost_count); do
3486 DEVNAME=$(ostdevname $num)
3487 writeconf_facet ost$num $DEVNAME || rc=$?
3493 nfs_client_mode && return
3495 sanity_mount_check ||
3496 error "environments are insane!"
3500 if [ -z "$CLIENTONLY" ]; then
3501 echo Setup mgs, mdt, osts
3502 echo $WRITECONF | grep -q "writeconf" && \
3504 if ! combined_mgs_mds ; then
3505 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3508 for num in `seq $MDSCOUNT`; do
3509 DEVNAME=$(mdsdevname $num)
3510 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3512 # We started mds, now we should set failover variables properly.
3513 # Set mds${num}failover_HOST if it is not set (the default failnode).
3514 local varname=mds${num}failover_HOST
3515 if [ -z "${!varname}" ]; then
3516 eval mds${num}failover_HOST=$(facet_host mds$num)
3519 if [ $IDENTITY_UPCALL != "default" ]; then
3520 switch_identity $num $IDENTITY_UPCALL
3523 for num in `seq $OSTCOUNT`; do
3524 DEVNAME=$(ostdevname $num)
3525 start ost$num $DEVNAME $OST_MOUNT_OPTS
3527 # We started ost$num, now we should set ost${num}failover variable properly.
3528 # Set ost${num}failover_HOST if it is not set (the default failnode).
3529 varname=ost${num}failover_HOST
3530 if [ -z "${!varname}" ]; then
3531 eval ost${num}failover_HOST=$(facet_host ost${num})
3539 # wait a while to allow sptlrpc configuration be propogated to targets,
3540 # only needed when mounting new target devices.
3545 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3547 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3550 if [ "$MOUNT_2" ]; then
3551 mount_client $MOUNT2
3552 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3557 # by remounting mdt before ost, initial connect from mdt to ost might
3558 # timeout because ost is not ready yet. wait some time to its fully
3559 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3560 # by a context negotiation rpc with $TIMEOUT.
3561 # FIXME better by monitoring import status.
3564 sleep $((TIMEOUT + 5))
3570 mounted_lustre_filesystems() {
3571 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3574 init_facet_vars () {
3575 [ "$CLIENTONLY" ] && return 0
3582 eval export ${facet}_dev=${device}
3583 eval export ${facet}_opt=\"$@\"
3585 local dev=${facet}_dev
3587 # We need to loop for the label
3588 # in case its not initialized yet.
3589 for wait_time in {0,1,3,5,10}; do
3591 if [ $wait_time -gt 0 ]; then
3592 echo "${!dev} not yet initialized,"\
3593 "waiting ${wait_time} seconds."
3597 local label=$(devicelabel ${facet} ${!dev})
3599 # Check to make sure the label does
3600 # not include ffff at the end of the label.
3601 # This indicates it has not been initialized yet.
3603 if [[ $label =~ [f|F]{4}$ ]]; then
3604 # label is not initialized, unset the result
3605 # and either try again or fail
3612 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3614 eval export ${facet}_svc=${label}
3616 local varname=${facet}failover_HOST
3617 if [ -z "${!varname}" ]; then
3618 eval export $varname=$(facet_host $facet)
3621 varname=${facet}_HOST
3622 if [ -z "${!varname}" ]; then
3623 eval export $varname=$(facet_host $facet)
3626 # ${facet}failover_dev is set in cfg file
3627 varname=${facet}failover_dev
3628 if [ -n "${!varname}" ] ; then
3629 eval export ${facet}failover_dev=${!varname}
3631 eval export ${facet}failover_dev=$device
3634 # get mount point of already mounted device
3635 # is facet_dev is already mounted then use the real
3636 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3637 # i.e. ${facet}_MOUNT if specified by user or default
3638 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3639 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3640 if [ -z $mntpt ]; then
3641 mntpt=$(facet_mntpt $facet)
3643 eval export ${facet}_MOUNT=$mntpt
3646 init_facets_vars () {
3649 if ! remote_mds_nodsh; then
3650 for num in $(seq $MDSCOUNT); do
3651 DEVNAME=`mdsdevname $num`
3652 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3656 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3658 if ! remote_ost_nodsh; then
3659 for num in $(seq $OSTCOUNT); do
3660 DEVNAME=$(ostdevname $num)
3661 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3666 osc_ensure_active () {
3671 while [ $period -lt $timeout ]; do
3672 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3673 if [ $count -eq 0 ]; then
3677 echo "There are $count OST are inactive, wait $period seconds, and try again"
3679 period=$((period+3))
3682 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3685 set_conf_param_and_check() {
3689 local ORIG=$(do_facet $myfacet "$TEST")
3690 if [ $# -gt 3 ]; then
3696 echo "Setting $PARAM from $ORIG to $FINAL"
3697 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3698 error "conf_param $PARAM failed"
3700 wait_update $(facet_host $myfacet) "$TEST" "$FINAL" ||
3701 error "check $PARAM failed!"
3704 init_param_vars () {
3706 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3708 log "Using TIMEOUT=$TIMEOUT"
3710 osc_ensure_active $SINGLEMDS $TIMEOUT
3711 osc_ensure_active client $TIMEOUT
3713 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
3714 local current_jobid_var=$($LCTL get_param -n jobid_var)
3716 if [ $JOBID_VAR = "existing" ]; then
3717 echo "keeping jobstats as $current_jobid_var"
3718 elif [ $current_jobid_var != $JOBID_VAR ]; then
3719 echo "seting jobstats to $JOBID_VAR"
3721 set_conf_param_and_check client \
3722 "$LCTL get_param -n jobid_var" \
3723 "$FSNAME.sys.jobid_var" $JOBID_VAR
3726 echo "jobstats not supported by server"
3729 if [ $QUOTA_AUTO -ne 0 ]; then
3730 if [ "$ENABLE_QUOTA" ]; then
3731 echo "enable quota as required"
3732 setup_quota $MOUNT || return 2
3734 echo "disable quota as required"
3735 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
3741 nfs_client_mode () {
3742 if [ "$NFSCLIENT" ]; then
3743 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
3744 local clients=$CLIENTS
3745 [ -z $clients ] && clients=$(hostname)
3747 # FIXME: remove hostname when 19215 fixed
3748 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
3749 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
3750 if [[ ${#nfsexport[@]} -eq 0 ]]; then
3751 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
3753 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
3759 check_config_client () {
3762 local mounted=$(mount | grep " $mntpt ")
3763 if [ "$CLIENTONLY" ]; then
3765 # CLIENTONLY should not depend on *_HOST settings
3766 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
3767 # in theory someone could create a new,
3768 # client-only config file that assumed lustre was already
3769 # configured and didn't set the MGSNID. If MGSNID is not set,
3770 # then we should use the mgs nid currently being used
3771 # as the default value. bug 18021
3772 [[ x$MGSNID = x ]] &&
3775 if [[ x$mgc != xMGC$MGSNID ]]; then
3776 if [ "$mgs_HOST" ]; then
3777 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
3778 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
3779 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
3785 local myMGS_host=$mgs_HOST
3786 if [ "$NETTYPE" = "ptl" ]; then
3787 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
3790 echo Checking config lustre mounted on $mntpt
3791 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
3792 mgshost=$(echo $mgshost | awk -F: '{print $1}')
3794 # if [ "$mgshost" != "$myMGS_host" ]; then
3795 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
3796 # Please use correct config or set mds_HOST correctly!"
3801 check_config_clients () {
3802 local clients=${CLIENTS:-$HOSTNAME}
3805 nfs_client_mode && return
3807 do_rpc_nodes "$clients" check_config_client $mntpt
3809 sanity_mount_check || error "environments are insane!"
3813 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3814 local cltimeout=$(lctl get_param -n timeout)
3815 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
3816 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
3823 [ -z $mntpt ] && return 1
3824 local mounted=$(mounted_lustre_filesystems)
3826 echo $mounted' ' | grep -w -q $mntpt' '
3830 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
3834 # empty lustre filesystem may have empty directories lost+found and .lustre
3836 # exclude .lustre & lost+found
3837 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
3838 -print | wc -l) = 1 ] || return 1
3839 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
3840 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
3841 # exclude .lustre/fid (LU-2780)
3842 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
3843 -print | wc -l) = 1 ] || return 1
3845 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
3850 check_and_setup_lustre() {
3851 nfs_client_mode && return
3853 local MOUNTED=$(mounted_lustre_filesystems)
3857 # both MOUNT and MOUNT2 are not mounted
3858 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
3859 [ "$REFORMAT" ] && formatall
3860 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
3862 is_mounted $MOUNT || error "NAME=$NAME not mounted"
3863 export I_MOUNTED=yes
3867 elif is_mounted $MOUNT2; then
3869 # MOUNT2 is mounted, while MOUNT_2 is not set
3870 if ! [ "$MOUNT_2" ]; then
3871 cleanup_mount $MOUNT2
3872 export I_UMOUNTED2=yes
3875 # MOUNT2 is mounted, MOUNT_2 is set
3877 # FIXME: what to do if check_config failed?
3879 # 1) remote client has mounted other Lustre fs ?
3880 # 2) it has insane env ?
3881 # let's try umount MOUNT2 on all clients and mount it again:
3882 if ! check_config_clients $MOUNT2; then
3883 cleanup_mount $MOUNT2
3884 restore_mount $MOUNT2
3885 export I_MOUNTED2=yes
3890 # MOUNT is mounted MOUNT2 is not mounted
3891 elif [ "$MOUNT_2" ]; then
3892 restore_mount $MOUNT2
3893 export I_MOUNTED2=yes
3897 # FIXME: what to do if check_config failed?
3899 # 1) remote client has mounted other Lustre fs?
3900 # 2) lustre is mounted on remote_clients atall ?
3901 check_config_clients $MOUNT
3905 set_default_debug_nodes $(comma_list $(nodes_list))
3908 if [ $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ] ; then
3910 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
3911 facets="$(get_facets OST)"
3912 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
3913 facets="$facets,$(get_facets MDS)"
3914 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
3915 facets="$facets,mgs"
3916 local nodes="$(facets_hosts ${facets})"
3917 if [ -n "$nodes" ] ; then
3918 do_nodes $nodes "$LCTL set_param \
3919 osd-ldiskfs.track_declares_assert=1 || true"
3928 #Enable remote MDT create for testing
3929 for num in $(seq $MDSCOUNT); do
3931 lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
3935 if [ "$ONLY" == "setup" ]; then
3941 local clients=${CLIENTS:-$HOSTNAME}
3944 zconf_mount_clients $clients $mntpt
3948 local clients=${CLIENTS:-$HOSTNAME}
3951 zconf_umount_clients $clients $mntpt
3954 cleanup_and_setup_lustre() {
3955 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
3956 lctl set_param debug=0 || true
3958 if [ "$ONLY" == "cleanup" ]; then
3962 check_and_setup_lustre
3965 # Get all of the server target devices from a given server node and type.
3972 if [ "$type" == ost ]; then
3973 devs=$(get_osd_param $node "" mntdev)
3975 devs=$(do_node $node $LCTL get_param -n osd-*.$FSNAME-M*.mntdev)
3977 for dev in $devs; do
3979 *loop*) do_node $node "losetup $dev" | \
3980 sed -e "s/.*(//" -e "s/).*//" ;;
3986 # Get all of the server target devices.
3991 # Master MDS parameters used by lfsck
3992 MDTNODE=$(facet_active_host $SINGLEMDS)
3993 MDTDEV=$(echo $(get_mnt_devs $MDTNODE mdt) | awk '{print $1}')
3997 for node in $(mdts_nodes); do
3998 MDTDEVS[i]=$(get_mnt_devs $node mdt)
4004 for node in $(osts_nodes); do
4005 OSTDEVS[i]=$(get_mnt_devs $node ost)
4010 # Run e2fsck on MDT or OST device.
4015 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
4016 local log=$TMP/e2fsck.log
4020 do_node $node $cmd 2>&1 | tee $log
4022 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
4024 if [ $MDSCOUNT -gt 1 ]; then
4025 skip "DNE mode isn't supported!"
4029 error "It's not DNE mode."
4034 [ $rc -le $FSCK_MAX_ERR ] ||
4035 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4041 # Run resize2fs on MDT or OST device.
4050 do_facet $facet "$RESIZE2FS $opts $device $size"
4053 # verify a directory is shared among nodes.
4054 check_shared_dir() {
4056 local list=${2:-$(comma_list $(nodes_list))}
4058 [ -z "$dir" ] && return 1
4059 do_rpc_nodes "$list" check_logdir $dir
4060 check_write_access $dir "$list" || return 1
4064 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
4071 [[ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]] ||
4072 { skip "Lustre 2.2.0 lacks the patch for LU-1255"; exit 0; }
4074 check_shared_dir $SHARED_DIRECTORY ||
4075 error "$SHARED_DIRECTORY isn't a shared directory"
4077 export MDSDB=$SHARED_DIRECTORY/mdsdb
4078 export OSTDB=$SHARED_DIRECTORY/ostdb
4080 # DNE is not supported, so when running e2fsck on a DNE filesystem,
4081 # we only pass master MDS parameters.
4082 run_e2fsck $MDTNODE $MDTDEV "-n --mdsdb $MDSDB"
4087 for node in $(osts_nodes); do
4088 for dev in ${OSTDEVS[i]}; do
4089 run_e2fsck $node $dev "-n --mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
4090 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
4091 ostidx=$((ostidx + 1))
4097 # Run lfsck on server node if lfsck can't be found on client (LU-2571)
4098 run_lfsck_remote() {
4099 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
4104 #Check if lustre is already mounted
4105 do_rpc_nodes $client is_mounted $MOUNT || mounted=false
4107 zconf_mount $client $MOUNT ||
4108 error "failed to mount Lustre on $client"
4112 do_node $client $cmd || rc=$?
4113 #Umount if necessary
4115 zconf_umount $client $MOUNT ||
4116 error "failed to unmount Lustre on $client"
4119 [ $rc -le $FSCK_MAX_ERR ] ||
4120 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
4121 echo "lfsck finished with rc=$rc"
4127 local facets="client $SINGLEMDS"
4133 for facet in $facets; do
4134 node=$(facet_active_host $facet)
4135 if check_progs_installed $node $LFSCK_BIN; then
4140 ! $found && error "None of \"$facets\" supports lfsck"
4142 run_lfsck_remote $node || rc=$?
4144 rm -rvf $MDSDB* $OSTDB* || true
4148 check_and_cleanup_lustre() {
4149 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
4155 if is_mounted $MOUNT; then
4156 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4157 error "remove sub-test dirs failed"
4158 [ "$ENABLE_QUOTA" ] && restore_quota || true
4161 if [ "$I_UMOUNTED2" = "yes" ]; then
4162 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4165 if [ "$I_MOUNTED2" = "yes" ]; then
4166 cleanup_mount $MOUNT2
4169 if [ "$I_MOUNTED" = "yes" ]; then
4170 cleanupall -f || error "cleanup failed"
4178 wait_for_function () {
4181 # suppress fn both stderr and stdout
4182 if [ "$1" = "--quiet" ]; then
4184 quiet=" > /dev/null 2>&1"
4196 eval $fn $quiet && return 0
4198 wait=$((wait + sleep))
4199 [ $wait -lt $max ] || return 1
4200 echo waiting $fn, $((max - wait)) secs left ...
4210 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4211 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4212 echo "Network not available!"
4216 echo `date +"%H:%M:%S (%s)"` network interface is UP
4224 # Convert a space-delimited list to a comma-delimited list. If the input is
4225 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4227 # echo is used to convert newlines to spaces, since it doesn't
4228 # introduce a trailing space as using "tr '\n' ' '" does
4229 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4235 echo $list | grep -qw $item
4238 # list, excluded are the comma separated lists
4239 exclude_items_from_list () {
4245 for item in ${excluded//,/ }; do
4246 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4248 echo $(comma_list $list)
4251 # list, expand are the comma separated lists
4253 local list=${1//,/ }
4254 local expand=${2//,/ }
4257 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4258 echo $(comma_list $expanded)
4261 testslist_filter () {
4262 local script=$LUSTRE/tests/${TESTSUITE}.sh
4264 [ -f $script ] || return 0
4266 local start_at=$START_AT
4267 local stop_at=$STOP_AT
4269 local var=${TESTSUITE//-/_}_START_AT
4270 [ x"${!var}" != x ] && start_at=${!var}
4271 var=${TESTSUITE//-/_}_STOP_AT
4272 [ x"${!var}" != x ] && stop_at=${!var}
4274 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4275 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4276 /^'${start_at}'$/ {flag = 0}
4277 {if (flag == 1) print $0}
4278 /^'${stop_at}'$/ { flag = 1 }'
4282 (cd `dirname $1`; echo $PWD/`basename $1`)
4286 local types=${1:-"OST MDS MGS"}
4290 for entry in $types; do
4291 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4292 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4295 MGS ) list="$list $name";;
4296 MDS|OST|AGT ) local count=${type}COUNT
4297 for ((i=1; i<=${!count}; i++)) do
4298 list="$list ${name}$i"
4300 * ) error "Invalid facet type"
4304 echo $(comma_list $list)
4307 ##################################
4308 # Adaptive Timeouts funcs
4311 # only check mds, we assume at_max is the same on all nodes
4312 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4313 if [ $at_max -eq 0 ]; then
4324 # suppose that all ost-s have the same $at value set
4325 [ $facet != "ost" ] || facet=ost1
4327 do_facet $facet "lctl get_param -n $at"
4345 if [ $facet == "ost" ]; then
4346 facet=$(get_facets OST)
4347 elif [ $facet == "mds" ]; then
4348 facet=$(get_facets MDS)
4350 hosts=$(expand_list $hosts $(facets_hosts $facet))
4353 do_nodes $hosts lctl set_param at_max=$at_max
4356 ##################################
4360 # OBD_FAIL_MDS_ALL_REQUEST_NET
4362 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4363 do_facet client "$1" || RC=$?
4364 do_facet $SINGLEMDS lctl set_param fail_loc=0
4369 # OBD_FAIL_MDS_ALL_REPLY_NET
4371 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
4373 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4377 drop_reint_reply() {
4378 # OBD_FAIL_MDS_REINT_NET_REP
4380 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
4382 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
4386 drop_update_reply() {
4387 # OBD_FAIL_UPDATE_OBJ_NET_REP
4391 do_facet mds${index} lctl set_param fail_loc=0x1701
4392 do_facet client "$@" || RC=$?
4393 do_facet mds${index} lctl set_param fail_loc=0
4398 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4401 local timeout=${2:-0}
4402 # default is (obd_timeout / 4) if unspecified
4403 echo "timeout is $timeout/$2"
4404 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
4405 do_facet client "$1" || RC=$?
4406 do_facet client "sync"
4407 do_facet ost1 lctl set_param fail_loc=0
4411 drop_ldlm_cancel() {
4412 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4414 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4415 do_nodes $list lctl set_param fail_loc=0x304
4417 do_facet client "$@" || RC=$?
4419 do_nodes $list lctl set_param fail_loc=0
4423 drop_bl_callback_once() {
4425 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4426 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4427 do_facet client lctl set_param fail_loc=0x80000305
4428 do_facet client "$@" || rc=$?
4429 do_facet client lctl set_param fail_loc=0
4430 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4434 drop_bl_callback() {
4436 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
4437 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4438 do_facet client lctl set_param fail_loc=0x305
4439 do_facet client "$@" || rc=$?
4440 do_facet client lctl set_param fail_loc=0
4441 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
4446 #define OBD_FAIL_LDLM_REPLY 0x30c
4448 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4449 do_nodes $list lctl set_param fail_loc=0x30c
4451 do_facet client "$@" || RC=$?
4453 do_nodes $list lctl set_param fail_loc=0
4457 drop_ldlm_reply_once() {
4458 #define OBD_FAIL_LDLM_REPLY 0x30c
4460 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4461 do_nodes $list lctl set_param fail_loc=0x8000030c
4463 do_facet client "$@" || RC=$?
4465 do_nodes $list lctl set_param fail_loc=0
4473 echo "clearing fail_loc on $facet"
4474 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4477 set_nodes_failloc () {
4478 do_nodes $(comma_list $1) lctl set_param fail_val=0 fail_loc=$2
4481 cancel_lru_locks() {
4482 $LCTL mark "cancel_lru_locks $1 start"
4484 if [ $1 != "MGC" ]; then
4485 for d in $(lctl get_param -N ldlm.namespaces.*.lru_size |
4487 $LCTL set_param -n $d=clear
4489 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 |
4493 /{proc,sys}/fs/lustre/ldlm/namespaces/*$1*/lru_size \
4499 /{proc,sys}/fs/lustre/ldlm/namespaces/*$1*/lock_unused_count \
4501 if [ $(cat $d) != 0 ]; then
4502 echo "ldlm.namespaces.$(echo "$d" |
4503 cut -f 7 -d'/').lock_unused_count=$(cat $d)"
4508 $LCTL mark "cancel_lru_locks $1 stop"
4513 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4514 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4515 echo "$DEFAULT_LRU_SIZE"
4520 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4523 lru_resize_disable()
4525 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4531 [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] && RC=1
4537 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4538 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4539 echo there is still data in page cache $FILE ?
4540 lctl get_param -n $FILE
4548 DEBUGSAVE="$(lctl get_param -n debug)"
4552 [ -n "$DEBUGSAVE" ] && \
4553 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
4558 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4561 debug_size_restore() {
4562 [ -n "$DEBUG_SIZE_SAVED" ] && \
4563 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4567 start_full_debug_logging() {
4572 local DEBUG_SIZE=150
4574 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4575 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4578 stop_full_debug_logging() {
4583 # prints bash call stack
4586 for (( i=1; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4587 local s=${BASH_SOURCE[$i]}
4588 local l=${BASH_LINENO[$i-1]}
4589 local f=${FUNCNAME[$i]}
4590 echo " = $s:$l:$f()"
4594 ##################################
4596 ##################################
4599 local TYPE=${TYPE:-"FAIL"}
4602 # do not dump logs if $1=false
4603 if [ "x$1" = "xfalse" ]; then
4609 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4613 # We need to dump the logs on all nodes
4615 gather_logs $(comma_list $(nodes_list))
4619 [ "$TESTSUITELOG" ] &&
4620 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4621 if [ -z "$*" ]; then
4622 echo "error() without useful message, please fix" > $LOGDIR/err
4624 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4625 echo "$@" > $LOGDIR/ignore
4627 echo "$@" > $LOGDIR/err
4634 local log=$TESTSUITELOG
4636 [ -f "$log" ] && grep -q FAIL $log && status=1
4649 # use only if we are ignoring failures for this test, bugno required.
4650 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4651 # e.g. error_ignore bz5494 "your message" or
4652 # error_ignore LU-5494 "your message"
4654 local TYPE="IGNORE ($1)"
4659 error_and_remount() {
4661 remount_client $MOUNT
4666 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4671 log " SKIP: $TESTSUITE $TESTNAME $@"
4673 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4674 skip_logged $TESTNAME "$@"
4677 echo "$@" > $LOGDIR/skip
4680 [[ -n "$TESTSUITELOG" ]] &&
4681 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
4684 build_test_filter() {
4685 EXCEPT="$EXCEPT $(testslist_filter)"
4688 if [[ $O = [0-9]*-[0-9]* ]]; then
4689 for num in $(seq $(echo $O | tr '-' ' ')); do
4697 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
4698 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
4699 [ "$EXCEPT_SLOW" ] && \
4700 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
4701 for E in $EXCEPT; do
4702 eval EXCEPT_${E}=true
4704 for E in $ALWAYS_EXCEPT; do
4705 eval EXCEPT_ALWAYS_${E}=true
4707 for E in $EXCEPT_SLOW; do
4708 eval EXCEPT_SLOW_${E}=true
4710 for G in $GRANT_CHECK_LIST; do
4711 eval GCHECK_ONLY_${G}=true
4716 if [[ $1 = [a-z]* ]]; then
4723 # print a newline if the last test was skipped
4724 export LAST_SKIPPED=
4725 export ALWAYS_SKIPPED=
4727 # Main entry into test-framework. This is called with the name and
4728 # description of a test. The name is used to find the function to run
4729 # the test using "test_$name".
4731 # This supports a variety of methods of specifying specific test to
4732 # run or not run. These need to be documented...
4737 export base=$(basetest $1)
4738 if [ -n "$ONLY" ]; then
4740 if [ ${!testname}x != x ]; then
4741 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4742 run_one_logged $1 "$2"
4746 if [ ${!testname}x != x ]; then
4747 [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4748 run_one_logged $1 "$2"
4758 if [ ${!testname}x != x ]; then
4759 TESTNAME=test_$1 skip "skipping excluded test $1"
4762 testname=EXCEPT_$base
4763 if [ ${!testname}x != x ]; then
4764 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
4767 testname=EXCEPT_ALWAYS_$1
4768 if [ ${!testname}x != x ]; then
4769 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
4772 testname=EXCEPT_ALWAYS_$base
4773 if [ ${!testname}x != x ]; then
4774 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
4777 testname=EXCEPT_SLOW_$1
4778 if [ ${!testname}x != x ]; then
4779 TESTNAME=test_$1 skip "skipping SLOW test $1"
4782 testname=EXCEPT_SLOW_$base
4783 if [ ${!testname}x != x ]; then
4784 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
4790 run_one_logged $1 "$2"
4797 module_loaded lnet || load_modules
4809 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
4814 strace -o $TMP/$1.strace -ttt $*
4816 log "FINISHED: $*: rc $RC"
4823 banner test complete, duration $duration sec
4824 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
4825 echo duration $duration >>$TESTSUITELOG
4829 # Set TEST_STATUS here. It will be used for logging the result.
4832 if [[ -f $LOGDIR/err ]]; then
4834 elif [[ -f $LOGDIR/skip ]]; then
4837 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
4841 local FFREE=$(do_node $SINGLEMDS \
4842 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
4843 local FTOTAL=$(do_node $SINGLEMDS \
4844 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
4846 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
4850 echo -n "Resetting fail_loc on all nodes..."
4851 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 \
4852 fail_val=0 2>/dev/null || true"
4858 # Log a message (on all nodes) padded with "=" before and after.
4859 # Also appends a timestamp and prepends the testsuite name.
4862 EQUALS="===================================================================================================="
4864 msg="== ${TESTSUITE} $*"
4866 [[ $last != "=" && $last != " " ]] && msg="$msg "
4867 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
4868 # always include at least == after the message
4869 log "$msg== $(date +"%H:%M:%S (%s)")"
4873 # Run a single test function and cleanup after it.
4875 # This function should be run in a subshell so the test func can
4876 # exit() without stopping the whole script.
4881 export tfile=f${testnum}.${TESTSUITE}
4882 export tdir=d${testnum}.${TESTSUITE}
4883 export TESTNAME=test_$testnum
4884 local SAVE_UMASK=`umask`
4887 banner "test $testnum: $message"
4888 test_${testnum} || error "test_$testnum failed with $?"
4891 check_grant ${testnum} || error "check_grant $testnum failed with $?"
4892 check_catastrophe || error "LBUG/LASSERT detected"
4893 if [ "$PARALLEL" != "yes" ]; then
4894 ps auxww | grep -v grep | grep -q multiop &&
4895 error "multiop still running"
4905 # Wrapper around run_one to ensure:
4906 # - test runs in subshell
4907 # - output of test is saved to separate log file for error reporting
4908 # - test result is saved to data file
4911 local BEFORE=$(date +%s)
4913 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
4914 local test_log=$LOGDIR/$name
4916 rm -rf $LOGDIR/ignore
4918 local SAVE_UMASK=$(umask)
4922 log_sub_test_begin test_${1}
4923 (run_one $1 "$2") 2>&1 | tee -i $test_log
4924 local RC=${PIPESTATUS[0]}
4926 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
4927 echo "test_$1 returned $RC" | tee $LOGDIR/err
4929 duration=$(($(date +%s) - $BEFORE))
4930 pass "$1" "(${duration}s)"
4932 if [[ -f $LOGDIR/err ]]; then
4933 TEST_ERROR=$(cat $LOGDIR/err)
4934 elif [[ -f $LOGDIR/ignore ]]; then
4935 TEST_ERROR=$(cat $LOGDIR/ignore)
4936 elif [[ -f $LOGDIR/skip ]]; then
4937 TEST_ERROR=$(cat $LOGDIR/skip)
4939 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
4941 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
4945 if [ -f $LOGDIR/err ]; then
4946 $FAIL_ON_ERROR && exit $RC
4955 # Print information of skipped tests to result.yml
4958 log_sub_test_begin $1
4960 log_sub_test_end "SKIP" "0" "0" "$@"
4964 (cd $(dirname $1); echo $PWD/$(basename $1))
4969 export base=$(basetest $1)
4970 [ "$CHECK_GRANT" == "no" ] && return 0
4972 testname=GCHECK_ONLY_${base}
4973 [ ${!testname}x == x ] && return 0
4975 echo -n "checking grant......"
4977 local clients=$CLIENTS
4978 [ -z "$clients" ] && clients=$(hostname)
4980 # sync all the data and make sure no pending data on server
4981 do_nodes $clients sync
4984 client_grant=$(do_nodes $clients \
4985 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
4986 awk '{ total += $1 } END { printf("%0.0f", total) }')
4989 server_grant=$(do_nodes $(comma_list $(osts_nodes)) \
4990 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
4991 awk '{ total += $1 } END { printf("%0.0f", total) }')
4993 # check whether client grant == server grant
4994 if [[ $client_grant -ne $server_grant ]]; then
4995 echo "failed: client:${client_grant} server: ${server_grant}."
4996 do_nodes $(comma_list $(osts_nodes)) \
4997 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
4998 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
5001 echo "pass: client:${client_grant} server: ${server_grant}"
5005 ########################
5011 ost=`echo $1 | awk -F_ '{print $3}'`
5012 if [ -z $ost ]; then
5013 ost=`echo $1 | sed 's/-osc.*//'`
5018 ostuuid_from_index()
5020 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5023 ostname_from_index() {
5024 local uuid=$(ostuuid_from_index $1)
5028 index_from_ostuuid()
5030 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
5033 mdtuuid_from_index()
5035 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
5039 # Return unique identifier for given hostname
5042 echo $host_name | md5sum | cut -d' ' -f1
5046 # Returns list of ip addresses for each interface
5048 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
5053 # Cache address list to avoid mutiple execution of local_addr_list
5054 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
5056 for i in $LOCAL_ADDR_LIST ; do
5057 [[ "$i" == "$addr" ]] && return 0
5064 local is_local="IS_LOCAL_$(host_id $host_name)"
5065 if [ -z "${!is_local-}" ] ; then
5067 local host_ip=$($LUSTRE/tests/resolveip $host_name)
5068 is_local_addr "$host_ip" && eval $is_local=1
5070 [[ "${!is_local}" == "1" ]]
5075 local_node $node && return 1
5082 for node in $(mdts_nodes); do
5083 remote_node $node && return 0
5090 [ "$CLIENTONLY" ] && return 0 || true
5091 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
5096 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
5097 MSKIPPED=1 && return 1
5104 for node in $(osts_nodes) ; do
5105 remote_node $node && return 0
5112 [ "$CLIENTONLY" ] && return 0 || true
5113 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5118 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
5119 OSKIPPED=1 && return 1
5126 MGS=$(facet_host mgs)
5127 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
5132 remote_mds_nodsh || remote_ost_nodsh || \
5133 $(single_local_node $(comma_list $(nodes_list)))
5137 remote_ost && remote_mds
5140 # Get the active nodes for facets.
5148 for facet in ${facets//,/ }; do
5149 nodes="$nodes $(facet_active_host $facet)"
5152 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5156 # Get all of the active MDS nodes.
5158 echo -n $(facets_nodes $(get_facets MDS))
5161 # Get all of the active OSS nodes.
5163 echo -n $(facets_nodes $(get_facets OST))
5166 # Get all of the active AGT (HSM agent) nodes.
5168 echo -n $(facets_nodes $(get_facets AGT))
5171 # Get all of the client nodes and active server nodes.
5173 local nodes=$HOSTNAME
5177 # CLIENTS (if specified) contains the local client
5178 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5180 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5181 nodes="$nodes $(facets_nodes $(get_facets))"
5184 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5188 # Get all of the remote client nodes and remote active server nodes.
5189 remote_nodes_list () {
5190 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5193 # Get all of the MDS nodes, including active and passive nodes.
5201 for i in $(seq $MDSCOUNT); do
5203 failover_host=mds${i}failover_HOST
5204 nodes="$nodes ${!host} ${!failover_host}"
5207 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5211 # Get all of the OSS nodes, including active and passive nodes.
5219 for i in $(seq $OSTCOUNT); do
5221 failover_host=ost${i}failover_HOST
5222 nodes="$nodes ${!host} ${!failover_host}"
5225 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5229 # Get all of the server nodes, including active and passive nodes.
5230 all_server_nodes () {
5235 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5237 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5241 # Get all of the client and server nodes, including active and passive nodes.
5243 local nodes=$HOSTNAME
5247 # CLIENTS (if specified) contains the local client
5248 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5250 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5251 nodes="$nodes $(all_server_nodes)"
5254 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5258 init_clients_lists () {
5259 # Sanity check: exclude the local client from RCLIENTS
5260 local clients=$(hostlist_expand "$RCLIENTS")
5261 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5263 # Sanity check: exclude the dup entries
5264 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5266 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5268 # Sanity check: exclude the dup entries from CLIENTS
5269 # for those configs which has SINGLCLIENT set to local client
5270 clients=$(for i in $clients; do echo $i; done | sort -u)
5272 CLIENTS=$(comma_list $clients)
5273 local -a remoteclients=($RCLIENTS)
5274 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5275 varname=CLIENT$((i + 2))
5276 eval $varname=${remoteclients[i]}
5279 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5282 get_random_entry () {
5285 rnodes=${rnodes//,/ }
5287 local -a nodes=($rnodes)
5288 local num=${#nodes[@]}
5289 local i=$((RANDOM * num * 2 / 65536))
5295 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
5300 lctl get_param version | grep -q patchless
5304 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5305 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5310 echo $nodes | wc -w || true
5314 local nodes=$(osts_nodes)
5315 local osscount=$(get_node_count "$nodes")
5316 [ ! "$OSTCOUNT" = "$osscount" ]
5320 local nodes=$(mdts_nodes)
5321 local mdtcount=$(get_node_count "$nodes")
5322 [ ! "$MDSCOUNT" = "$mdtcount" ]
5325 generate_machine_file() {
5326 local nodes=${1//,/ }
5327 local machinefile=$2
5329 for node in $nodes; do
5330 echo $node >>$machinefile || \
5331 { echo "can not generate machinefile $machinefile" && return 1; }
5336 local file=$1/stripe
5339 $LFS getstripe -v $file || error "getstripe $file failed"
5343 setstripe_nfsserver () {
5346 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5347 { print $1 }' /proc/mounts | cut -f 1 -d : | head -n1)
5349 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5351 do_nodev $nfsserver lfs setstripe "$@"
5354 # Check and add a test group.
5360 local gid=$(getent group $group_name | cut -d: -f3)
5361 if [[ -n "$gid" ]]; then
5362 [[ "$gid" -eq "$group_id" ]] || {
5363 error_noexit "inconsistent group ID:" \
5364 "new: $group_id, old: $gid"
5368 groupadd -g $group_id $group_name
5375 # Check and add a test user.
5388 local uid=$(getent passwd $user_name | cut -d: -f3)
5389 if [[ -n "$uid" ]]; then
5390 if [[ "$uid" -eq "$user_id" ]]; then
5391 local dir=$(getent passwd $user_name | cut -d: -f6)
5392 if [[ "$dir" != "$home" ]]; then
5394 usermod -d $home $user_name
5398 error_noexit "inconsistent user ID:" \
5399 "new: $user_id, old: $uid"
5404 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5411 check_runas_id_ret() {
5413 local myRUNAS_UID=$1
5414 local myRUNAS_GID=$2
5417 if [ -z "$myRUNAS" ]; then
5418 error_exit "myRUNAS command must be specified for check_runas_id"
5421 $myRUNAS krb5_login.sh || \
5422 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5424 mkdir $DIR/d0_runas_test
5426 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5427 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5428 rm -rf $DIR/d0_runas_test
5433 local myRUNAS_UID=$1
5434 local myRUNAS_GID=$2
5437 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5438 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5439 Please set RUNAS_ID to some UID which exists on MDS and client or
5440 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5443 # obtain the UID/GID for MPI_USER
5447 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5448 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5450 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5451 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5454 # obtain and cache Kerberos ticket-granting ticket
5455 refresh_krb5_tgt() {
5456 local myRUNAS_UID=$1
5457 local myRUNAS_GID=$2
5460 if [ -z "$myRUNAS" ]; then
5461 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5464 CLIENTS=${CLIENTS:-$HOSTNAME}
5465 do_nodes $CLIENTS "set -x
5466 if ! $myRUNAS krb5_login.sh; then
5467 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5472 # Run multiop in the background, but wait for it to print
5473 # "PAUSING" to its stdout before returning from this function.
5474 multiop_bg_pause() {
5475 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5479 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5482 echo "$MULTIOP_PROG $FILE v$ARGS"
5483 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5485 echo "TMPPIPE=${TMPPIPE}"
5486 read -t 60 multiop_output < $TMPPIPE
5487 if [ $? -ne 0 ]; then
5492 if [ "$multiop_output" != "PAUSING" ]; then
5493 echo "Incorrect multiop output: $multiop_output"
5508 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5514 inodes_available () {
5515 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
5516 sort -un | head -n1) || return 1
5520 mdsrate_inodes_available () {
5521 local min_inodes=$(inodes_available)
5522 echo $((min_inodes * 99 / 100))
5525 # reset llite stat counters
5526 clear_llite_stats(){
5527 lctl set_param -n llite.*.stats 0
5530 # sum llite stat items
5531 calc_llite_stats() {
5532 local res=$(lctl get_param -n llite.*.stats |
5533 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5537 # reset osc stat counters
5539 lctl set_param -n osc.*.osc_stats 0
5542 # sum osc stat items
5544 local res=$(lctl get_param -n osc.*.osc_stats |
5545 awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
5550 awk '{sum += $1} END { printf("%0.0f", sum) }'
5553 calc_osc_kbytes () {
5554 df $MOUNT > /dev/null
5555 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5558 # save_lustre_params(comma separated facet list, parameter_mask)
5559 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5560 save_lustre_params() {
5566 for facet in ${facets//,/ }; do
5567 node=$(facet_active_host $facet)
5568 [[ *\ $node\ * = " $nodes " ]] && continue
5569 nodes="$nodes $node"
5571 do_node $node "$LCTL get_param $2 |
5572 while read s; do echo $facet \\\$s; done"
5576 # restore lustre parameters from input stream, produces by save_lustre_params
5577 restore_lustre_params() {
5582 while IFS=" =" read facet name val; do
5583 do_facet $facet "$LCTL set_param -n $name $val"
5587 check_catastrophe() {
5588 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
5589 VAR=$(lctl get_param -n catastrophe 2>&1)
5590 if [ $? = 0 ] ; then
5591 if [ $VAR != 0 ]; then
5596 [ -z "$rnodes" ] && return 0
5599 data=$(do_nodes "$rnodes" "rc=\\\$(lctl get_param -n catastrophe);
5600 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
5603 if [ -n "$data" ]; then
5610 # CMD: determine mds index where directory inode presents
5615 SEQ=$(lfs path2fid $dir | tr '[:]' ' '|cut -f2 -d ' ')
5616 if [ "$SEQ" == "" ]; then
5617 error "can't get sequence for $dir"
5622 do_facet mds1 "cat /proc/fs/lustre/fld/srv-*-MDT0000/fldb" | \
5624 while read SS EE IDX TYP; do \
5625 if let "SEQ >= SS && SEQ < EE"; then \
5631 mdsrate_cleanup () {
5633 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
5634 --nfiles $3 --dir $4 --filefmt $5 $6
5639 delayed_recovery_enabled () {
5640 local var=${SINGLEMDS}_svc
5641 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5644 ########################
5646 convert_facet2label() {
5649 if [ x$facet = xost ]; then
5653 local varsvc=${facet}_svc
5655 if [ -n ${!varsvc} ]; then
5658 error "No lablel for $facet!"
5662 get_clientosc_proc_path() {
5666 get_lustre_version () {
5667 local facet=${1:-"$SINGLEMDS"}
5668 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
5671 lustre_version_code() {
5672 local facet=${1:-"$SINGLEMDS"}
5673 version_code $(get_lustre_version $1)
5676 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5677 # used by MDT would not be changed.
5678 # mdt lov: fsname-mdtlov
5679 # mdt osc: fsname-OSTXXXX-osc
5680 mds_on_old_device() {
5681 local mds=${1:-"$SINGLEMDS"}
5683 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5684 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5685 > /dev/null 2>&1" && return 0
5690 get_mdtosc_proc_path() {
5692 local ost_label=${2:-"*OST*"}
5694 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5695 local mdt_label=$(convert_facet2label $mds_facet)
5696 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5698 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5699 mds_on_old_device $mds_facet; then
5700 echo "${ost_label}-osc"
5702 echo "${ost_label}-osc-${mdt_index}"
5706 get_osc_import_name() {
5709 local label=$(convert_facet2label $ost)
5711 if [ "${facet:0:3}" = "mds" ]; then
5712 get_mdtosc_proc_path $facet $label
5716 get_clientosc_proc_path $label
5720 _wait_import_state () {
5723 local maxtime=${3:-$(max_recovery_time)}
5727 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5728 while [ "${CONN_STATE}" != "${expected}" ]; do
5729 if [ "${expected}" == "DISCONN" ]; then
5730 # for disconn we can check after proc entry is removed
5731 [ "x${CONN_STATE}" == "x" ] && return 0
5732 # with AT enabled, we can have connect request timeout near of
5733 # reconnect timeout and test can't see real disconnect
5734 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
5736 [ $i -ge $maxtime ] && \
5737 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
5740 # Add uniq for multi-mount case
5741 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5745 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
5749 wait_import_state() {
5752 local maxtime=${3:-$(max_recovery_time)}
5755 for param in ${params//,/ }; do
5756 _wait_import_state $state $param $maxtime || return
5760 wait_import_state_mount() {
5761 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
5765 wait_import_state $*
5768 # One client request could be timed out because server was not ready
5769 # when request was sent by client.
5770 # The request timeout calculation details :
5772 # /* We give the server rq_timeout secs to process the req, and
5773 # add the network latency for our local timeout. */
5774 # request->rq_deadline = request->rq_sent + request->rq_timeout +
5775 # ptlrpc_at_get_net_latency(request) ;
5777 # ptlrpc_connect_import ()
5778 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5781 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
5782 # ptlrpc_at_get_net_latency(request) ->
5783 # at_get (max (iat_net_latency=0, at_min)) = at_min
5786 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
5787 # INITIAL_CONNECT_TIMEOUT + at_min
5789 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
5790 # because we can not get this value in runtime,
5791 # the value depends on configure options, and it is not stored in /proc.
5793 # #define CONNECTION_SWITCH_MIN 5U
5794 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5796 request_timeout () {
5799 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5800 local init_connect_timeout=$TIMEOUT
5801 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5803 local at_min=$(at_get $facet at_min)
5805 echo $(( init_connect_timeout + at_min ))
5808 _wait_osc_import_state() {
5812 local ost=$(get_osc_import_name $facet $ost_facet)
5813 local param="osc.${ost}.ost_server_uuid"
5817 # 1. wait the deadline of client 1st request (it could be skipped)
5818 # 2. wait the deadline of client 2nd request
5819 local maxtime=$(( 2 * $(request_timeout $facet)))
5821 if [[ $facet == client* ]]; then
5822 # During setup time, the osc might not be setup, it need wait
5823 # until list_param can return valid value. And also if there
5824 # are mulitple osc entries we should list all of them before
5826 params=$($LCTL list_param $param 2>/dev/null || true)
5827 while [ -z "$params" ]; do
5828 if [ $i -ge $maxtime ]; then
5829 echo "can't get $param in $maxtime secs"
5834 params=$($LCTL list_param $param 2>/dev/null || true)
5837 if ! do_rpc_nodes "$(facet_active_host $facet)" \
5838 wait_import_state $expected "$params" $maxtime; then
5839 error "import is not in ${expected} state"
5846 wait_osc_import_state() {
5852 if [[ $facet = mds ]]; then
5853 for num in $(seq $MDSCOUNT); do
5854 _wait_osc_import_state mds$num "$ost_facet" "$expected"
5857 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
5861 get_clientmdc_proc_path() {
5869 [ -z "$list" ] && return 0
5871 # Add paths to lustre tests for 32 and 64 bit systems.
5872 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
5873 local TESTPATH="$RLUSTRE/tests:"
5874 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
5875 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
5878 wait_clients_import_state () {
5885 if [ "$FAILURE_MODE" = HARD ]; then
5886 facets=$(facets_on_host $(facet_active_host $facet))
5889 for facet in ${facets//,/ }; do
5890 local label=$(convert_facet2label $facet)
5893 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
5894 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
5895 *) error "unknown facet!" ;;
5897 local params=$(expand_list $params $proc_path)
5900 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params; then
5901 error "import is not in ${expected} state"
5911 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
5912 $LCTL get_param obdfilter.*.kbytesavail))
5913 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
5914 $LCTL get_param -n obdfilter.*.tot_granted))
5915 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
5916 $LCTL get_param -n obdfilter.*.kbytestotal))
5917 for ((i=0; i<${#AVAILA[@]}; i++)); do
5918 local -a AVAIL1=(${AVAILA[$i]//=/ })
5919 local -a TOTAL=(${TOTALA[$i]//=/ })
5920 GRANT=$((${GRANTA[$i]}/1024))
5921 # allow 1% of total space in bavail because of delayed
5922 # allocation with ZFS which might release some free space after
5923 # txg commit. For small devices, we set a mininum of 8MB
5924 local LIMIT=$((${TOTAL} / 100 + 8000))
5925 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
5926 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
5927 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
5928 echo " FULL" || echo
5934 do_facet mgs lctl pool_list $1
5938 local fsname=${1%%.*}
5939 local poolname=${1##$fsname.}
5941 do_facet mgs lctl pool_new $1
5943 # get param should return err unless pool is created
5944 [[ $RC -ne 0 ]] && return $RC
5946 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
5947 2>/dev/null || echo foo" "" || RC=1
5948 if [[ $RC -eq 0 ]]; then
5951 error "pool_new failed $1"
5956 add_pool_to_list () {
5957 local fsname=${1%%.*}
5958 local poolname=${1##$fsname.}
5960 local listvar=${fsname}_CREATED_POOLS
5961 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
5964 remove_pool_from_list () {
5965 local fsname=${1%%.*}
5966 local poolname=${1##$fsname.}
5968 local listvar=${fsname}_CREATED_POOLS
5969 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
5972 destroy_pool_int() {
5974 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
5975 awk '$1 !~ /^Pool:/ {print $1}')
5976 for ost in $OSTS; do
5977 do_facet mgs lctl pool_remove $1 $ost
5979 do_facet mgs lctl pool_destroy $1
5982 # <fsname>.<poolname> or <poolname>
5984 local fsname=${1%%.*}
5985 local poolname=${1##$fsname.}
5987 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
5991 pool_list $fsname.$poolname || return $?
5993 destroy_pool_int $fsname.$poolname
5995 [[ $RC -ne 0 ]] && return $RC
5997 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
5998 2>/dev/null || echo foo" "foo" || RC=1
6000 if [[ $RC -eq 0 ]]; then
6001 remove_pool_from_list $fsname.$poolname
6003 error "destroy pool failed $1"
6009 local fsname=${1:-$FSNAME}
6011 local listvar=${fsname}_CREATED_POOLS
6015 [ x${!listvar} = x ] && return 0
6017 echo destroy the created pools: ${!listvar}
6018 for poolname in ${!listvar//,/ }; do
6019 destroy_pool $fsname.$poolname
6024 local fsname=${1:-$FSNAME}
6026 destroy_pools $fsname
6032 local ts=$(date +%s)
6035 if [[ ! -f "$YAML_LOG" ]]; then
6036 # init_logging is not performed before gather_logs,
6037 # so the $LOGDIR needs to be checked here
6038 check_shared_dir $LOGDIR && touch $LOGDIR/shared
6041 [ -f $LOGDIR/shared ] && docp=false
6043 # dump lustre logs, dmesg
6045 prefix="$TESTLOG_PREFIX.$TESTNAME"
6047 echo "Dumping lctl log to ${prefix}.*.${suffix}"
6049 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
6050 echo "Dumping logs only on local client."
6051 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
6052 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
6057 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
6058 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
6059 if [ ! -f $LOGDIR/shared ]; then
6060 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
6073 for i in $(seq 0 $num_mntpts); do
6074 cmd="ls -laf ${mntpt_root}$i/$dir"
6080 for pid in $pids; do
6087 # target_start_and_reset_recovery_timer()
6088 # service_time = at_est2timeout(service_time);
6089 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
6090 # INITIAL_CONNECT_TIMEOUT);
6091 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
6092 #define CONNECTION_SWITCH_INC 1
6093 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
6094 #define CONNECTION_SWITCH_MIN 5U
6096 max_recovery_time () {
6097 local init_connect_timeout=$(( TIMEOUT / 20 ))
6098 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
6100 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
6105 get_clients_mount_count () {
6106 local clients=${CLIENTS:-`hostname`}
6108 # we need to take into account the clients mounts and
6109 # exclude mds/ost mounts if any;
6110 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
6114 PROC_CLI="srpc_info"
6122 if [ $M -lt $N ]; then
6126 while [ $N -lt $M ]; do
6136 calc_connection_cnt() {
6139 # MDT->MDT = 2 * C(M, 2)
6143 comb_m2=$(combination $MDSCOUNT 2)
6145 local num_clients=$(get_clients_mount_count)
6147 local cnt_mdt2mdt=$((comb_m2 * 2))
6148 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
6149 local cnt_cli2ost=$((num_clients * OSTCOUNT))
6150 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
6151 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
6152 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
6153 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
6167 local cmd="$tgt.srpc.flavor"
6169 if [ $net == "any" ]; then
6174 if [ $dir != "any" ]; then
6179 log "Setting sptlrpc rule: $cmd"
6180 do_facet mgs "$LCTL conf_param $cmd"
6189 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
6190 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
6192 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
6194 if [ "x$bulkspec" != "x" ]; then
6195 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
6197 if [ "x$algs" != "x" ]; then
6198 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
6200 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
6201 if [ $bulk == "bulkn" ]; then
6202 bulk_count=`echo "$output" | grep "bulk flavor" \
6203 | grep "null/null" | wc -l`
6204 elif [ $bulk == "bulki" ]; then
6205 bulk_count=`echo "$output" | grep "bulk flavor" \
6206 | grep "/null" | grep -v "null/" | wc -l`
6208 bulk_count=`echo "$output" | grep "bulk flavor" \
6209 | grep -v "/null" | grep -v "null/" | wc -l`
6213 [ $bulk_count -lt $count ] && count=$bulk_count
6224 local clients=${CLIENTS:-`hostname`}
6226 for c in ${clients//,/ }; do
6227 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
6228 tmpcnt=`count_flvr "$output" $flavor`
6229 cnt=$((cnt + tmpcnt))
6239 local clients=${CLIENTS:-`hostname`}
6241 for c in ${clients//,/ }; do
6242 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
6243 tmpcnt=`count_flvr "$output" $flavor`
6244 cnt=$((cnt + tmpcnt))
6254 if [ $MDSCOUNT -le 1 ]; then
6259 for num in `seq $MDSCOUNT`; do
6260 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
6261 tmpcnt=`count_flvr "$output" $flavor`
6262 cnt=$((cnt + tmpcnt))
6273 for num in `seq $MDSCOUNT`; do
6274 mdtosc=$(get_mdtosc_proc_path mds$num)
6275 mdtosc=${mdtosc/-MDT*/-MDT\*}
6276 output=$(do_facet mds$num lctl get_param -n \
6277 osc.$mdtosc.$PROC_CLI 2>/dev/null)
6278 tmpcnt=`count_flvr "$output" $flavor`
6279 cnt=$((cnt + tmpcnt))
6288 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
6289 count_flvr "$output" $flavor
6294 local dir=$1 # from to
6295 local flavor=$2 # flavor expected
6298 if [ $dir == "cli2mdt" ]; then
6299 res=`flvr_cnt_cli2mdt $flavor`
6300 elif [ $dir == "cli2ost" ]; then
6301 res=`flvr_cnt_cli2ost $flavor`
6302 elif [ $dir == "mdt2mdt" ]; then
6303 res=`flvr_cnt_mdt2mdt $flavor`
6304 elif [ $dir == "mdt2ost" ]; then
6305 res=`flvr_cnt_mdt2ost $flavor`
6306 elif [ $dir == "all2ost" ]; then
6307 res1=`flvr_cnt_mdt2ost $flavor`
6308 res2=`flvr_cnt_cli2ost $flavor`
6309 res=$((res1 + res2))
6310 elif [ $dir == "all2mdt" ]; then
6311 res1=`flvr_cnt_mdt2mdt $flavor`
6312 res2=`flvr_cnt_cli2mdt $flavor`
6313 res=$((res1 + res2))
6314 elif [ $dir == "all2all" ]; then
6315 res1=`flvr_cnt_mdt2ost $flavor`
6316 res2=`flvr_cnt_cli2ost $flavor`
6317 res3=`flvr_cnt_mdt2mdt $flavor`
6318 res4=`flvr_cnt_cli2mdt $flavor`
6319 res=$((res1 + res2 + res3 + res4))
6327 local dir=$1 # from to
6328 local flavor=$2 # flavor expected
6329 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6333 for ((i=0;i<20;i++)); do
6334 echo -n "checking $dir..."
6335 res=$(do_check_flavor $dir $flavor)
6336 echo "found $res/$expect $flavor connections"
6337 [ $res -ge $expect ] && return 0
6341 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6345 restore_to_default_flavor()
6347 local proc="mgs.MGS.live.$FSNAME"
6349 echo "restoring to default flavor..."
6351 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6353 # remove all existing rules if any
6354 if [ $nrule -ne 0 ]; then
6355 echo "$nrule existing rules"
6356 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6357 echo "remove rule: $rule"
6358 spec=`echo $rule | awk -F = '{print $1}'`
6359 do_facet mgs "$LCTL conf_param -d $spec"
6363 # verify no rules left
6364 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6365 [ $nrule -ne 0 ] && error "still $nrule rules left"
6367 # wait for default flavor to be applied
6368 # currently default flavor for all connections are 'null'
6369 wait_flavor all2all null
6370 echo "now at default flavor settings"
6375 local flavor=${1:-null}
6377 echo "setting all flavor to $flavor"
6379 # FIXME need parameter to this fn
6380 # and remove global vars
6381 local cnt_all2all=$(calc_connection_cnt all2all)
6383 local res=$(do_check_flavor all2all $flavor)
6384 if [ $res -eq $cnt_all2all ]; then
6385 echo "already have total $res $flavor connections"
6389 echo "found $res $flavor out of total $cnt_all2all connections"
6390 restore_to_default_flavor
6392 [[ $flavor = null ]] && return 0
6394 set_rule $FSNAME any any $flavor
6395 wait_flavor all2all $flavor
6401 # Checking for shared logdir
6402 if [ ! -d $dir ]; then
6403 # Not found. Create local logdir
6406 touch $dir/check_file.$(hostname -s)
6411 check_write_access() {
6413 local list=${2:-$(comma_list $(nodes_list))}
6417 for node in ${list//,/ }; do
6418 file=$dir/check_file.$(short_nodename $node)
6419 if [[ ! -f "$file" ]]; then
6420 # Logdir not accessible/writable from this node.
6423 rm -f $file || return 1
6429 if [[ -n $YAML_LOG ]]; then
6432 local SAVE_UMASK=`umask`
6435 export YAML_LOG=${LOGDIR}/results.yml
6439 if [ ! -f $YAML_LOG ]; then # If the yaml log already exists then we will just append to it
6440 if check_shared_dir $LOGDIR; then
6441 touch $LOGDIR/shared
6442 echo "Logging to shared log directory: $LOGDIR"
6444 echo "Logging to local directory: $LOGDIR"
6447 yml_nodes_file $LOGDIR >> $YAML_LOG
6448 yml_results_file >> $YAML_LOG
6455 yml_log_test $1 >> $YAML_LOG
6459 yml_log_test_status $@ >> $YAML_LOG
6462 log_sub_test_begin() {
6463 yml_log_sub_test_begin "$@" >> $YAML_LOG
6466 log_sub_test_end() {
6467 yml_log_sub_test_end "$@" >> $YAML_LOG
6473 local llverdev_opts=$2
6474 local devname=$(basename $1)
6475 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6476 # loop devices aren't in /proc/partitions
6477 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6479 size=$(($size / 1024 / 1024)) # Gb
6481 local partial_arg=""
6482 # Run in partial (fast) mode if the size
6483 # of a partition > 1 GB
6484 [ $size -gt 1 ] && partial_arg="-p"
6486 llverdev --force $partial_arg $llverdev_opts $dev
6492 local llverfs_opts=$2
6493 local use_partial_arg=$3
6494 local partial_arg=""
6495 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6497 # Run in partial (fast) mode if the size
6498 # of a partition > 1 GB
6499 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6501 llverfs $partial_arg $llverfs_opts $dir
6504 #Remove objects from OST
6505 remove_ost_objects() {
6511 local mntpt=$(facet_mntpt $facet)
6512 local opts=$OST_MOUNT_OPTS
6516 echo "removing objects from $ostdev on $facet: $objids"
6517 if ! test -b $ostdev; then
6518 opts=$(csa_add "$opts" -o loop)
6520 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
6523 for i in $objids; do
6524 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
6526 umount -f $mntpt || return $?
6530 #Remove files from MDT
6531 remove_mdt_files() {
6536 local mntpt=$(facet_mntpt $facet)
6537 local opts=$MDS_MOUNT_OPTS
6539 echo "removing files from $mdtdev on $facet: $files"
6540 if [ $(facet_fstype $facet) == ldiskfs ] &&
6541 ! do_facet $facet test -b $mdtdev; then
6542 opts=$(csa_add "$opts" -o loop)
6544 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6548 rm $mntpt/ROOT/$f || { rc=$?; break; }
6550 umount -f $mntpt || return $?
6554 duplicate_mdt_files() {
6559 local mntpt=$(facet_mntpt $facet)
6560 local opts=$MDS_MOUNT_OPTS
6562 echo "duplicating files on $mdtdev on $facet: $files"
6563 mkdir -p $mntpt || return $?
6564 if [ $(facet_fstype $facet) == ldiskfs ] &&
6565 ! do_facet $facet test -b $mdtdev; then
6566 opts=$(csa_add "$opts" -o loop)
6568 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6579 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
6580 pushd $mntpt/ROOT > /dev/null || return $?
6583 touch $f.bad || return $?
6584 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
6586 [ $rc -eq 0 ] || return $rc
6587 setfattr --restore $tmp || return $?
6593 local devs=${1//,/ }
6596 local rslt=$TMP/sgpdd_survey
6598 # sgpdd-survey cleanups ${rslt}.* files
6600 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
6606 # returns the canonical name for an ldiskfs device
6611 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
6612 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
6613 echo dm-\\\${foo##*:};
6615 echo \\\$(basename \\\$dv);
6619 is_sanity_benchmark() {
6620 local benchmarks="dbench bonnie iozone fsx"
6622 for b in $benchmarks; do
6623 if [ "$b" == "$suite" ]; then
6631 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
6635 # Get the available size (KB) of a given obd target.
6642 [[ $facet != client ]] || return 0
6644 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
6649 # Get the page size (bytes) on a given facet node.
6655 size=$(do_facet $facet getconf PAGE_SIZE)
6656 [[ ${PIPESTATUS[0]} = 0 && -n "$size" ]] || size=4096
6661 # Get the block count of the filesystem.
6668 count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6669 awk '/^Block count:/ {print $3}')
6673 # Get the block size of the filesystem.
6679 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6680 awk '/^Block size:/ {print $3}')
6684 # Check whether the "large_xattr" feature is enabled or not.
6685 large_xattr_enabled() {
6686 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
6688 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6690 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
6691 grep -E -q '(ea_inode|large_xattr)'"
6692 return ${PIPESTATUS[0]}
6695 # Get the maximum xattr size supported by the filesystem.
6699 if large_xattr_enabled; then
6700 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
6703 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6704 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
6706 # maximum xattr size = size of block - size of header -
6707 # size of 1 entry - 4 null bytes
6708 size=$((block_size - 32 - 32 - 4))
6714 # Dump the value of the named xattr from a file.
6719 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
6722 # Generate a string with size of $size bytes.
6724 local size=${1:-1024} # in bytes
6726 echo "$(head -c $size < /dev/zero | tr '\0' y)"
6729 reformat_external_journal() {
6732 if [ ! -z ${EJOURNAL} ]; then
6733 local rcmd="do_facet $facet"
6735 echo "reformat external journal on $facet:${EJOURNAL}"
6736 ${rcmd} mke2fs -O journal_dev ${EJOURNAL} || return 1
6740 # MDT file-level backup/restore
6741 mds_backup_restore() {
6744 local devname=$(mdsdevname $(facet_number $facet))
6745 local mntpt=$(facet_mntpt brpt)
6746 local rcmd="do_facet $facet"
6747 local metaea=${TMP}/backup_restore.ea
6748 local metadata=${TMP}/backup_restore.tgz
6749 local opts=${MDS_MOUNT_OPTS}
6750 local svc=${facet}_svc
6752 if ! ${rcmd} test -b ${devname}; then
6753 opts=$(csa_add "$opts" -o loop)
6756 echo "file-level backup/restore on $facet:${devname}"
6758 # step 1: build mount point
6759 ${rcmd} mkdir -p $mntpt
6760 # step 2: cleanup old backup
6761 ${rcmd} rm -f $metaea $metadata
6763 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
6764 if [ ! -z $igif ]; then
6765 # step 3.5: rm .lustre
6766 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
6768 # step 4: backup metaea
6770 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
6772 # step 5: backup metadata
6774 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
6776 ${rcmd} umount -d $mntpt || return 4
6777 # step 7: reformat external journal if needed
6778 reformat_external_journal $facet || return 5
6779 # step 8: reformat dev
6780 echo "reformat new device"
6781 add $facet $(mkfs_opts $facet ${devname}) --backfstype ldiskfs \
6782 --reformat ${devname} $(mdsvdevname $(facet_number $facet)) \
6783 > /dev/null || exit 6
6785 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
6786 # step 10: restore metadata
6788 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
6789 # step 11: restore metaea
6791 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
6792 # step 12: remove recovery logs
6793 echo "remove recovery logs"
6794 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
6795 # step 13: umount dev
6796 ${rcmd} umount -d $mntpt || return 10
6797 # step 14: cleanup tmp backup
6798 ${rcmd} rm -f $metaea $metadata
6799 # step 15: reset device label - it's not virgin on
6800 ${rcmd} e2label $devname ${!svc}
6807 local devname=$(mdsdevname $(facet_number $facet))
6808 local mntpt=$(facet_mntpt brpt)
6809 local rcmd="do_facet $facet"
6810 local opts=${MDS_MOUNT_OPTS}
6812 if ! ${rcmd} test -b ${devname}; then
6813 opts=$(csa_add "$opts" -o loop)
6816 echo "removing OI files on $facet: idx=${idx}"
6818 # step 1: build mount point
6819 ${rcmd} mkdir -p $mntpt
6821 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
6822 if [ -z $idx ]; then
6823 # step 3: remove all OI files
6824 ${rcmd} rm -fv $mntpt/oi.16*
6825 elif [ $idx -lt 2 ]; then
6826 ${rcmd} rm -fv $mntpt/oi.16.${idx}
6830 # others, rm oi.16.[idx, idx * idx, idx ** ...]
6831 for ((i=${idx}; i<64; i=$((i * idx)))); do
6832 ${rcmd} rm -fv $mntpt/oi.16.${i}
6836 ${rcmd} umount -d $mntpt || return 2
6837 # OI files will be recreated when mounted as lustre next time.
6840 # generate maloo upload-able log file name
6841 # \param logname specify unique part of file name
6842 generate_logname() {
6843 local logname=${1:-"default_logname"}
6845 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
6848 # make directory on different MDTs
6856 local stripe_count=2
6866 *) error "Only creating single directory is supported";;
6869 child=$(basename $path)
6870 parent=$(dirname $path)
6872 if [ "$option" == "-p" -o "$option2" == "-p" ]; then
6873 if [ -d $parent/$child ]; then
6879 if [ "${option:0:2}" == "-c" ]; then
6880 stripe_count=$(echo $option | sed 's/^-c//')
6883 if [ "${option2:0:2}" == "-c" ]; then
6884 stripe_count=$(echo $option2 | sed 's/^-c//')
6887 if [ ! -d ${parent} ]; then
6888 if [ "$p_option" == "-p" ]; then
6895 if [ $MDSCOUNT -le 1 ]; then
6896 mkdir $p_option $parent/$child || rc=$?
6898 local mdt_idx=$($LFS getstripe -M $parent)
6899 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
6901 mdt_idx=$((test_num % MDSCOUNT))
6902 echo "striped dir -i$mdt_idx -c$stripe_count $path"
6903 $LFS setdirstripe -i$mdt_idx -c$stripe_count $path || rc=$?
6908 # find the smallest and not in use file descriptor
6911 local max_fd=$(ulimit -n)
6913 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
6916 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
6920 check_mount_and_prep()
6922 is_mounted $MOUNT || setupall
6924 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
6925 mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
6928 # calcule how many ost-objects to be created.
6929 precreated_ost_obj_count()
6933 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
6934 local ost_name="OST$(printf '%04x' $ost_idx)"
6935 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
6936 local last_id=$(do_facet mds${mdt_idx} lctl get_param -n \
6937 osp.$proc_path.prealloc_last_id)
6938 local next_id=$(do_facet mds${mdt_idx} lctl get_param -n \
6939 osp.$proc_path.prealloc_next_id)
6941 echo $((last_id - next_id + 1))
6944 check_file_in_pool()
6949 local res=$($GETSTRIPE $file | grep 0x | cut -f2)
6952 for t in $tlist ; do
6953 [ "$i" -eq "$t" ] && continue 2
6956 echo "pool list: $tlist"
6957 echo "striping: $res"
6958 error_noexit "$file not allocated in $pool"
6965 echo "Creating new pool"
6968 create_pool $FSNAME.$pool ||
6969 { error_noexit "No pool created, result code $?"; return 1; }
6970 [ $($LFS pool_list $FSNAME | grep -c $pool) -eq 1 ] ||
6971 { error_noexit "$pool not in lfs pool_list"; return 2; }
6974 pool_add_targets() {
6975 echo "Adding targets to pool"
6981 local list=$(seq $first $step $last)
6983 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
6984 do_facet mgs $LCTL pool_add \
6985 $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
6986 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
6987 | sort -u | tr '\n' ' ' " "$t" || {
6988 error_noexit "Add to pool failed"
6991 local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
6992 local addcount=$(((last - first) / step + 1))
6993 [ $lfscount -eq $addcount ] || {
6994 error_noexit "lfs pool_list bad ost count" \
6995 "$lfscount != $addcount"
7003 echo "Setting pool on directory $tdir"
7005 $SETSTRIPE -c 2 -p $pool $tdir && return 0
7007 error_noexit "Cannot set pool $pool to $tdir"
7014 echo "Checking pool on directory $tdir"
7016 local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
7017 [ "$res" = "$pool" ] && return 0
7019 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
7023 pool_dir_rel_path() {
7024 echo "Testing relative path works well"
7029 mkdir -p $root/$tdir/$tdir
7031 pool_set_dir $pool $tdir || return 1
7032 pool_set_dir $pool ./$tdir || return 2
7033 pool_set_dir $pool ../$tdir || return 3
7034 pool_set_dir $pool ../$tdir/$tdir || return 4
7035 rm -rf $tdir; cd - > /dev/null
7038 pool_alloc_files() {
7039 echo "Checking files allocation from directory pool"
7046 for i in $(seq -w 1 $count)
7048 local file=$tdir/file-$i
7050 check_file_in_pool $file $pool "$tlist" || \
7051 failed=$((failed + 1))
7053 [ "$failed" = 0 ] && return 0
7055 error_noexit "$failed files not allocated in $pool"
7059 pool_create_files() {
7060 echo "Creating files in pool"
7068 for i in $(seq -w 1 $count)
7070 local file=$tdir/spoo-$i
7071 $SETSTRIPE -p $pool $file
7072 check_file_in_pool $file $pool "$tlist" || \
7073 failed=$((failed + 1))
7075 [ "$failed" = 0 ] && return 0
7077 error_noexit "$failed files not allocated in $pool"
7082 echo "Checking 'lfs df' output"
7085 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
7087 local res=$($LFS df --pool $FSNAME.$pool |
7089 grep "$FSNAME-OST" |
7091 [ "$res" = "$t" ] && return 0
7093 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
7097 pool_file_rel_path() {
7098 echo "Creating files in a pool with relative pathname"
7103 { error_noexit "unable to create $tdir"; return 1 ; }
7104 local file="/..$tdir/$tfile-1"
7105 $SETSTRIPE -p $pool $file ||
7106 { error_noexit "unable to create $file" ; return 2 ; }
7109 $SETSTRIPE -p $pool $tfile-2 || {
7110 error_noexit "unable to create $tfile-2 in $tdir"
7115 pool_remove_first_target() {
7116 echo "Removing first target from a pool"
7119 local pname="lov.$FSNAME-*.pools.$pool"
7120 local t=$($LCTL get_param -n $pname | head -1)
7121 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7122 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
7123 error_noexit "$t not removed from $FSNAME.$pool"
7128 pool_remove_all_targets() {
7129 echo "Removing all targets from pool"
7132 local pname="lov.$FSNAME-*.pools.$pool"
7133 for t in $($LCTL get_param -n $pname | sort -u)
7135 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
7137 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
7138 error_noexit "Pool $FSNAME.$pool cannot be drained"
7141 # striping on an empty/nonexistant pool should fall back
7142 # to "pool of everything"
7144 error_noexit "failed to use fallback striping for empty pool"
7147 # setstripe on an empty pool should fail
7148 $SETSTRIPE -p $pool $file 2>/dev/null && {
7149 error_noexit "expected failure when creating file" \
7157 echo "Destroying pool"
7161 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
7164 # striping on an empty/nonexistant pool should fall back
7165 # to "pool of everything"
7167 error_noexit "failed to use fallback striping for missing pool"
7170 # setstripe on an empty pool should fail
7171 $SETSTRIPE -p $pool $file 2>/dev/null && {
7172 error_noexit "expected failure when creating file" \
7177 # get param should return err once pool is gone
7178 if wait_update $HOSTNAME "lctl get_param -n \
7179 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
7181 remove_pool_from_list $FSNAME.$pool
7184 error_noexit "Pool $FSNAME.$pool is not destroyed"