3 trap 'print_summary && touch $TF_FAIL && \
4 echo "test-framework exiting on error"' ERR
9 export EJOURNAL=${EJOURNAL:-""}
10 export REFORMAT=${REFORMAT:-""}
11 export WRITECONF=${WRITECONF:-""}
12 export VERBOSE=${VERBOSE:-false}
13 export CATASTROPHE=${CATASTROPHE:-/proc/sys/lnet/catastrophe}
16 export GSS_PIPEFS=false
17 export IDENTITY_UPCALL=default
19 # specify environment variable containing batch job name for server statistics
20 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
22 # LOAD_LLOOP: LU-409: only load llite_lloop module if kernel < 2.6.32 or
23 # LOAD_LLOOP is true. LOAD_LLOOP is false by default.
24 export LOAD_LLOOP=${LOAD_LLOOP:-false}
26 #export PDSH="pdsh -S -Rssh -w"
28 # function used by scripts run on remote nodes
29 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
30 . $LUSTRE/tests/functions.sh
31 . $LUSTRE/tests/yaml.sh
33 export LD_LIBRARY_PATH=${LUSTRE}/utils:${LD_LIBRARY_PATH}
35 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
37 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
39 if [ -f "$EXCEPT_LIST_FILE" ]; then
40 echo "Reading test skip list from $EXCEPT_LIST_FILE"
45 # check config files for options in decreasing order of preference
46 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
47 MODPROBECONF=/etc/modprobe.d/lustre.conf
48 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
49 MODPROBECONF=/etc/modprobe.d/Lustre
50 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
51 MODPROBECONF=/etc/modprobe.conf
55 [[ $DIR/ = $MOUNT/* ]] || \
56 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
57 [[ $DIR1/ = $MOUNT1/* ]] || \
58 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
59 [[ $DIR2/ = $MOUNT2/* ]] || \
60 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
62 [ -n "$failed" ] && exit 99 || true
66 echo "usage: $0 [-r] [-f cfgfile]"
74 [ "$TESTSUITE" == "lfsck" ] && return 0
75 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
77 local form="%-13s %-17s %-9s %s %s\n"
78 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
79 echo "------------------------------------------------------------------------------------"
80 for O in $DEFAULT_SUITES; do
81 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
82 [ "${!O}" = "no" ] && continue || true
83 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
84 local log=${TMP}/${o}.log
85 if is_sanity_benchmark $o; then
86 log=${TMP}/sanity-benchmark.log
91 local status=Unfinished
93 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
94 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | sort -nr -k 3 | head -5 | awk '{ print $2":"$3"s" }')
95 total=$(grep duration $log | awk '{ print $2}')
96 if [ "${!O}" = "done" ]; then
100 local durations=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | awk '{ print $2":"$3"|" }')
101 details=$(printf "%s\n%s %s %s\n" "$details" "DDETAILS" "$O" "$(echo $durations)")
104 printf "$form" $status "$O" "${total}" "E=$skipped"
105 printf "$form" "-" "-" "-" "S=$(echo $slow)"
108 for O in $DEFAULT_SUITES; do
109 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
110 if [ "${!O}" = "no" ]; then
111 printf "$form" "Skipped" "$O" ""
115 # print the detailed tests durations if DDETAILS=true
122 export LUSTRE=$(absolute_path $LUSTRE)
123 export TESTSUITE=$(basename $0 .sh)
124 export TEST_FAILED=false
125 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
126 export RPC_MODE=${RPC_MODE:-false}
128 export MKE2FS=$MKE2FS
129 if [ -z "$MKE2FS" ]; then
130 if which mkfs.ldiskfs >/dev/null 2>&1; then
131 export MKE2FS=mkfs.ldiskfs
137 export DEBUGFS=$DEBUGFS
138 if [ -z "$DEBUGFS" ]; then
139 if which debugfs.ldiskfs >/dev/null 2>&1; then
140 export DEBUGFS=debugfs.ldiskfs
142 export DEBUGFS=debugfs
146 export TUNE2FS=$TUNE2FS
147 if [ -z "$TUNE2FS" ]; then
148 if which tunefs.ldiskfs >/dev/null 2>&1; then
149 export TUNE2FS=tunefs.ldiskfs
151 export TUNE2FS=tune2fs
155 export E2LABEL=$E2LABEL
156 if [ -z "$E2LABEL" ]; then
157 if which label.ldiskfs >/dev/null 2>&1; then
158 export E2LABEL=label.ldiskfs
160 export E2LABEL=e2label
164 export DUMPE2FS=$DUMPE2FS
165 if [ -z "$DUMPE2FS" ]; then
166 if which dumpfs.ldiskfs >/dev/null 2>&1; then
167 export DUMPE2FS=dumpfs.ldiskfs
169 export DUMPE2FS=dumpe2fs
173 export E2FSCK=$E2FSCK
174 if [ -z "$E2FSCK" ]; then
175 if which fsck.ldiskfs >/dev/null 2>&1; then
176 export E2FSCK=fsck.ldiskfs
182 export RESIZE2FS=$RESIZE2FS
183 if [ -z "$RESIZE2FS" ]; then
184 if which resizefs.ldiskfs >/dev/null 2>&1; then
185 export RESIZE2FS=resizefs.ldiskfs
187 export RESIZE2FS=resize2fs
191 export LFSCK_BIN=${LFSCK_BIN:-lfsck}
192 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after each test suite
193 export FSCK_MAX_ERR=4 # File system errors left uncorrected
195 export ZFS=${ZFS:-zfs}
196 export ZPOOL=${ZPOOL:-zpool}
197 export ZDB=${ZDB:-zdb}
198 export PARTPROBE=${PARTPROBE:-partprobe}
200 #[ -d /r ] && export ROOT=${ROOT:-/r}
201 export TMP=${TMP:-$ROOT/tmp}
202 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
203 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
204 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
206 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
207 if ! echo $PATH | grep -q $LUSTRE/utils; then
208 export PATH=$LUSTRE/utils:$PATH
210 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
211 export PATH=$LUSTRE/utils/gss:$PATH
213 if ! echo $PATH | grep -q $LUSTRE/tests; then
214 export PATH=$LUSTRE/tests:$PATH
216 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
217 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
219 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
220 [ ! -f "$LST" ] && export LST=$(which lst)
221 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
222 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
223 # Ubuntu, at least, has a truncate command in /usr/bin
224 # so fully path our truncate command.
225 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
226 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
227 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
228 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
229 export PATH=$LUSTRE/tests/racer:$PATH:
231 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
232 export PATH=$LUSTRE/tests/mpi:$PATH
234 export RSYNC_RSH=${RSYNC_RSH:-rsh}
236 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
237 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
238 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
239 [ ! -f "$LFS" ] && export LFS=$(which lfs)
240 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
241 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
243 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
244 if [ ! -f "$L_GETIDENTITY" ]; then
245 if `which l_getidentity > /dev/null 2>&1`; then
246 export L_GETIDENTITY=$(which l_getidentity)
248 export L_GETIDENTITY=NONE
251 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
252 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
253 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
254 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
255 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
256 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
257 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
258 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
259 [ ! -f "$LUSTRE_RMMOD" ] &&
260 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
261 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
262 [ ! -f "$LFS_MIGRATE" ] &&
263 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
264 export NAME=${NAME:-local}
265 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
266 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
267 export LGSSD=$(which lgssd)
268 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
269 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
270 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
272 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
275 if [ "$ACCEPTOR_PORT" ]; then
276 export PORT_OPT="--port $ACCEPTOR_PORT"
281 echo "Using GSS/krb5 ptlrpc security flavor"
282 which lgss_keyring > /dev/null 2>&1 || \
283 error_exit "built with gss disabled! SEC=$SEC"
294 IDENTITY_UPCALL=false
298 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
300 # Paths on remote nodes, if different
301 export RLUSTRE=${RLUSTRE:-$LUSTRE}
302 export RPWD=${RPWD:-$PWD}
303 export I_MOUNTED=${I_MOUNTED:-"no"}
304 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
305 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
306 ! -f $LUSTRE/mdt/mdt.ko ]; then
307 export CLIENTMODSONLY=yes
310 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
311 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
315 while getopts "rvwf:" opt $*; do
318 r) REFORMAT=--reformat;;
320 w) WRITECONF=writeconf;;
325 shift $((OPTIND - 1))
328 # print the durations of each test if "true"
329 DDETAILS=${DDETAILS:-false}
330 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
340 ncpts=$(do_facet $facet "lctl get_param -n " \
341 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
343 if [ $ncpts -eq 0 ]; then
351 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
352 eval set -- $(tr "[:punct:]" " " <<< $*)
354 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
357 export LINUX_VERSION=$(uname -r | sed -e "s/[-.]/ /3" -e "s/ .*//")
358 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
361 /sbin/lsmod | grep -q "^\<$1\>"
364 # Load a module on the system where this is running.
366 # Synopsis: load_module module_name [module arguments for insmod/modprobe]
368 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
369 # will be used as the arguments. Otherwise arguments will be obtained from
370 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
377 BASE=`basename $module $EXT`
379 module_loaded ${BASE} && return
381 # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
383 if [ $# -eq 0 ]; then
384 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
385 # Bash until 4.x, so we resort to eval.
386 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
387 eval set -- \$$optvar
388 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
389 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
391 opt=$(awk -v var="^options $BASE" '$0 ~ var \
392 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
393 set -- $(echo -n $opt)
395 # Ensure we have accept=all for lnet
396 if [ $(basename $module) = lnet ]; then
397 # OK, this is a bit wordy...
398 local arg accept_all_present=false
401 [ "$arg" = accept=all ] && \
402 accept_all_present=true
404 $accept_all_present || set -- "$@" accept=all
410 [ $# -gt 0 ] && echo "${module} options: '$*'"
412 # Note that insmod will ignore anything in modprobe.conf, which is why we're
413 # passing options on the command-line.
414 if [ "$BASE" == "lnet_selftest" ] && \
415 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
416 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
417 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
418 insmod ${LUSTRE}/${module}${EXT} "$@"
420 # must be testing a "make install" or "rpm" installation
421 # note failed to load ptlrpc_gss is considered not fatal
422 if [ "$BASE" == "ptlrpc_gss" ]; then
423 modprobe $BASE "$@" 2>/dev/null || echo "gss/krb5 is not supported"
430 llite_lloop_enabled() {
431 local n1=$(uname -r | cut -d. -f1)
432 local n2=$(uname -r | cut -d. -f2)
433 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
435 # load the llite_lloop module for < 2.6.32 kernels
436 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
437 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
444 load_modules_local() {
445 if [ -n "$MODPROBE" ]; then
447 echo "Using modprobe to load modules"
451 echo Loading modules from $LUSTRE
455 if [ -f /sys/devices/system/cpu/online ]; then
456 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
457 echo "detected $ncpus online CPUs by sysfs"
459 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
461 if [ $rc -eq 0 ]; then
462 echo "detected $ncpus online CPUs by getconf"
464 echo "Can't detect number of CPUs"
469 # if there is only one CPU core, libcfs can only create one partition
470 # if there is more than 4 CPU cores, libcfs should create multiple CPU
471 # partitions. So we just force libcfs to create 2 partitions for
472 # system with 2 or 4 cores
473 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
474 # force to enable multiple CPU partitions
475 echo "Force libcfs to create 2 CPU partitions"
476 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
478 echo "libcfs will create CPU partition based on online CPUs"
481 load_module ../libcfs/libcfs/libcfs
483 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
484 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
485 load_module ../lnet/lnet/lnet
486 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
487 load_module ../lnet/klnds/$LNETLND
488 load_module obdclass/obdclass
489 load_module ptlrpc/ptlrpc
490 load_module ptlrpc/gss/ptlrpc_gss
498 load_module obdecho/obdecho
499 if ! client_only; then
500 SYMLIST=/proc/kallsyms
501 grep -q crc16 $SYMLIST || { modprobe crc16 2>/dev/null || true; }
502 grep -q -w jbd $SYMLIST || { modprobe jbd 2>/dev/null || true; }
503 grep -q -w jbd2 $SYMLIST || { modprobe jbd2 2>/dev/null || true; }
504 load_module lfsck/lfsck
505 [ "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
506 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
508 load_module osd-zfs/osd_zfs
510 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
511 grep -q exportfs_decode_fh $SYMLIST ||
512 { modprobe exportfs 2> /dev/null || true; }
513 load_module ../ldiskfs/ldiskfs
514 load_module osd-ldiskfs/osd_ldiskfs
527 load_module llite/lustre
528 llite_lloop_enabled && load_module llite/llite_lloop
529 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
531 rm -f $OGDB/ogdb-$HOSTNAME
532 $LCTL modules > $OGDB/ogdb-$HOSTNAME
534 # 'mount' doesn't look in $PATH, just sbin
535 if [ -f $LUSTRE/utils/mount.lustre ] && \
536 ! grep -qe "/sbin/mount\.lustre " /proc/mounts; then
537 [ ! -f /sbin/mount.lustre ] && touch /sbin/mount.lustre
538 mount --bind $LUSTRE/utils/mount.lustre /sbin/mount.lustre || true
545 # load modules on remote nodes optionally
546 # lustre-tests have to be installed on these nodes
547 if $LOAD_MODULES_REMOTE; then
548 local list=$(comma_list $(remote_nodes_list))
549 if [ -n "$list" ]; then
550 echo "loading modules on: '$list'"
551 do_rpc_nodes "$list" load_modules_local
557 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
558 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
559 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
560 echo "$LEAK_LUSTRE" 1>&2
561 echo "$LEAK_PORTALS" 1>&2
562 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
563 echo "Memory leaks detected"
564 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
570 wait_exit_ST client # bug 12845
572 $LUSTRE_RMMOD ldiskfs || return 2
574 if $LOAD_MODULES_REMOTE; then
575 local list=$(comma_list $(remote_nodes_list))
576 if [ -n "$list" ]; then
577 echo "unloading modules on: '$list'"
578 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
579 do_rpc_nodes "$list" check_mem_leak
583 if grep -qe "/sbin/mount\.lustre" /proc/mounts; then
584 umount /sbin/mount.lustre || true
585 [ -w /sbin/mount.lustre -a ! -s /sbin/mount.lustre ] && \
586 rm -f /sbin/mount.lustre || true
589 check_mem_leak || return 254
591 echo "modules unloaded."
596 local facet=${1:-$SINGLEMDS}
597 local fstype=$(facet_fstype $facet)
600 ldiskfs) size=50;; # largest seen is 44, leave some headroom
601 zfs) size=400;; # largest seen is 384
607 check_gss_daemon_nodes() {
611 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
612 if [ \\\"\\\$num\\\" -ne 1 ]; then
613 echo \\\$num instance of $dname;
618 check_gss_daemon_facet() {
622 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
623 if [ $num -ne 1 ]; then
624 echo "$num instance of $dname on $facet"
633 echo Stopping $@ on $list
634 do_nodes $list "killall -2 $@ 2>/dev/null || true"
637 # start gss daemons on all nodes, or
638 # "daemon" on "list" if set
639 start_gss_daemons() {
643 if [ "$list" ] && [ "$daemon" ] ; then
644 echo "Starting gss daemon on nodes: $list"
645 do_nodes $list "$daemon" || return 8
649 local list=$(comma_list $(mdts_nodes))
651 echo "Starting gss daemon on mds: $list"
652 do_nodes $list "$LSVCGSSD -v" || return 1
654 do_nodes $list "$LGSSD -v" || return 2
657 list=$(comma_list $(osts_nodes))
658 echo "Starting gss daemon on ost: $list"
659 do_nodes $list "$LSVCGSSD -v" || return 3
660 # starting on clients
662 local clients=${CLIENTS:-`hostname`}
664 echo "Starting $LGSSD on clients $clients "
665 do_nodes $clients "$LGSSD -v" || return 4
668 # wait daemons entering "stable" status
672 # check daemons are running
674 list=$(comma_list $(mdts_nodes) $(osts_nodes))
675 check_gss_daemon_nodes $list lsvcgssd || return 5
677 list=$(comma_list $(mdts_nodes))
678 check_gss_daemon_nodes $list lgssd || return 6
681 check_gss_daemon_nodes $clients lgssd || return 7
686 local list=$(comma_list $(mdts_nodes))
688 send_sigint $list lsvcgssd lgssd
690 list=$(comma_list $(osts_nodes))
691 send_sigint $list lsvcgssd
693 list=${CLIENTS:-`hostname`}
694 send_sigint $list lgssd
699 if ! module_loaded ptlrpc_gss; then
700 load_module ptlrpc/gss/ptlrpc_gss
701 module_loaded ptlrpc_gss ||
702 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
704 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
706 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
707 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
715 # maybe cleanup credential cache?
721 local var=${facet}_svc
729 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
730 tr '[:lower:]' '[:upper:]'
736 if [ $facet == mgs ]; then
740 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
748 if [ -n "${!var}" ]; then
753 var=$(facet_type $facet)FSTYPE
754 if [ -n "${!var}" ]; then
759 if [ -n "$FSTYPE" ]; then
764 if [[ $facet == mgs ]] && combined_mgs_mds; then
776 local facets=$(get_facets)
779 for facet in ${facets//,/ }; do
780 if [ $node == $(facet_host $facet) ] ||
781 [ $node == "$(facet_failover_host $facet)" ]; then
782 fstype=$(facet_fstype $facet)
783 if [[ $fstypes != *$fstype* ]]; then
784 fstypes+="${fstypes:+,}$fstype"
795 local fstype=$(facet_fstype $facet)
799 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
801 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
802 ${dev} 2>/dev/null");;
804 error "unknown fstype!";;
812 local device=$(mdsdevname $num)
813 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
819 local device=$(ostdevname $num)
820 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
825 # Get the device of a facet.
832 mgs) device=$(mgsdevname) ;;
833 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
834 ost*) device=$(ostdevname $(facet_number $facet)) ;;
835 fs2mds) device=$(mdsdevname 1_2) ;;
836 fs2ost) device=$(ostdevname 1_2) ;;
837 fs3ost) device=$(ostdevname 2_2) ;;
845 # Get the virtual device of a facet.
852 mgs) device=$(mgsvdevname) ;;
853 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
854 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
855 fs2mds) device=$(mdsvdevname 1_2) ;;
856 fs2ost) device=$(ostvdevname 1_2) ;;
857 fs3ost) device=$(ostvdevname 2_2) ;;
865 # Re-read the partition table on failover partner host.
866 # After a ZFS storage pool is created on a shared device, the partition table
867 # on the device may change. However, the operating system on the failover
868 # host may not notice the change automatically. Without the up-to-date partition
869 # block devices, 'zpool import ..' cannot find the labels, whose positions are
870 # relative to partition rather than disk beginnings.
872 # This function performs partprobe on the failover host to make it re-read the
875 refresh_partition_table() {
880 host=$(facet_passive_host $facet)
881 if [[ -n "$host" ]]; then
882 do_node $host "$PARTPROBE $device"
887 # Get ZFS storage pool name.
894 device=$(facet_device $facet)
895 # poolname is string before "/"
896 poolname="${device%%/*}"
902 # Export ZFS storage pool.
903 # Before exporting the pool, all datasets within the pool should be unmounted.
911 poolname=$(zpool_name $facet)
913 if [[ -n "$poolname" ]]; then
914 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
915 grep -q ^$poolname/ /proc/mounts ||
916 $ZPOOL export $opts $poolname"
921 # Import ZFS storage pool.
922 # Force importing, even if the pool appears to be potentially active.
927 local opts=${@:-"-o cachefile=none"}
930 poolname=$(zpool_name $facet)
932 if [[ -n "$poolname" ]]; then
933 opts+=" -d $(dirname $(facet_vdevice $facet))"
934 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
935 $ZPOOL import -f $opts $poolname"
940 # Set the "cachefile=none" property on ZFS storage pool so that the pool
941 # is not automatically imported on system startup.
943 # In a failover environment, this will provide resource level fencing which
944 # will ensure that the same ZFS storage pool will not be imported concurrently
945 # on different nodes.
947 disable_zpool_cache() {
951 poolname=$(zpool_name $facet)
953 if [[ -n "$poolname" ]]; then
954 do_facet $facet "$ZPOOL set cachefile=none $poolname"
959 # This and set_osd_param() shall be used to access OSD parameters
960 # once existed under "obdfilter":
965 # writethrough_cache_enable
969 local device=${2:-$FSNAME-OST*}
972 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
973 osd-*.$device.$name 2>&1" | grep -v 'Found no match'
978 local device=${2:-$FSNAME-OST*}
982 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
983 osd-*.$device.$name=$value 2>&1" | grep -v 'Found no match'
987 local dz=${1:-$DEBUG_SIZE}
989 if [ -f /sys/devices/system/cpu/possible ]; then
990 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
992 local cpus=$(getconf _NPROCESSORS_CONF)
995 # bug 19944, adjust size to be -gt num_possible_cpus()
996 # promise 2MB for every cpu at least
997 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1000 lctl set_param debug_mb=$dz
1003 set_default_debug () {
1004 local debug=${1:-"$PTLDEBUG"}
1005 local subsys=${2:-"$SUBSYSTEM"}
1006 local debug_size=${3:-$DEBUG_SIZE}
1008 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1009 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1011 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1014 set_default_debug_nodes () {
1017 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1018 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1022 do_rpc_nodes "$nodes" set_default_debug \
1023 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1026 set_default_debug_facet () {
1028 local node=$(facet_active_host $facet)
1029 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1031 set_default_debug_nodes $node
1036 local facets=${1:-$(get_facets)}
1039 for facet in ${facets//,/ }; do
1042 [ $RC -eq 0 ] && continue
1044 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1045 skip "Restart of $facet failed!." && touch $LU482_FAILED
1047 error "Restart of $facet failed!"
1054 # Add argument "arg" (e.g., "loop") to the comma-separated list
1055 # of arguments for option "opt" (e.g., "-o") on command
1056 # line "opts" (e.g., "-o flock").
1062 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1064 if echo "$opts" | grep -q $opt_pattern; then
1065 opts=$(echo "$opts" | sed -e \
1066 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1068 opts+="${opts:+ }$opt $arg"
1076 local dev=$(facet_active $facet)_dev
1077 local opt=${facet}_opt
1078 local mntpt=$(facet_mntpt $facet)
1079 local opts="${!opt} $@"
1081 if [ $(facet_fstype $facet) == ldiskfs ] &&
1082 ! do_facet $facet test -b ${!dev}; then
1083 opts=$(csa_add "$opts" -o loop)
1086 if [[ $(facet_fstype $facet) == zfs ]]; then
1087 # import ZFS storage pool
1088 import_zpool $facet || return ${PIPESTATUS[0]}
1091 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1092 # for testing LU-482 error handling in mount_facets() and test_0a()
1093 if [ -f $TMP/test-lu482-trigger ]; then
1096 do_facet ${facet} "mkdir -p $mntpt; mount -t lustre $opts \
1100 if [ $RC -ne 0 ]; then
1101 echo "Start of ${!dev} on ${facet} failed ${RC}"
1103 set_default_debug_facet $facet
1105 label=$(devicelabel ${facet} ${!dev})
1106 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1107 eval export ${facet}_svc=${label}
1108 echo Started ${label}
1113 # start facet device options
1119 eval export ${facet}_dev=${device}
1120 eval export ${facet}_opt=\"$@\"
1122 local varname=${facet}failover_dev
1123 if [ -n "${!varname}" ] ; then
1124 eval export ${facet}failover_dev=${!varname}
1126 eval export ${facet}failover_dev=$device
1129 local mntpt=$(facet_mntpt $facet)
1130 do_facet ${facet} mkdir -p $mntpt
1131 eval export ${facet}_MOUNT=$mntpt
1132 mount_facet ${facet}
1141 local HOST=`facet_active_host $facet`
1142 [ -z $HOST ] && echo stop: no host for $facet && return 0
1144 local mntpt=$(facet_mntpt $facet)
1145 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1146 if [ ${running} -ne 0 ]; then
1147 echo "Stopping $mntpt (opts:$@) on $HOST"
1148 do_facet ${facet} umount -d $@ $mntpt
1151 # umount should block, but we should wait for unrelated obd's
1152 # like the MGS or MGC to also stop.
1153 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1155 if [[ $(facet_fstype $facet) == zfs ]]; then
1156 # export ZFS storage pool
1161 # save quota version (both administrative and operational quotas)
1162 # add an additional parameter if mountpoint is ever different from $MOUNT
1164 # XXX This function is kept for interoperability with old server (< 2.3.50),
1165 # it should be removed whenever we drop the interoperability for such
1167 quota_save_version() {
1168 local fsname=${2:-$FSNAME}
1170 local ver=$(tr -c -d "123" <<< $spec)
1171 local type=$(tr -c -d "ug" <<< $spec)
1173 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1175 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1177 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1179 local osts=$(get_facets OST)
1180 for ost in ${osts//,/ }; do
1182 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1186 # client could mount several lustre
1188 # XXX This function is kept for interoperability with old server (< 2.3.50),
1189 # it should be removed whenever we drop the interoperability for such
1192 local fsname=${1:-$FSNAME}
1194 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1196 do_nodes $(comma_list $(osts_nodes)) \
1197 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1201 # XXX This function is kept for interoperability with old server (< 2.3.50),
1202 # it should be removed whenever we drop the interoperability for such
1204 restore_quota_old() {
1205 local mntpt=${1:-$MOUNT}
1206 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
1207 if [ ! "$old_QUOTA_TYPE" ] ||
1208 [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
1211 quota_save_version $old_QUOTA_TYPE
1214 # XXX This function is kept for interoperability with old server (< 2.3.50),
1215 # it should be removed whenever we drop the interoperability for such
1220 # no quota enforcement for now and accounting works out of the box
1223 # We need save the original quota_type params, and restore them after testing
1225 # Suppose that quota type the same on mds and ost
1226 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
1227 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
1228 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
1229 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
1230 export old_QUOTA_TYPE=$quota_type
1231 quota_save_version $QUOTA_TYPE
1233 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
1234 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
1237 local quota_usrs=$QUOTA_USERS
1239 # get_filesystem_size
1240 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1241 local blk_soft=$((disksz + 1024))
1242 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1244 local Inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1245 local i_soft=$Inodes
1246 local i_hard=$((i_soft + i_soft / 20))
1248 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
1249 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
1252 for usr in $quota_usrs; do
1253 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1255 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1257 eval $cmd || error "$cmd FAILED!"
1259 # display the quota status
1260 echo "Quota settings for $usr : "
1261 $LFS quota -v -u $usr $mntpt || true
1265 # get mdt quota type
1267 local varsvc=${SINGLEMDS}_svc
1268 do_facet $SINGLEMDS $LCTL get_param -n \
1269 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1272 # get ost quota type
1274 # All OSTs should have same quota type
1275 local varsvc=ost1_svc
1276 do_facet ost1 $LCTL get_param -n \
1277 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1280 # restore old quota type settings
1282 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1287 if [ "$old_MDT_QUOTA_TYPE" ]; then
1288 do_facet mgs $LCTL conf_param \
1289 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1291 if [ "$old_OST_QUOTA_TYPE" ]; then
1292 do_facet mgs $LCTL conf_param \
1293 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1297 # Handle the case when there is a space in the lfs df
1298 # "filesystem summary" line the same as when there is no space.
1299 # This will allow fixing the "lfs df" summary line in the future.
1301 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1304 # Get free inodes on the MDT specified by mdt index, free indoes on
1305 # the whole filesystem will be returned when index == -1.
1311 if [ $index -eq -1 ]; then
1314 mdt_uuid=$(mdtuuid_from_index $index)
1317 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1322 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1329 # save old quota type & set new quota type
1330 local mdt_qtype=$(mdt_quota_type)
1331 local ost_qtype=$(ost_quota_type)
1333 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1334 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1336 export old_MDT_QUOTA_TYPE=$mdt_qtype
1337 export old_OST_QUOTA_TYPE=$ost_qtype
1339 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1340 error "set mdt quota type failed"
1341 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1342 error "set ost quota type failed"
1344 local quota_usrs=$QUOTA_USERS
1346 # get_filesystem_size
1347 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1348 local blk_soft=$((disksz + 1024))
1349 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1351 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1352 local i_soft=$inodes
1353 local i_hard=$((i_soft + i_soft / 20))
1355 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1356 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1357 "inode-hardlimit: $i_hard"
1360 for usr in $quota_usrs; do
1361 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1363 cmd="$LFS setquota -$type $usr -b $blk_soft"
1364 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1366 eval $cmd || error "$cmd FAILED!"
1368 # display the quota status
1369 echo "Quota settings for $usr : "
1370 $LFS quota -v -u $usr $mntpt || true
1377 local OPTIONS=${3:-$MOUNTOPT}
1379 local device=$MGSNID:/$FSNAME
1380 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1381 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
1385 echo "Starting client: $client: $OPTIONS $device $mnt"
1386 do_node $client mkdir -p $mnt
1387 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
1389 set_default_debug_nodes $client
1401 [ "$3" ] && force=-f
1402 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1403 if [ $running -ne 0 ]; then
1404 echo "Stopping client $client $mnt (opts:$force)"
1405 do_node $client lsof -t $mnt || need_kill=no
1406 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1407 pids=$(do_node $client lsof -t $mnt | sort -u);
1408 if [ -n $pids ]; then
1409 do_node $client kill -9 $pids || true
1413 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1414 if [ $busy -ne 0 ] ; then
1415 echo "$mnt is still busy, wait one second" && sleep 1
1416 do_node $client umount $force $mnt
1421 # nodes is comma list
1422 sanity_mount_check_nodes () {
1428 # FIXME: assume that all cluster nodes run the same os
1429 [ "$(uname)" = Linux ] || return 0
1432 for mnt in $mnts ; do
1433 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1434 mpts=\\\$(mount | grep -c $mnt' ');
1435 if [ \\\$running -ne \\\$mpts ]; then
1436 echo \\\$(hostname) env are INSANE!;
1439 [ $? -eq 0 ] || rc=1
1444 sanity_mount_check_servers () {
1445 [ "$CLIENTONLY" ] &&
1446 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1447 echo Checking servers environments
1449 # FIXME: modify get_facets to display all facets wo params
1450 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1454 for facet in ${facets//,/ }; do
1455 node=$(facet_host ${facet})
1456 mntpt=$(facet_mntpt $facet)
1457 sanity_mount_check_nodes $node $mntpt ||
1458 { error "server $node environments are insane!"; return 1; }
1462 sanity_mount_check_clients () {
1463 local clients=${1:-$CLIENTS}
1464 local mntpt=${2:-$MOUNT}
1465 local mntpt2=${3:-$MOUNT2}
1467 [ -z $clients ] && clients=$(hostname)
1468 echo Checking clients $clients environments
1470 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1471 error "clients environments are insane!"
1474 sanity_mount_check () {
1475 sanity_mount_check_servers || return 1
1476 sanity_mount_check_clients || return 2
1479 # mount clients if not mouted
1480 zconf_mount_clients() {
1483 local OPTIONS=${3:-$MOUNTOPT}
1485 local device=$MGSNID:/$FSNAME
1486 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1487 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
1491 echo "Starting client $clients: $OPTIONS $device $mnt"
1494 running=\\\$(mount | grep -c $mnt' ');
1496 if [ \\\$running -eq 0 ] ; then
1498 mount -t lustre $OPTIONS $device $mnt;
1501 exit \\\$rc" || return ${PIPESTATUS[0]}
1503 echo "Started clients $clients: "
1504 do_nodes $clients "mount | grep $mnt' '"
1506 set_default_debug_nodes $clients
1511 zconf_umount_clients() {
1516 [ "$3" ] && force=-f
1518 echo "Stopping clients: $clients $mnt (opts:$force)"
1519 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1520 if [ \\\$running -ne 0 ] ; then
1521 echo Stopping client \\\$(hostname) $mnt opts:$force;
1522 lsof $mnt || need_kill=no;
1523 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1524 pids=\\\$(lsof -t $mnt | sort -u);
1525 if [ -n \\\"\\\$pids\\\" ]; then
1529 while umount $force $mnt 2>&1 | grep -q "busy"; do
1530 echo "$mnt is still busy, wait one second" && sleep 1;
1537 echo + $POWER_DOWN $node
1541 shutdown_node_hard () {
1543 local attempts=$SHUTDOWN_ATTEMPTS
1545 for i in $(seq $attempts) ; do
1548 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1549 echo "waiting for $host to fail attempts=$attempts"
1550 [ $i -lt $attempts ] || \
1551 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1557 local mnt=${2:-$MOUNT}
1560 if [ "$FAILURE_MODE" = HARD ]; then
1561 shutdown_node_hard $client
1563 zconf_umount_clients $client $mnt -f
1569 local facets="$(get_facets OST),$(get_facets MDS)"
1572 combined_mgs_mds || facets="$facets,mgs"
1574 for facet in ${facets//,/ }; do
1575 if [ $(facet_active_host $facet) == $host ]; then
1576 affected="$affected $facet"
1580 echo $(comma_list $affected)
1585 local host=${2:-$(facet_host $facet)}
1587 local label=$(convert_facet2label $facet)
1588 do_node $host $LCTL dl | awk '{print $4}' | grep -q -x $label
1591 facets_up_on_host () {
1593 local facets=$(facets_on_host $host)
1596 for facet in ${facets//,/ }; do
1597 if $(facet_up $facet $host); then
1598 affected_up="$affected_up $facet"
1602 echo $(comma_list $affected_up)
1608 if [ "$FAILURE_MODE" = HARD ]; then
1609 shutdown_node_hard $(facet_active_host $facet)
1617 echo + $POWER_UP $node
1630 if [ "$FAILURE_MODE" = HARD ]; then
1631 reboot_node $(facet_active_host $facet)
1639 if [ "$FAILURE_MODE" = HARD ]; then
1649 for facet in ${facets//,/ }; do
1650 hosts=$(expand_list $hosts $(facet_host $facet) )
1656 _check_progs_installed () {
1660 for prog in $progs; do
1661 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1662 echo $prog missing on $(hostname)
1669 check_progs_installed () {
1673 do_rpc_nodes "$nodes" _check_progs_installed $@
1676 # recovery-scale functions
1678 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1681 start_client_load() {
1684 local var=$(node_var_name $client)_load
1685 eval export ${var}=$load
1687 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1688 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1689 END_RUN_FILE=$END_RUN_FILE \
1690 LOAD_PID_FILE=$LOAD_PID_FILE \
1691 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1692 TESTNAME=$TESTNAME \
1693 DBENCH_LIB=$DBENCH_LIB \
1694 DBENCH_SRC=$DBENCH_SRC \
1695 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1699 log "Started client load: ${load} on $client"
1701 # get the children process IDs
1702 local pids=$(ps --ppid $ppid -o pid= | xargs)
1703 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1707 start_client_loads () {
1708 local -a clients=(${1//,/ })
1709 local numloads=${#CLIENT_LOADS[@]}
1712 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1713 testnum=$((nodenum % numloads))
1714 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1716 # bug 22169: wait the background threads to start
1720 # only for remote client
1721 check_client_load () {
1723 local var=$(node_var_name $client)_load
1724 local TESTLOAD=run_${!var}.sh
1726 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1728 # bug 18914: try to connect several times not only when
1729 # check ps, but while check_catastrophe also
1732 while [ $RC = 254 -a $tries -gt 0 ]; do
1736 if ! check_catastrophe $client; then
1738 if [ $RC -eq 254 ]; then
1739 # FIXME: not sure how long we shuold sleep here
1743 echo "check catastrophe failed: RC=$RC "
1747 # We can continue try to connect if RC=254
1748 # Just print the warning about this
1749 if [ $RC = 254 ]; then
1750 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1753 # see if the load is still on the client
1756 while [ $RC = 254 -a $tries -gt 0 ]; do
1760 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1765 if [ $RC = 254 ]; then
1766 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1767 # see if we can diagnose a bit why this is
1772 check_client_loads () {
1773 local clients=${1//,/ }
1777 for client in $clients; do
1778 check_client_load $client
1780 if [ "$rc" != 0 ]; then
1781 log "Client load failed on node $client, rc=$rc"
1787 restart_client_loads () {
1788 local clients=${1//,/ }
1789 local expectedfail=${2:-""}
1793 for client in $clients; do
1794 check_client_load $client
1796 if [ "$rc" != 0 -a "$expectedfail" ]; then
1797 local var=$(node_var_name $client)_load
1798 start_client_load $client ${!var}
1799 echo "Restarted client load ${!var}: on $client. Checking ..."
1800 check_client_load $client
1802 if [ "$rc" != 0 ]; then
1803 log "Client load failed to restart on node $client, rc=$rc"
1804 # failure one client load means test fail
1805 # we do not need to check other
1814 # Start vmstat and save its process ID in a file.
1819 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1822 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1823 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1826 # Display the nodes on which client loads failed.
1827 print_end_run_file() {
1831 [ -s $file ] || return 0
1833 echo "Found the END_RUN_FILE file: $file"
1836 # A client load will stop if it finds the END_RUN_FILE file.
1837 # That does not mean the client load actually failed though.
1838 # The first node in END_RUN_FILE is the one we are interested in.
1841 if [ -n "$node" ]; then
1842 local var=$(node_var_name $node)_load
1844 local prefix=$TESTLOG_PREFIX
1845 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
1846 local stdout_log=$prefix.run_${!var}_stdout.$node.log
1847 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
1849 echo "Client load ${!var} failed on node $node:"
1855 # Stop the process which had its PID saved in a file.
1860 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1862 do_nodes $nodes "test -f $pid_file &&
1863 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
1866 # Stop all client loads.
1867 stop_client_loads() {
1868 local nodes=${1:-$CLIENTS}
1871 # stop the client loads
1872 stop_process $nodes $pid_file
1874 # clean up the processes that started them
1875 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
1877 # End recovery-scale functions
1879 # verify that lustre actually cleaned up properly
1881 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
1882 error "LBUG/LASSERT detected"
1883 BUSY=`dmesg | grep -i destruct || true`
1884 if [ "$BUSY" ]; then
1886 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
1890 check_mem_leak || exit 204
1892 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl &&
1893 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
1896 if module_loaded lnet || module_loaded libcfs; then
1897 echo "$TESTSUITE: modules still loaded..." 1>&2
1906 if [[ "$1" == "--verbose" ]]; then
1922 RESULT=$(do_node $node "$TEST")
1923 if [[ "$RESULT" == "$FINAL" ]]; then
1924 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
1925 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
1929 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
1930 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
1934 [[ $WAIT -ge $MAX ]] && break
1935 [[ $((WAIT % print)) -eq 0 ]] &&
1936 echo "Waiting $((MAX - WAIT)) secs for update"
1937 WAIT=$((WAIT + sleep))
1940 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
1944 wait_update_facet() {
1947 wait_update $(facet_active_host $facet) "$@"
1951 do_nodes $(comma_list $(mdts_nodes)) \
1952 "lctl set_param -n osd*.*MDT*.force_sync 1"
1953 do_nodes $(comma_list $(osts_nodes)) \
1954 "lctl set_param -n osd*.*OS*.force_sync 1" 2>&1 |
1955 grep -v 'Found no match'
1958 wait_delete_completed_mds() {
1959 local MAX_WAIT=${1:-20}
1961 local stime=`date +%s`
1966 # find MDS with pending deletions
1967 for node in $(mdts_nodes); do
1968 changes=$(do_node $node "lctl get_param -n osc.*MDT*.sync_*" \
1969 2>/dev/null | calc_sum)
1970 if [ -z "$changes" ] || [ $changes -eq 0 ]; then
1973 mds2sync="$mds2sync $node"
1975 if [ "$mds2sync" == "" ]; then
1978 mds2sync=$(comma_list $mds2sync)
1980 # sync MDS transactions
1981 do_nodes $mds2sync "lctl set_param -n osd*.*MD*.force_sync 1"
1983 # wait till all changes are sent and commmitted by OSTs
1984 # for ldiskfs space is released upon execution, but DMU
1985 # do this upon commit
1988 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
1989 changes=$(do_nodes $mds2sync "lctl get_param -n osc.*MDT*.sync_*" \
1991 #echo "$node: $changes changes on all"
1992 if [ "$changes" -eq "0" ]; then
1994 #echo "delete took $((etime - stime)) seconds"
2002 echo "Delete is not completed in $((etime - stime)) seconds"
2003 do_nodes $mds2sync "lctl get_param osc.*MDT*.sync_*"
2009 # we can use "for" here because we are waiting the slowest
2010 for host in ${hostlist//,/ }; do
2011 check_network "$host" 900
2013 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2020 for facet in ${facetlist//,/ }; do
2021 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2023 wait_for_host $hostlist
2026 _wait_recovery_complete () {
2029 # Use default policy if $2 is not passed by caller.
2030 local MAX=${2:-$(max_recovery_time)}
2035 while [ $WAIT -lt $MAX ]; do
2036 STATUS=$(lctl get_param -n $param | grep status)
2038 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2041 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2043 echo "$param recovery not done in $MAX sec. $STATUS"
2047 wait_recovery_complete () {
2050 # with an assumption that at_max is the same on all nodes
2051 local MAX=${2:-$(max_recovery_time)}
2054 if [ "$FAILURE_MODE" = HARD ]; then
2055 facets=$(facets_on_host $(facet_active_host $facet))
2057 echo affected facets: $facets
2059 # we can use "for" here because we are waiting the slowest
2060 for facet in ${facets//,/ }; do
2061 local var_svc=${facet}_svc
2062 local param="*.${!var_svc}.recovery_status"
2064 local host=$(facet_active_host $facet)
2065 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2069 wait_mds_ost_sync () {
2070 # just because recovery is done doesn't mean we've finished
2071 # orphan cleanup. Wait for llogs to get synchronized.
2072 echo "Waiting for orphan cleanup..."
2073 # MAX value includes time needed for MDS-OST reconnection
2074 local MAX=$(( TIMEOUT * 2 ))
2075 local WAIT_TIMEOUT=${1:-$MAX}
2078 local list=$(comma_list $(mdts_nodes))
2079 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2080 if ! do_facet $SINGLEMDS \
2081 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2083 # old way, use mds_sync
2085 list=$(comma_list $(osts_nodes))
2086 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2089 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2090 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2091 local -a sync=($(do_nodes $list "$cmd"))
2094 for ((i=0; i<${#sync[@]}; i++)); do
2096 [ ${sync[$i]} -eq 1 ] && continue
2098 [ ${sync[$i]} -eq 0 ] && continue
2100 # there is a not finished MDS-OST synchronization
2104 sleep 2 # increase waiting time and cover statfs cache
2105 [ ${con} -eq 1 ] && return 0
2106 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2110 # show which nodes are not finished.
2111 do_nodes $list "$cmd"
2112 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2116 wait_destroy_complete () {
2117 echo "Waiting for local destroys to complete"
2118 # MAX value shouldn't be big as this mean server responsiveness
2119 # never increase this just to make test pass but investigate
2120 # why it takes so long time
2123 while [ $WAIT -lt $MAX ]; do
2124 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2128 for ((i=0; i<${#RPCs[@]}; i++)); do
2129 [ ${RPCs[$i]} -eq 0 ] && continue
2130 # there are still some destroy RPCs in flight
2135 [ ${con} -eq 1 ] && return 0 # done waiting
2136 echo "Waiting ${WAIT}s for local destroys to complete"
2139 echo "Local destroys weren't done in $MAX sec."
2143 wait_delete_completed() {
2144 wait_delete_completed_mds $1 || return $?
2145 wait_destroy_complete
2154 # conf-sanity 31 takes a long time cleanup
2155 while [ $WAIT -lt 300 ]; do
2156 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2157 [ -z "${running}" ] && return 0
2158 echo "waited $WAIT for${running}"
2159 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2161 WAIT=$((WAIT + INTERVAL))
2163 echo "service didn't stop after $WAIT seconds. Still running:"
2168 wait_remote_prog () {
2174 [ "$PDSH" = "no_dsh" ] && return 0
2176 while [ $WAIT -lt $2 ]; do
2177 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2178 [ -z "${running}" ] && return 0 || true
2179 echo "waited $WAIT for: "
2181 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2183 WAIT=$((WAIT + INTERVAL))
2185 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2186 [ -z "$pids" ] && return 0
2187 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2188 # FIXME: not portable
2189 for pid in $pids; do
2190 cat /proc/${pid}/status || true
2191 cat /proc/${pid}/wchan || true
2193 kill -9 $pid || true
2202 # not every config has many clients
2204 if [ ! -z "$CLIENTS" ]; then
2205 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
2207 stat -f $MOUNT > /dev/null
2213 # usually checked on particular client or locally
2215 if [ ! -z "$client" ]; then
2216 $PDSH $client "stat -f $MOUNT" > /dev/null
2218 stat -f $MOUNT > /dev/null
2226 client_reconnect() {
2227 uname -n >> $MOUNT/recon
2228 if [ -z "$CLIENTS" ]; then
2229 df $MOUNT; uname -n >> $MOUNT/recon
2231 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
2233 echo Connected clients:
2235 ls -l $MOUNT/recon > /dev/null
2239 affected_facets () {
2242 local host=$(facet_active_host $facet)
2243 local affected=$facet
2245 if [ "$FAILURE_MODE" = HARD ]; then
2246 affected=$(facets_up_on_host $host)
2260 #Because it will only get up facets, we need get affected
2261 #facets before shutdown
2262 #For HARD Failure mode, it needs make sure facets on the same
2263 #HOST will only be shutdown and reboot once
2264 for facet in ${facets//,/ }; do
2265 local affected_facet
2267 #check whether facet has been included in other affected facets
2268 for ((index=0; index<$total; index++)); do
2269 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2272 if [ $skip -eq 0 ]; then
2273 affecteds[$total]=$(affected_facets $facet)
2278 for ((index=0; index<$total; index++)); do
2279 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2280 local host=$(facet_active_host $facet)
2281 echo "Failing ${affecteds[index]} on $host"
2282 shutdown_facet $facet
2285 for ((index=0; index<$total; index++)); do
2286 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2287 echo reboot facets: ${affecteds[index]}
2291 change_active ${affecteds[index]}
2293 wait_for_facet ${affecteds[index]}
2294 # start mgs first if it is affected
2295 if ! combined_mgs_mds &&
2296 list_member ${affecteds[index]} mgs; then
2297 mount_facet mgs || error "Restart of mgs failed"
2299 # FIXME; has to be changed to mount all facets concurrently
2300 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2301 echo mount facets: ${affecteds[index]}
2302 mount_facets ${affecteds[index]}
2312 do_facet $facet "sync; sync; sync"
2315 # make sure there will be no seq change
2316 local clients=${CLIENTS:-$HOSTNAME}
2317 local f=fsa-\\\$\(hostname\)
2318 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2319 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2321 local svc=${facet}_svc
2322 do_facet $facet $LCTL --device ${!svc} notransno
2324 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2325 # in-memory state has to be cleared by either rebooting the host or
2326 # exporting and reimporting the pool.
2328 # Although the uberblocks are not updated when a pool is freezed,
2329 # transactions are still written to the disks. Modified blocks may be
2330 # cached in memory when tests try reading them back. The
2331 # export-and-reimport process also evicts any cached pool data from
2332 # memory to provide the correct "data loss" semantics.
2334 # In the test framework, the exporting and importing operations are
2335 # handled by stop() and mount_facet() separately, which are used
2336 # inside fail() and fail_abort().
2338 do_facet $facet $LCTL --device ${!svc} readonly
2339 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2340 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2343 replay_barrier_nodf() {
2344 local facet=$1 echo running=${running}
2345 do_facet $facet "sync; sync; sync"
2346 local svc=${facet}_svc
2347 echo Replay barrier on ${!svc}
2348 do_facet $facet $LCTL --device ${!svc} notransno
2349 do_facet $facet $LCTL --device ${!svc} readonly
2350 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2351 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2354 replay_barrier_nosync() {
2355 local facet=$1 echo running=${running}
2356 local svc=${facet}_svc
2357 echo Replay barrier on ${!svc}
2358 do_facet $facet $LCTL --device ${!svc} notransno
2359 do_facet $facet $LCTL --device ${!svc} readonly
2360 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2361 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2365 # Get Lustre client uuid for a given Lustre mount point.
2368 local mntpnt=${1:-$MOUNT}
2370 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2371 local uuid=$($LCTL get_param -n llite.$name.uuid)
2376 mds_evict_client() {
2377 local mntpnt=${1:-$MOUNT}
2378 local uuid=$(get_client_uuid $mntpnt)
2380 do_facet $SINGLEMDS \
2381 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2384 ost_evict_client() {
2385 local mntpnt=${1:-$MOUNT}
2386 local uuid=$(get_client_uuid $mntpnt)
2389 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2394 local clients=${CLIENTS:-$HOSTNAME}
2396 facet_failover $* || error "failover: $?"
2397 wait_clients_import_state "$clients" "$facets" FULL
2398 clients_up || error "post-failover df: $?"
2403 facet_failover $facet
2409 change_active $facet
2410 wait_for_facet $facet
2411 mount_facet $facet -o abort_recovery
2412 clients_up || echo "first df failed: $?"
2413 clients_up || error "post-failover df: $?"
2417 echo There is no lmc. This is mountconf, baby.
2421 host_nids_address() {
2425 if [ -n "$kind" ]; then
2426 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2428 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2434 if [ "$1" = "'*'" ]; then echo \'*\'; else
2440 if [ "$1" = "'*'" ]; then echo \'*\'; else
2441 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2443 if [ -z "$ID" ]; then
2444 echo "Could not get a ptl id for $1..."
2453 h2name_or_ip "$1" "tcp"
2458 if [ "$1" = "'*'" ]; then echo \'*\'; else
2459 if type __h2elan >/dev/null 2>&1; then
2462 ID=`echo $1 | sed 's/[^0-9]*//g'`
2470 h2name_or_ip "$1" "o2ib"
2474 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2475 # expressions format. As a bonus we can then just pass in those variables
2476 # to pdsh. What this function does is take a HOSTLIST type string and
2477 # expand it into a space deliminated list for us.
2485 [ -z "$hostlist" ] && return
2487 # Translate the case of [..],..,[..] to [..] .. [..]
2488 list="${hostlist/],/] }"
2490 [[ "$front" == *,* ]] && {
2493 list=${list/${old}/${new}}
2496 for item in $list; do
2497 # Test if we have any []'s at all
2498 if [ "$item" != "${item/\[/}" ]; then {
2499 # Expand the [*] into list
2503 if [ "$name" != "$item" ]; then
2504 group=${item#$name[*}
2507 for range in ${group//,/ }; do
2511 # Number of leading zeros
2514 end=$(echo $end | sed 's/0*//')
2515 [[ -z "$end" ]] && end=0
2516 [[ $padlen2 -gt $padlen ]] && {
2517 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2520 begin=$(echo $begin | sed 's/0*//')
2521 [ -z $begin ] && begin=0
2523 for num in $(seq -f "%0${padlen}g" $begin $end); do
2524 value="${name#*,}${num}${back}"
2525 [ "$value" != "${value/\[/}" ] && {
2526 value=$(hostlist_expand "$value")
2528 myList="$myList $value"
2533 myList="$myList $item"
2536 myList=${myList//,/ }
2537 myList=${myList:1} # Remove first character which is a space
2539 # Filter any duplicates without sorting
2541 myList="${list%% *}"
2543 while [[ "$list" != ${myList##* } ]]; do
2544 list=${list//${list%% *} /}
2545 myList="$myList ${list%% *}"
2547 myList="${myList%* }";
2549 # We can select an object at a offset in the list
2552 for item in $myList; do
2554 [ $cnt -eq $offset ] && {
2558 [ $(get_node_count $myList) -ne 1 ] && myList=""
2567 [ "$facet" == client ] && echo -n $HOSTNAME && return
2568 varname=${facet}_HOST
2569 if [ -z "${!varname}" ]; then
2570 if [ "${facet:0:3}" == "ost" ]; then
2571 eval export ${facet}_HOST=${ost_HOST}
2572 elif [ "${facet:0:3}" == "mdt" -o \
2573 "${facet:0:3}" == "mds" -o \
2574 "${facet:0:3}" == "mgs" ]; then
2575 eval export ${facet}_HOST=${mds_HOST}
2581 facet_failover_host() {
2585 var=${facet}failover_HOST
2586 if [ -n "${!var}" ]; then
2591 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2592 "${facet:0:3}" == "mgs" ]; then
2594 eval export ${facet}failover_host=${mds_HOST}
2599 if [[ $facet == ost* ]]; then
2600 eval export ${facet}failover_host=${ost_HOST}
2608 local activevar=${facet}active
2610 if [ -f $TMP/${facet}active ] ; then
2611 source $TMP/${facet}active
2614 active=${!activevar}
2615 if [ -z "$active" ] ; then
2622 facet_active_host() {
2624 local active=`facet_active $facet`
2625 if [ "$facet" == client ]; then
2628 echo `facet_host $active`
2632 # Get the passive failover partner host of facet.
2633 facet_passive_host() {
2635 [[ $facet = client ]] && return
2637 local host=${facet}_HOST
2638 local failover_host=${facet}failover_HOST
2639 local active_host=$(facet_active_host $facet)
2641 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2643 if [[ $active_host = ${!host} ]]; then
2644 echo -n ${!failover_host}
2654 facetlist=$(exclude_items_from_list $facetlist mgs)
2656 for facet in ${facetlist//,/ }; do
2657 local failover=${facet}failover
2658 local host=`facet_host $failover`
2659 [ -z "$host" ] && return
2661 local curactive=`facet_active $facet`
2662 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2663 eval export ${facet}active=$facet
2665 eval export ${facet}active=$failover
2667 # save the active host for this facet
2668 local activevar=${facet}active
2669 echo "$activevar=${!activevar}" > $TMP/$activevar
2670 [[ $facet = mds1 ]] && combined_mgs_mds && \
2671 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2672 local TO=`facet_active_host $facet`
2673 echo "Failover $facet to $TO"
2679 # do not stripe off hostname if verbose, bug 19215
2680 if [ x$1 = x--verbose ]; then
2688 if [ "$HOST" = "$HOSTNAME" ]; then
2690 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2691 echo "cannot run remote command on $HOST with $myPDSH"
2695 echo "CMD: $HOST $@" >&2
2696 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2699 if [ "$myPDSH" = "rsh" ]; then
2700 # we need this because rsh does not return exit code of an executed command
2701 local command_status="$TMP/cs"
2702 rsh $HOST ":> $command_status"
2703 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2704 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2705 echo command failed >$command_status"
2706 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2711 # print HOSTNAME for myPDSH="no_dsh"
2712 if [[ $myPDSH = no_dsh ]]; then
2713 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2715 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2718 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2720 return ${PIPESTATUS[0]}
2724 do_node --verbose "$@"
2727 single_local_node () {
2728 [ "$1" = "$HOSTNAME" ]
2731 # Outputs environment variable assignments that should be passed to remote nodes
2735 local facets=$(get_facets)
2738 for var in ${!MODOPTS_*}; do
2740 echo -n " ${var}=\"$value\""
2743 for facet in ${facets//,/ }; do
2745 if [ -n "${!var}" ]; then
2746 echo -n " $var=${!var}"
2750 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2751 if [ -n "${!var}" ]; then
2752 echo -n " $var=${!var}"
2756 if [ -n "$FSTYPE" ]; then
2757 echo -n " FSTYPE=$FSTYPE"
2763 # do not stripe off hostname if verbose, bug 19215
2764 if [ x$1 = x--verbose ]; then
2772 if single_local_node $rnodes; then
2774 do_nodev $rnodes "$@"
2776 do_node $rnodes "$@"
2781 # This is part from do_node
2784 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2785 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2787 export FANOUT=$(get_node_count "${rnodes//,/ }")
2789 echo "CMD: $rnodes $@" >&2
2790 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2793 # do not replace anything from pdsh output if -N is used
2794 # -N Disable hostname: prefix on lines of output.
2795 if $verbose || [[ $myPDSH = *-N* ]]; then
2796 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2798 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2800 return ${PIPESTATUS[0]}
2806 local HOST=`facet_active_host $facet`
2807 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
2811 # Function: do_facet_random_file $FACET $FILE $SIZE
2812 # Creates FILE with random content on the given FACET of given SIZE
2814 do_facet_random_file() {
2818 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
2819 do_facet $facet "$cmd 2>/dev/null"
2822 do_facet_create_file() {
2826 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
2827 do_facet $facet "$cmd 2>/dev/null"
2831 do_nodes --verbose "$@"
2837 # make sure its not already running
2839 rm -f $TMP/${facet}active
2840 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
2841 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
2843 if [[ $(facet_fstype $facet) == zfs ]]; then
2845 # After formatting a ZFS target, "cachefile=none" property will
2846 # be set on the ZFS storage pool so that the pool is not
2847 # automatically imported on system startup. And then the pool
2848 # will be exported so as to leave the importing and exporting
2849 # operations handled by mount_facet() and stop() separately.
2851 refresh_partition_table $facet $(facet_vdevice $facet)
2852 disable_zpool_cache $facet
2861 local fstype=$(facet_fstype ost$num)
2865 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2866 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2868 #dataset name is independent of vdev device names
2869 eval DEVPTR=${FSNAME}-ost${num}/ost${num};;
2871 error "unknown fstype!";;
2881 local fstype=$(facet_fstype ost$num)
2885 # vdevs are not supported by ldiskfs
2888 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2889 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2891 error "unknown fstype!";;
2901 local fstype=$(facet_fstype mds$num)
2905 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
2906 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
2908 #dataset name is independent of vdev device names
2909 eval DEVPTR=${FSNAME}-mdt${num}/mdt${num};;
2911 error "unknown fstype!";;
2921 local fstype=$(facet_fstype mds$num)
2925 # vdevs are not supported by ldiskfs
2928 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
2929 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
2931 error "unknown fstype!";;
2939 local fstype=$(facet_fstype mgs)
2943 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
2944 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
2945 DEVPTR=$(mdsdevname 1)
2950 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
2951 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsvdevname 1) ] ); then
2952 DEVPTR=$(mdsdevname 1)
2954 DEVPTR=${FSNAME}-mgs/mgs
2957 error "unknown fstype!";;
2967 local fstype=$(facet_fstype mgs)
2971 # vdevs are not supported by ldiskfs
2974 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
2975 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsvdevname 1) ] ); then
2976 VDEVPTR=$(mdsvdevname 1)
2981 error "unknown fstype!";;
2989 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
2991 local var=${facet}_MOUNT
2992 eval mntpt=${!var:-${MOUNT%/*}/$facet}
3001 # make sure we are using the primary server, so test-framework will
3002 # be able to clean up properly.
3003 activemds=`facet_active mds1`
3004 if [ $activemds != "mds1" ]; then
3008 local clients=$CLIENTS
3009 [ -z $clients ] && clients=$(hostname)
3011 zconf_umount_clients $clients $MOUNT "$*" || true
3012 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3014 [ "$CLIENTONLY" ] && return
3015 # The add fn does rm ${facet}active file, this would be enough
3016 # if we use do_facet <facet> only after the facet added, but
3017 # currently we use do_facet mds in local.sh
3018 for num in `seq $MDSCOUNT`; do
3020 rm -f ${TMP}/mds${num}active
3022 combined_mgs_mds && rm -f $TMP/mgsactive
3024 for num in `seq $OSTCOUNT`; do
3026 rm -f $TMP/ost${num}active
3029 if ! combined_mgs_mds ; then
3036 cleanup_echo_devs () {
3037 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3039 for dev in $devs; do
3040 $LCTL --device $dev cleanup
3041 $LCTL --device $dev detach
3046 nfs_client_mode && return
3055 combined_mgs_mds () {
3056 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3057 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3061 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3065 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3071 local fsname=${3:-"$FSNAME"}
3072 local type=$(facet_type $facet)
3073 local index=$(($(facet_number $facet) - 1))
3074 local fstype=$(facet_fstype $facet)
3075 local host=$(facet_host $facet)
3080 if [ $type == MGS ] && combined_mgs_mds; then
3084 if [ $type == MGS ] || ( [ $type == MDS ] &&
3085 [ "$dev" == $(mgsdevname) ] &&
3086 [ "$host" == "$(facet_host mgs)" ] ); then
3089 opts="--mgsnode=$MGSNID"
3092 if [ $type != MGS ]; then
3093 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3097 var=${facet}failover_HOST
3098 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3099 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3102 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3103 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3105 if [ $type == MDS ]; then
3106 opts+=${SECLEVEL:+" --param=mdt.sec_level"}
3107 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3108 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3109 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3110 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3112 if [ $fstype == ldiskfs ]; then
3113 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3114 if [ ! -z $EJOURNAL ]; then
3115 fs_mkfs_opts+=${MDSJOURNALSIZE:+" device=$EJOURNAL"}
3117 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3121 if [ $type == OST ]; then
3122 opts+=${SECLEVEL:+" --param=ost.sec_level"}
3123 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3125 if [ $fstype == ldiskfs ]; then
3126 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3130 opts+=" --backfstype=$fstype"
3133 if [ -n "${!var}" ]; then
3134 opts+=" --device-size=${!var}"
3137 var=$(upper $fstype)_MKFS_OPTS
3138 fs_mkfs_opts+=${!var:+" ${!var}"}
3140 var=${type}_FS_MKFS_OPTS
3141 fs_mkfs_opts+=${!var:+" ${!var}"}
3143 if [ -n "${fs_mkfs_opts## }" ]; then
3144 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3148 opts+=${!var:+" ${!var}"}
3161 # We need ldiskfs here, may as well load them all
3163 [ "$CLIENTONLY" ] && return
3164 echo Formatting mgs, mds, osts
3165 if ! combined_mgs_mds ; then
3166 echo "Format mgs: $(mgsdevname)"
3167 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3168 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} ||
3172 for num in $(seq $MDSCOUNT); do
3173 echo "Format mds$num: $(mdsdevname $num)"
3174 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3175 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3176 ${quiet:+>/dev/null} || exit 10
3179 for num in $(seq $OSTCOUNT); do
3180 echo "Format ost$num: $(ostdevname $num)"
3181 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3182 --reformat $(ostdevname $num) $(ostvdevname ${num}) \
3183 ${quiet:+>/dev/null} || exit 10
3188 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3192 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3196 # 0: success, the old identity set already.
3197 # 1: success, the old identity does not set.
3202 local j=`expr $num - 1`
3203 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3205 if [ -z "$MDT" ]; then
3209 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3212 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3214 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3217 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3219 if [ $old = "NONE" ]; then
3228 zconf_umount `hostname` $1 || error "umount failed"
3229 zconf_mount `hostname` $1 || error "mount failed"
3237 rm -f $TMP/${facet}active
3238 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3243 local mdt_count=${1:-$MDSCOUNT}
3244 local ost_count=${2:-$OSTCOUNT}
3247 for num in $(seq $mdt_count); do
3248 DEVNAME=$(mdsdevname $num)
3249 writeconf_facet mds$num $DEVNAME || rc=$?
3252 for num in $(seq $ost_count); do
3253 DEVNAME=$(ostdevname $num)
3254 writeconf_facet ost$num $DEVNAME || rc=$?
3260 nfs_client_mode && return
3262 sanity_mount_check ||
3263 error "environments are insane!"
3267 if [ -z "$CLIENTONLY" ]; then
3268 echo Setup mgs, mdt, osts
3269 echo $WRITECONF | grep -q "writeconf" && \
3271 if ! combined_mgs_mds ; then
3272 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3275 for num in `seq $MDSCOUNT`; do
3276 DEVNAME=$(mdsdevname $num)
3277 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3279 # We started mds, now we should set failover variables properly.
3280 # Set mds${num}failover_HOST if it is not set (the default failnode).
3281 local varname=mds${num}failover_HOST
3282 if [ -z "${!varname}" ]; then
3283 eval mds${num}failover_HOST=$(facet_host mds$num)
3286 if [ $IDENTITY_UPCALL != "default" ]; then
3287 switch_identity $num $IDENTITY_UPCALL
3290 for num in `seq $OSTCOUNT`; do
3291 DEVNAME=$(ostdevname $num)
3292 start ost$num $DEVNAME $OST_MOUNT_OPTS
3294 # We started ost$num, now we should set ost${num}failover variable properly.
3295 # Set ost${num}failover_HOST if it is not set (the default failnode).
3296 varname=ost${num}failover_HOST
3297 if [ -z "${!varname}" ]; then
3298 eval ost${num}failover_HOST=$(facet_host ost${num})
3306 # wait a while to allow sptlrpc configuration be propogated to targets,
3307 # only needed when mounting new target devices.
3312 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3314 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3317 if [ "$MOUNT_2" ]; then
3318 mount_client $MOUNT2
3319 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3324 # by remounting mdt before ost, initial connect from mdt to ost might
3325 # timeout because ost is not ready yet. wait some time to its fully
3326 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3327 # by a context negotiation rpc with $TIMEOUT.
3328 # FIXME better by monitoring import status.
3331 sleep $((TIMEOUT + 5))
3337 mounted_lustre_filesystems() {
3338 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3341 init_facet_vars () {
3342 [ "$CLIENTONLY" ] && return 0
3349 eval export ${facet}_dev=${device}
3350 eval export ${facet}_opt=\"$@\"
3352 local dev=${facet}_dev
3354 # We need to loop for the label
3355 # in case its not initialized yet.
3356 for wait_time in {0,1,3,5,10}; do
3358 if [ $wait_time -gt 0 ]; then
3359 echo "${!dev} not yet initialized,"\
3360 "waiting ${wait_time} seconds."
3364 local label=$(devicelabel ${facet} ${!dev})
3366 # Check to make sure the label does
3367 # not include ffff at the end of the label.
3368 # This indicates it has not been initialized yet.
3370 if [[ $label =~ [f|F]{4}$ ]]; then
3371 # label is not initialized, unset the result
3372 # and either try again or fail
3379 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3381 eval export ${facet}_svc=${label}
3383 local varname=${facet}failover_HOST
3384 if [ -z "${!varname}" ]; then
3385 eval export $varname=$(facet_host $facet)
3388 varname=${facet}_HOST
3389 if [ -z "${!varname}" ]; then
3390 eval export $varname=$(facet_host $facet)
3393 # ${facet}failover_dev is set in cfg file
3394 varname=${facet}failover_dev
3395 if [ -n "${!varname}" ] ; then
3396 eval export ${facet}failover_dev=${!varname}
3398 eval export ${facet}failover_dev=$device
3401 # get mount point of already mounted device
3402 # is facet_dev is already mounted then use the real
3403 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3404 # i.e. ${facet}_MOUNT if specified by user or default
3405 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3406 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3407 if [ -z $mntpt ]; then
3408 mntpt=$(facet_mntpt $facet)
3410 eval export ${facet}_MOUNT=$mntpt
3413 init_facets_vars () {
3416 if ! remote_mds_nodsh; then
3417 for num in $(seq $MDSCOUNT); do
3418 DEVNAME=`mdsdevname $num`
3419 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3423 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3425 if ! remote_ost_nodsh; then
3426 for num in $(seq $OSTCOUNT); do
3427 DEVNAME=$(ostdevname $num)
3428 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3433 osc_ensure_active () {
3438 while [ $period -lt $timeout ]; do
3439 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3440 if [ $count -eq 0 ]; then
3444 echo "There are $count OST are inactive, wait $period seconds, and try again"
3446 period=$((period+3))
3449 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3452 set_conf_param_and_check() {
3456 local ORIG=$(do_facet $myfacet "$TEST")
3457 if [ $# -gt 3 ]; then
3463 echo "Setting $PARAM from $ORIG to $FINAL"
3464 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3465 error "conf_param $PARAM failed"
3467 wait_update $(facet_host $myfacet) "$TEST" "$FINAL" ||
3468 error "check $PARAM failed!"
3471 init_param_vars () {
3473 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3475 log "Using TIMEOUT=$TIMEOUT"
3477 osc_ensure_active $SINGLEMDS $TIMEOUT
3478 osc_ensure_active client $TIMEOUT
3480 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
3481 local current_jobid_var=$($LCTL get_param -n jobid_var)
3483 if [ $JOBID_VAR = "existing" ]; then
3484 echo "keeping jobstats as $current_jobid_var"
3485 elif [ $current_jobid_var != $JOBID_VAR ]; then
3486 echo "seting jobstats to $JOBID_VAR"
3488 set_conf_param_and_check client \
3489 "$LCTL get_param -n jobid_var" \
3490 "$FSNAME.sys.jobid_var" $JOBID_VAR
3493 echo "jobstats not supported by server"
3496 if [ $QUOTA_AUTO -ne 0 ]; then
3497 if [ "$ENABLE_QUOTA" ]; then
3498 echo "enable quota as required"
3499 setup_quota $MOUNT || return 2
3501 echo "disable quota as required"
3502 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
3508 nfs_client_mode () {
3509 if [ "$NFSCLIENT" ]; then
3510 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
3511 local clients=$CLIENTS
3512 [ -z $clients ] && clients=$(hostname)
3514 # FIXME: remove hostname when 19215 fixed
3515 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
3516 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
3517 if [[ ${#nfsexport[@]} -eq 0 ]]; then
3518 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
3520 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
3526 check_config_client () {
3529 local mounted=$(mount | grep " $mntpt ")
3530 if [ "$CLIENTONLY" ]; then
3532 # CLIENTONLY should not depend on *_HOST settings
3533 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
3534 # in theory someone could create a new,
3535 # client-only config file that assumed lustre was already
3536 # configured and didn't set the MGSNID. If MGSNID is not set,
3537 # then we should use the mgs nid currently being used
3538 # as the default value. bug 18021
3539 [[ x$MGSNID = x ]] &&
3542 if [[ x$mgc != xMGC$MGSNID ]]; then
3543 if [ "$mgs_HOST" ]; then
3544 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
3545 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
3546 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
3552 local myMGS_host=$mgs_HOST
3553 if [ "$NETTYPE" = "ptl" ]; then
3554 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
3557 echo Checking config lustre mounted on $mntpt
3558 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
3559 mgshost=$(echo $mgshost | awk -F: '{print $1}')
3561 # if [ "$mgshost" != "$myMGS_host" ]; then
3562 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
3563 # Please use correct config or set mds_HOST correctly!"
3568 check_config_clients () {
3569 local clients=${CLIENTS:-$HOSTNAME}
3572 nfs_client_mode && return
3574 do_rpc_nodes "$clients" check_config_client $mntpt
3576 sanity_mount_check || error "environments are insane!"
3580 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3581 local cltimeout=$(lctl get_param -n timeout)
3582 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
3583 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
3590 [ -z $mntpt ] && return 1
3591 local mounted=$(mounted_lustre_filesystems)
3593 echo $mounted' ' | grep -w -q $mntpt' '
3597 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
3601 # empty lustre filesystem may have empty directories lost+found and .lustre
3603 # exclude .lustre & lost+found
3604 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
3605 -print | wc -l) = 1 ] || return 1
3606 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
3607 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
3608 # exclude .lustre/fid (LU-2780)
3609 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
3610 -print | wc -l) = 1 ] || return 1
3612 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
3617 check_and_setup_lustre() {
3618 nfs_client_mode && return
3620 local MOUNTED=$(mounted_lustre_filesystems)
3624 # both MOUNT and MOUNT2 are not mounted
3625 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
3626 [ "$REFORMAT" ] && formatall
3627 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
3629 is_mounted $MOUNT || error "NAME=$NAME not mounted"
3630 export I_MOUNTED=yes
3634 elif is_mounted $MOUNT2; then
3636 # MOUNT2 is mounted, while MOUNT_2 is not set
3637 if ! [ "$MOUNT_2" ]; then
3638 cleanup_mount $MOUNT2
3639 export I_UMOUNTED2=yes
3642 # MOUNT2 is mounted, MOUNT_2 is set
3644 # FIXME: what to do if check_config failed?
3646 # 1) remote client has mounted other Lustre fs ?
3647 # 2) it has insane env ?
3648 # let's try umount MOUNT2 on all clients and mount it again:
3649 if ! check_config_clients $MOUNT2; then
3650 cleanup_mount $MOUNT2
3651 restore_mount $MOUNT2
3652 export I_MOUNTED2=yes
3657 # MOUNT is mounted MOUNT2 is not mounted
3658 elif [ "$MOUNT_2" ]; then
3659 restore_mount $MOUNT2
3660 export I_MOUNTED2=yes
3664 # FIXME: what to do if check_config failed?
3666 # 1) remote client has mounted other Lustre fs?
3667 # 2) lustre is mounted on remote_clients atall ?
3668 check_config_clients $MOUNT
3672 set_default_debug_nodes $(comma_list $(nodes_list))
3675 if [ $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ] ; then
3677 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
3678 facets="$(get_facets OST)"
3679 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
3680 facets="$facets,$(get_facets MDS)"
3681 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
3682 facets="$facets,mgs"
3683 local nodes="$(facets_hosts ${facets})"
3684 if [ -n "$nodes" ] ; then
3685 do_nodes $nodes "$LCTL set_param \
3686 osd-ldiskfs.track_declares_assert=1 || true"
3695 if [ "$ONLY" == "setup" ]; then
3701 local clients=${CLIENTS:-$HOSTNAME}
3704 zconf_mount_clients $clients $mntpt
3708 local clients=${CLIENTS:-$HOSTNAME}
3711 zconf_umount_clients $clients $mntpt
3714 cleanup_and_setup_lustre() {
3715 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
3716 lctl set_param debug=0 || true
3718 if [ "$ONLY" == "cleanup" ]; then
3722 check_and_setup_lustre
3725 # Get all of the server target devices from a given server node and type.
3732 if [ "$type" == ost ]; then
3733 devs=$(get_osd_param $node "" mntdev)
3735 devs=$(do_node $node \
3736 "lctl get_param -n osd-*.$FSNAME-M*.mntdev")
3738 for dev in $devs; do
3740 *loop*) do_node $node "losetup $dev" | \
3741 sed -e "s/.*(//" -e "s/).*//" ;;
3747 # Get all of the server target devices.
3752 MDTDEV=$(get_mnt_devs $(mdts_nodes) mdt)
3756 for node in $(osts_nodes); do
3757 OSTDEVS[i]=$(get_mnt_devs $node ost)
3762 # Run e2fsck on MDT or OST device.
3768 df > /dev/null # update statfs data on disk
3769 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
3772 do_node $node $cmd || rc=$?
3773 [ $rc -le $FSCK_MAX_ERR ] || \
3774 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
3779 # Run resize2fs on MDT or OST device.
3788 do_facet $facet "$RESIZE2FS $opts $device $size"
3791 # verify a directory is shared among nodes.
3792 check_shared_dir() {
3794 local list=${2:-$(comma_list $(nodes_list))}
3796 [ -z "$dir" ] && return 1
3797 do_rpc_nodes "$list" check_logdir $dir
3798 check_write_access $dir "$list" || return 1
3802 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
3808 [[ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]] ||
3809 { skip "Lustre 2.2.0 lacks the patch for LU-1255"; exit 0; }
3811 check_shared_dir $SHARED_DIRECTORY ||
3812 error "$SHARED_DIRECTORY isn't a shared directory"
3814 export MDSDB=$SHARED_DIRECTORY/mdsdb
3815 export OSTDB=$SHARED_DIRECTORY/ostdb
3817 [ $MDSCOUNT -eq 1 ] || error "CMD is not supported"
3819 run_e2fsck $(mdts_nodes) $MDTDEV "-n --mdsdb $MDSDB"
3824 for node in $(osts_nodes); do
3825 for dev in ${OSTDEVS[i]}; do
3826 run_e2fsck $node $dev "-n --mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
3827 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
3828 ostidx=$((ostidx + 1))
3834 # Run lfsck on server node if lfsck can't be found on client (LU-2571)
3835 run_lfsck_remote() {
3836 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
3841 #Check if lustre is already mounted
3842 do_rpc_nodes $client is_mounted $MOUNT || mounted=false
3844 zconf_mount $client $MOUNT ||
3845 error "failed to mount Lustre on $client"
3849 do_node $node $cmd || rc=$?
3850 #Umount if necessary
3852 zconf_umount $client $MOUNT ||
3853 error "failed to unmount Lustre on $client"
3856 [ $rc -le $FSCK_MAX_ERR ] ||
3857 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
3858 echo "lfsck finished with rc=$rc"
3864 local facets="client $SINGLEMDS"
3870 for facet in $facets; do
3871 node=$(facet_active_host $facet)
3872 if check_progs_installed $node $LFSCK_BIN; then
3877 ! $found && error "None of \"$facets\" supports lfsck"
3879 run_lfsck_remote $node || rc=$?
3881 rm -rvf $MDSDB* $OSTDB* || true
3885 check_and_cleanup_lustre() {
3886 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
3892 if is_mounted $MOUNT; then
3893 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
3894 error "remove sub-test dirs failed"
3895 [ "$ENABLE_QUOTA" ] && restore_quota || true
3898 if [ "$I_UMOUNTED2" = "yes" ]; then
3899 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
3902 if [ "$I_MOUNTED2" = "yes" ]; then
3903 cleanup_mount $MOUNT2
3906 if [ "$I_MOUNTED" = "yes" ]; then
3907 cleanupall -f || error "cleanup failed"
3915 wait_for_function () {
3918 # suppress fn both stderr and stdout
3919 if [ "$1" = "--quiet" ]; then
3921 quiet=" > /dev/null 2>&1"
3933 eval $fn $quiet && return 0
3935 wait=$((wait + sleep))
3936 [ $wait -lt $max ] || return 1
3937 echo waiting $fn, $((max - wait)) secs left ...
3947 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
3948 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
3949 echo "Network not available!"
3953 echo `date +"%H:%M:%S (%s)"` network interface is UP
3961 # Convert a space-delimited list to a comma-delimited list. If the input is
3962 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
3964 # echo is used to convert newlines to spaces, since it doesn't
3965 # introduce a trailing space as using "tr '\n' ' '" does
3966 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
3972 echo $list | grep -qw $item
3975 # list, excluded are the comma separated lists
3976 exclude_items_from_list () {
3982 for item in ${excluded//,/ }; do
3983 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
3985 echo $(comma_list $list)
3988 # list, expand are the comma separated lists
3990 local list=${1//,/ }
3991 local expand=${2//,/ }
3994 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
3995 echo $(comma_list $expanded)
3998 testslist_filter () {
3999 local script=$LUSTRE/tests/${TESTSUITE}.sh
4001 [ -f $script ] || return 0
4003 local start_at=$START_AT
4004 local stop_at=$STOP_AT
4006 local var=${TESTSUITE//-/_}_START_AT
4007 [ x"${!var}" != x ] && start_at=${!var}
4008 var=${TESTSUITE//-/_}_STOP_AT
4009 [ x"${!var}" != x ] && stop_at=${!var}
4011 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4012 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4013 /^'${start_at}'$/ {flag = 0}
4014 {if (flag == 1) print $0}
4015 /^'${stop_at}'$/ { flag = 1 }'
4019 (cd `dirname $1`; echo $PWD/`basename $1`)
4023 local types=${1:-"OST MDS MGS"}
4027 for entry in $types; do
4028 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4029 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4032 MGS ) list="$list $name";;
4033 MDS|OST|AGT ) local count=${type}COUNT
4034 for ((i=1; i<=${!count}; i++)) do
4035 list="$list ${name}$i"
4037 * ) error "Invalid facet type"
4041 echo $(comma_list $list)
4044 ##################################
4045 # Adaptive Timeouts funcs
4048 # only check mds, we assume at_max is the same on all nodes
4049 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4050 if [ $at_max -eq 0 ]; then
4061 # suppose that all ost-s have the same $at value set
4062 [ $facet != "ost" ] || facet=ost1
4064 do_facet $facet "lctl get_param -n $at"
4082 if [ $facet == "ost" ]; then
4083 facet=$(get_facets OST)
4084 elif [ $facet == "mds" ]; then
4085 facet=$(get_facets MDS)
4087 hosts=$(expand_list $hosts $(facets_hosts $facet))
4090 do_nodes $hosts lctl set_param at_max=$at_max
4093 ##################################
4097 # OBD_FAIL_MDS_ALL_REQUEST_NET
4099 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4100 do_facet client "$1" || RC=$?
4101 do_facet $SINGLEMDS lctl set_param fail_loc=0
4106 # OBD_FAIL_MDS_ALL_REPLY_NET
4108 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
4109 do_facet client "$@" || RC=$?
4110 do_facet $SINGLEMDS lctl set_param fail_loc=0
4114 drop_reint_reply() {
4115 # OBD_FAIL_MDS_REINT_NET_REP
4117 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
4118 do_facet client "$@" || RC=$?
4119 do_facet $SINGLEMDS lctl set_param fail_loc=0
4123 drop_update_reply() {
4124 # OBD_FAIL_UPDATE_OBJ_NET_REP
4128 do_facet mds${index} lctl set_param fail_loc=0x1701
4129 do_facet client "$@" || RC=$?
4130 do_facet mds${index} lctl set_param fail_loc=0
4135 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4137 do_facet ost1 lctl set_param fail_loc=0x214
4138 do_facet client "$1" || RC=$?
4139 do_facet client "sync"
4140 do_facet ost1 lctl set_param fail_loc=0
4144 drop_ldlm_cancel() {
4145 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4147 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4148 do_nodes $list lctl set_param fail_loc=0x304
4150 do_facet client "$@" || RC=$?
4152 do_nodes $list lctl set_param fail_loc=0
4156 drop_bl_callback() {
4157 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4159 do_facet client lctl set_param fail_loc=0x80000305
4160 do_facet client "$@" || RC=$?
4161 do_facet client lctl set_param fail_loc=0
4166 #define OBD_FAIL_LDLM_REPLY 0x30c
4168 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
4169 do_facet client "$@" || RC=$?
4170 do_facet $SINGLEMDS lctl set_param fail_loc=0
4178 echo "clearing fail_loc on $facet"
4179 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4182 set_nodes_failloc () {
4183 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
4186 cancel_lru_locks() {
4187 $LCTL mark "cancel_lru_locks $1 start"
4188 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
4189 $LCTL set_param -n $d=clear
4191 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
4192 $LCTL mark "cancel_lru_locks $1 stop"
4197 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4198 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4199 echo "$DEFAULT_LRU_SIZE"
4204 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4207 lru_resize_disable()
4209 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4214 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4215 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4216 echo there is still data in page cache $FILE ?
4217 lctl get_param -n $FILE
4225 DEBUGSAVE="$(lctl get_param -n debug)"
4229 [ -n "$DEBUGSAVE" ] && \
4230 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
4235 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4238 debug_size_restore() {
4239 [ -n "$DEBUG_SIZE_SAVED" ] && \
4240 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4244 start_full_debug_logging() {
4249 local DEBUG_SIZE=150
4251 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4252 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4255 stop_full_debug_logging() {
4260 # prints bash call stack
4263 for (( i=1; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4264 local s=${BASH_SOURCE[$i]}
4265 local l=${BASH_LINENO[$i-1]}
4266 local f=${FUNCNAME[$i]}
4267 echo " = $s:$l:$f()"
4271 ##################################
4273 ##################################
4276 local TYPE=${TYPE:-"FAIL"}
4279 # do not dump logs if $1=false
4280 if [ "x$1" = "xfalse" ]; then
4286 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4290 # We need to dump the logs on all nodes
4292 gather_logs $(comma_list $(nodes_list))
4296 [ "$TESTSUITELOG" ] &&
4297 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4298 if [ -z "$*" ]; then
4299 echo "error() without useful message, please fix" > $LOGDIR/err
4301 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4302 echo "$@" > $LOGDIR/ignore
4304 echo "$@" > $LOGDIR/err
4311 local log=$TESTSUITELOG
4313 [ -f "$log" ] && grep -q FAIL $log && status=1
4326 # use only if we are ignoring failures for this test, bugno required.
4327 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4328 # e.g. error_ignore bz5494 "your message" or
4329 # error_ignore LU-5494 "your message"
4331 local TYPE="IGNORE ($1)"
4336 error_and_remount() {
4338 remount_client $MOUNT
4343 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4348 log " SKIP: $TESTSUITE $TESTNAME $@"
4350 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4351 skip_logged $TESTNAME "$@"
4354 echo "$@" > $LOGDIR/skip
4357 [[ -n "$TESTSUITELOG" ]] &&
4358 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
4361 build_test_filter() {
4362 EXCEPT="$EXCEPT $(testslist_filter)"
4364 [ "$ONLY" ] && log "only running test `echo $ONLY`"
4368 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
4369 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
4370 [ "$EXCEPT_SLOW" ] && \
4371 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
4372 for E in $EXCEPT; do
4373 eval EXCEPT_${E}=true
4375 for E in $ALWAYS_EXCEPT; do
4376 eval EXCEPT_ALWAYS_${E}=true
4378 for E in $EXCEPT_SLOW; do
4379 eval EXCEPT_SLOW_${E}=true
4381 for G in $GRANT_CHECK_LIST; do
4382 eval GCHECK_ONLY_${G}=true
4387 if [[ $1 = [a-z]* ]]; then
4394 # print a newline if the last test was skipped
4395 export LAST_SKIPPED=
4396 export ALWAYS_SKIPPED=
4398 # Main entry into test-framework. This is called with the name and
4399 # description of a test. The name is used to find the function to run
4400 # the test using "test_$name".
4402 # This supports a variety of methods of specifying specific test to
4403 # run or not run. These need to be documented...
4408 export base=`basetest $1`
4409 if [ ! -z "$ONLY" ]; then
4411 if [ ${!testname}x != x ]; then
4412 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4413 run_one_logged $1 "$2"
4417 if [ ${!testname}x != x ]; then
4418 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4419 run_one_logged $1 "$2"
4429 if [ ${!testname}x != x ]; then
4430 TESTNAME=test_$1 skip "skipping excluded test $1"
4433 testname=EXCEPT_$base
4434 if [ ${!testname}x != x ]; then
4435 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
4438 testname=EXCEPT_ALWAYS_$1
4439 if [ ${!testname}x != x ]; then
4440 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
4443 testname=EXCEPT_ALWAYS_$base
4444 if [ ${!testname}x != x ]; then
4445 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
4448 testname=EXCEPT_SLOW_$1
4449 if [ ${!testname}x != x ]; then
4450 TESTNAME=test_$1 skip "skipping SLOW test $1"
4453 testname=EXCEPT_SLOW_$base
4454 if [ ${!testname}x != x ]; then
4455 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
4461 run_one_logged $1 "$2"
4468 module_loaded lnet || load_modules
4480 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
4485 strace -o $TMP/$1.strace -ttt $*
4487 log "FINISHED: $*: rc $RC"
4494 banner test complete, duration $duration sec
4495 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
4496 echo duration $duration >>$TESTSUITELOG
4500 # Set TEST_STATUS here. It will be used for logging the result.
4503 if [[ -f $LOGDIR/err ]]; then
4505 elif [[ -f $LOGDIR/skip ]]; then
4508 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
4512 local FFREE=$(do_node $SINGLEMDS \
4513 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
4514 local FTOTAL=$(do_node $SINGLEMDS \
4515 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
4517 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
4521 echo -n "Resetting fail_loc on all nodes..."
4522 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
4528 # Log a message (on all nodes) padded with "=" before and after.
4529 # Also appends a timestamp and prepends the testsuite name.
4532 EQUALS="===================================================================================================="
4534 msg="== ${TESTSUITE} $*"
4536 [[ $last != "=" && $last != " " ]] && msg="$msg "
4537 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
4538 # always include at least == after the message
4539 log "$msg== $(date +"%H:%M:%S (%s)")"
4543 # Run a single test function and cleanup after it.
4545 # This function should be run in a subshell so the test func can
4546 # exit() without stopping the whole script.
4551 tfile=f.${TESTSUITE}.${testnum}
4552 export tdir=d0.${TESTSUITE}/d${base}
4553 export TESTNAME=test_$testnum
4554 local SAVE_UMASK=`umask`
4557 banner "test $testnum: $message"
4558 test_${testnum} || error "test_$testnum failed with $?"
4561 check_grant ${testnum} || error "check_grant $testnum failed with $?"
4562 check_catastrophe || error "LBUG/LASSERT detected"
4563 if [ "$PARALLEL" != "yes" ]; then
4564 ps auxww | grep -v grep | grep -q multiop &&
4565 error "multiop still running"
4574 # Wrapper around run_one to ensure:
4575 # - test runs in subshell
4576 # - output of test is saved to separate log file for error reporting
4577 # - test result is saved to data file
4580 local BEFORE=`date +%s`
4582 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
4583 local test_log=$LOGDIR/$name
4585 rm -rf $LOGDIR/ignore
4587 local SAVE_UMASK=`umask`
4591 log_sub_test_begin test_${1}
4592 (run_one $1 "$2") 2>&1 | tee -i $test_log
4593 local RC=${PIPESTATUS[0]}
4595 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
4596 echo "test_$1 returned $RC" | tee $LOGDIR/err
4598 duration=$((`date +%s` - $BEFORE))
4599 pass "$1" "(${duration}s)"
4601 if [[ -f $LOGDIR/err ]]; then
4602 TEST_ERROR=$(cat $LOGDIR/err)
4603 elif [[ -f $LOGDIR/ignore ]]; then
4604 TEST_ERROR=$(cat $LOGDIR/ignore)
4605 elif [[ -f $LOGDIR/skip ]]; then
4606 TEST_ERROR=$(cat $LOGDIR/skip)
4608 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
4610 if [ -f $LOGDIR/err ]; then
4611 $FAIL_ON_ERROR && exit $RC
4620 # Print information of skipped tests to result.yml
4623 log_sub_test_begin $1
4625 log_sub_test_end "SKIP" "0" "0" "$@"
4629 (cd `dirname $1`; echo $PWD/`basename $1`)
4634 export base=`basetest $1`
4635 [ "$CHECK_GRANT" == "no" ] && return 0
4637 testname=GCHECK_ONLY_${base}
4638 [ ${!testname}x == x ] && return 0
4640 echo -n "checking grant......"
4642 local clients=$CLIENTS
4643 [ -z $clients ] && clients=$(hostname)
4645 # sync all the data and make sure no pending data on server
4646 do_nodes $clients sync
4649 client_grant=`do_nodes $clients \
4650 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" | \
4651 awk '{total += $1} END{print total}'`
4654 server_grant=`do_nodes $(comma_list $(osts_nodes)) \
4655 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
4656 awk '{total += $1} END{print total}'`
4658 # check whether client grant == server grant
4659 if [ $client_grant -ne $server_grant ]; then
4660 echo "failed: client:${client_grant} server: ${server_grant}."
4661 do_nodes $(comma_list $(osts_nodes)) \
4662 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
4663 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
4666 echo "pass: client:${client_grant} server: ${server_grant}"
4671 ########################
4677 ost=`echo $1 | awk -F_ '{print $3}'`
4678 if [ -z $ost ]; then
4679 ost=`echo $1 | sed 's/-osc.*//'`
4684 ostuuid_from_index()
4686 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
4689 ostname_from_index() {
4690 local uuid=$(ostuuid_from_index $1)
4694 index_from_ostuuid()
4696 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
4699 mdtuuid_from_index()
4701 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
4705 # Return unique identifier for given hostname
4708 echo $host_name | md5sum | cut -d' ' -f1
4712 # Returns list of ip addresses for each interface
4714 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
4719 # Cache address list to avoid mutiple execution of local_addr_list
4720 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
4722 for i in $LOCAL_ADDR_LIST ; do
4723 [[ "$i" == "$addr" ]] && return 0
4730 local is_local="IS_LOCAL_$(host_id $host_name)"
4731 if [ -z "${!is_local-}" ] ; then
4733 local host_ip=$($LUSTRE/tests/resolveip $host_name)
4734 is_local_addr "$host_ip" && eval $is_local=1
4736 [[ "${!is_local}" == "1" ]]
4741 local_node $node && return 1
4748 for node in $(mdts_nodes); do
4749 remote_node $node && return 0
4756 [ "$CLIENTONLY" ] && return 0 || true
4757 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
4762 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
4763 MSKIPPED=1 && return 1
4770 for node in $(osts_nodes) ; do
4771 remote_node $node && return 0
4778 [ "$CLIENTONLY" ] && return 0 || true
4779 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
4784 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
4785 OSKIPPED=1 && return 1
4792 MGS=$(facet_host mgs)
4793 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
4798 remote_mds_nodsh || remote_ost_nodsh || \
4799 $(single_local_node $(comma_list $(nodes_list)))
4803 remote_ost && remote_mds
4806 # Get the active nodes for facets.
4814 for facet in ${facets//,/ }; do
4815 nodes="$nodes $(facet_active_host $facet)"
4818 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
4822 # Get all of the active MDS nodes.
4824 echo -n $(facets_nodes $(get_facets MDS))
4827 # Get all of the active OSS nodes.
4829 echo -n $(facets_nodes $(get_facets OST))
4832 # Get all of the active AGT (HSM agent) nodes.
4834 echo -n $(facets_nodes $(get_facets AGT))
4837 # Get all of the client nodes and active server nodes.
4839 local nodes=$HOSTNAME
4843 # CLIENTS (if specified) contains the local client
4844 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
4846 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
4847 nodes="$nodes $(facets_nodes $(get_facets))"
4850 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
4854 # Get all of the remote client nodes and remote active server nodes.
4855 remote_nodes_list () {
4856 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
4859 # Get all of the MDS nodes, including active and passive nodes.
4867 for i in $(seq $MDSCOUNT); do
4869 failover_host=mds${i}failover_HOST
4870 nodes="$nodes ${!host} ${!failover_host}"
4873 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
4877 # Get all of the OSS nodes, including active and passive nodes.
4885 for i in $(seq $OSTCOUNT); do
4887 failover_host=ost${i}failover_HOST
4888 nodes="$nodes ${!host} ${!failover_host}"
4891 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
4895 # Get all of the server nodes, including active and passive nodes.
4896 all_server_nodes () {
4901 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
4903 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
4907 # Get all of the client and server nodes, including active and passive nodes.
4909 local nodes=$HOSTNAME
4913 # CLIENTS (if specified) contains the local client
4914 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
4916 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
4917 nodes="$nodes $(all_server_nodes)"
4920 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
4924 init_clients_lists () {
4925 # Sanity check: exclude the local client from RCLIENTS
4926 local clients=$(hostlist_expand "$RCLIENTS")
4927 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
4929 # Sanity check: exclude the dup entries
4930 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
4932 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
4934 # Sanity check: exclude the dup entries from CLIENTS
4935 # for those configs which has SINGLCLIENT set to local client
4936 clients=$(for i in $clients; do echo $i; done | sort -u)
4938 CLIENTS=$(comma_list $clients)
4939 local -a remoteclients=($RCLIENTS)
4940 for ((i=0; $i<${#remoteclients[@]}; i++)); do
4941 varname=CLIENT$((i + 2))
4942 eval $varname=${remoteclients[i]}
4945 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
4948 get_random_entry () {
4951 rnodes=${rnodes//,/ }
4953 local -a nodes=($rnodes)
4954 local num=${#nodes[@]}
4955 local i=$((RANDOM * num * 2 / 65536))
4961 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
4966 lctl get_param version | grep -q patchless
4970 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
4971 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
4976 echo $nodes | wc -w || true
4980 local nodes=$(osts_nodes)
4981 local osscount=$(get_node_count "$nodes")
4982 [ ! "$OSTCOUNT" = "$osscount" ]
4986 local nodes=$(mdts_nodes)
4987 local mdtcount=$(get_node_count "$nodes")
4988 [ ! "$MDSCOUNT" = "$mdtcount" ]
4991 generate_machine_file() {
4992 local nodes=${1//,/ }
4993 local machinefile=$2
4995 for node in $nodes; do
4996 echo $node >>$machinefile || \
4997 { echo "can not generate machinefile $machinefile" && return 1; }
5002 local file=$1/stripe
5005 $LFS getstripe -v $file || error "getstripe $file failed"
5009 setstripe_nfsserver () {
5012 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5013 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
5015 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5017 do_nodev $nfsserver lfs setstripe "$@"
5020 # Check and add a test group.
5026 local gid=$(getent group $group_name | cut -d: -f3)
5027 if [[ -n "$gid" ]]; then
5028 [[ "$gid" -eq "$group_id" ]] || {
5029 error_noexit "inconsistent group ID:" \
5030 "new: $group_id, old: $gid"
5034 groupadd -g $group_id $group_name
5041 # Check and add a test user.
5054 local uid=$(getent passwd $user_name | cut -d: -f3)
5055 if [[ -n "$uid" ]]; then
5056 if [[ "$uid" -eq "$user_id" ]]; then
5057 local dir=$(getent passwd $user_name | cut -d: -f6)
5058 if [[ "$dir" != "$home" ]]; then
5060 usermod -d $home $user_name
5064 error_noexit "inconsistent user ID:" \
5065 "new: $user_id, old: $uid"
5070 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5077 check_runas_id_ret() {
5079 local myRUNAS_UID=$1
5080 local myRUNAS_GID=$2
5083 if [ -z "$myRUNAS" ]; then
5084 error_exit "myRUNAS command must be specified for check_runas_id"
5087 $myRUNAS krb5_login.sh || \
5088 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5090 mkdir $DIR/d0_runas_test
5092 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5093 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5094 rm -rf $DIR/d0_runas_test
5099 local myRUNAS_UID=$1
5100 local myRUNAS_GID=$2
5103 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5104 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5105 Please set RUNAS_ID to some UID which exists on MDS and client or
5106 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5109 # obtain the UID/GID for MPI_USER
5113 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5114 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5116 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5117 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5120 # obtain and cache Kerberos ticket-granting ticket
5121 refresh_krb5_tgt() {
5122 local myRUNAS_UID=$1
5123 local myRUNAS_GID=$2
5126 if [ -z "$myRUNAS" ]; then
5127 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5130 CLIENTS=${CLIENTS:-$HOSTNAME}
5131 do_nodes $CLIENTS "set -x
5132 if ! $myRUNAS krb5_login.sh; then
5133 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5138 # Run multiop in the background, but wait for it to print
5139 # "PAUSING" to its stdout before returning from this function.
5140 multiop_bg_pause() {
5141 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5145 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5148 echo "$MULTIOP_PROG $FILE v$ARGS"
5149 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5151 echo "TMPPIPE=${TMPPIPE}"
5152 read -t 60 multiop_output < $TMPPIPE
5153 if [ $? -ne 0 ]; then
5158 if [ "$multiop_output" != "PAUSING" ]; then
5159 echo "Incorrect multiop output: $multiop_output"
5174 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5180 inodes_available () {
5181 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
5185 mdsrate_inodes_available () {
5186 local min_inodes=$(inodes_available)
5187 echo $((min_inodes * 99 / 100))
5190 # reset llite stat counters
5191 clear_llite_stats(){
5192 lctl set_param -n llite.*.stats 0
5195 # sum llite stat items
5196 calc_llite_stats() {
5197 local res=$(lctl get_param -n llite.*.stats |
5198 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
5202 # reset osc stat counters
5204 lctl set_param -n osc.*.osc_stats 0
5207 # sum osc stat items
5209 local res=$(lctl get_param -n osc.*.osc_stats |
5210 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
5215 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
5218 calc_osc_kbytes () {
5219 df $MOUNT > /dev/null
5220 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5223 # save_lustre_params(comma separated facet list, parameter_mask)
5224 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5225 save_lustre_params() {
5231 for facet in ${facets//,/ }; do
5232 node=$(facet_active_host $facet)
5233 [[ *\ $node\ * = " $nodes " ]] && continue
5234 nodes="$nodes $node"
5236 do_node $node "$LCTL get_param $2 |
5237 while read s; do echo $facet \\\$s; done"
5241 # restore lustre parameters from input stream, produces by save_lustre_params
5242 restore_lustre_params() {
5247 while IFS=" =" read facet name val; do
5248 do_facet $facet "$LCTL set_param -n $name $val"
5252 check_catastrophe() {
5253 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
5254 local C=$CATASTROPHE
5255 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
5257 [ -z "$rnodes" ] && return 0
5260 data=$(do_nodes "$rnodes" "rc=\\\$([ -f $C ] &&
5261 echo \\\$(< $C) || echo 0);
5262 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
5265 if [ -n "$data" ]; then
5272 # CMD: determine mds index where directory inode presents
5275 local file=$dir/f0.get_mds_dir_tmpfile
5280 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
5281 local -a oldused=($iused)
5283 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
5285 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
5286 local -a newused=($iused)
5289 for ((i=0; i<${#newused[@]}; i++)); do
5290 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
5296 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
5299 mdsrate_cleanup () {
5301 mpi_run -np $1 ${MACHINEFILE_OPTION} $2 ${MDSRATE} --unlink \
5302 --nfiles $3 --dir $4 --filefmt $5 $6
5307 delayed_recovery_enabled () {
5308 local var=${SINGLEMDS}_svc
5309 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5312 ########################
5314 convert_facet2label() {
5317 if [ x$facet = xost ]; then
5321 local varsvc=${facet}_svc
5323 if [ -n ${!varsvc} ]; then
5326 error "No lablel for $facet!"
5330 get_clientosc_proc_path() {
5334 get_lustre_version () {
5335 local facet=${1:-"$SINGLEMDS"}
5336 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
5339 lustre_version_code() {
5340 local facet=${1:-"$SINGLEMDS"}
5341 version_code $(get_lustre_version $1)
5344 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5345 # used by MDT would not be changed.
5346 # mdt lov: fsname-mdtlov
5347 # mdt osc: fsname-OSTXXXX-osc
5348 mds_on_old_device() {
5349 local mds=${1:-"$SINGLEMDS"}
5351 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5352 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5353 > /dev/null 2>&1" && return 0
5358 get_mdtosc_proc_path() {
5360 local ost_label=${2:-"*OST*"}
5362 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5363 local mdt_label=$(convert_facet2label $mds_facet)
5364 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5366 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5367 mds_on_old_device $mds_facet; then
5368 echo "${ost_label}-osc"
5370 echo "${ost_label}-osc-${mdt_index}"
5374 get_osc_import_name() {
5377 local label=$(convert_facet2label $ost)
5379 if [ "${facet:0:3}" = "mds" ]; then
5380 get_mdtosc_proc_path $facet $label
5384 get_clientosc_proc_path $label
5388 _wait_import_state () {
5391 local maxtime=${3:-$(max_recovery_time)}
5395 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5396 while [ "${CONN_STATE}" != "${expected}" ]; do
5397 if [ "${expected}" == "DISCONN" ]; then
5398 # for disconn we can check after proc entry is removed
5399 [ "x${CONN_STATE}" == "x" ] && return 0
5400 # with AT enabled, we can have connect request timeout near of
5401 # reconnect timeout and test can't see real disconnect
5402 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
5404 [ $i -ge $maxtime ] && \
5405 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
5408 # Add uniq for multi-mount case
5409 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5413 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
5417 wait_import_state() {
5420 local maxtime=${3:-$(max_recovery_time)}
5423 for param in ${params//,/ }; do
5424 _wait_import_state $state $param $maxtime || return
5428 wait_import_state_mount() {
5429 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
5433 wait_import_state $*
5436 # One client request could be timed out because server was not ready
5437 # when request was sent by client.
5438 # The request timeout calculation details :
5440 # /* We give the server rq_timeout secs to process the req, and
5441 # add the network latency for our local timeout. */
5442 # request->rq_deadline = request->rq_sent + request->rq_timeout +
5443 # ptlrpc_at_get_net_latency(request) ;
5445 # ptlrpc_connect_import ()
5446 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5449 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
5450 # ptlrpc_at_get_net_latency(request) ->
5451 # at_get (max (iat_net_latency=0, at_min)) = at_min
5454 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
5455 # INITIAL_CONNECT_TIMEOUT + at_min
5457 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
5458 # because we can not get this value in runtime,
5459 # the value depends on configure options, and it is not stored in /proc.
5461 # #define CONNECTION_SWITCH_MIN 5U
5462 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5464 request_timeout () {
5467 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5468 local init_connect_timeout=$TIMEOUT
5469 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5471 local at_min=$(at_get $facet at_min)
5473 echo $(( init_connect_timeout + at_min ))
5476 _wait_osc_import_state() {
5480 local ost=$(get_osc_import_name $facet $ost_facet)
5482 local param="osc.${ost}.ost_server_uuid"
5485 # 1. wait the deadline of client 1st request (it could be skipped)
5486 # 2. wait the deadline of client 2nd request
5487 local maxtime=$(( 2 * $(request_timeout $facet)))
5489 #During setup time, the osc might not be setup, it need wait
5490 #until list_param can return valid value. And also if there
5491 #are mulitple osc entries we should list all of them before
5493 local params=$($LCTL list_param $param 2>/dev/null || true)
5494 while [ -z "$params" ]; do
5495 if [ $i -ge $maxtime ]; then
5496 echo "can't get $param by list_param in $maxtime secs"
5497 if [[ $facet != client* ]]; then
5498 echo "Go with $param directly"
5507 params=$($LCTL list_param $param 2>/dev/null || true)
5510 if ! do_rpc_nodes "$(facet_active_host $facet)" \
5511 wait_import_state $expected "$params" $maxtime; then
5512 error "import is not in ${expected} state"
5519 wait_osc_import_state() {
5525 if [[ $facet = mds ]]; then
5526 for num in $(seq $MDSCOUNT); do
5527 _wait_osc_import_state mds$num "$ost_facet" "$expected"
5530 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
5534 get_clientmdc_proc_path() {
5542 [ -z "$list" ] && return 0
5544 # Add paths to lustre tests for 32 and 64 bit systems.
5545 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
5546 local TESTPATH="$RLUSTRE/tests:"
5547 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
5548 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
5551 wait_clients_import_state () {
5558 if [ "$FAILURE_MODE" = HARD ]; then
5559 facets=$(facets_on_host $(facet_active_host $facet))
5562 for facet in ${facets//,/ }; do
5563 local label=$(convert_facet2label $facet)
5566 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
5567 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
5568 *) error "unknown facet!" ;;
5570 local params=$(expand_list $params $proc_path)
5573 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params; then
5574 error "import is not in ${expected} state"
5584 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
5585 $LCTL get_param obdfilter.*.kbytesavail))
5586 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
5587 $LCTL get_param -n obdfilter.*.tot_granted))
5588 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
5589 $LCTL get_param -n obdfilter.*.kbytestotal))
5590 for ((i=0; i<${#AVAILA[@]}; i++)); do
5591 local -a AVAIL1=(${AVAILA[$i]//=/ })
5592 local -a TOTAL=(${TOTALA[$i]//=/ })
5593 GRANT=$((${GRANTA[$i]}/1024))
5594 # allow 1% of total space in bavail because of delayed
5595 # allocation with ZFS which might release some free space after
5596 # txg commit. For small devices, we set a mininum of 8MB
5597 local LIMIT=$((${TOTAL} / 100 + 8000))
5598 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
5599 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
5600 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
5601 echo " FULL" || echo
5607 do_facet mgs lctl pool_list $1
5611 local fsname=${1%%.*}
5612 local poolname=${1##$fsname.}
5614 do_facet mgs lctl pool_new $1
5616 # get param should return err unless pool is created
5617 [[ $RC -ne 0 ]] && return $RC
5619 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
5620 2>/dev/null || echo foo" "" || RC=1
5621 if [[ $RC -eq 0 ]]; then
5624 error "pool_new failed $1"
5629 add_pool_to_list () {
5630 local fsname=${1%%.*}
5631 local poolname=${1##$fsname.}
5633 local listvar=${fsname}_CREATED_POOLS
5634 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
5637 remove_pool_from_list () {
5638 local fsname=${1%%.*}
5639 local poolname=${1##$fsname.}
5641 local listvar=${fsname}_CREATED_POOLS
5642 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
5645 destroy_pool_int() {
5647 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
5648 awk '$1 !~ /^Pool:/ {print $1}')
5649 for ost in $OSTS; do
5650 do_facet mgs lctl pool_remove $1 $ost
5652 do_facet mgs lctl pool_destroy $1
5655 # <fsname>.<poolname> or <poolname>
5657 local fsname=${1%%.*}
5658 local poolname=${1##$fsname.}
5660 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
5664 pool_list $fsname.$poolname || return $?
5666 destroy_pool_int $fsname.$poolname
5668 [[ $RC -ne 0 ]] && return $RC
5670 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
5671 2>/dev/null || echo foo" "foo" || RC=1
5673 if [[ $RC -eq 0 ]]; then
5674 remove_pool_from_list $fsname.$poolname
5676 error "destroy pool failed $1"
5682 local fsname=${1:-$FSNAME}
5684 local listvar=${fsname}_CREATED_POOLS
5688 [ x${!listvar} = x ] && return 0
5690 echo destroy the created pools: ${!listvar}
5691 for poolname in ${!listvar//,/ }; do
5692 destroy_pool $fsname.$poolname
5697 local fsname=${1:-$FSNAME}
5699 destroy_pools $fsname
5705 local ts=$(date +%s)
5708 if [[ ! -f "$YAML_LOG" ]]; then
5709 # init_logging is not performed before gather_logs,
5710 # so the $LOGDIR needs to be checked here
5711 check_shared_dir $LOGDIR && touch $LOGDIR/shared
5714 [ -f $LOGDIR/shared ] && docp=false
5716 # dump lustre logs, dmesg
5718 prefix="$TESTLOG_PREFIX.$TESTNAME"
5720 echo "Dumping lctl log to ${prefix}.*.${suffix}"
5722 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
5723 echo "Dumping logs only on local client."
5724 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
5725 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
5730 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
5731 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
5732 if [ ! -f $LOGDIR/shared ]; then
5733 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
5746 for i in $(seq 0 $num_mntpts); do
5747 cmd="ls -laf ${mntpt_root}$i/$dir"
5753 for pid in $pids; do
5760 # target_start_and_reset_recovery_timer()
5761 # service_time = at_est2timeout(service_time);
5762 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
5763 # INITIAL_CONNECT_TIMEOUT);
5764 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
5765 #define CONNECTION_SWITCH_INC 1
5766 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5767 #define CONNECTION_SWITCH_MIN 5U
5769 max_recovery_time () {
5770 local init_connect_timeout=$(( TIMEOUT / 20 ))
5771 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5773 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
5778 get_clients_mount_count () {
5779 local clients=${CLIENTS:-`hostname`}
5781 # we need to take into account the clients mounts and
5782 # exclude mds/ost mounts if any;
5783 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
5787 PROC_CLI="srpc_info"
5795 if [ $M -lt $N ]; then
5799 while [ $N -lt $M ]; do
5809 calc_connection_cnt() {
5812 # MDT->MDT = 2 * C(M, 2)
5816 comb_m2=$(combination $MDSCOUNT 2)
5818 local num_clients=$(get_clients_mount_count)
5820 local cnt_mdt2mdt=$((comb_m2 * 2))
5821 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
5822 local cnt_cli2ost=$((num_clients * OSTCOUNT))
5823 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
5824 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
5825 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
5826 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
5840 local cmd="$tgt.srpc.flavor"
5842 if [ $net == "any" ]; then
5847 if [ $dir != "any" ]; then
5852 log "Setting sptlrpc rule: $cmd"
5853 do_facet mgs "$LCTL conf_param $cmd"
5862 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
5863 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
5865 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
5867 if [ "x$bulkspec" != "x" ]; then
5868 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
5870 if [ "x$algs" != "x" ]; then
5871 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
5873 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
5874 if [ $bulk == "bulkn" ]; then
5875 bulk_count=`echo "$output" | grep "bulk flavor" \
5876 | grep "null/null" | wc -l`
5877 elif [ $bulk == "bulki" ]; then
5878 bulk_count=`echo "$output" | grep "bulk flavor" \
5879 | grep "/null" | grep -v "null/" | wc -l`
5881 bulk_count=`echo "$output" | grep "bulk flavor" \
5882 | grep -v "/null" | grep -v "null/" | wc -l`
5886 [ $bulk_count -lt $count ] && count=$bulk_count
5897 local clients=${CLIENTS:-`hostname`}
5899 for c in ${clients//,/ }; do
5900 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
5901 tmpcnt=`count_flvr "$output" $flavor`
5902 cnt=$((cnt + tmpcnt))
5912 local clients=${CLIENTS:-`hostname`}
5914 for c in ${clients//,/ }; do
5915 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
5916 tmpcnt=`count_flvr "$output" $flavor`
5917 cnt=$((cnt + tmpcnt))
5927 if [ $MDSCOUNT -le 1 ]; then
5932 for num in `seq $MDSCOUNT`; do
5933 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
5934 tmpcnt=`count_flvr "$output" $flavor`
5935 cnt=$((cnt + tmpcnt))
5946 for num in `seq $MDSCOUNT`; do
5947 mdtosc=$(get_mdtosc_proc_path mds$num)
5948 mdtosc=${mdtosc/-MDT*/-MDT\*}
5949 output=$(do_facet mds$num lctl get_param -n \
5950 osc.$mdtosc.$PROC_CLI 2>/dev/null)
5951 tmpcnt=`count_flvr "$output" $flavor`
5952 cnt=$((cnt + tmpcnt))
5961 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
5962 count_flvr "$output" $flavor
5967 local dir=$1 # from to
5968 local flavor=$2 # flavor expected
5971 if [ $dir == "cli2mdt" ]; then
5972 res=`flvr_cnt_cli2mdt $flavor`
5973 elif [ $dir == "cli2ost" ]; then
5974 res=`flvr_cnt_cli2ost $flavor`
5975 elif [ $dir == "mdt2mdt" ]; then
5976 res=`flvr_cnt_mdt2mdt $flavor`
5977 elif [ $dir == "mdt2ost" ]; then
5978 res=`flvr_cnt_mdt2ost $flavor`
5979 elif [ $dir == "all2ost" ]; then
5980 res1=`flvr_cnt_mdt2ost $flavor`
5981 res2=`flvr_cnt_cli2ost $flavor`
5982 res=$((res1 + res2))
5983 elif [ $dir == "all2mdt" ]; then
5984 res1=`flvr_cnt_mdt2mdt $flavor`
5985 res2=`flvr_cnt_cli2mdt $flavor`
5986 res=$((res1 + res2))
5987 elif [ $dir == "all2all" ]; then
5988 res1=`flvr_cnt_mdt2ost $flavor`
5989 res2=`flvr_cnt_cli2ost $flavor`
5990 res3=`flvr_cnt_mdt2mdt $flavor`
5991 res4=`flvr_cnt_cli2mdt $flavor`
5992 res=$((res1 + res2 + res3 + res4))
6000 local dir=$1 # from to
6001 local flavor=$2 # flavor expected
6002 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6006 for ((i=0;i<20;i++)); do
6007 echo -n "checking $dir..."
6008 res=$(do_check_flavor $dir $flavor)
6009 echo "found $res/$expect $flavor connections"
6010 [ $res -ge $expect ] && return 0
6014 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6018 restore_to_default_flavor()
6020 local proc="mgs.MGS.live.$FSNAME"
6022 echo "restoring to default flavor..."
6024 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6026 # remove all existing rules if any
6027 if [ $nrule -ne 0 ]; then
6028 echo "$nrule existing rules"
6029 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6030 echo "remove rule: $rule"
6031 spec=`echo $rule | awk -F = '{print $1}'`
6032 do_facet mgs "$LCTL conf_param -d $spec"
6036 # verify no rules left
6037 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6038 [ $nrule -ne 0 ] && error "still $nrule rules left"
6040 # wait for default flavor to be applied
6041 # currently default flavor for all connections are 'null'
6042 wait_flavor all2all null
6043 echo "now at default flavor settings"
6048 local flavor=${1:-null}
6050 echo "setting all flavor to $flavor"
6052 # FIXME need parameter to this fn
6053 # and remove global vars
6054 local cnt_all2all=$(calc_connection_cnt all2all)
6056 local res=$(do_check_flavor all2all $flavor)
6057 if [ $res -eq $cnt_all2all ]; then
6058 echo "already have total $res $flavor connections"
6062 echo "found $res $flavor out of total $cnt_all2all connections"
6063 restore_to_default_flavor
6065 [[ $flavor = null ]] && return 0
6067 set_rule $FSNAME any any $flavor
6068 wait_flavor all2all $flavor
6074 # Checking for shared logdir
6075 if [ ! -d $dir ]; then
6076 # Not found. Create local logdir
6079 touch $dir/check_file.$(hostname -s)
6084 check_write_access() {
6086 local list=${2:-$(comma_list $(nodes_list))}
6090 for node in ${list//,/ }; do
6091 file=$dir/check_file.$(short_hostname $node)
6092 if [[ ! -f "$file" ]]; then
6093 # Logdir not accessible/writable from this node.
6096 rm -f $file || return 1
6102 if [[ -n $YAML_LOG ]]; then
6105 local SAVE_UMASK=`umask`
6108 export YAML_LOG=${LOGDIR}/results.yml
6112 if [ ! -f $YAML_LOG ]; then # If the yaml log already exists then we will just append to it
6113 if check_shared_dir $LOGDIR; then
6114 touch $LOGDIR/shared
6115 echo "Logging to shared log directory: $LOGDIR"
6117 echo "Logging to local directory: $LOGDIR"
6120 yml_nodes_file $LOGDIR >> $YAML_LOG
6121 yml_results_file >> $YAML_LOG
6128 yml_log_test $1 >> $YAML_LOG
6132 yml_log_test_status $@ >> $YAML_LOG
6135 log_sub_test_begin() {
6136 yml_log_sub_test_begin "$@" >> $YAML_LOG
6139 log_sub_test_end() {
6140 yml_log_sub_test_end "$@" >> $YAML_LOG
6146 local llverdev_opts=$2
6147 local devname=$(basename $1)
6148 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6149 # loop devices aren't in /proc/partitions
6150 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6152 size=$(($size / 1024 / 1024)) # Gb
6154 local partial_arg=""
6155 # Run in partial (fast) mode if the size
6156 # of a partition > 1 GB
6157 [ $size -gt 1 ] && partial_arg="-p"
6159 llverdev --force $partial_arg $llverdev_opts $dev
6165 local llverfs_opts=$2
6166 local use_partial_arg=$3
6167 local partial_arg=""
6168 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6170 # Run in partial (fast) mode if the size
6171 # of a partition > 1 GB
6172 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6174 llverfs $partial_arg $llverfs_opts $dir
6177 #Remove objects from OST
6178 remove_ost_objects() {
6184 local mntpt=$(facet_mntpt $facet)
6185 local opts=$OST_MOUNT_OPTS
6189 echo "removing objects from $ostdev on $facet: $objids"
6190 if ! test -b $ostdev; then
6191 opts=$(csa_add "$opts" -o loop)
6193 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
6196 for i in $objids; do
6197 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
6199 umount -f $mntpt || return $?
6203 #Remove files from MDT
6204 remove_mdt_files() {
6209 local mntpt=$(facet_mntpt $facet)
6210 local opts=$MDS_MOUNT_OPTS
6212 echo "removing files from $mdtdev on $facet: $files"
6213 if [ $(facet_fstype $facet) == ldiskfs ] &&
6214 ! do_facet $facet test -b $mdtdev; then
6215 opts=$(csa_add "$opts" -o loop)
6217 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6221 rm $mntpt/ROOT/$f || { rc=$?; break; }
6223 umount -f $mntpt || return $?
6227 duplicate_mdt_files() {
6232 local mntpt=$(facet_mntpt $facet)
6233 local opts=$MDS_MOUNT_OPTS
6235 echo "duplicating files on $mdtdev on $facet: $files"
6236 mkdir -p $mntpt || return $?
6237 if [ $(facet_fstype $facet) == ldiskfs ] &&
6238 ! do_facet $facet test -b $mdtdev; then
6239 opts=$(csa_add "$opts" -o loop)
6241 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6252 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
6253 pushd $mntpt/ROOT > /dev/null || return $?
6256 touch $f.bad || return $?
6257 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
6259 [ $rc -eq 0 ] || return $rc
6260 setfattr --restore $tmp || return $?
6266 local devs=${1//,/ }
6269 local rslt=$TMP/sgpdd_survey
6271 # sgpdd-survey cleanups ${rslt}.* files
6273 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
6279 # returns the canonical name for an ldiskfs device
6284 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
6285 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
6286 echo dm-\\\${foo##*:};
6288 echo \\\$(basename \\\$dv);
6292 is_sanity_benchmark() {
6293 local benchmarks="dbench bonnie iozone fsx"
6295 for b in $benchmarks; do
6296 if [ "$b" == "$suite" ]; then
6304 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
6308 # Get the block count of the filesystem.
6315 count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6316 awk '/^Block count:/ {print $3}')
6320 # Get the block size of the filesystem.
6326 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6327 awk '/^Block size:/ {print $3}')
6331 # Check whether the "large_xattr" feature is enabled or not.
6332 large_xattr_enabled() {
6333 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
6335 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6337 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
6338 grep -E -q '(ea_inode|large_xattr)'"
6339 return ${PIPESTATUS[0]}
6342 # Get the maximum xattr size supported by the filesystem.
6346 if large_xattr_enabled; then
6347 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
6350 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6351 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
6353 # maximum xattr size = size of block - size of header -
6354 # size of 1 entry - 4 null bytes
6355 size=$((block_size - 32 - 32 - 4))
6361 # Dump the value of the named xattr from a file.
6366 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
6369 # Generate a string with size of $size bytes.
6371 local size=${1:-1024} # in bytes
6373 echo "$(head -c $size < /dev/zero | tr '\0' y)"
6376 reformat_external_journal() {
6379 if [ ! -z ${EJOURNAL} ]; then
6380 local rcmd="do_facet $facet"
6382 echo "reformat external journal on $facet:${EJOURNAL}"
6383 ${rcmd} mke2fs -O journal_dev ${EJOURNAL} || return 1
6387 # MDT file-level backup/restore
6388 mds_backup_restore() {
6391 local devname=$(mdsdevname $(facet_number $facet))
6392 local mntpt=$(facet_mntpt brpt)
6393 local rcmd="do_facet $facet"
6394 local metaea=${TMP}/backup_restore.ea
6395 local metadata=${TMP}/backup_restore.tgz
6396 local opts=${MDS_MOUNT_OPTS}
6397 local svc=${facet}_svc
6399 if ! ${rcmd} test -b ${devname}; then
6400 opts=$(csa_add "$opts" -o loop)
6403 echo "file-level backup/restore on $facet:${devname}"
6405 # step 1: build mount point
6406 ${rcmd} mkdir -p $mntpt
6407 # step 2: cleanup old backup
6408 ${rcmd} rm -f $metaea $metadata
6410 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
6411 if [ ! -z $igif ]; then
6412 # step 3.5: rm .lustre
6413 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
6415 # step 4: backup metaea
6417 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
6419 # step 5: backup metadata
6421 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
6423 ${rcmd} umount -d $mntpt || return 4
6424 # step 7: reformat external journal if needed
6425 reformat_external_journal $facet || return 5
6426 # step 8: reformat dev
6427 echo "reformat new device"
6428 add $facet $(mkfs_opts $facet ${devname}) --backfstype ldiskfs \
6429 --reformat ${devname} $(mdsvdevname $(facet_number $facet)) \
6430 > /dev/null || exit 6
6432 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
6433 # step 10: restore metadata
6435 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
6436 # step 11: restore metaea
6438 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
6439 # step 12: remove recovery logs
6440 echo "remove recovery logs"
6441 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
6442 # step 13: umount dev
6443 ${rcmd} umount -d $mntpt || return 10
6444 # step 14: cleanup tmp backup
6445 ${rcmd} rm -f $metaea $metadata
6446 # step 15: reset device label - it's not virgin on
6447 ${rcmd} e2label $devname ${!svc}
6454 local devname=$(mdsdevname $(facet_number $facet))
6455 local mntpt=$(facet_mntpt brpt)
6456 local rcmd="do_facet $facet"
6457 local opts=${MDS_MOUNT_OPTS}
6459 if ! ${rcmd} test -b ${devname}; then
6460 opts=$(csa_add "$opts" -o loop)
6463 echo "removing OI files on $facet: idx=${idx}"
6465 # step 1: build mount point
6466 ${rcmd} mkdir -p $mntpt
6468 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
6469 if [ -z $idx ]; then
6470 # step 3: remove all OI files
6471 ${rcmd} rm -fv $mntpt/oi.16*
6472 elif [ $idx -lt 2 ]; then
6473 ${rcmd} rm -fv $mntpt/oi.16.${idx}
6477 # others, rm oi.16.[idx, idx * idx, idx ** ...]
6478 for ((i=${idx}; i<64; i=$((i * idx)))); do
6479 ${rcmd} rm -fv $mntpt/oi.16.${i}
6483 ${rcmd} umount -d $mntpt || return 2
6484 # OI files will be recreated when mounted as lustre next time.
6487 # generate maloo upload-able log file name
6488 # \param logname specify unique part of file name
6489 generate_logname() {
6490 local logname=${1:-"default_logname"}
6492 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
6495 # make directory on different MDTs
6507 *) error "Only creating single directory is supported";;
6510 child=$(basename $path)
6511 parent=$(dirname $path)
6513 if [ "$option" == "-p" -a -d $parent/$child ]; then
6517 if [ ! -d ${parent} ]; then
6518 if [ "$option" == "-p" ]; then
6525 if [ $MDSCOUNT -le 1 ]; then
6526 mkdir $option $parent/$child || rc=$?
6528 local mdt_idx=$($LFS getstripe -M $parent)
6529 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
6531 if [ "$mdt_idx" -ne 0 ]; then
6532 mkdir $option $parent/$child || rc=$?
6534 mdt_idx=$((test_num % MDSCOUNT))
6535 echo "mkdir $mdt_idx for $parent/$child"
6536 $LFS setdirstripe -i $mdt_idx $parent/$child || rc=$?