3 trap 'print_summary && touch $TF_FAIL && \
4 echo "test-framework exiting on error"' ERR
8 export EJOURNAL=${EJOURNAL:-""}
9 export REFORMAT=${REFORMAT:-""}
10 export WRITECONF=${WRITECONF:-""}
11 export VERBOSE=${VERBOSE:-false}
12 export CATASTROPHE=${CATASTROPHE:-/proc/sys/lnet/catastrophe}
15 export GSS_PIPEFS=false
16 export IDENTITY_UPCALL=default
19 # LOAD_LLOOP: LU-409: only load llite_lloop module if kernel < 2.6.32 or
20 # LOAD_LLOOP is true. LOAD_LLOOP is false by default.
21 export LOAD_LLOOP=${LOAD_LLOOP:-false}
23 #export PDSH="pdsh -S -Rssh -w"
25 # function used by scripts run on remote nodes
26 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
27 . $LUSTRE/tests/functions.sh
28 . $LUSTRE/tests/yaml.sh
30 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
32 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
34 if [ -f "$EXCEPT_LIST_FILE" ]; then
35 echo "Reading test skip list from $EXCEPT_LIST_FILE"
40 # check config files for options in decreasing order of preference
41 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
42 MODPROBECONF=/etc/modprobe.d/lustre.conf
43 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
44 MODPROBECONF=/etc/modprobe.d/Lustre
45 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
46 MODPROBECONF=/etc/modprobe.conf
50 [[ $DIR/ = $MOUNT/* ]] || \
51 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
52 [[ $DIR1/ = $MOUNT1/* ]] || \
53 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
54 [[ $DIR2/ = $MOUNT2/* ]] || \
55 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
57 [ -n "$failed" ] && exit 99 || true
61 echo "usage: $0 [-r] [-f cfgfile]"
69 [ "$TESTSUITE" == "lfsck" ] && return 0
70 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
72 local form="%-13s %-17s %-9s %s %s\n"
73 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
74 echo "------------------------------------------------------------------------------------"
75 for O in $DEFAULT_SUITES; do
76 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
77 [ "${!O}" = "no" ] && continue || true
78 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
79 local log=${TMP}/${o}.log
80 if is_sanity_benchmark $o; then
81 log=${TMP}/sanity-benchmark.log
86 local status=Unfinished
88 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
89 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | sort -nr -k 3 | head -5 | awk '{ print $2":"$3"s" }')
90 total=$(grep duration $log | awk '{ print $2}')
91 if [ "${!O}" = "done" ]; then
95 local durations=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | awk '{ print $2":"$3"|" }')
96 details=$(printf "%s\n%s %s %s\n" "$details" "DDETAILS" "$O" "$(echo $durations)")
99 printf "$form" $status "$O" "${total}" "E=$skipped"
100 printf "$form" "-" "-" "-" "S=$(echo $slow)"
103 for O in $DEFAULT_SUITES; do
104 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
105 if [ "${!O}" = "no" ]; then
106 printf "$form" "Skipped" "$O" ""
110 # print the detailed tests durations if DDETAILS=true
117 export LUSTRE=`absolute_path $LUSTRE`
118 export TESTSUITE=`basename $0 .sh`
119 export TEST_FAILED=false
120 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
122 export MKE2FS=${MKE2FS:-mke2fs}
123 export DEBUGFS=${DEBUGFS:-debugfs}
124 export TUNE2FS=${TUNE2FS:-tune2fs}
125 export E2LABEL=${E2LABEL:-e2label}
126 export DUMPE2FS=${DUMPE2FS:-dumpe2fs}
127 export E2FSCK=${E2FSCK:-e2fsck}
128 export LFSCK_BIN=${LFSCK_BIN:-lfsck}
130 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after each test suite
131 export FSCK_MAX_ERR=4 # File system errors left uncorrected
133 export ZFS=${ZFS:-zfs}
134 export ZPOOL=${ZPOOL:-zpool}
135 export ZDB=${ZDB:-zdb}
137 #[ -d /r ] && export ROOT=${ROOT:-/r}
138 export TMP=${TMP:-$ROOT/tmp}
139 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
140 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
141 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
143 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
144 if ! echo $PATH | grep -q $LUSTRE/utils; then
145 export PATH=$LUSTRE/utils:$PATH
147 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
148 export PATH=$LUSTRE/utils/gss:$PATH
150 if ! echo $PATH | grep -q $LUSTRE/tests; then
151 export PATH=$LUSTRE/tests:$PATH
153 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
154 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
156 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
157 [ ! -f "$LST" ] && export LST=$(which lst)
158 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
159 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
160 # Ubuntu, at least, has a truncate command in /usr/bin
161 # so fully path our truncate command.
162 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
163 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
164 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
165 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
166 export PATH=$LUSTRE/tests/racer:$PATH:
168 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
169 export PATH=$LUSTRE/tests/mpi:$PATH
171 export RSYNC_RSH=${RSYNC_RSH:-rsh}
173 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
174 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
175 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
176 [ ! -f "$LFS" ] && export LFS=$(which lfs)
177 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
178 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
180 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
181 if [ ! -f "$L_GETIDENTITY" ]; then
182 if `which l_getidentity > /dev/null 2>&1`; then
183 export L_GETIDENTITY=$(which l_getidentity)
185 export L_GETIDENTITY=NONE
188 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
189 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID=$(which ll_decode_filter_fid)
190 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
191 [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre)
192 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
193 [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre)
194 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
195 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
196 [ ! -f "$LUSTRE_RMMOD" ] &&
197 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
198 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
199 [ ! -f "$LFS_MIGRATE" ] &&
200 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
201 export NAME=${NAME:-local}
202 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
203 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
204 export LGSSD=$(which lgssd)
205 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
206 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
207 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
209 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
212 if [ "$ACCEPTOR_PORT" ]; then
213 export PORT_OPT="--port $ACCEPTOR_PORT"
218 echo "Using GSS/krb5 ptlrpc security flavor"
219 which lgss_keyring > /dev/null 2>&1 || \
220 error_exit "built with gss disabled! SEC=$SEC"
231 IDENTITY_UPCALL=false
234 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
236 # Paths on remote nodes, if different
237 export RLUSTRE=${RLUSTRE:-$LUSTRE}
238 export RPWD=${RPWD:-$PWD}
239 export I_MOUNTED=${I_MOUNTED:-"no"}
240 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mds.ko -a \
241 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mds.ko -a \
242 ! -f `dirname $0`/../mds/mds.ko ]; then
243 export CLIENTMODSONLY=yes
246 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
250 while getopts "rvwf:" opt $*; do
253 r) REFORMAT=--reformat;;
255 w) WRITECONF=writeconf;;
260 shift $((OPTIND - 1))
263 # print the durations of each test if "true"
264 DDETAILS=${DDETAILS:-false}
265 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
272 ncpts=$(lctl get_param -n cpu_partition_table 2>/dev/null| wc -l)
273 if [ $ncpts -eq 0 ]; then
281 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
282 eval set -- $(tr "[:punct:]" " " <<< $*)
284 echo -n $((($1 << 16) | ($2 << 8) | $3))
287 export LINUX_VERSION=$(uname -r | sed -e "s/[-.]/ /3" -e "s/ .*//")
288 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
291 /sbin/lsmod | grep -q "^\<$1\>"
294 # Load a module on the system where this is running.
296 # Synopsis: load_module module_name [module arguments for insmod/modprobe]
298 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
299 # will be used as the arguments. Otherwise arguments will be obtained from
300 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
307 BASE=`basename $module $EXT`
309 module_loaded ${BASE} && return
311 # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
313 if [ $# -eq 0 ]; then
314 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
315 # Bash until 4.x, so we resort to eval.
316 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
317 eval set -- \$$optvar
318 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
319 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
320 set -- $(grep -P "^options\\s+${BASE}" $MODPROBECONF)
321 # Get rid of "options $module"
322 (($# > 0)) && shift 2
324 # Ensure we have accept=all for lnet
325 if [ $(basename $module) = lnet ]; then
326 # OK, this is a bit wordy...
327 local arg accept_all_present=false
329 [ "$arg" = accept=all ] && accept_all_present=true
331 $accept_all_present || set -- "$@" accept=all
336 [ $# -gt 0 ] && echo "${module} options: '$*'"
338 # Note that insmod will ignore anything in modprobe.conf, which is why we're
339 # passing options on the command-line.
340 if [ "$BASE" == "lnet_selftest" ] && \
341 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
342 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
343 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
344 insmod ${LUSTRE}/${module}${EXT} "$@"
346 # must be testing a "make install" or "rpm" installation
347 # note failed to load ptlrpc_gss is considered not fatal
348 if [ "$BASE" == "ptlrpc_gss" ]; then
349 modprobe $BASE "$@" 2>/dev/null || echo "gss/krb5 is not supported"
356 llite_lloop_enabled() {
357 local n1=$(uname -r | cut -d. -f1)
358 local n2=$(uname -r | cut -d. -f2)
359 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
361 # load the llite_lloop module for < 2.6.32 kernels
362 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
363 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
370 load_modules_local() {
371 if [ "$USE_OFD" == yes ]; then
372 if module_loaded obdfilter; then
373 if ! $LUSTRE_RMMOD ldiskfs; then
374 echo "$HOSTNAME may still be using obdfilter.ko"
379 if module_loaded ofd; then
380 if ! $LUSTRE_RMMOD ldiskfs; then
381 echo "$HOSTNAME may still be using ofd.ko"
387 if [ -n "$MODPROBE" ]; then
389 echo "Using modprobe to load modules"
393 echo Loading modules from $LUSTRE
397 if [ -f /sys/devices/system/cpu/online ]; then
398 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
399 echo "detected $ncpus online CPUs by sysfs"
401 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
403 if [ $rc -eq 0 ]; then
404 echo "detected $ncpus online CPUs by getconf"
406 echo "Can't detect number of CPUs"
412 # if there is only one CPU core, libcfs can only create one partition
413 # if there is more than 4 CPU cores, libcfs should create multiple CPU
414 # partitions. So we just force libcfs to create 2 partitions for
415 # system with 2 or 4 cores
416 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
417 # force to enable multiple CPU partitions
418 echo "Force libcfs to create 2 CPU partitions"
421 echo "libcfs will create CPU partition based on online CPUs"
424 load_module ../libcfs/libcfs/libcfs cpu_npartitions=$ncpts
426 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
427 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
428 load_module ../lnet/lnet/lnet
429 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
430 load_module ../lnet/klnds/$LNETLND
431 load_module lvfs/lvfs
432 load_module obdclass/obdclass
433 load_module ptlrpc/ptlrpc
434 load_module ptlrpc/gss/ptlrpc_gss
442 load_module obdecho/obdecho
443 if ! client_only; then
444 SYMLIST=/proc/kallsyms
445 grep -q crc16 $SYMLIST || { modprobe crc16 2>/dev/null || true; }
446 grep -q -w jbd $SYMLIST || { modprobe jbd 2>/dev/null || true; }
447 grep -q -w jbd2 $SYMLIST || { modprobe jbd2 2>/dev/null || true; }
448 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
449 grep -q exportfs_decode_fh $SYMLIST ||
450 { modprobe exportfs 2> /dev/null || true; }
451 load_module ../ldiskfs/ldiskfs/ldiskfs
453 [ "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
458 load_module lvfs/fsfilt_ldiskfs
460 load_module osd-ldiskfs/osd_ldiskfs
462 if [ "$USE_OFD" == yes ]; then
465 load_module obdfilter/obdfilter
470 load_module llite/lustre
471 llite_lloop_enabled && load_module llite/llite_lloop
472 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
474 rm -f $OGDB/ogdb-$HOSTNAME
475 $LCTL modules > $OGDB/ogdb-$HOSTNAME
477 # 'mount' doesn't look in $PATH, just sbin
478 if [ -f $LUSTRE/utils/mount.lustre ] && \
479 ! grep -qe "/sbin/mount\.lustre " /proc/mounts; then
480 [ ! -f /sbin/mount.lustre ] && touch /sbin/mount.lustre
481 mount --bind $LUSTRE/utils/mount.lustre /sbin/mount.lustre || true
488 # load modules on remote nodes optionally
489 # lustre-tests have to be installed on these nodes
490 if $LOAD_MODULES_REMOTE ; then
491 local list=$(comma_list $(remote_nodes_list))
492 echo loading modules on $list
493 do_rpc_nodes $list load_modules_local
498 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
499 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
500 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
501 echo "$LEAK_LUSTRE" 1>&2
502 echo "$LEAK_PORTALS" 1>&2
503 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
504 echo "Memory leaks detected"
505 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
511 wait_exit_ST client # bug 12845
513 $LUSTRE_RMMOD ldiskfs || return 2
515 if $LOAD_MODULES_REMOTE ; then
516 local list=$(comma_list $(remote_nodes_list))
517 if [ ! -z $list ]; then
518 echo unloading modules on $list
519 do_rpc_nodes $list $LUSTRE_RMMOD ldiskfs
520 do_rpc_nodes $list check_mem_leak
524 if grep -qe "/sbin/mount\.lustre" /proc/mounts; then
525 umount /sbin/mount.lustre || true
526 [ -w /sbin/mount.lustre -a ! -s /sbin/mount.lustre ] && \
527 rm -f /sbin/mount.lustre || true
530 check_mem_leak || return 254
532 echo "modules unloaded."
536 check_gss_daemon_nodes() {
540 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
541 if [ \\\"\\\$num\\\" -ne 1 ]; then
542 echo \\\$num instance of $dname;
547 check_gss_daemon_facet() {
551 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
552 if [ $num -ne 1 ]; then
553 echo "$num instance of $dname on $facet"
562 echo Stopping $@ on $list
563 do_nodes $list "killall -2 $@ 2>/dev/null || true"
566 # start gss daemons on all nodes, or
567 # "daemon" on "list" if set
568 start_gss_daemons() {
572 if [ "$list" ] && [ "$daemon" ] ; then
573 echo "Starting gss daemon on nodes: $list"
574 do_nodes $list "$daemon" || return 8
578 local list=$(comma_list $(mdts_nodes))
580 echo "Starting gss daemon on mds: $list"
581 do_nodes $list "$LSVCGSSD -v" || return 1
583 do_nodes $list "$LGSSD -v" || return 2
586 list=$(comma_list $(osts_nodes))
587 echo "Starting gss daemon on ost: $list"
588 do_nodes $list "$LSVCGSSD -v" || return 3
589 # starting on clients
591 local clients=${CLIENTS:-`hostname`}
593 echo "Starting $LGSSD on clients $clients "
594 do_nodes $clients "$LGSSD -v" || return 4
597 # wait daemons entering "stable" status
601 # check daemons are running
603 list=$(comma_list $(mdts_nodes) $(osts_nodes))
604 check_gss_daemon_nodes $list lsvcgssd || return 5
606 list=$(comma_list $(mdts_nodes))
607 check_gss_daemon_nodes $list lgssd || return 6
610 check_gss_daemon_nodes $clients lgssd || return 7
615 local list=$(comma_list $(mdts_nodes))
617 send_sigint $list lsvcgssd lgssd
619 list=$(comma_list $(osts_nodes))
620 send_sigint $list lsvcgssd
622 list=${CLIENTS:-`hostname`}
623 send_sigint $list lgssd
628 if ! module_loaded ptlrpc_gss; then
629 load_module ptlrpc/gss/ptlrpc_gss
630 module_loaded ptlrpc_gss ||
631 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
633 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
635 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
636 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
644 # maybe cleanup credential cache?
651 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9]\+//' |
652 tr '[:lower:]' '[:upper:]'
658 if [ $facet == mgs ]; then
662 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
670 if [ -n "${!var}" ]; then
675 var=$(facet_type $facet)FSTYPE
676 if [ -n "${!var}" ]; then
681 if [ -n "$FSTYPE" ]; then
693 local facets=$(get_facets)
696 for facet in ${facets//,/ }; do
697 if [ $node == $(facet_host $facet) ] ||
698 [ $node == "$(facet_failover_host $facet)" ]; then
699 fstype=$(facet_fstype $facet)
700 if [[ $fstypes != *$fstype* ]]; then
701 fstypes+="${fstypes:+,}$fstype"
712 local fstype=$(facet_fstype $facet)
716 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
718 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
719 ${dev} 2>/dev/null");;
721 error "unknown fstype!";;
729 local device=$(mdsdevname $num)
730 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
736 local device=$(ostdevname $num)
737 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
742 # This and set_obdfilter_param() shall be used to access OSD parameters
743 # once existed under "obdfilter":
748 # writethrough_cache_enable
750 get_obdfilter_param() {
752 local device=${2:-$FSNAME-OST*}
755 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
756 osd-*.$device.$name" 2>&1 | grep -v 'Found no match'
759 set_obdfilter_param() {
761 local device=${2:-$FSNAME-OST*}
765 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
766 osd-*.$device.$name=$value" 2>&1 | grep -v 'Found no match'
770 local dz=${1:-$DEBUG_SIZE}
772 if [ -f /sys/devices/system/cpu/possible ]; then
773 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
775 local cpus=$(getconf _NPROCESSORS_CONF)
778 # bug 19944, adjust size to be -gt num_possible_cpus()
779 # promise 2MB for every cpu at least
780 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
783 lctl set_param debug_mb=$dz
786 set_default_debug () {
787 local debug=${1:-"$PTLDEBUG"}
788 local subsys=${2:-"$SUBSYSTEM"}
789 local debug_size=${3:-$DEBUG_SIZE}
791 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
792 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
794 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
797 set_default_debug_nodes () {
800 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
801 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
805 [[ -n $nodes ]] && do_rpc_nodes $nodes set_default_debug \
806 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
809 set_default_debug_facet () {
811 local node=$(facet_active_host $facet)
812 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
814 set_default_debug_nodes $node
819 local facets=${1:-$(get_facets)}
822 for facet in ${facets//,/ }; do
825 [ $RC -eq 0 ] && continue
827 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
828 skip "Restart of $facet failed!." && touch $LU482_FAILED
830 error "Restart of $facet failed!"
837 # Add argument "arg" (e.g., "loop") to the comma-separated list
838 # of arguments for option "opt" (e.g., "-o") on command
839 # line "opts" (e.g., "-o flock").
845 local opt_pattern="\([[:space:]]\+\|^\)$opt"
847 if echo "$opts" | grep -q $opt_pattern; then
848 opts=$(echo "$opts" | sed -e \
849 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
851 opts+="${opts:+ }$opt $arg"
859 local dev=$(facet_active $facet)_dev
860 local opt=${facet}_opt
861 local mntpt=$(facet_mntpt $facet)
862 local opts="${!opt} $@"
864 if [ $(facet_fstype $facet) == ldiskfs ] &&
865 ! do_facet $facet test -b ${!dev}; then
866 opts=$(csa_add "$opts" -o loop)
869 echo "Starting ${facet}: $opts ${!dev} $mntpt"
870 # for testing LU-482 error handling in mount_facets() and test_0a()
871 if [ -f $TMP/test-lu482-trigger ]; then
874 do_facet ${facet} "mkdir -p $mntpt; mount -t lustre $opts \
878 if [ $RC -ne 0 ]; then
879 echo "Start of ${!dev} on ${facet} failed ${RC}"
881 set_default_debug_facet $facet
883 label=$(devicelabel ${facet} ${!dev})
884 [ -z "$label" ] && echo no label for ${!dev} && exit 1
885 eval export ${facet}_svc=${label}
886 echo Started ${label}
891 # start facet device options
897 eval export ${facet}_dev=${device}
898 eval export ${facet}_opt=\"$@\"
900 local varname=${facet}failover_dev
901 if [ -n "${!varname}" ] ; then
902 eval export ${facet}failover_dev=${!varname}
904 eval export ${facet}failover_dev=$device
907 local mntpt=$(facet_mntpt $facet)
908 do_facet ${facet} mkdir -p $mntpt
909 eval export ${facet}_MOUNT=$mntpt
916 # When a ZFS OSD is made read-only by replay_barrier(), its pool is "freezed".
917 # Because stopping corresponding target may not clear this in-memory state, we
918 # need to zap the pool from memory by exporting and reimporting the pool.
920 # Although the uberblocks are not updated when a pool is freezed, transactions
921 # are still written to the disks. Modified blocks may be cached in memory when
922 # tests try reading them back. The export-and-reimport process also evicts any
923 # cached pool data from memory to provide the correct "data loss" semantics.
927 local fstype=$(facet_fstype $facet)
932 if [ "${fstype}" == "zfs" ]; then
933 _dev=$(facet_active $facet)_dev
934 dev=${!_dev} # expand _dev to its value, e.g. ${mds1_dev}
935 poolname="${dev%%/*}" # poolname is string before "/"
937 if [ "${poolname}" == "" ]; then
938 echo "invalid dataset name: $dev"
941 do_facet $facet "cp /etc/zfs/zpool.cache /tmp/zpool.cache.back"
942 do_facet $facet "$ZPOOL export ${poolname}"
943 do_facet $facet "$ZPOOL import -f -c /tmp/zpool.cache.back \
952 local HOST=`facet_active_host $facet`
953 [ -z $HOST ] && echo stop: no host for $facet && return 0
955 local mntpt=$(facet_mntpt $facet)
956 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
957 if [ ${running} -ne 0 ]; then
958 echo "Stopping $mntpt (opts:$@) on $HOST"
959 do_facet ${facet} umount -d $@ $mntpt
962 # umount should block, but we should wait for unrelated obd's
963 # like the MGS or MGC to also stop.
964 wait_exit_ST ${facet}
967 # save quota version (both administrative and operational quotas)
968 # add an additional parameter if mountpoint is ever different from $MOUNT
969 quota_save_version() {
970 local fsname=${2:-$FSNAME}
972 local ver=$(tr -c -d "123" <<< $spec)
973 local type=$(tr -c -d "ug" <<< $spec)
975 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
977 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
979 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
981 local osts=$(get_facets OST)
982 for ost in ${osts//,/ }; do
984 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
988 # client could mount several lustre
990 local fsname=${1:-$FSNAME}
992 do_facet mgs lctl get_param mdd.${fsname}-MDT*.quota_type || rc=$?
993 do_nodes $(comma_list $(osts_nodes)) \
994 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
998 restore_quota_type () {
999 local mntpt=${1:-$MOUNT}
1000 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
1001 if [ ! "$old_QUOTA_TYPE" ] || [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
1004 quota_save_version $old_QUOTA_TYPE
1010 if [ "$USE_OFD" = "yes" ]; then
1011 $LFS quotacheck $mntpt || error "quotacheck failed"
1015 # We need save the original quota_type params, and restore them after testing
1017 # Suppose that quota type the same on mds and ost
1018 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
1019 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
1020 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
1021 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
1022 export old_QUOTA_TYPE=$quota_type
1023 quota_save_version $QUOTA_TYPE
1025 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
1026 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
1029 local quota_usrs=$QUOTA_USERS
1031 # get_filesystem_size
1032 local disksz=$(lfs df $mntpt | grep "filesystem summary:" | awk '{print $3}')
1033 local blk_soft=$((disksz + 1024))
1034 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1036 local Inodes=$(lfs df -i $mntpt | grep "filesystem summary:" | awk '{print $3}')
1037 local i_soft=$Inodes
1038 local i_hard=$((i_soft + i_soft / 20))
1040 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
1041 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
1044 for usr in $quota_usrs; do
1045 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1047 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1049 eval $cmd || error "$cmd FAILED!"
1051 # display the quota status
1052 echo "Quota settings for $usr : "
1053 $LFS quota -v -u $usr $mntpt || true
1060 local OPTIONS=${3:-$MOUNTOPT}
1062 local device=$MGSNID:/$FSNAME
1063 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1064 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
1068 echo "Starting client: $client: $OPTIONS $device $mnt"
1069 do_node $client mkdir -p $mnt
1070 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
1072 set_default_debug_nodes $client
1084 [ "$3" ] && force=-f
1085 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1086 if [ $running -ne 0 ]; then
1087 echo "Stopping client $client $mnt (opts:$force)"
1088 do_node $client lsof -t $mnt || need_kill=no
1089 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1090 pids=$(do_node $client lsof -t $mnt | sort -u);
1091 if [ -n $pids ]; then
1092 do_node $client kill -9 $pids || true
1096 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1097 if [ $busy -ne 0 ] ; then
1098 echo "$mnt is still busy, wait one second" && sleep 1
1099 do_node $client umount $force $mnt
1104 # nodes is comma list
1105 sanity_mount_check_nodes () {
1111 # FIXME: assume that all cluster nodes run the same os
1112 [ "$(uname)" = Linux ] || return 0
1115 for mnt in $mnts ; do
1116 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1117 mpts=\\\$(mount | grep -c $mnt' ');
1118 if [ \\\$running -ne \\\$mpts ]; then
1119 echo \\\$(hostname) env are INSANE!;
1122 [ $? -eq 0 ] || rc=1
1127 sanity_mount_check_servers () {
1128 [ "$CLIENTONLY" ] &&
1129 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1130 echo Checking servers environments
1132 # FIXME: modify get_facets to display all facets wo params
1133 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1137 for facet in ${facets//,/ }; do
1138 node=$(facet_host ${facet})
1139 mntpt=$(facet_mntpt $facet)
1140 sanity_mount_check_nodes $node $mntpt ||
1141 { error "server $node environments are insane!"; return 1; }
1145 sanity_mount_check_clients () {
1146 local clients=${1:-$CLIENTS}
1147 local mntpt=${2:-$MOUNT}
1148 local mntpt2=${3:-$MOUNT2}
1150 [ -z $clients ] && clients=$(hostname)
1151 echo Checking clients $clients environments
1153 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1154 error "clients environments are insane!"
1157 sanity_mount_check () {
1158 sanity_mount_check_servers || return 1
1159 sanity_mount_check_clients || return 2
1162 # mount clients if not mouted
1163 zconf_mount_clients() {
1166 local OPTIONS=${3:-$MOUNTOPT}
1168 local device=$MGSNID:/$FSNAME
1169 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1170 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
1174 echo "Starting client $clients: $OPTIONS $device $mnt"
1177 running=\\\$(mount | grep -c $mnt' ');
1179 if [ \\\$running -eq 0 ] ; then
1181 mount -t lustre $OPTIONS $device $mnt;
1184 exit \\\$rc" || return ${PIPESTATUS[0]}
1186 echo "Started clients $clients: "
1187 do_nodes $clients "mount | grep $mnt' '"
1189 set_default_debug_nodes $clients
1194 zconf_umount_clients() {
1199 [ "$3" ] && force=-f
1201 echo "Stopping clients: $clients $mnt (opts:$force)"
1202 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1203 if [ \\\$running -ne 0 ] ; then
1204 echo Stopping client \\\$(hostname) $mnt opts:$force;
1205 lsof $mnt || need_kill=no;
1206 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1207 pids=\\\$(lsof -t $mnt | sort -u);
1208 if [ -n \\\"\\\$pids\\\" ]; then
1212 while umount $force $mnt 2>&1 | grep -q "busy"; do
1213 echo "$mnt is still busy, wait one second" && sleep 1;
1220 echo + $POWER_DOWN $node
1224 shutdown_node_hard () {
1226 local attempts=$SHUTDOWN_ATTEMPTS
1228 for i in $(seq $attempts) ; do
1231 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1232 echo "waiting for $host to fail attempts=$attempts"
1233 [ $i -lt $attempts ] || \
1234 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1240 local mnt=${2:-$MOUNT}
1243 if [ "$FAILURE_MODE" = HARD ]; then
1244 shutdown_node_hard $client
1246 zconf_umount_clients $client $mnt -f
1252 local facets="$(get_facets OST),$(get_facets MDS)"
1255 combined_mgs_mds || facets="$facets,mgs"
1257 for facet in ${facets//,/ }; do
1258 if [ $(facet_active_host $facet) == $host ]; then
1259 affected="$affected $facet"
1263 echo $(comma_list $affected)
1268 local host=${2:-$(facet_host $facet)}
1270 local label=$(convert_facet2label $facet)
1271 do_node $host lctl dl | awk '{print $4}' | grep -q $label
1274 facets_up_on_host () {
1276 local facets=$(facets_on_host $host)
1279 for facet in ${facets//,/ }; do
1280 if $(facet_up $facet $host); then
1281 affected_up="$affected_up $facet"
1285 echo $(comma_list $affected_up)
1291 if [ "$FAILURE_MODE" = HARD ]; then
1292 shutdown_node_hard $(facet_active_host $facet)
1300 echo + $POWER_UP $node
1313 if [ "$FAILURE_MODE" = HARD ]; then
1314 reboot_node $(facet_active_host $facet)
1316 refresh_disk ${facet}
1323 if [ "$FAILURE_MODE" = HARD ]; then
1333 for facet in ${facets//,/ }; do
1334 hosts=$(expand_list $hosts $(facet_host $facet) )
1340 _check_progs_installed () {
1344 for prog in $progs; do
1345 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1346 echo $prog missing on $(hostname)
1353 check_progs_installed () {
1357 do_rpc_nodes $nodes _check_progs_installed $@
1360 # recovery-scale functions
1362 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1365 start_client_load() {
1368 local var=$(node_var_name $client)_load
1369 eval export ${var}=$load
1371 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1372 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1373 END_RUN_FILE=$END_RUN_FILE \
1374 LOAD_PID_FILE=$LOAD_PID_FILE \
1375 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1376 TESTNAME=$TESTNAME \
1377 DBENCH_LIB=$DBENCH_LIB \
1378 DBENCH_SRC=$DBENCH_SRC \
1381 log "Started client load: ${load} on $client"
1383 # get the children process IDs
1384 local pids=$(ps --ppid $ppid -o pid= | xargs)
1385 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1389 start_client_loads () {
1390 local -a clients=(${1//,/ })
1391 local numloads=${#CLIENT_LOADS[@]}
1394 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1395 testnum=$((nodenum % numloads))
1396 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1398 # bug 22169: wait the background threads to start
1402 # only for remote client
1403 check_client_load () {
1405 local var=$(node_var_name $client)_load
1406 local TESTLOAD=run_${!var}.sh
1408 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1410 # bug 18914: try to connect several times not only when
1411 # check ps, but while check_catastrophe also
1414 while [ $RC = 254 -a $tries -gt 0 ]; do
1418 if ! check_catastrophe $client; then
1420 if [ $RC -eq 254 ]; then
1421 # FIXME: not sure how long we shuold sleep here
1425 echo "check catastrophe failed: RC=$RC "
1429 # We can continue try to connect if RC=254
1430 # Just print the warning about this
1431 if [ $RC = 254 ]; then
1432 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1435 # see if the load is still on the client
1438 while [ $RC = 254 -a $tries -gt 0 ]; do
1442 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1447 if [ $RC = 254 ]; then
1448 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1449 # see if we can diagnose a bit why this is
1454 check_client_loads () {
1455 local clients=${1//,/ }
1459 for client in $clients; do
1460 check_client_load $client
1462 if [ "$rc" != 0 ]; then
1463 log "Client load failed on node $client, rc=$rc"
1469 restart_client_loads () {
1470 local clients=${1//,/ }
1471 local expectedfail=${2:-""}
1475 for client in $clients; do
1476 check_client_load $client
1478 if [ "$rc" != 0 -a "$expectedfail" ]; then
1479 local var=$(node_var_name $client)_load
1480 start_client_load $client ${!var}
1481 echo "Restarted client load ${!var}: on $client. Checking ..."
1482 check_client_load $client
1484 if [ "$rc" != 0 ]; then
1485 log "Client load failed to restart on node $client, rc=$rc"
1486 # failure one client load means test fail
1487 # we do not need to check other
1496 # Start vmstat and save its process ID in a file.
1501 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1504 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1505 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1508 # Display the nodes on which client loads failed.
1509 print_end_run_file() {
1513 [ -s $file ] || return 0
1515 echo "Found the END_RUN_FILE file: $file"
1518 # A client load will stop if it finds the END_RUN_FILE file.
1519 # That does not mean the client load actually failed though.
1520 # The first node in END_RUN_FILE is the one we are interested in.
1523 if [ -n "$node" ]; then
1524 local var=$(node_var_name $node)_load
1526 local prefix=$TESTLOG_PREFIX
1527 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
1528 local stdout_log=$prefix.run_${!var}_stdout.$node.log
1529 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
1531 echo "Client load ${!var} failed on node $node:"
1537 # Stop the process which had its PID saved in a file.
1542 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1544 do_nodes $nodes "test -f $pid_file &&
1545 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
1548 # Stop all client loads.
1549 stop_client_loads() {
1550 local nodes=${1:-$CLIENTS}
1553 # stop the client loads
1554 stop_process $nodes $pid_file
1556 # clean up the processes that started them
1557 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
1559 # End recovery-scale functions
1561 # verify that lustre actually cleaned up properly
1563 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
1564 error "LBUG/LASSERT detected"
1565 BUSY=`dmesg | grep -i destruct || true`
1566 if [ "$BUSY" ]; then
1568 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
1572 check_mem_leak || exit 204
1574 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
1575 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
1577 if module_loaded lnet || module_loaded libcfs; then
1578 echo "$0: modules still loaded..." 1>&2
1596 RESULT=$(do_node $node "$TEST")
1597 if [ "$RESULT" == "$FINAL" ]; then
1598 [ -z "$RESULT" -o $WAIT -le $sleep ] ||
1599 echo "Updated after ${WAIT}s: wanted '$FINAL' got '$RESULT'"
1602 [ $WAIT -ge $MAX ] && break
1603 [ $((WAIT % print)) -eq 0 ] &&
1604 echo "Waiting $((MAX - WAIT)) secs for update"
1605 WAIT=$((WAIT + sleep))
1608 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
1612 wait_update_facet () {
1614 wait_update $(facet_active_host $facet) "$@"
1618 do_node $(osts_nodes) "lctl set_param -n osd*.*OS*.force_sync 1" 2>&1 |
1619 grep -v 'Found no match'
1622 wait_delete_completed () {
1623 local TOTALPREV=`lctl get_param -n osc.*.kbytesavail | \
1624 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1628 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
1630 TOTAL=`lctl get_param -n osc.*.kbytesavail | \
1631 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1632 [ "$TOTAL" -eq "$TOTALPREV" ] && return 0
1633 echo "Waiting delete completed ... prev: $TOTALPREV current: $TOTAL "
1637 echo "Delete is not completed in $MAX_WAIT sec"
1644 # we can use "for" here because we are waiting the slowest
1645 for host in ${hostlist//,/ }; do
1646 check_network "$host" 900
1648 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
1655 for facet in ${facetlist//,/ }; do
1656 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
1658 wait_for_host $hostlist
1661 _wait_recovery_complete () {
1664 # Use default policy if $2 is not passed by caller.
1665 local MAX=${2:-$(max_recovery_time)}
1670 while [ $WAIT -lt $MAX ]; do
1671 STATUS=$(lctl get_param -n $param | grep status)
1673 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
1676 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
1678 echo "$param recovery not done in $MAX sec. $STATUS"
1682 wait_recovery_complete () {
1685 # with an assumption that at_max is the same on all nodes
1686 local MAX=${2:-$(max_recovery_time)}
1689 if [ "$FAILURE_MODE" = HARD ]; then
1690 facets=$(facets_on_host $(facet_active_host $facet))
1692 echo affected facets: $facets
1694 # we can use "for" here because we are waiting the slowest
1695 for facet in ${facets//,/ }; do
1696 local var_svc=${facet}_svc
1697 local param="*.${!var_svc}.recovery_status"
1699 local host=$(facet_active_host $facet)
1700 do_rpc_nodes $host _wait_recovery_complete $param $MAX
1704 wait_mds_ost_sync () {
1705 # just because recovery is done doesn't mean we've finished
1706 # orphan cleanup. Wait for llogs to get synchronized.
1707 echo "Waiting for orphan cleanup..."
1708 # MAX value includes time needed for MDS-OST reconnection
1709 local MAX=$(( TIMEOUT * 2 ))
1711 while [ $WAIT -lt $MAX ]; do
1712 local -a sync=($(do_nodes $(comma_list $(osts_nodes)) \
1713 "$LCTL get_param -n obdfilter.*.mds_sync"))
1716 for ((i=0; i<${#sync[@]}; i++)); do
1717 [ ${sync[$i]} -eq 0 ] && continue
1718 # there is a not finished MDS-OST synchronization
1722 sleep 2 # increase waiting time and cover statfs cache
1723 [ ${con} -eq 1 ] && return 0
1724 echo "Waiting $WAIT secs for $facet mds-ost sync done."
1727 echo "$facet recovery not done in $MAX sec. $STATUS"
1731 wait_destroy_complete () {
1732 echo "Waiting for destroy to be done..."
1733 # MAX value shouldn't be big as this mean server responsiveness
1734 # never increase this just to make test pass but investigate
1735 # why it takes so long time
1738 while [ $WAIT -lt $MAX ]; do
1739 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
1741 for ((i=0; i<${#RPCs[@]}; i++)); do
1742 [ ${RPCs[$i]} -eq 0 ] && continue
1743 # there are still some destroy RPCs in flight
1748 [ ${con} -eq 1 ] && return 0 # done waiting
1749 echo "Waiting $WAIT secs for destroys to be done."
1752 echo "Destroys weren't done in $MAX sec."
1762 # conf-sanity 31 takes a long time cleanup
1763 while [ $WAIT -lt 300 ]; do
1764 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
1765 [ -z "${running}" ] && return 0
1766 echo "waited $WAIT for${running}"
1767 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
1769 WAIT=$((WAIT + INTERVAL))
1771 echo "service didn't stop after $WAIT seconds. Still running:"
1776 wait_remote_prog () {
1782 [ "$PDSH" = "no_dsh" ] && return 0
1784 while [ $WAIT -lt $2 ]; do
1785 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
1786 [ -z "${running}" ] && return 0 || true
1787 echo "waited $WAIT for: "
1789 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
1791 WAIT=$((WAIT + INTERVAL))
1793 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
1794 [ -z "$pids" ] && return 0
1795 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
1796 # FIXME: not portable
1797 for pid in $pids; do
1798 cat /proc/${pid}/status || true
1799 cat /proc/${pid}/wchan || true
1801 kill -9 $pid || true
1810 # not every config has many clients
1812 if [ ! -z "$CLIENTS" ]; then
1813 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
1815 stat -f $MOUNT > /dev/null
1821 # usually checked on particular client or locally
1823 if [ ! -z "$client" ]; then
1824 $PDSH $client "stat -f $MOUNT" > /dev/null
1826 stat -f $MOUNT > /dev/null
1834 client_reconnect() {
1835 uname -n >> $MOUNT/recon
1836 if [ -z "$CLIENTS" ]; then
1837 df $MOUNT; uname -n >> $MOUNT/recon
1839 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
1841 echo Connected clients:
1843 ls -l $MOUNT/recon > /dev/null
1847 affected_facets () {
1850 local host=$(facet_active_host $facet)
1851 local affected=$facet
1853 if [ "$FAILURE_MODE" = HARD ]; then
1854 affected=$(facets_up_on_host $host)
1862 local host=$(facet_active_host $facet)
1864 echo "Failing $facet on node $host"
1866 local affected=$(affected_facets $facet)
1868 shutdown_facet $facet
1870 echo affected facets: $affected
1872 [ -n "$sleep_time" ] && sleep $sleep_time
1876 change_active $affected
1878 wait_for_facet $affected
1879 # start mgs first if it is affected
1880 if ! combined_mgs_mds && list_member $affected mgs; then
1881 mount_facet mgs || error "Restart of mgs failed"
1883 # FIXME; has to be changed to mount all facets concurrently
1884 affected=$(exclude_items_from_list $affected mgs)
1885 mount_facets $affected
1894 do_facet $facet "sync; sync; sync"
1897 # make sure there will be no seq change
1898 local clients=${CLIENTS:-$HOSTNAME}
1899 do_nodes $clients "f=${MOUNT}/fsa-\\\$(hostname); mcreate \\\$f; rm \\\$f"
1901 local svc=${facet}_svc
1902 do_facet $facet $LCTL --device %${!svc} notransno
1903 do_facet $facet $LCTL --device %${!svc} readonly
1904 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1905 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1908 replay_barrier_nodf() {
1909 local facet=$1 echo running=${running}
1910 do_facet $facet "sync; sync; sync"
1911 local svc=${facet}_svc
1912 echo Replay barrier on ${!svc}
1913 do_facet $facet $LCTL --device %${!svc} notransno
1914 do_facet $facet $LCTL --device %${!svc} readonly
1915 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1916 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1919 replay_barrier_nosync() {
1920 local facet=$1 echo running=${running}
1921 local svc=${facet}_svc
1922 echo Replay barrier on ${!svc}
1923 do_facet $facet $LCTL --device %${!svc} notransno
1924 do_facet $facet $LCTL --device %${!svc} readonly
1925 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1926 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1929 mds_evict_client() {
1930 UUID=`lctl get_param -n mdc.${mds1_svc}-mdc-*.uuid`
1931 do_facet mds1 "lctl set_param -n mdt.${mds1_svc}.evict_client $UUID"
1934 ost_evict_client() {
1935 UUID=`lctl get_param -n devices| grep ${ost1_svc}-osc- | egrep -v 'MDT' | awk '{print $5}'`
1936 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
1940 facet_failover $* || error "failover: $?"
1941 clients_up || error "post-failover df: $?"
1946 facet_failover $facet
1952 refresh_disk ${facet}
1953 change_active $facet
1954 wait_for_facet $facet
1955 mount_facet $facet -o abort_recovery
1956 clients_up || echo "first df failed: $?"
1957 clients_up || error "post-failover df: $?"
1961 echo There is no lmc. This is mountconf, baby.
1965 host_nids_address() {
1969 if [ -n "$kind" ]; then
1970 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
1972 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
1978 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1984 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1985 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
1986 if [ -z "$ID" ]; then
1987 echo "Could not get a ptl id for $1..."
1996 h2name_or_ip "$1" "tcp"
2001 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
2002 if type __h2elan >/dev/null 2>&1; then
2005 ID=`echo $1 | sed 's/[^0-9]*//g'`
2013 h2name_or_ip "$1" "o2ib"
2017 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2018 # expressions format. As a bonus we can then just pass in those variables
2019 # to pdsh. What this function does is take a HOSTLIST type string and
2020 # expand it into a space deliminated list for us.
2028 [ -z "$hostlist" ] && return
2030 # Translate the case of [..],..,[..] to [..] .. [..]
2031 list="${hostlist/],/] }"
2033 [[ "$front" == *,* ]] && {
2036 list=${list/${old}/${new}}
2039 for item in $list; do
2040 # Test if we have any []'s at all
2041 if [ "$item" != "${item/\[/}" ]; then {
2042 # Expand the [*] into list
2046 if [ "$name" != "$item" ]; then
2047 group=${item#$name[*}
2050 for range in ${group//,/ }; do
2054 # Number of leading zeros
2057 end=$(echo $end | sed 's/0*//')
2058 [[ -z "$end" ]] && end=0
2059 [[ $padlen2 -gt $padlen ]] && {
2060 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2063 begin=$(echo $begin | sed 's/0*//')
2064 [ -z $begin ] && begin=0
2066 for num in $(seq -f "%0${padlen}g" $begin $end); do
2067 value="${name#*,}${num}${back}"
2068 [ "$value" != "${value/\[/}" ] && {
2069 value=$(hostlist_expand "$value")
2071 myList="$myList $value"
2076 myList="$myList $item"
2079 myList=${myList//,/ }
2080 myList=${myList:1} # Remove first character which is a space
2082 # Filter any duplicates without sorting
2084 myList="${list%% *}"
2086 while [[ "$list" != ${myList##* } ]]; do
2087 list=${list//${list%% *} /}
2088 myList="$myList ${list%% *}"
2090 myList="${myList%* }";
2092 # We can select an object at a offset in the list
2095 for item in $myList; do
2097 [ $cnt -eq $offset ] && {
2101 [ $(get_node_count $myList) -ne 1 ] && myList=""
2109 [ "$facet" == client ] && echo -n $HOSTNAME && return
2110 varname=${facet}_HOST
2111 if [ -z "${!varname}" ]; then
2112 if [ "${facet:0:3}" == "ost" ]; then
2113 eval ${facet}_HOST=${ost_HOST}
2119 facet_failover_host() {
2123 var=${facet}failover_HOST
2124 if [ -n "${!var}" ]; then
2129 if [[ $facet == ost* ]]; then
2130 var=ostfailover_HOST
2131 if [ -n "${!var}" ]; then
2140 local activevar=${facet}active
2142 if [ -f $TMP/${facet}active ] ; then
2143 source $TMP/${facet}active
2146 active=${!activevar}
2147 if [ -z "$active" ] ; then
2154 facet_active_host() {
2156 local active=`facet_active $facet`
2157 if [ "$facet" == client ]; then
2160 echo `facet_host $active`
2168 facetlist=$(exclude_items_from_list $facetlist mgs)
2170 for facet in ${facetlist//,/ }; do
2171 local failover=${facet}failover
2172 local host=`facet_host $failover`
2173 [ -z "$host" ] && return
2175 local curactive=`facet_active $facet`
2176 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2177 eval export ${facet}active=$facet
2179 eval export ${facet}active=$failover
2181 # save the active host for this facet
2182 local activevar=${facet}active
2183 echo "$activevar=${!activevar}" > $TMP/$activevar
2184 [[ $facet = mds1 ]] && combined_mgs_mds && \
2185 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2186 local TO=`facet_active_host $facet`
2187 echo "Failover $facet to $TO"
2193 # do not stripe off hostname if verbose, bug 19215
2194 if [ x$1 = x--verbose ]; then
2202 if [ "$HOST" = "$HOSTNAME" ]; then
2204 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2205 echo "cannot run remote command on $HOST with $myPDSH"
2209 echo "CMD: $HOST $@" >&2
2210 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2213 if [ "$myPDSH" = "rsh" ]; then
2214 # we need this because rsh does not return exit code of an executed command
2215 local command_status="$TMP/cs"
2216 rsh $HOST ":> $command_status"
2217 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2218 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2219 echo command failed >$command_status"
2220 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2225 # print HOSTNAME for myPDSH="no_dsh"
2226 if [[ $myPDSH = no_dsh ]]; then
2227 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2229 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2232 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2234 return ${PIPESTATUS[0]}
2238 do_node --verbose "$@"
2241 single_local_node () {
2242 [ "$1" = "$HOSTNAME" ]
2245 # Outputs environment variable assignments that should be passed to remote nodes
2250 for var in ${!MODOPTS_*}; do
2252 echo -n " ${var}=\"$value\""
2255 echo -n " USE_OFD=$USE_OFD"
2260 # do not stripe off hostname if verbose, bug 19215
2261 if [ x$1 = x--verbose ]; then
2269 if single_local_node $rnodes; then
2271 do_nodev $rnodes "$@"
2273 do_node $rnodes "$@"
2278 # This is part from do_node
2281 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2282 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2284 export FANOUT=$(get_node_count "${rnodes//,/ }")
2286 echo "CMD: $rnodes $@" >&2
2287 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2290 # do not replace anything from pdsh output if -N is used
2291 # -N Disable hostname: prefix on lines of output.
2292 if $verbose || [[ $myPDSH = *-N* ]]; then
2293 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2295 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2297 return ${PIPESTATUS[0]}
2303 local HOST=`facet_active_host $facet`
2304 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
2309 do_nodes --verbose "$@"
2315 # make sure its not already running
2317 rm -f $TMP/${facet}active
2318 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
2319 do_facet ${facet} $MKFS $*
2326 local fstype=$(facet_fstype ost$num)
2330 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2331 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2333 #dataset name is independent of vdev device names
2334 eval DEVPTR=${FSNAME}-ost${num}/ost${num};;
2336 error "unknown fstype!";;
2346 local fstype=$(facet_fstype ost$num)
2350 # vdevs are not supported by ldiskfs
2353 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2354 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2356 error "unknown fstype!";;
2366 local fstype=$(facet_fstype mds$num)
2370 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
2371 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
2373 #dataset name is independent of vdev device names
2374 eval DEVPTR=${FSNAME}-mdt${num}/mdt${num};;
2376 error "unknown fstype!";;
2386 local fstype=$(facet_fstype mds$num)
2390 # vdevs are not supported by ldiskfs
2393 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
2394 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
2396 error "unknown fstype!";;
2405 local fstype=$(facet_fstype mds$num)
2409 #if $MGSDEV isn't defined, default is $MDSDEV1
2410 eval DEVPTR=${!DEVNAME:=${MDSDEV1}};;
2412 #dataset name is independent of vdev device names
2413 eval DEVPTR=${FSNAME}-mgs/mgs;;
2415 error "unknown fstype!";;
2424 local fstype=$(facet_fstype mds$num)
2428 # vdevs are not supported by ldiskfs
2431 #if $MGSDEV isn't defined, default is $MGSDEV1
2432 eval VDEVPTR=${!DEVNAME:=${MDSDEV1}};;
2434 error "unknown fstype!";;
2442 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
2444 local var=${facet}_MOUNT
2445 eval mntpt=${!var:-${MOUNT%/*}/$facet}
2454 # make sure we are using the primary server, so test-framework will
2455 # be able to clean up properly.
2456 activemds=`facet_active mds1`
2457 if [ $activemds != "mds1" ]; then
2461 local clients=$CLIENTS
2462 [ -z $clients ] && clients=$(hostname)
2464 zconf_umount_clients $clients $MOUNT "$*" || true
2465 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
2467 [ "$CLIENTONLY" ] && return
2468 # The add fn does rm ${facet}active file, this would be enough
2469 # if we use do_facet <facet> only after the facet added, but
2470 # currently we use do_facet mds in local.sh
2471 for num in `seq $MDSCOUNT`; do
2473 rm -f ${TMP}/mds${num}active
2475 combined_mgs_mds && rm -f $TMP/mgsactive
2477 for num in `seq $OSTCOUNT`; do
2479 rm -f $TMP/ost${num}active
2482 if ! combined_mgs_mds ; then
2489 cleanup_echo_devs () {
2490 local devs=$($LCTL dl | grep echo | awk '{print $4}')
2492 for dev in $devs; do
2493 $LCTL --device $dev cleanup
2494 $LCTL --device $dev detach
2499 nfs_client_mode && return
2508 combined_mgs_mds () {
2509 [[ $MDSDEV1 = $MGSDEV ]] && [[ $mds1_HOST = $mgs_HOST ]]
2513 echo -n "$1" | tr '[:upper:]' '[:lower:]'
2517 echo -n "$1" | tr '[:lower:]' '[:upper:]'
2522 local type=$(facet_type $facet)
2523 local index=$(($(facet_number $facet) - 1))
2524 local fstype=$(facet_fstype $facet)
2529 if [ $type == MGS ] && combined_mgs_mds; then
2533 if [ $type == MGS ] || ( [ $type == MDS ] && combined_mgs_mds ); then
2536 opts="--mgsnode=$MGSNID"
2539 if [ $type != MGS ]; then
2540 opts+=" --fsname=$FSNAME --$(lower ${type/MDS/MDT}) --index=$index"
2543 var=${facet}failover_HOST
2544 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
2545 opts+=" --failnode=$(h2$NETTYPE ${!var})"
2548 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
2549 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
2551 if [ $type == MDS ]; then
2552 opts+=${SECLEVEL:+" --param=mdt.sec_level"}
2553 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
2554 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
2555 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
2556 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
2558 if [ $fstype == ldiskfs ]; then
2559 opts+=${IAMDIR:+" --iam-dir"}
2561 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
2562 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
2566 if [ $type == OST ]; then
2567 opts+=${SECLEVEL:+" --param=ost.sec_level"}
2568 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
2570 if [ $fstype == ldiskfs ]; then
2571 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
2575 opts+=" --backfstype=$fstype"
2578 if [ -n "${!var}" ]; then
2579 opts+=" --device-size=${!var}"
2582 var=$(upper $fstype)_MKFS_OPTS
2583 fs_mkfs_opts+=${!var:+" ${!var}"}
2585 var=${type}_FS_MKFS_OPTS
2586 fs_mkfs_opts+=${!var:+" ${!var}"}
2588 if [ -n "${fs_mkfs_opts## }" ]; then
2589 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
2593 opts+=${!var:+" ${!var}"}
2606 # We need ldiskfs here, may as well load them all
2608 [ "$CLIENTONLY" ] && return
2609 echo Formatting mgs, mds, osts
2610 if ! combined_mgs_mds ; then
2611 echo "Format mgs: $(mgsdevname)"
2612 add mgs $(mkfs_opts mgs) --reformat $(mgsdevname) \
2613 $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
2616 for num in `seq $MDSCOUNT`; do
2617 echo "Format mds$num: $(mdsdevname $num)"
2618 add mds$num $(mkfs_opts mds$num) --reformat \
2619 $(mdsdevname $num) $(mdsvdevname $num) \
2620 ${quiet:+>/dev/null} || exit 10
2623 for num in `seq $OSTCOUNT`; do
2624 echo "Format ost$num: $(ostdevname $num)"
2625 add ost$num $(mkfs_opts ost$num) --reformat \
2626 $(ostdevname $num) $(ostvdevname ${num}) \
2627 ${quiet:+>/dev/null} || exit 10
2632 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
2636 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
2640 # 0: success, the old identity set already.
2641 # 1: success, the old identity does not set.
2646 local j=`expr $num - 1`
2647 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
2649 if [ -z "$MDT" ]; then
2653 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
2656 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
2658 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
2661 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
2663 if [ $old = "NONE" ]; then
2672 zconf_umount `hostname` $1 || error "umount failed"
2673 zconf_mount `hostname` $1 || error "mount failed"
2676 writeconf_facet () {
2680 do_facet $facet "$TUNEFS --writeconf $dev"
2684 for num in `seq $MDSCOUNT`; do
2685 DEVNAME=$(mdsdevname $num)
2686 writeconf_facet mds$num $DEVNAME
2689 for num in `seq $OSTCOUNT`; do
2690 DEVNAME=$(ostdevname $num)
2691 writeconf_facet ost$num $DEVNAME
2696 nfs_client_mode && return
2698 sanity_mount_check ||
2699 error "environments are insane!"
2703 if [ -z "$CLIENTONLY" ]; then
2704 echo Setup mgs, mdt, osts
2705 echo $WRITECONF | grep -q "writeconf" && \
2707 if ! combined_mgs_mds ; then
2708 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
2711 for num in `seq $MDSCOUNT`; do
2712 DEVNAME=$(mdsdevname $num)
2713 start mds$num $DEVNAME $MDS_MOUNT_OPTS
2715 # We started mds, now we should set failover variables properly.
2716 # Set mds${num}failover_HOST if it is not set (the default failnode).
2717 local varname=mds${num}failover_HOST
2718 if [ -z "${!varname}" ]; then
2719 eval mds${num}failover_HOST=$(facet_host mds$num)
2722 if [ $IDENTITY_UPCALL != "default" ]; then
2723 switch_identity $num $IDENTITY_UPCALL
2726 for num in `seq $OSTCOUNT`; do
2727 DEVNAME=$(ostdevname $num)
2728 start ost$num $DEVNAME $OST_MOUNT_OPTS
2730 # We started ost$num, now we should set ost${num}failover variable properly.
2731 # Set ost${num}failover_HOST if it is not set (the default failnode).
2732 varname=ost${num}failover_HOST
2733 if [ -z "${!varname}" ]; then
2734 eval ost${num}failover_HOST=$(facet_host ost${num})
2742 # wait a while to allow sptlrpc configuration be propogated to targets,
2743 # only needed when mounting new target devices.
2748 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
2750 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
2753 if [ "$MOUNT_2" ]; then
2754 mount_client $MOUNT2
2755 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
2760 # by remounting mdt before ost, initial connect from mdt to ost might
2761 # timeout because ost is not ready yet. wait some time to its fully
2762 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
2763 # by a context negotiation rpc with $TIMEOUT.
2764 # FIXME better by monitoring import status.
2767 sleep $((TIMEOUT + 5))
2773 mounted_lustre_filesystems() {
2774 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
2777 init_facet_vars () {
2778 [ "$CLIENTONLY" ] && return 0
2785 eval export ${facet}_dev=${device}
2786 eval export ${facet}_opt=\"$@\"
2788 local dev=${facet}_dev
2789 local label=$(devicelabel ${facet} ${!dev})
2790 [ -z "$label" ] && echo no label for ${!dev} && exit 1
2792 eval export ${facet}_svc=${label}
2794 local varname=${facet}failover_HOST
2795 if [ -z "${!varname}" ]; then
2796 eval $varname=$(facet_host $facet)
2799 # ${facet}failover_dev is set in cfg file
2800 varname=${facet}failover_dev
2801 if [ -n "${!varname}" ] ; then
2802 eval export ${facet}failover_dev=${!varname}
2804 eval export ${facet}failover_dev=$device
2807 # get mount point of already mounted device
2808 # is facet_dev is already mounted then use the real
2809 # mount point of this facet; otherwise use $(facet_mntpt $facet)
2810 # i.e. ${facet}_MOUNT if specified by user or default
2811 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
2812 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
2813 if [ -z $mntpt ]; then
2814 mntpt=$(facet_mntpt $facet)
2816 eval export ${facet}_MOUNT=$mntpt
2819 init_facets_vars () {
2822 if ! remote_mds_nodsh; then
2823 for num in `seq $MDSCOUNT`; do
2824 DEVNAME=`mdsdevname $num`
2825 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
2829 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
2831 remote_ost_nodsh && return
2833 for num in `seq $OSTCOUNT`; do
2834 DEVNAME=`ostdevname $num`
2835 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
2839 osc_ensure_active () {
2844 while [ $period -lt $timeout ]; do
2845 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
2846 if [ $count -eq 0 ]; then
2850 echo "There are $count OST are inactive, wait $period seconds, and try again"
2852 period=$((period+3))
2855 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
2858 init_param_vars () {
2860 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2862 log "Using TIMEOUT=$TIMEOUT"
2864 osc_ensure_active $SINGLEMDS $TIMEOUT
2865 osc_ensure_active client $TIMEOUT
2867 if [ $QUOTA_AUTO -ne 0 ]; then
2868 if [ "$ENABLE_QUOTA" ]; then
2869 echo "enable quota as required"
2870 setup_quota $MOUNT || return 2
2872 echo "disable quota as required"
2873 $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
2880 nfs_client_mode () {
2881 if [ "$NFSCLIENT" ]; then
2882 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
2883 local clients=$CLIENTS
2884 [ -z $clients ] && clients=$(hostname)
2886 # FIXME: remove hostname when 19215 fixed
2887 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
2888 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
2889 if [[ ${#nfsexport[@]} -eq 0 ]]; then
2890 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
2892 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
2898 check_config_client () {
2901 local mounted=$(mount | grep " $mntpt ")
2902 if [ "$CLIENTONLY" ]; then
2904 # CLIENTONLY should not depend on *_HOST settings
2905 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
2906 # in theory someone could create a new,
2907 # client-only config file that assumed lustre was already
2908 # configured and didn't set the MGSNID. If MGSNID is not set,
2909 # then we should use the mgs nid currently being used
2910 # as the default value. bug 18021
2911 [[ x$MGSNID = x ]] &&
2914 if [[ x$mgc != xMGC$MGSNID ]]; then
2915 if [ "$mgs_HOST" ]; then
2916 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
2917 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
2918 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
2924 local myMGS_host=$mgs_HOST
2925 if [ "$NETTYPE" = "ptl" ]; then
2926 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
2929 echo Checking config lustre mounted on $mntpt
2930 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
2931 mgshost=$(echo $mgshost | awk -F: '{print $1}')
2933 # if [ "$mgshost" != "$myMGS_host" ]; then
2934 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
2935 # Please use correct config or set mds_HOST correctly!"
2940 check_config_clients () {
2941 local clients=${CLIENTS:-$HOSTNAME}
2944 nfs_client_mode && return
2946 do_rpc_nodes $clients check_config_client $mntpt
2948 sanity_mount_check ||
2949 error "environments are insane!"
2953 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2954 local cltimeout=$(lctl get_param -n timeout)
2955 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
2956 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
2963 [ -z $mntpt ] && return 1
2964 local mounted=$(mounted_lustre_filesystems)
2966 echo $mounted' ' | grep -w -q $mntpt' '
2970 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
2974 # empty lustre filesystem may have empty directories lost+found and .lustre
2976 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
2977 -print | wc -l) = 1 ] || return 1
2978 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found && return 0
2979 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre && return 0
2983 check_and_setup_lustre() {
2984 nfs_client_mode && return
2986 local MOUNTED=$(mounted_lustre_filesystems)
2990 # both MOUNT and MOUNT2 are not mounted
2991 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
2992 [ "$REFORMAT" ] && formatall
2993 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
2995 is_mounted $MOUNT || error "NAME=$NAME not mounted"
2996 export I_MOUNTED=yes
3000 elif is_mounted $MOUNT2; then
3002 # MOUNT2 is mounted, while MOUNT_2 is not set
3003 if ! [ "$MOUNT_2" ]; then
3004 cleanup_mount $MOUNT2
3005 export I_UMOUNTED2=yes
3008 # MOUNT2 is mounted, MOUNT_2 is set
3010 # FIXME: what to do if check_config failed?
3012 # 1) remote client has mounted other Lustre fs ?
3013 # 2) it has insane env ?
3014 # let's try umount MOUNT2 on all clients and mount it again:
3015 if ! check_config_clients $MOUNT2; then
3016 cleanup_mount $MOUNT2
3017 restore_mount $MOUNT2
3018 export I_MOUNTED2=yes
3023 # MOUNT is mounted MOUNT2 is not mounted
3024 elif [ "$MOUNT_2" ]; then
3025 restore_mount $MOUNT2
3026 export I_MOUNTED2=yes
3030 # FIXME: what to do if check_config failed?
3032 # 1) remote client has mounted other Lustre fs?
3033 # 2) lustre is mounted on remote_clients atall ?
3034 check_config_clients $MOUNT
3038 set_default_debug_nodes $(comma_list $(nodes_list))
3046 if [ "$ONLY" == "setup" ]; then
3052 local clients=${CLIENTS:-$HOSTNAME}
3055 zconf_mount_clients $clients $mntpt
3059 local clients=${CLIENTS:-$HOSTNAME}
3062 zconf_umount_clients $clients $mntpt
3065 cleanup_and_setup_lustre() {
3066 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
3067 lctl set_param debug=0 || true
3069 if [ "$ONLY" == "cleanup" ]; then
3073 check_and_setup_lustre
3076 # Get all of the server target devices from a given server node and type.
3083 if [ "$type" == ost ]; then
3084 devs=$(get_obdfilter_param $node "" mntdev)
3086 devs=$(do_node $node \
3087 "lctl get_param -n osd-*.$FSNAME-M*.mntdev")
3089 for dev in $devs; do
3091 *loop*) do_node $node "losetup $dev" | \
3092 sed -e "s/.*(//" -e "s/).*//" ;;
3098 # Get all of the server target devices.
3103 MDTDEV=$(get_mnt_devs $(mdts_nodes) mdt)
3107 for node in $(osts_nodes); do
3108 OSTDEVS[i]=$(get_mnt_devs $node ost)
3113 # Run e2fsck on MDT or OST device.
3119 df > /dev/null # update statfs data on disk
3120 local cmd="$E2FSCK -d -v -t -t -f -n $extra_opts $target_dev"
3123 do_node $node $cmd || rc=$?
3124 [ $rc -le $FSCK_MAX_ERR ] || \
3125 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
3129 # verify a directory is shared among nodes.
3130 check_shared_dir() {
3133 [ -z "$dir" ] && return 1
3134 do_rpc_nodes $(comma_list $(nodes_list)) check_logdir $dir
3135 check_write_access $dir || return 1
3139 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
3145 check_shared_dir $SHARED_DIRECTORY ||
3146 error "$SHARED_DIRECTORY isn't a shared directory"
3148 export MDSDB=$SHARED_DIRECTORY/mdsdb
3149 export OSTDB=$SHARED_DIRECTORY/ostdb
3151 [ $MDSCOUNT -eq 1 ] || error "CMD is not supported"
3153 run_e2fsck $(mdts_nodes) $MDTDEV "--mdsdb $MDSDB"
3158 for node in $(osts_nodes); do
3159 for dev in ${OSTDEVS[i]}; do
3160 run_e2fsck $node $dev "--mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
3161 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
3162 ostidx=$((ostidx + 1))
3169 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
3173 [ $rc -le $FSCK_MAX_ERR ] || \
3174 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
3175 echo "lfsck finished with rc=$rc"
3177 rm -rvf $MDSDB* $OSTDB* || true
3181 check_and_cleanup_lustre() {
3182 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
3188 if is_mounted $MOUNT; then
3189 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
3190 error "remove sub-test dirs failed"
3191 [ "$ENABLE_QUOTA" ] && restore_quota_type || true
3194 if [ "$I_UMOUNTED2" = "yes" ]; then
3195 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
3198 if [ "$I_MOUNTED2" = "yes" ]; then
3199 cleanup_mount $MOUNT2
3202 if [ "$I_MOUNTED" = "yes" ]; then
3203 cleanupall -f || error "cleanup failed"
3211 wait_for_function () {
3214 # suppress fn both stderr and stdout
3215 if [ "$1" = "--quiet" ]; then
3217 quiet=" > /dev/null 2>&1"
3229 eval $fn $quiet && return 0
3231 wait=$((wait + sleep))
3232 [ $wait -lt $max ] || return 1
3233 echo waiting $fn, $((max - wait)) secs left ...
3243 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
3244 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
3245 echo "Network not available!"
3249 echo `date +"%H:%M:%S (%s)"` network interface is UP
3258 # the sed converts spaces to commas, but leaves the last space
3259 # alone, so the line doesn't end with a comma.
3260 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
3266 echo $list | grep -qw $item
3269 # list, excluded are the comma separated lists
3270 exclude_items_from_list () {
3276 for item in ${excluded//,/ }; do
3277 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
3279 echo $(comma_list $list)
3282 # list, expand are the comma separated lists
3284 local list=${1//,/ }
3285 local expand=${2//,/ }
3288 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
3289 echo $(comma_list $expanded)
3292 testslist_filter () {
3293 local script=$LUSTRE/tests/${TESTSUITE}.sh
3295 [ -f $script ] || return 0
3297 local start_at=$START_AT
3298 local stop_at=$STOP_AT
3300 local var=${TESTSUITE//-/_}_START_AT
3301 [ x"${!var}" != x ] && start_at=${!var}
3302 var=${TESTSUITE//-/_}_STOP_AT
3303 [ x"${!var}" != x ] && stop_at=${!var}
3305 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
3306 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
3307 /^'${start_at}'$/ {flag = 0}
3308 {if (flag == 1) print $0}
3309 /^'${stop_at}'$/ { flag = 1 }'
3313 (cd `dirname $1`; echo $PWD/`basename $1`)
3317 local types=${1:-"OST MDS MGS"}
3321 for entry in $types; do
3322 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
3323 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
3326 MGS ) list="$list $name";;
3327 MDS|OST ) local count=${type}COUNT
3328 for ((i=1; i<=${!count}; i++)) do
3329 list="$list ${name}$i"
3331 * ) error "Invalid facet type"
3335 echo $(comma_list $list)
3338 ##################################
3339 # Adaptive Timeouts funcs
3342 # only check mds, we assume at_max is the same on all nodes
3343 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
3344 if [ $at_max -eq 0 ]; then
3355 # suppose that all ost-s have the same $at value set
3356 [ $facet != "ost" ] || facet=ost1
3358 do_facet $facet "lctl get_param -n $at"
3376 if [ $facet == "ost" ]; then
3377 facet=$(get_facets OST)
3378 elif [ $facet == "mds" ]; then
3379 facet=$(get_facets MDS)
3381 hosts=$(expand_list $hosts $(facets_hosts $facet))
3384 do_nodes $hosts lctl set_param at_max=$at_max
3387 ##################################
3391 # OBD_FAIL_MDS_ALL_REQUEST_NET
3393 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
3394 do_facet client "$1" || RC=$?
3395 do_facet $SINGLEMDS lctl set_param fail_loc=0
3400 # OBD_FAIL_MDS_ALL_REPLY_NET
3402 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
3403 do_facet client "$@" || RC=$?
3404 do_facet $SINGLEMDS lctl set_param fail_loc=0
3408 drop_reint_reply() {
3409 # OBD_FAIL_MDS_REINT_NET_REP
3411 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
3412 do_facet client "$@" || RC=$?
3413 do_facet $SINGLEMDS lctl set_param fail_loc=0
3418 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
3420 do_facet ost1 lctl set_param fail_loc=0x214
3421 do_facet client "$1" || RC=$?
3422 do_facet client "sync"
3423 do_facet ost1 lctl set_param fail_loc=0
3427 drop_ldlm_cancel() {
3428 #define OBD_FAIL_LDLM_CANCEL 0x304
3430 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
3431 do_nodes $list lctl set_param fail_loc=0x304
3433 do_facet client "$@" || RC=$?
3435 do_nodes $list lctl set_param fail_loc=0
3439 drop_bl_callback() {
3440 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
3442 do_facet client lctl set_param fail_loc=0x305
3443 do_facet client "$@" || RC=$?
3444 do_facet client lctl set_param fail_loc=0
3449 #define OBD_FAIL_LDLM_REPLY 0x30c
3451 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
3452 do_facet client "$@" || RC=$?
3453 do_facet $SINGLEMDS lctl set_param fail_loc=0
3461 echo "clearing fail_loc on $facet"
3462 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
3465 set_nodes_failloc () {
3466 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
3469 cancel_lru_locks() {
3470 $LCTL mark "cancel_lru_locks $1 start"
3471 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
3472 $LCTL set_param -n $d=clear
3474 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
3475 $LCTL mark "cancel_lru_locks $1 stop"
3480 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
3481 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
3482 echo "$DEFAULT_LRU_SIZE"
3487 lctl set_param ldlm.namespaces.*$1*.lru_size=0
3490 lru_resize_disable()
3492 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
3497 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
3498 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
3499 echo there is still data in page cache $FILE ?
3500 lctl get_param -n $FILE
3508 DEBUGSAVE="$(lctl get_param -n debug)"
3512 [ -n "$DEBUGSAVE" ] && \
3513 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
3518 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
3521 debug_size_restore() {
3522 [ -n "$DEBUG_SIZE_SAVED" ] && \
3523 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
3527 start_full_debug_logging() {
3532 local DEBUG_SIZE=150
3534 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
3535 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
3538 stop_full_debug_logging() {
3543 ##################################
3545 ##################################
3548 local TYPE=${TYPE:-"FAIL"}
3551 # do not dump logs if $1=false
3552 if [ "x$1" = "xfalse" ]; then
3557 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
3560 # We need to dump the logs on all nodes
3562 gather_logs $(comma_list $(nodes_list))
3566 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
3567 echo "$@" > $LOGDIR/err
3572 local log=$TESTSUITELOG
3574 [ -f "$log" ] && grep -q FAIL: $log && status=1
3587 # use only if we are ignoring failures for this test, bugno required.
3588 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
3589 # e.g. error_ignore 5494 "your message"
3591 local TYPE="IGNORE (bz$1)"
3597 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
3602 log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
3603 [ "$ALWAYS_SKIPPED" ] && \
3604 skip_logged ${TESTNAME} "$@" || true
3605 [ "$TESTSUITELOG" ] && \
3606 echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
3609 build_test_filter() {
3610 EXCEPT="$EXCEPT $(testslist_filter)"
3612 [ "$ONLY" ] && log "only running test `echo $ONLY`"
3616 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
3617 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
3618 [ "$EXCEPT_SLOW" ] && \
3619 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
3620 for E in $EXCEPT; do
3621 eval EXCEPT_${E}=true
3623 for E in $ALWAYS_EXCEPT; do
3624 eval EXCEPT_ALWAYS_${E}=true
3626 for E in $EXCEPT_SLOW; do
3627 eval EXCEPT_SLOW_${E}=true
3629 for G in $GRANT_CHECK_LIST; do
3630 eval GCHECK_ONLY_${G}=true
3635 if [[ $1 = [a-z]* ]]; then
3642 # print a newline if the last test was skipped
3643 export LAST_SKIPPED=
3644 export ALWAYS_SKIPPED=
3646 # Main entry into test-framework. This is called with the name and
3647 # description of a test. The name is used to find the function to run
3648 # the test using "test_$name".
3650 # This supports a variety of methods of specifying specific test to
3651 # run or not run. These need to be documented...
3656 export base=`basetest $1`
3657 if [ ! -z "$ONLY" ]; then
3659 if [ ${!testname}x != x ]; then
3660 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
3661 run_one_logged $1 "$2"
3665 if [ ${!testname}x != x ]; then
3666 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
3667 run_one_logged $1 "$2"
3675 if [ ${!testname}x != x ]; then
3677 TESTNAME=test_$1 skip "skipping excluded test $1"
3680 testname=EXCEPT_$base
3681 if [ ${!testname}x != x ]; then
3683 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
3686 testname=EXCEPT_ALWAYS_$1
3687 if [ ${!testname}x != x ]; then
3690 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
3693 testname=EXCEPT_ALWAYS_$base
3694 if [ ${!testname}x != x ]; then
3697 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
3700 testname=EXCEPT_SLOW_$1
3701 if [ ${!testname}x != x ]; then
3703 TESTNAME=test_$1 skip "skipping SLOW test $1"
3706 testname=EXCEPT_SLOW_$base
3707 if [ ${!testname}x != x ]; then
3709 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
3715 run_one_logged $1 "$2"
3726 module_loaded lnet || load_modules
3738 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
3743 strace -o $TMP/$1.strace -ttt $*
3745 log "FINISHED: $*: rc $RC"
3750 equals_msg $1 test complete, duration $2 sec
3751 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
3752 echo duration $2 >>$TESTSUITELOG
3756 # Set TEST_STATUS here; will be used for logging the result
3757 if [ -f $LOGDIR/err ]; then
3762 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
3766 local FFREE=$(do_node $SINGLEMDS \
3767 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
3768 local FTOTAL=$(do_node $SINGLEMDS \
3769 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
3771 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
3775 echo -n "Resetting fail_loc on all nodes..."
3776 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
3782 # Log a message (on all nodes) padded with "=" before and after.
3783 # Also appends a timestamp and prepends the testsuite name.
3786 EQUALS="===================================================================================================="
3788 msg="== ${TESTSUITE} $*"
3790 [[ $last != "=" && $last != " " ]] && msg="$msg "
3791 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
3792 # always include at least == after the message
3793 log "$msg== $(date +"%H:%M:%S (%s)")"
3797 # Run a single test function and cleanup after it.
3799 # This function should be run in a subshell so the test func can
3800 # exit() without stopping the whole script.
3806 export tdir=d0.${TESTSUITE}/d${base}
3807 export TESTNAME=test_$testnum
3808 local SAVE_UMASK=`umask`
3811 banner "test $testnum: $message"
3812 test_${testnum} || error "test_$testnum failed with $?"
3815 check_grant ${testnum} || error "check_grant $testnum failed with $?"
3816 check_catastrophe || error "LBUG/LASSERT detected"
3817 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
3825 # Wrapper around run_one to ensure:
3826 # - test runs in subshell
3827 # - output of test is saved to separate log file for error reporting
3828 # - test result is saved to data file
3831 local BEFORE=`date +%s`
3833 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
3834 local test_log=$LOGDIR/$name
3836 local SAVE_UMASK=`umask`
3840 log_sub_test_begin test_${1}
3841 (run_one $1 "$2") 2>&1 | tee -i $test_log
3842 local RC=${PIPESTATUS[0]}
3844 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] && \
3845 echo "test_$1 returned $RC" | tee $LOGDIR/err
3847 duration=$((`date +%s` - $BEFORE))
3848 pass "$1" "(${duration}s)"
3849 [ -f $LOGDIR/err ] && TEST_ERROR=$(cat $LOGDIR/err)
3850 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
3852 if [ -f $LOGDIR/err ]; then
3853 $FAIL_ON_ERROR && exit $RC
3862 # Print information of skipped tests to result.yml
3865 log_sub_test_begin $1
3866 log_sub_test_end "SKIP" "0" "0" "\"$2\""
3870 (cd `dirname $1`; echo $PWD/`basename $1`)
3875 export base=`basetest $1`
3876 [ "$CHECK_GRANT" == "no" ] && return 0
3878 testname=GCHECK_ONLY_${base}
3879 [ ${!testname}x == x ] && return 0
3881 echo -n "checking grant......"
3883 local clients=$CLIENTS
3884 [ -z $clients ] && clients=$(hostname)
3886 # sync all the data and make sure no pending data on server
3887 do_nodes $clients sync
3890 client_grant=`do_nodes $clients \
3891 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" | \
3892 awk '{total += $1} END{print total}'`
3895 server_grant=`do_nodes $(comma_list $(osts_nodes)) \
3896 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
3897 awk '{total += $1} END{print total}'`
3899 # check whether client grant == server grant
3900 if [ $client_grant -ne $server_grant ]; then
3901 echo "failed: client:${client_grant} server: ${server_grant}."
3902 do_nodes $(comma_list $(osts_nodes)) \
3903 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
3904 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
3907 echo "pass: client:${client_grant} server: ${server_grant}"
3912 ########################
3918 ost=`echo $1 | awk -F_ '{print $3}'`
3919 if [ -z $ost ]; then
3920 ost=`echo $1 | sed 's/-osc.*//'`
3925 ostuuid_from_index()
3927 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
3930 ostname_from_index() {
3931 local uuid=$(ostuuid_from_index $1)
3935 index_from_ostuuid()
3937 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
3940 mdtuuid_from_index()
3942 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
3947 [ "$node" != "$(hostname)" ]
3953 for node in $(mdts_nodes); do
3954 remote_node $node && return 0
3961 [ "$CLIENTONLY" ] && return 0 || true
3962 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
3967 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
3968 MSKIPPED=1 && return 1
3975 for node in $(osts_nodes) ; do
3976 remote_node $node && return 0
3983 [ "$CLIENTONLY" ] && return 0 || true
3984 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
3989 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
3990 OSKIPPED=1 && return 1
3997 MGS=$(facet_host mgs)
3998 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
4003 remote_mds_nodsh || remote_ost_nodsh || \
4004 $(single_local_node $(comma_list $(nodes_list)))
4010 for num in `seq $MDSCOUNT`; do
4011 MDSNODES="$MDSNODES $(facet_host mds$num)"
4013 NODES_sort=$(for i in $MDSNODES; do echo $i; done | sort -u)
4019 remote_ost && remote_mds
4027 for facet in ${facets//,/ }; do
4028 if [ "$FAILURE_MODE" = HARD ]; then
4029 nodes="$nodes $(facet_active_host $facet)"
4031 nodes="$nodes $(facet_host $facet)"
4034 NODES_sort=$(for i in $nodes; do echo $i; done | sort -u)
4040 local facets=$(get_facets OST)
4041 local nodes=$(facets_nodes $facets)
4047 # FIXME. We need a list of clients
4048 local myNODES=$HOSTNAME
4051 # CLIENTS (if specified) contains the local client
4052 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
4054 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
4055 myNODES="$myNODES $(facets_nodes $(get_facets))"
4058 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
4063 remote_nodes_list () {
4064 local rnodes=$(nodes_list)
4065 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
4069 init_clients_lists () {
4070 # Sanity check: exclude the local client from RCLIENTS
4071 local clients=$(hostlist_expand "$RCLIENTS")
4072 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
4074 # Sanity check: exclude the dup entries
4075 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
4077 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
4079 # Sanity check: exclude the dup entries from CLIENTS
4080 # for those configs which has SINGLCLIENT set to local client
4081 clients=$(for i in $clients; do echo $i; done | sort -u)
4083 CLIENTS=$(comma_list $clients)
4084 local -a remoteclients=($RCLIENTS)
4085 for ((i=0; $i<${#remoteclients[@]}; i++)); do
4086 varname=CLIENT$((i + 2))
4087 eval $varname=${remoteclients[i]}
4090 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
4093 get_random_entry () {
4096 rnodes=${rnodes//,/ }
4098 local -a nodes=($rnodes)
4099 local num=${#nodes[@]}
4100 local i=$((RANDOM * num * 2 / 65536))
4106 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
4111 lctl get_param version | grep -q patchless
4115 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
4116 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
4121 echo $nodes | wc -w || true
4125 local nodes=$(osts_nodes)
4126 local osscount=$(get_node_count "$nodes")
4127 [ ! "$OSTCOUNT" = "$osscount" ]
4131 local nodes=$(mdts_nodes)
4132 local mdtcount=$(get_node_count "$nodes")
4133 [ ! "$MDSCOUNT" = "$mdtcount" ]
4136 generate_machine_file() {
4137 local nodes=${1//,/ }
4138 local machinefile=$2
4140 for node in $nodes; do
4141 echo $node >>$machinefile || \
4142 { echo "can not generate machinefile $machinefile" && return 1; }
4147 local file=$1/stripe
4149 $LFS getstripe -v $file || error
4153 setstripe_nfsserver () {
4156 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
4157 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
4159 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
4161 do_nodev $nfsserver lfs setstripe "$@"
4164 check_runas_id_ret() {
4166 local myRUNAS_UID=$1
4167 local myRUNAS_GID=$2
4170 if [ -z "$myRUNAS" ]; then
4171 error_exit "myRUNAS command must be specified for check_runas_id"
4174 $myRUNAS krb5_login.sh || \
4175 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
4177 mkdir $DIR/d0_runas_test
4179 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
4180 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
4181 rm -rf $DIR/d0_runas_test
4186 local myRUNAS_UID=$1
4187 local myRUNAS_GID=$2
4190 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
4191 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
4192 Please set RUNAS_ID to some UID which exists on MDS and client or
4193 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
4196 # obtain the UID/GID for MPI_USER
4200 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
4201 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
4203 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
4204 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
4207 # obtain and cache Kerberos ticket-granting ticket
4208 refresh_krb5_tgt() {
4209 local myRUNAS_UID=$1
4210 local myRUNAS_GID=$2
4213 if [ -z "$myRUNAS" ]; then
4214 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
4217 CLIENTS=${CLIENTS:-$HOSTNAME}
4218 do_nodes $CLIENTS "set -x
4219 if ! $myRUNAS krb5_login.sh; then
4220 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
4225 # Run multiop in the background, but wait for it to print
4226 # "PAUSING" to its stdout before returning from this function.
4227 multiop_bg_pause() {
4228 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
4232 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
4235 echo "$MULTIOP_PROG $FILE v$ARGS"
4236 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
4238 echo "TMPPIPE=${TMPPIPE}"
4239 read -t 60 multiop_output < $TMPPIPE
4240 if [ $? -ne 0 ]; then
4245 if [ "$multiop_output" != "PAUSING" ]; then
4246 echo "Incorrect multiop output: $multiop_output"
4261 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
4267 inodes_available () {
4268 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
4272 mdsrate_inodes_available () {
4273 local min_inodes=$(inodes_available)
4274 echo $((min_inodes * 99 / 100))
4277 # reset llite stat counters
4278 clear_llite_stats(){
4279 lctl set_param -n llite.*.stats 0
4282 # sum llite stat items
4283 calc_llite_stats() {
4284 local res=$(lctl get_param -n llite.*.stats |
4285 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
4289 # reset osc stat counters
4291 lctl set_param -n osc.*.osc_stats 0
4294 # sum osc stat items
4296 local res=$(lctl get_param -n osc.*.osc_stats |
4297 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
4302 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
4305 calc_osc_kbytes () {
4306 df $MOUNT > /dev/null
4307 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
4310 # save_lustre_params(node, parameter_mask)
4311 # generate a stream of formatted strings (<node> <param name>=<param value>)
4312 save_lustre_params() {
4314 do_nodesv $1 "lctl get_param $2 | while read s; do echo \\\$s; done"
4317 # restore lustre parameters from input stream, produces by save_lustre_params
4318 restore_lustre_params() {
4322 while IFS=" =" read node name val; do
4323 do_node ${node//:/} "lctl set_param -n $name $val"
4327 check_catastrophe() {
4328 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
4329 local C=$CATASTROPHE
4330 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
4332 if [ $rnodes ]; then
4333 do_nodes $rnodes "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
4334 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
4339 # CMD: determine mds index where directory inode presents
4342 local file=$dir/f0.get_mds_dir_tmpfile
4347 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
4348 local -a oldused=($iused)
4350 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
4352 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
4353 local -a newused=($iused)
4356 for ((i=0; i<${#newused[@]}; i++)); do
4357 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
4363 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
4366 mdsrate_cleanup () {
4368 mpi_run -np $1 -machinefile $2 ${MDSRATE} --unlink --nfiles $3 --dir $4 --filefmt $5 $6
4373 delayed_recovery_enabled () {
4374 local var=${SINGLEMDS}_svc
4375 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
4378 ########################
4380 convert_facet2label() {
4383 if [ x$facet = xost ]; then
4387 local varsvc=${facet}_svc
4389 if [ -n ${!varsvc} ]; then
4392 error "No lablel for $facet!"
4396 get_clientosc_proc_path() {
4397 echo "${1}-osc-[^M]*"
4400 get_lustre_version () {
4401 local facet=${1:-"$SINGLEMDS"}
4402 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
4405 lustre_version_code() {
4406 local facet=${1:-"$SINGLEMDS"}
4407 version_code $(get_lustre_version $1)
4410 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
4411 # used by MDT would not be changed.
4412 # mdt lov: fsname-mdtlov
4413 # mdt osc: fsname-OSTXXXX-osc
4414 mds_on_old_device() {
4415 local mds=${1:-"$SINGLEMDS"}
4417 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
4418 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
4419 > /dev/null 2>&1" && return 0
4424 get_mdtosc_proc_path() {
4426 local ost_label=${2:-"*OST*"}
4428 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
4429 local mdt_label=$(convert_facet2label $mds_facet)
4430 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
4432 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
4433 mds_on_old_device $mds_facet; then
4434 echo "${ost_label}-osc"
4436 echo "${ost_label}-osc-${mdt_index}"
4440 get_osc_import_name() {
4443 local label=$(convert_facet2label $ost)
4445 if [ "${facet:0:3}" = "mds" ]; then
4446 get_mdtosc_proc_path $facet $label
4450 get_clientosc_proc_path $label
4454 _wait_import_state () {
4457 local maxtime=${3:-$(max_recovery_time)}
4461 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
4462 while [ "${CONN_STATE}" != "${expected}" ]; do
4463 if [ "${expected}" == "DISCONN" ]; then
4464 # for disconn we can check after proc entry is removed
4465 [ "x${CONN_STATE}" == "x" ] && return 0
4466 # with AT enabled, we can have connect request timeout near of
4467 # reconnect timeout and test can't see real disconnect
4468 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
4470 [ $i -ge $maxtime ] && \
4471 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
4474 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
4478 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
4482 wait_import_state() {
4485 local maxtime=${3:-$(max_recovery_time)}
4488 for param in ${params//,/ }; do
4489 _wait_import_state $state $param $maxtime || return
4493 # One client request could be timed out because server was not ready
4494 # when request was sent by client.
4495 # The request timeout calculation details :
4497 # /* We give the server rq_timeout secs to process the req, and
4498 # add the network latency for our local timeout. */
4499 # request->rq_deadline = request->rq_sent + request->rq_timeout +
4500 # ptlrpc_at_get_net_latency(request) ;
4502 # ptlrpc_connect_import ()
4503 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
4506 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
4507 # ptlrpc_at_get_net_latency(request) ->
4508 # at_get (max (iat_net_latency=0, at_min)) = at_min
4511 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
4512 # INITIAL_CONNECT_TIMEOUT + at_min
4514 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
4515 # because we can not get this value in runtime,
4516 # the value depends on configure options, and it is not stored in /proc.
4518 # #define CONNECTION_SWITCH_MIN 5U
4519 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
4521 request_timeout () {
4524 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
4525 local init_connect_timeout=$TIMEOUT
4526 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
4528 local at_min=$(at_get $facet at_min)
4530 echo $(( init_connect_timeout + at_min ))
4533 wait_osc_import_state() {
4537 local ost=$(get_osc_import_name $facet $ost_facet)
4539 local param="osc.${ost}.ost_server_uuid"
4541 # 1. wait the deadline of client 1st request (it could be skipped)
4542 # 2. wait the deadline of client 2nd request
4543 local maxtime=$(( 2 * $(request_timeout $facet)))
4545 if ! do_rpc_nodes $(facet_host $facet) \
4546 _wait_import_state $expected $param $maxtime; then
4547 error "import is not in ${expected} state"
4554 get_clientmdc_proc_path() {
4562 # Add paths to lustre tests for 32 and 64 bit systems.
4563 local RPATH="PATH=$RLUSTRE/tests:/usr/lib/lustre/tests:/usr/lib64/lustre/tests:$PATH"
4564 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
4567 wait_clients_import_state () {
4574 if [ "$FAILURE_MODE" = HARD ]; then
4575 facets=$(facets_on_host $(facet_active_host $facet))
4578 for facet in ${facets//,/ }; do
4579 local label=$(convert_facet2label $facet)
4582 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
4583 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
4584 *) error "unknown facet!" ;;
4586 local params=$(expand_list $params $proc_path)
4589 if ! do_rpc_nodes $list wait_import_state $expected $params; then
4590 error "import is not in ${expected} state"
4600 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
4601 $LCTL get_param obdfilter.*.kbytesavail))
4602 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
4603 $LCTL get_param -n obdfilter.*.tot_granted))
4604 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
4605 $LCTL get_param -n obdfilter.*.kbytestotal))
4606 for ((i=0; i<${#AVAILA[@]}; i++)); do
4607 local -a AVAIL1=(${AVAILA[$i]//=/ })
4608 local -a TOTAL=(${TOTALA[$i]//=/ })
4609 GRANT=$((${GRANTA[$i]}/1024))
4610 # allow 1% of total space in bavail because of delayed
4611 # allocation with ZFS which might release some free space after
4612 # txg commit. For small devices, we set a mininum of 8MB
4613 local LIMIT=$((${TOTAL} / 100 + 8000))
4614 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
4615 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
4616 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
4617 echo " FULL" || echo
4623 do_facet mgs lctl pool_list $1
4627 local fsname=${1%%.*}
4628 local poolname=${1##$fsname.}
4630 do_facet mgs lctl pool_new $1
4632 # get param should return err unless pool is created
4633 [[ $RC -ne 0 ]] && return $RC
4635 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4636 2>/dev/null || echo foo" "" || RC=1
4637 if [[ $RC -eq 0 ]]; then
4640 error "pool_new failed $1"
4645 add_pool_to_list () {
4646 local fsname=${1%%.*}
4647 local poolname=${1##$fsname.}
4649 local listvar=${fsname}_CREATED_POOLS
4650 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
4653 remove_pool_from_list () {
4654 local fsname=${1%%.*}
4655 local poolname=${1##$fsname.}
4657 local listvar=${fsname}_CREATED_POOLS
4658 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
4661 destroy_pool_int() {
4663 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
4664 awk '$1 !~ /^Pool:/ {print $1}')
4665 for ost in $OSTS; do
4666 do_facet mgs lctl pool_remove $1 $ost
4668 do_facet mgs lctl pool_destroy $1
4671 # <fsname>.<poolname> or <poolname>
4673 local fsname=${1%%.*}
4674 local poolname=${1##$fsname.}
4676 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
4680 pool_list $fsname.$poolname || return $?
4682 destroy_pool_int $fsname.$poolname
4684 [[ $RC -ne 0 ]] && return $RC
4686 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4687 2>/dev/null || echo foo" "foo" || RC=1
4689 if [[ $RC -eq 0 ]]; then
4690 remove_pool_from_list $fsname.$poolname
4692 error "destroy pool failed $1"
4698 local fsname=${1:-$FSNAME}
4700 local listvar=${fsname}_CREATED_POOLS
4704 [ x${!listvar} = x ] && return 0
4706 echo destroy the created pools: ${!listvar}
4707 for poolname in ${!listvar//,/ }; do
4708 destroy_pool $fsname.$poolname
4713 local fsname=${1:-$FSNAME}
4715 destroy_pools $fsname
4721 local ts=$(date +%s)
4724 if [[ ! -f "$YAML_LOG" ]]; then
4725 # init_logging is not performed before gather_logs,
4726 # so the $LOGDIR needs to be checked here
4727 check_shared_dir $LOGDIR && touch $LOGDIR/shared
4730 [ -f $LOGDIR/shared ] && docp=false
4732 # dump lustre logs, dmesg
4734 prefix="$TESTLOG_PREFIX.$TESTNAME"
4736 echo "Dumping lctl log to ${prefix}.*.${suffix}"
4738 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
4739 echo "Dumping logs only on local client."
4740 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
4741 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
4746 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
4747 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
4748 if [ ! -f $LOGDIR/shared ]; then
4749 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
4762 for i in $(seq 0 $num_mntpts); do
4763 cmd="ls -laf ${mntpt_root}$i/$dir"
4769 for pid in $pids; do
4776 # target_start_and_reset_recovery_timer()
4777 # service_time = at_est2timeout(service_time);
4778 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
4779 # INITIAL_CONNECT_TIMEOUT);
4780 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
4781 #define CONNECTION_SWITCH_INC 1
4782 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
4783 #define CONNECTION_SWITCH_MIN 5U
4785 max_recovery_time () {
4786 local init_connect_timeout=$(( TIMEOUT / 20 ))
4787 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
4789 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
4794 get_clients_mount_count () {
4795 local clients=${CLIENTS:-`hostname`}
4797 # we need to take into account the clients mounts and
4798 # exclude mds/ost mounts if any;
4799 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
4803 PROC_CLI="srpc_info"
4811 if [ $M -lt $N ]; then
4815 while [ $N -lt $M ]; do
4825 calc_connection_cnt() {
4828 # MDT->MDT = 2 * C(M, 2)
4832 comb_m2=$(combination $MDSCOUNT 2)
4834 local num_clients=$(get_clients_mount_count)
4836 local cnt_mdt2mdt=$((comb_m2 * 2))
4837 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
4838 local cnt_cli2ost=$((num_clients * OSTCOUNT))
4839 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
4840 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
4841 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
4842 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
4856 local cmd="$tgt.srpc.flavor"
4858 if [ $net == "any" ]; then
4863 if [ $dir != "any" ]; then
4868 log "Setting sptlrpc rule: $cmd"
4869 do_facet mgs "$LCTL conf_param $cmd"
4878 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
4879 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
4881 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
4883 if [ "x$bulkspec" != "x" ]; then
4884 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
4886 if [ "x$algs" != "x" ]; then
4887 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
4889 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
4890 if [ $bulk == "bulkn" ]; then
4891 bulk_count=`echo "$output" | grep "bulk flavor" \
4892 | grep "null/null" | wc -l`
4893 elif [ $bulk == "bulki" ]; then
4894 bulk_count=`echo "$output" | grep "bulk flavor" \
4895 | grep "/null" | grep -v "null/" | wc -l`
4897 bulk_count=`echo "$output" | grep "bulk flavor" \
4898 | grep -v "/null" | grep -v "null/" | wc -l`
4902 [ $bulk_count -lt $count ] && count=$bulk_count
4913 local clients=${CLIENTS:-`hostname`}
4915 for c in ${clients//,/ }; do
4916 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
4917 tmpcnt=`count_flvr "$output" $flavor`
4918 cnt=$((cnt + tmpcnt))
4928 local clients=${CLIENTS:-`hostname`}
4930 for c in ${clients//,/ }; do
4931 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
4932 tmpcnt=`count_flvr "$output" $flavor`
4933 cnt=$((cnt + tmpcnt))
4943 if [ $MDSCOUNT -le 1 ]; then
4948 for num in `seq $MDSCOUNT`; do
4949 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
4950 tmpcnt=`count_flvr "$output" $flavor`
4951 cnt=$((cnt + tmpcnt))
4962 for num in `seq $MDSCOUNT`; do
4963 mdtosc=$(get_mdtosc_proc_path mds$num)
4964 mdtosc=${mdtosc/-MDT*/-MDT\*}
4965 output=$(do_facet mds$num lctl get_param -n \
4966 osc.$mdtosc.$PROC_CLI 2>/dev/null)
4967 tmpcnt=`count_flvr "$output" $flavor`
4968 cnt=$((cnt + tmpcnt))
4977 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
4978 count_flvr "$output" $flavor
4983 local dir=$1 # from to
4984 local flavor=$2 # flavor expected
4987 if [ $dir == "cli2mdt" ]; then
4988 res=`flvr_cnt_cli2mdt $flavor`
4989 elif [ $dir == "cli2ost" ]; then
4990 res=`flvr_cnt_cli2ost $flavor`
4991 elif [ $dir == "mdt2mdt" ]; then
4992 res=`flvr_cnt_mdt2mdt $flavor`
4993 elif [ $dir == "mdt2ost" ]; then
4994 res=`flvr_cnt_mdt2ost $flavor`
4995 elif [ $dir == "all2ost" ]; then
4996 res1=`flvr_cnt_mdt2ost $flavor`
4997 res2=`flvr_cnt_cli2ost $flavor`
4998 res=$((res1 + res2))
4999 elif [ $dir == "all2mdt" ]; then
5000 res1=`flvr_cnt_mdt2mdt $flavor`
5001 res2=`flvr_cnt_cli2mdt $flavor`
5002 res=$((res1 + res2))
5003 elif [ $dir == "all2all" ]; then
5004 res1=`flvr_cnt_mdt2ost $flavor`
5005 res2=`flvr_cnt_cli2ost $flavor`
5006 res3=`flvr_cnt_mdt2mdt $flavor`
5007 res4=`flvr_cnt_cli2mdt $flavor`
5008 res=$((res1 + res2 + res3 + res4))
5016 local dir=$1 # from to
5017 local flavor=$2 # flavor expected
5018 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
5022 for ((i=0;i<20;i++)); do
5023 echo -n "checking $dir..."
5024 res=$(do_check_flavor $dir $flavor)
5025 echo "found $res/$expect $flavor connections"
5026 [ $res -ge $expect ] && return 0
5030 echo "Error checking $flavor of $dir: expect $expect, actual $res"
5034 restore_to_default_flavor()
5036 local proc="mgs.MGS.live.$FSNAME"
5038 echo "restoring to default flavor..."
5040 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
5042 # remove all existing rules if any
5043 if [ $nrule -ne 0 ]; then
5044 echo "$nrule existing rules"
5045 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
5046 echo "remove rule: $rule"
5047 spec=`echo $rule | awk -F = '{print $1}'`
5048 do_facet mgs "$LCTL conf_param -d $spec"
5052 # verify no rules left
5053 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
5054 [ $nrule -ne 0 ] && error "still $nrule rules left"
5056 # wait for default flavor to be applied
5057 # currently default flavor for all connections are 'null'
5058 wait_flavor all2all null
5059 echo "now at default flavor settings"
5064 local flavor=${1:-null}
5066 echo "setting all flavor to $flavor"
5068 # FIXME need parameter to this fn
5069 # and remove global vars
5070 local cnt_all2all=$(calc_connection_cnt all2all)
5072 local res=$(do_check_flavor all2all $flavor)
5073 if [ $res -eq $cnt_all2all ]; then
5074 echo "already have total $res $flavor connections"
5078 echo "found $res $flavor out of total $cnt_all2all connections"
5079 restore_to_default_flavor
5081 [[ $flavor = null ]] && return 0
5083 set_rule $FSNAME any any $flavor
5084 wait_flavor all2all $flavor
5090 # Checking for shared logdir
5091 if [ ! -d $dir ]; then
5092 # Not found. Create local logdir
5095 touch $dir/check_file.$(hostname -s)
5100 check_write_access() {
5105 for node in $(nodes_list); do
5106 file=$dir/check_file.$(short_hostname $node)
5107 if [[ ! -f "$file" ]]; then
5108 # Logdir not accessible/writable from this node.
5111 rm -f $file || return 1
5117 if [[ -n $YAML_LOG ]]; then
5120 local SAVE_UMASK=`umask`
5123 export YAML_LOG=${LOGDIR}/results.yml
5127 if [ ! -f $YAML_LOG ]; then # If the yaml log already exists then we will just append to it
5128 if check_shared_dir $LOGDIR; then
5129 touch $LOGDIR/shared
5130 echo "Logging to shared log directory: $LOGDIR"
5132 echo "Logging to local directory: $LOGDIR"
5135 yml_nodes_file $LOGDIR >> $YAML_LOG
5136 yml_results_file >> $YAML_LOG
5143 yml_log_test $1 >> $YAML_LOG
5147 yml_log_test_status $@ >> $YAML_LOG
5150 log_sub_test_begin() {
5151 yml_log_sub_test_begin "$@" >> $YAML_LOG
5154 log_sub_test_end() {
5155 yml_log_sub_test_end "$@" >> $YAML_LOG
5161 local llverdev_opts=$2
5162 local devname=$(basename $1)
5163 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
5164 # loop devices aren't in /proc/partitions
5165 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
5167 size=$(($size / 1024 / 1024)) # Gb
5169 local partial_arg=""
5170 # Run in partial (fast) mode if the size
5171 # of a partition > 1 GB
5172 [ $size -gt 1 ] && partial_arg="-p"
5174 llverdev --force $partial_arg $llverdev_opts $dev
5180 local llverfs_opts=$2
5181 local partial_arg=""
5182 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
5184 # Run in partial (fast) mode if the size
5185 # of a partition > 1 GB
5186 [ $size -gt 1 ] && partial_arg="-p"
5188 llverfs $partial_arg $llverfs_opts $dir
5191 remove_mdt_files() {
5196 local mntpt=$(facet_mntpt $facet)
5197 local opts=$MDS_MOUNT_OPTS
5199 echo "removing files from $mdtdev on $facet: $files"
5200 if [ $(facet_fstype $facet) == ldiskfs ] &&
5201 ! do_facet $facet test -b ${!dev}; then
5202 opts=$(csa_add "$opts" -o loop)
5204 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
5208 rm $mntpt/ROOT/$f || { rc=$?; break; }
5210 umount -f $mntpt || return $?
5214 duplicate_mdt_files() {
5219 local mntpt=$(facet_mntpt $facet)
5220 local opts=$MDS_MOUNT_OPTS
5222 echo "duplicating files on $mdtdev on $facet: $files"
5223 mkdir -p $mntpt || return $?
5224 if [ $(facet_fstype $facet) == ldiskfs ] &&
5225 ! do_facet $facet test -b ${!dev}; then
5226 opts=$(csa_add "$opts" -o loop)
5228 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
5239 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
5240 pushd $mntpt/ROOT > /dev/null || return $?
5243 touch $f.bad || return $?
5244 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
5246 [ $rc -eq 0 ] || return $rc
5247 setfattr --restore $tmp || return $?
5253 local devs=${1//,/ }
5256 local rslt=$TMP/sgpdd_survey
5258 # sgpdd-survey cleanups ${rslt}.* files
5260 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
5266 # returns the canonical name for an ldiskfs device
5271 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
5272 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
5273 echo dm-\\\${foo##*:};
5275 echo \\\$(basename \\\$dv);
5279 is_sanity_benchmark() {
5280 local benchmarks="dbench bonnie iozone fsx"
5282 for b in $benchmarks; do
5283 if [ "$b" == "$suite" ]; then
5291 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
5294 # Get the block size of the filesystem.
5300 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
5301 awk '/^Block size:/ {print $3}')
5305 # Check whether the "large_xattr" feature is enabled or not.
5306 large_xattr_enabled() {
5307 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
5309 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 | grep -q large_xattr"
5310 return ${PIPESTATUS[0]}
5313 # Get the maximum xattr size supported by the filesystem.
5317 if large_xattr_enabled; then
5318 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
5321 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
5322 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
5324 # maximum xattr size = size of block - size of header -
5325 # size of 1 entry - 4 null bytes
5326 size=$((block_size - 32 - 32 - 4))
5332 # Dump the value of the named xattr from a file.
5337 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
5340 # Generate a string with size of $size bytes.
5342 local size=${1:-1024} # in bytes
5344 echo "$(head -c $size < /dev/zero | tr '\0' y)"
5347 reformat_external_journal() {
5348 if [ ! -z ${EJOURNAL} ]; then
5349 local rcmd="do_facet ${SINGLEMDS}"
5351 echo "reformat external journal on ${SINGLEMDS}:${EJOURNAL}"
5352 ${rcmd} mke2fs -O journal_dev ${EJOURNAL} || return 1
5356 # MDT file-level backup/restore
5357 mds_backup_restore() {
5358 local devname=$(mdsdevname ${SINGLEMDS//mds/})
5359 local mntpt=$(facet_mntpt brpt)
5360 local rcmd="do_facet ${SINGLEMDS}"
5361 local metaea=${TMP}/backup_restore.ea
5362 local metadata=${TMP}/backup_restore.tgz
5363 local opts=${MDS_MOUNT_OPTS}
5365 if ! ${rcmd} test -b ${devname}; then
5366 opts=$(csa_add "$opts" -o loop)
5369 echo "file-level backup/restore on ${SINGLEMDS}:${devname}"
5371 # step 1: build mount point
5372 ${rcmd} mkdir -p $mntpt
5373 # step 2: cleanup old backup
5374 ${rcmd} rm -f $metaea $metadata
5376 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
5377 # step 4: backup metaea
5379 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
5381 # step 5: backup metadata
5383 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
5385 ${rcmd} umount -d $mntpt || return 4
5386 # step 7: reformat external journal if needed
5387 reformat_external_journal || return 5
5388 # step 8: reformat dev
5389 echo "reformat new device"
5390 add ${SINGLEMDS} $(mkfs_opts ${SINGLEMDS}) --backfstype ldiskfs \
5391 --reformat $devname > /dev/null || return 6
5393 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
5394 # step 10: restore metadata
5396 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
5397 # step 11: restore metaea
5399 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
5400 # step 12: remove recovery logs
5401 echo "remove recovery logs"
5402 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
5403 # step 13: umount dev
5404 ${rcmd} umount -d $mntpt || return 10
5405 # step 14: cleanup tmp backup
5406 ${rcmd} rm -f $metaea $metadata
5411 local devname=$(mdsdevname ${SINGLEMDS//mds/})
5412 local mntpt=$(facet_mntpt brpt)
5413 local rcmd="do_facet ${SINGLEMDS}"
5415 local opts=${MDS_MOUNT_OPTS}
5417 if ! ${rcmd} test -b ${devname}; then
5418 opts=$(csa_add "$opts" -o loop)
5421 echo "remove OI files: idx=${idx}"
5423 # step 1: build mount point
5424 ${rcmd} mkdir -p $mntpt
5426 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
5427 if [ -z $idx ]; then
5428 # step 3: remove all OI files
5429 ${rcmd} rm -fv $mntpt/oi.16*
5430 elif [ $idx -lt 2 ]; then
5431 ${rcmd} rm -fv $mntpt/oi.16.${idx}
5435 # others, rm oi.16.[idx, idx * idx, idx ** ...]
5436 for ((i=${idx}; i<64; i=$((i * idx)))); do
5437 ${rcmd} rm -fv $mntpt/oi.16.${i}
5441 ${rcmd} umount -d $mntpt || return 2
5442 # OI files will be recreated when mounted as lustre next time.