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 /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
307 ! -f $LUSTRE/mdt/mdt.ko ]; then
308 export CLIENTMODSONLY=yes
311 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
312 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
316 while getopts "rvwf:" opt $*; do
319 r) REFORMAT=--reformat;;
321 w) WRITECONF=writeconf;;
326 shift $((OPTIND - 1))
329 # print the durations of each test if "true"
330 DDETAILS=${DDETAILS:-false}
331 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
341 ncpts=$(do_facet $facet "lctl get_param -n " \
342 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
344 if [ $ncpts -eq 0 ]; then
352 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
353 eval set -- $(tr "[:punct:]" " " <<< $*)
355 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
358 export LINUX_VERSION=$(uname -r | sed -e "s/[-.]/ /3" -e "s/ .*//")
359 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
362 /sbin/lsmod | grep -q "^\<$1\>"
365 # Load a module on the system where this is running.
367 # Synopsis: load_module module_name [module arguments for insmod/modprobe]
369 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
370 # will be used as the arguments. Otherwise arguments will be obtained from
371 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
378 BASE=`basename $module $EXT`
380 module_loaded ${BASE} && return
382 # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
384 if [ $# -eq 0 ]; then
385 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
386 # Bash until 4.x, so we resort to eval.
387 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
388 eval set -- \$$optvar
389 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
390 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
392 opt=$(awk -v var="^options $BASE" '$0 ~ var \
393 {gsub("'"options $BASE"'",""); print}' $MODPROBECONF)
394 set -- $(echo -n $opt)
396 # Ensure we have accept=all for lnet
397 if [ $(basename $module) = lnet ]; then
398 # OK, this is a bit wordy...
399 local arg accept_all_present=false
402 [ "$arg" = accept=all ] && \
403 accept_all_present=true
405 $accept_all_present || set -- "$@" accept=all
411 [ $# -gt 0 ] && echo "${module} options: '$*'"
413 # Note that insmod will ignore anything in modprobe.conf, which is why we're
414 # passing options on the command-line.
415 if [ "$BASE" == "lnet_selftest" ] && \
416 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
417 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
418 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
419 insmod ${LUSTRE}/${module}${EXT} "$@"
421 # must be testing a "make install" or "rpm" installation
422 # note failed to load ptlrpc_gss is considered not fatal
423 if [ "$BASE" == "ptlrpc_gss" ]; then
424 modprobe $BASE "$@" 2>/dev/null || echo "gss/krb5 is not supported"
431 llite_lloop_enabled() {
432 local n1=$(uname -r | cut -d. -f1)
433 local n2=$(uname -r | cut -d. -f2)
434 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
436 # load the llite_lloop module for < 2.6.32 kernels
437 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
438 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
445 load_modules_local() {
446 if [ -n "$MODPROBE" ]; then
448 echo "Using modprobe to load modules"
452 echo Loading modules from $LUSTRE
456 if [ -f /sys/devices/system/cpu/online ]; then
457 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
458 echo "detected $ncpus online CPUs by sysfs"
460 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
462 if [ $rc -eq 0 ]; then
463 echo "detected $ncpus online CPUs by getconf"
465 echo "Can't detect number of CPUs"
470 # if there is only one CPU core, libcfs can only create one partition
471 # if there is more than 4 CPU cores, libcfs should create multiple CPU
472 # partitions. So we just force libcfs to create 2 partitions for
473 # system with 2 or 4 cores
474 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
475 # force to enable multiple CPU partitions
476 echo "Force libcfs to create 2 CPU partitions"
477 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
479 echo "libcfs will create CPU partition based on online CPUs"
482 load_module ../libcfs/libcfs/libcfs
484 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
485 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
486 load_module ../lnet/lnet/lnet
487 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
488 load_module ../lnet/klnds/$LNETLND
489 load_module obdclass/obdclass
490 load_module ptlrpc/ptlrpc
491 load_module ptlrpc/gss/ptlrpc_gss
499 load_module obdecho/obdecho
500 if ! client_only; then
501 SYMLIST=/proc/kallsyms
502 grep -q crc16 $SYMLIST || { modprobe crc16 2>/dev/null || true; }
503 grep -q -w jbd $SYMLIST || { modprobe jbd 2>/dev/null || true; }
504 grep -q -w jbd2 $SYMLIST || { modprobe jbd2 2>/dev/null || true; }
505 load_module lfsck/lfsck
506 [ "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
507 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
509 load_module osd-zfs/osd_zfs
511 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
512 grep -q exportfs_decode_fh $SYMLIST ||
513 { modprobe exportfs 2> /dev/null || true; }
514 load_module ../ldiskfs/ldiskfs
515 load_module osd-ldiskfs/osd_ldiskfs
517 load_module nodemap/nodemap
529 load_module llite/lustre
530 llite_lloop_enabled && load_module llite/llite_lloop
531 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
533 rm -f $OGDB/ogdb-$HOSTNAME
534 $LCTL modules > $OGDB/ogdb-$HOSTNAME
536 # 'mount' doesn't look in $PATH, just sbin
537 if [ -f $LUSTRE/utils/mount.lustre ] && \
538 ! grep -qe "/sbin/mount\.lustre " /proc/mounts; then
539 [ ! -f /sbin/mount.lustre ] && touch /sbin/mount.lustre
540 mount --bind $LUSTRE/utils/mount.lustre /sbin/mount.lustre || true
547 # load modules on remote nodes optionally
548 # lustre-tests have to be installed on these nodes
549 if $LOAD_MODULES_REMOTE; then
550 local list=$(comma_list $(remote_nodes_list))
551 if [ -n "$list" ]; then
552 echo "loading modules on: '$list'"
553 do_rpc_nodes "$list" load_modules_local
559 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
560 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
561 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
562 echo "$LEAK_LUSTRE" 1>&2
563 echo "$LEAK_PORTALS" 1>&2
564 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
565 echo "Memory leaks detected"
566 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
572 wait_exit_ST client # bug 12845
574 $LUSTRE_RMMOD ldiskfs || return 2
576 if $LOAD_MODULES_REMOTE; then
577 local list=$(comma_list $(remote_nodes_list))
578 if [ -n "$list" ]; then
579 echo "unloading modules on: '$list'"
580 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
581 do_rpc_nodes "$list" check_mem_leak
585 if grep -qe "/sbin/mount\.lustre" /proc/mounts; then
586 umount /sbin/mount.lustre || true
587 [ -w /sbin/mount.lustre -a ! -s /sbin/mount.lustre ] && \
588 rm -f /sbin/mount.lustre || true
591 check_mem_leak || return 254
593 echo "modules unloaded."
598 local facet=${1:-$SINGLEMDS}
599 local fstype=$(facet_fstype $facet)
602 ldiskfs) size=50;; # largest seen is 44, leave some headroom
603 zfs) size=400;; # largest seen is 384
609 check_gss_daemon_nodes() {
613 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
614 if [ \\\"\\\$num\\\" -ne 1 ]; then
615 echo \\\$num instance of $dname;
620 check_gss_daemon_facet() {
624 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
625 if [ $num -ne 1 ]; then
626 echo "$num instance of $dname on $facet"
635 echo Stopping $@ on $list
636 do_nodes $list "killall -2 $@ 2>/dev/null || true"
639 # start gss daemons on all nodes, or
640 # "daemon" on "list" if set
641 start_gss_daemons() {
645 if [ "$list" ] && [ "$daemon" ] ; then
646 echo "Starting gss daemon on nodes: $list"
647 do_nodes $list "$daemon" || return 8
651 local list=$(comma_list $(mdts_nodes))
653 echo "Starting gss daemon on mds: $list"
654 do_nodes $list "$LSVCGSSD -v" || return 1
656 do_nodes $list "$LGSSD -v" || return 2
659 list=$(comma_list $(osts_nodes))
660 echo "Starting gss daemon on ost: $list"
661 do_nodes $list "$LSVCGSSD -v" || return 3
662 # starting on clients
664 local clients=${CLIENTS:-`hostname`}
666 echo "Starting $LGSSD on clients $clients "
667 do_nodes $clients "$LGSSD -v" || return 4
670 # wait daemons entering "stable" status
674 # check daemons are running
676 list=$(comma_list $(mdts_nodes) $(osts_nodes))
677 check_gss_daemon_nodes $list lsvcgssd || return 5
679 list=$(comma_list $(mdts_nodes))
680 check_gss_daemon_nodes $list lgssd || return 6
683 check_gss_daemon_nodes $clients lgssd || return 7
688 local list=$(comma_list $(mdts_nodes))
690 send_sigint $list lsvcgssd lgssd
692 list=$(comma_list $(osts_nodes))
693 send_sigint $list lsvcgssd
695 list=${CLIENTS:-`hostname`}
696 send_sigint $list lgssd
701 if ! module_loaded ptlrpc_gss; then
702 load_module ptlrpc/gss/ptlrpc_gss
703 module_loaded ptlrpc_gss ||
704 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
706 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
708 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
709 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
717 # maybe cleanup credential cache?
723 local var=${facet}_svc
731 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
732 tr '[:lower:]' '[:upper:]'
738 if [ $facet == mgs ]; then
742 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
750 if [ -n "${!var}" ]; then
755 var=$(facet_type $facet)FSTYPE
756 if [ -n "${!var}" ]; then
761 if [ -n "$FSTYPE" ]; then
766 if [[ $facet == mgs ]] && combined_mgs_mds; then
778 local facets=$(get_facets)
781 for facet in ${facets//,/ }; do
782 if [ $node == $(facet_host $facet) ] ||
783 [ $node == "$(facet_failover_host $facet)" ]; then
784 fstype=$(facet_fstype $facet)
785 if [[ $fstypes != *$fstype* ]]; then
786 fstypes+="${fstypes:+,}$fstype"
797 local fstype=$(facet_fstype $facet)
801 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
803 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
804 ${dev} 2>/dev/null");;
806 error "unknown fstype!";;
814 local device=$(mdsdevname $num)
815 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
821 local device=$(ostdevname $num)
822 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
827 # Get the device of a facet.
834 mgs) device=$(mgsdevname) ;;
835 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
836 ost*) device=$(ostdevname $(facet_number $facet)) ;;
837 fs2mds) device=$(mdsdevname 1_2) ;;
838 fs2ost) device=$(ostdevname 1_2) ;;
839 fs3ost) device=$(ostdevname 2_2) ;;
847 # Get the virtual device of a facet.
854 mgs) device=$(mgsvdevname) ;;
855 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
856 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
857 fs2mds) device=$(mdsvdevname 1_2) ;;
858 fs2ost) device=$(ostvdevname 1_2) ;;
859 fs3ost) device=$(ostvdevname 2_2) ;;
867 # Re-read the partition table on failover partner host.
868 # After a ZFS storage pool is created on a shared device, the partition table
869 # on the device may change. However, the operating system on the failover
870 # host may not notice the change automatically. Without the up-to-date partition
871 # block devices, 'zpool import ..' cannot find the labels, whose positions are
872 # relative to partition rather than disk beginnings.
874 # This function performs partprobe on the failover host to make it re-read the
877 refresh_partition_table() {
882 host=$(facet_passive_host $facet)
883 if [[ -n "$host" ]]; then
884 do_node $host "$PARTPROBE $device"
889 # Get ZFS storage pool name.
896 device=$(facet_device $facet)
897 # poolname is string before "/"
898 poolname="${device%%/*}"
904 # Create ZFS storage pool.
911 local opts=${@:-"-o cachefile=none"}
913 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
914 $ZPOOL create -f $opts $poolname $vdev"
918 # Create ZFS file system.
924 local opts=${@:-"-o mountpoint=legacy"}
926 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
927 $ZFS create $opts $dataset"
931 # Export ZFS storage pool.
932 # Before exporting the pool, all datasets within the pool should be unmounted.
940 poolname=$(zpool_name $facet)
942 if [[ -n "$poolname" ]]; then
943 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
944 grep -q ^$poolname/ /proc/mounts ||
945 $ZPOOL export $opts $poolname"
950 # Destroy ZFS storage pool.
951 # Destroy the given pool and free up any devices for other use. This command
952 # tries to unmount any active datasets before destroying the pool.
953 # -f Force any active datasets contained within the pool to be unmounted.
957 local poolname=${2:-$(zpool_name $facet)}
959 if [[ -n "$poolname" ]]; then
960 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
961 $ZPOOL destroy -f $poolname"
966 # Import ZFS storage pool.
967 # Force importing, even if the pool appears to be potentially active.
972 local opts=${@:-"-o cachefile=none"}
975 poolname=$(zpool_name $facet)
977 if [[ -n "$poolname" ]]; then
978 opts+=" -d $(dirname $(facet_vdevice $facet))"
979 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
980 $ZPOOL import -f $opts $poolname"
985 # Set the "cachefile=none" property on ZFS storage pool so that the pool
986 # is not automatically imported on system startup.
988 # In a failover environment, this will provide resource level fencing which
989 # will ensure that the same ZFS storage pool will not be imported concurrently
990 # on different nodes.
992 disable_zpool_cache() {
996 poolname=$(zpool_name $facet)
998 if [[ -n "$poolname" ]]; then
999 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1004 # This and set_osd_param() shall be used to access OSD parameters
1005 # once existed under "obdfilter":
1010 # writethrough_cache_enable
1014 local device=${2:-$FSNAME-OST*}
1017 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1018 osd-*.$device.$name 2>&1" | grep -v 'Found no match'
1023 local device=${2:-$FSNAME-OST*}
1027 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1028 osd-*.$device.$name=$value 2>&1" | grep -v 'Found no match'
1032 local dz=${1:-$DEBUG_SIZE}
1034 if [ -f /sys/devices/system/cpu/possible ]; then
1035 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1037 local cpus=$(getconf _NPROCESSORS_CONF)
1040 # bug 19944, adjust size to be -gt num_possible_cpus()
1041 # promise 2MB for every cpu at least
1042 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1045 lctl set_param debug_mb=$dz
1048 set_default_debug () {
1049 local debug=${1:-"$PTLDEBUG"}
1050 local subsys=${2:-"$SUBSYSTEM"}
1051 local debug_size=${3:-$DEBUG_SIZE}
1053 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1054 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1056 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1059 set_default_debug_nodes () {
1062 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1063 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1067 do_rpc_nodes "$nodes" set_default_debug \
1068 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1071 set_default_debug_facet () {
1073 local node=$(facet_active_host $facet)
1074 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1076 set_default_debug_nodes $node
1081 local facets=${1:-$(get_facets)}
1084 for facet in ${facets//,/ }; do
1087 [ $RC -eq 0 ] && continue
1089 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1090 skip "Restart of $facet failed!." && touch $LU482_FAILED
1092 error "Restart of $facet failed!"
1099 # Add argument "arg" (e.g., "loop") to the comma-separated list
1100 # of arguments for option "opt" (e.g., "-o") on command
1101 # line "opts" (e.g., "-o flock").
1107 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1109 if echo "$opts" | grep -q $opt_pattern; then
1110 opts=$(echo "$opts" | sed -e \
1111 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1113 opts+="${opts:+ }$opt $arg"
1121 local dev=$(facet_active $facet)_dev
1122 local opt=${facet}_opt
1123 local mntpt=$(facet_mntpt $facet)
1124 local opts="${!opt} $@"
1126 if [ $(facet_fstype $facet) == ldiskfs ] &&
1127 ! do_facet $facet test -b ${!dev}; then
1128 opts=$(csa_add "$opts" -o loop)
1131 if [[ $(facet_fstype $facet) == zfs ]]; then
1132 # import ZFS storage pool
1133 import_zpool $facet || return ${PIPESTATUS[0]}
1136 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1137 # for testing LU-482 error handling in mount_facets() and test_0a()
1138 if [ -f $TMP/test-lu482-trigger ]; then
1141 do_facet ${facet} "mkdir -p $mntpt; mount -t lustre $opts \
1145 if [ $RC -ne 0 ]; then
1146 echo "Start of ${!dev} on ${facet} failed ${RC}"
1148 set_default_debug_facet $facet
1150 label=$(devicelabel ${facet} ${!dev})
1151 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1152 eval export ${facet}_svc=${label}
1153 echo Started ${label}
1158 # start facet device options
1164 eval export ${facet}_dev=${device}
1165 eval export ${facet}_opt=\"$@\"
1167 local varname=${facet}failover_dev
1168 if [ -n "${!varname}" ] ; then
1169 eval export ${facet}failover_dev=${!varname}
1171 eval export ${facet}failover_dev=$device
1174 local mntpt=$(facet_mntpt $facet)
1175 do_facet ${facet} mkdir -p $mntpt
1176 eval export ${facet}_MOUNT=$mntpt
1177 mount_facet ${facet}
1186 local HOST=`facet_active_host $facet`
1187 [ -z $HOST ] && echo stop: no host for $facet && return 0
1189 local mntpt=$(facet_mntpt $facet)
1190 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1191 if [ ${running} -ne 0 ]; then
1192 echo "Stopping $mntpt (opts:$@) on $HOST"
1193 do_facet ${facet} umount -d $@ $mntpt
1196 # umount should block, but we should wait for unrelated obd's
1197 # like the MGS or MGC to also stop.
1198 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1200 if [[ $(facet_fstype $facet) == zfs ]]; then
1201 # export ZFS storage pool
1206 # save quota version (both administrative and operational quotas)
1207 # add an additional parameter if mountpoint is ever different from $MOUNT
1209 # XXX This function is kept for interoperability with old server (< 2.3.50),
1210 # it should be removed whenever we drop the interoperability for such
1212 quota_save_version() {
1213 local fsname=${2:-$FSNAME}
1215 local ver=$(tr -c -d "123" <<< $spec)
1216 local type=$(tr -c -d "ug" <<< $spec)
1218 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1220 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1222 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1224 local osts=$(get_facets OST)
1225 for ost in ${osts//,/ }; do
1227 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1231 # client could mount several lustre
1233 # XXX This function is kept for interoperability with old server (< 2.3.50),
1234 # it should be removed whenever we drop the interoperability for such
1237 local fsname=${1:-$FSNAME}
1239 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1241 do_nodes $(comma_list $(osts_nodes)) \
1242 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1246 # XXX This function is kept for interoperability with old server (< 2.3.50),
1247 # it should be removed whenever we drop the interoperability for such
1249 restore_quota_old() {
1250 local mntpt=${1:-$MOUNT}
1251 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
1252 if [ ! "$old_QUOTA_TYPE" ] ||
1253 [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
1256 quota_save_version $old_QUOTA_TYPE
1259 # XXX This function is kept for interoperability with old server (< 2.3.50),
1260 # it should be removed whenever we drop the interoperability for such
1265 # no quota enforcement for now and accounting works out of the box
1268 # We need save the original quota_type params, and restore them after testing
1270 # Suppose that quota type the same on mds and ost
1271 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
1272 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
1273 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
1274 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
1275 export old_QUOTA_TYPE=$quota_type
1276 quota_save_version $QUOTA_TYPE
1278 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
1279 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
1282 local quota_usrs=$QUOTA_USERS
1284 # get_filesystem_size
1285 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1286 local blk_soft=$((disksz + 1024))
1287 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1289 local Inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1290 local i_soft=$Inodes
1291 local i_hard=$((i_soft + i_soft / 20))
1293 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
1294 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
1297 for usr in $quota_usrs; do
1298 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1300 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1302 eval $cmd || error "$cmd FAILED!"
1304 # display the quota status
1305 echo "Quota settings for $usr : "
1306 $LFS quota -v -u $usr $mntpt || true
1310 # get mdt quota type
1312 local varsvc=${SINGLEMDS}_svc
1313 do_facet $SINGLEMDS $LCTL get_param -n \
1314 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1317 # get ost quota type
1319 # All OSTs should have same quota type
1320 local varsvc=ost1_svc
1321 do_facet ost1 $LCTL get_param -n \
1322 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1325 # restore old quota type settings
1327 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1332 if [ "$old_MDT_QUOTA_TYPE" ]; then
1333 do_facet mgs $LCTL conf_param \
1334 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1336 if [ "$old_OST_QUOTA_TYPE" ]; then
1337 do_facet mgs $LCTL conf_param \
1338 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1342 # Handle the case when there is a space in the lfs df
1343 # "filesystem summary" line the same as when there is no space.
1344 # This will allow fixing the "lfs df" summary line in the future.
1346 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1349 # Get free inodes on the MDT specified by mdt index, free indoes on
1350 # the whole filesystem will be returned when index == -1.
1356 if [ $index -eq -1 ]; then
1359 mdt_uuid=$(mdtuuid_from_index $index)
1362 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1367 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1374 # save old quota type & set new quota type
1375 local mdt_qtype=$(mdt_quota_type)
1376 local ost_qtype=$(ost_quota_type)
1378 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1379 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1381 export old_MDT_QUOTA_TYPE=$mdt_qtype
1382 export old_OST_QUOTA_TYPE=$ost_qtype
1384 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1385 error "set mdt quota type failed"
1386 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1387 error "set ost quota type failed"
1389 local quota_usrs=$QUOTA_USERS
1391 # get_filesystem_size
1392 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1393 local blk_soft=$((disksz + 1024))
1394 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1396 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1397 local i_soft=$inodes
1398 local i_hard=$((i_soft + i_soft / 20))
1400 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1401 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1402 "inode-hardlimit: $i_hard"
1405 for usr in $quota_usrs; do
1406 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1408 cmd="$LFS setquota -$type $usr -b $blk_soft"
1409 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1411 eval $cmd || error "$cmd FAILED!"
1413 # display the quota status
1414 echo "Quota settings for $usr : "
1415 $LFS quota -v -u $usr $mntpt || true
1422 local OPTIONS=${3:-$MOUNTOPT}
1424 local device=$MGSNID:/$FSNAME
1425 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1426 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
1430 echo "Starting client: $client: $OPTIONS $device $mnt"
1431 do_node $client mkdir -p $mnt
1432 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
1434 set_default_debug_nodes $client
1446 [ "$3" ] && force=-f
1447 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1448 if [ $running -ne 0 ]; then
1449 echo "Stopping client $client $mnt (opts:$force)"
1450 do_node $client lsof -t $mnt || need_kill=no
1451 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1452 pids=$(do_node $client lsof -t $mnt | sort -u);
1453 if [ -n $pids ]; then
1454 do_node $client kill -9 $pids || true
1458 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1459 if [ $busy -ne 0 ] ; then
1460 echo "$mnt is still busy, wait one second" && sleep 1
1461 do_node $client umount $force $mnt
1466 # nodes is comma list
1467 sanity_mount_check_nodes () {
1473 # FIXME: assume that all cluster nodes run the same os
1474 [ "$(uname)" = Linux ] || return 0
1477 for mnt in $mnts ; do
1478 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1479 mpts=\\\$(mount | grep -c $mnt' ');
1480 if [ \\\$running -ne \\\$mpts ]; then
1481 echo \\\$(hostname) env are INSANE!;
1484 [ $? -eq 0 ] || rc=1
1489 sanity_mount_check_servers () {
1490 [ "$CLIENTONLY" ] &&
1491 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1492 echo Checking servers environments
1494 # FIXME: modify get_facets to display all facets wo params
1495 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1499 for facet in ${facets//,/ }; do
1500 node=$(facet_host ${facet})
1501 mntpt=$(facet_mntpt $facet)
1502 sanity_mount_check_nodes $node $mntpt ||
1503 { error "server $node environments are insane!"; return 1; }
1507 sanity_mount_check_clients () {
1508 local clients=${1:-$CLIENTS}
1509 local mntpt=${2:-$MOUNT}
1510 local mntpt2=${3:-$MOUNT2}
1512 [ -z $clients ] && clients=$(hostname)
1513 echo Checking clients $clients environments
1515 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1516 error "clients environments are insane!"
1519 sanity_mount_check () {
1520 sanity_mount_check_servers || return 1
1521 sanity_mount_check_clients || return 2
1524 # mount clients if not mouted
1525 zconf_mount_clients() {
1528 local OPTIONS=${3:-$MOUNTOPT}
1530 local device=$MGSNID:/$FSNAME
1531 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1532 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
1536 echo "Starting client $clients: $OPTIONS $device $mnt"
1539 running=\\\$(mount | grep -c $mnt' ');
1541 if [ \\\$running -eq 0 ] ; then
1543 mount -t lustre $OPTIONS $device $mnt;
1546 exit \\\$rc" || return ${PIPESTATUS[0]}
1548 echo "Started clients $clients: "
1549 do_nodes $clients "mount | grep $mnt' '"
1551 set_default_debug_nodes $clients
1556 zconf_umount_clients() {
1561 [ "$3" ] && force=-f
1563 echo "Stopping clients: $clients $mnt (opts:$force)"
1564 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1565 if [ \\\$running -ne 0 ] ; then
1566 echo Stopping client \\\$(hostname) $mnt opts:$force;
1567 lsof $mnt || need_kill=no;
1568 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1569 pids=\\\$(lsof -t $mnt | sort -u);
1570 if [ -n \\\"\\\$pids\\\" ]; then
1574 while umount $force $mnt 2>&1 | grep -q "busy"; do
1575 echo "$mnt is still busy, wait one second" && sleep 1;
1582 echo + $POWER_DOWN $node
1586 shutdown_node_hard () {
1588 local attempts=$SHUTDOWN_ATTEMPTS
1590 for i in $(seq $attempts) ; do
1593 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1594 echo "waiting for $host to fail attempts=$attempts"
1595 [ $i -lt $attempts ] || \
1596 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1602 local mnt=${2:-$MOUNT}
1605 if [ "$FAILURE_MODE" = HARD ]; then
1606 shutdown_node_hard $client
1608 zconf_umount_clients $client $mnt -f
1614 local facets="$(get_facets OST),$(get_facets MDS)"
1617 combined_mgs_mds || facets="$facets,mgs"
1619 for facet in ${facets//,/ }; do
1620 if [ $(facet_active_host $facet) == $host ]; then
1621 affected="$affected $facet"
1625 echo $(comma_list $affected)
1630 local host=${2:-$(facet_host $facet)}
1632 local label=$(convert_facet2label $facet)
1633 do_node $host $LCTL dl | awk '{print $4}' | grep -q -x $label
1636 facets_up_on_host () {
1638 local facets=$(facets_on_host $host)
1641 for facet in ${facets//,/ }; do
1642 if $(facet_up $facet $host); then
1643 affected_up="$affected_up $facet"
1647 echo $(comma_list $affected_up)
1653 if [ "$FAILURE_MODE" = HARD ]; then
1654 shutdown_node_hard $(facet_active_host $facet)
1662 echo + $POWER_UP $node
1675 if [ "$FAILURE_MODE" = HARD ]; then
1676 reboot_node $(facet_active_host $facet)
1684 if [ "$FAILURE_MODE" = HARD ]; then
1694 for facet in ${facets//,/ }; do
1695 hosts=$(expand_list $hosts $(facet_host $facet) )
1701 _check_progs_installed () {
1705 for prog in $progs; do
1706 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1707 echo $prog missing on $(hostname)
1714 check_progs_installed () {
1718 do_rpc_nodes "$nodes" _check_progs_installed $@
1721 # recovery-scale functions
1723 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1726 start_client_load() {
1729 local var=$(node_var_name $client)_load
1730 eval export ${var}=$load
1732 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1733 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1734 END_RUN_FILE=$END_RUN_FILE \
1735 LOAD_PID_FILE=$LOAD_PID_FILE \
1736 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1737 TESTNAME=$TESTNAME \
1738 DBENCH_LIB=$DBENCH_LIB \
1739 DBENCH_SRC=$DBENCH_SRC \
1740 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1744 log "Started client load: ${load} on $client"
1746 # get the children process IDs
1747 local pids=$(ps --ppid $ppid -o pid= | xargs)
1748 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1752 start_client_loads () {
1753 local -a clients=(${1//,/ })
1754 local numloads=${#CLIENT_LOADS[@]}
1757 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1758 testnum=$((nodenum % numloads))
1759 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1761 # bug 22169: wait the background threads to start
1765 # only for remote client
1766 check_client_load () {
1768 local var=$(node_var_name $client)_load
1769 local TESTLOAD=run_${!var}.sh
1771 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1773 # bug 18914: try to connect several times not only when
1774 # check ps, but while check_catastrophe also
1777 while [ $RC = 254 -a $tries -gt 0 ]; do
1781 if ! check_catastrophe $client; then
1783 if [ $RC -eq 254 ]; then
1784 # FIXME: not sure how long we shuold sleep here
1788 echo "check catastrophe failed: RC=$RC "
1792 # We can continue try to connect if RC=254
1793 # Just print the warning about this
1794 if [ $RC = 254 ]; then
1795 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1798 # see if the load is still on the client
1801 while [ $RC = 254 -a $tries -gt 0 ]; do
1805 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1810 if [ $RC = 254 ]; then
1811 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1812 # see if we can diagnose a bit why this is
1817 check_client_loads () {
1818 local clients=${1//,/ }
1822 for client in $clients; do
1823 check_client_load $client
1825 if [ "$rc" != 0 ]; then
1826 log "Client load failed on node $client, rc=$rc"
1832 restart_client_loads () {
1833 local clients=${1//,/ }
1834 local expectedfail=${2:-""}
1838 for client in $clients; do
1839 check_client_load $client
1841 if [ "$rc" != 0 -a "$expectedfail" ]; then
1842 local var=$(node_var_name $client)_load
1843 start_client_load $client ${!var}
1844 echo "Restarted client load ${!var}: on $client. Checking ..."
1845 check_client_load $client
1847 if [ "$rc" != 0 ]; then
1848 log "Client load failed to restart on node $client, rc=$rc"
1849 # failure one client load means test fail
1850 # we do not need to check other
1859 # Start vmstat and save its process ID in a file.
1864 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1867 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1868 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1871 # Display the nodes on which client loads failed.
1872 print_end_run_file() {
1876 [ -s $file ] || return 0
1878 echo "Found the END_RUN_FILE file: $file"
1881 # A client load will stop if it finds the END_RUN_FILE file.
1882 # That does not mean the client load actually failed though.
1883 # The first node in END_RUN_FILE is the one we are interested in.
1886 if [ -n "$node" ]; then
1887 local var=$(node_var_name $node)_load
1889 local prefix=$TESTLOG_PREFIX
1890 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
1891 local stdout_log=$prefix.run_${!var}_stdout.$node.log
1892 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
1894 echo "Client load ${!var} failed on node $node:"
1900 # Stop the process which had its PID saved in a file.
1905 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1907 do_nodes $nodes "test -f $pid_file &&
1908 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
1911 # Stop all client loads.
1912 stop_client_loads() {
1913 local nodes=${1:-$CLIENTS}
1916 # stop the client loads
1917 stop_process $nodes $pid_file
1919 # clean up the processes that started them
1920 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
1922 # End recovery-scale functions
1924 # verify that lustre actually cleaned up properly
1926 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
1927 error "LBUG/LASSERT detected"
1928 BUSY=`dmesg | grep -i destruct || true`
1929 if [ "$BUSY" ]; then
1931 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
1935 check_mem_leak || exit 204
1937 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl &&
1938 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
1941 if module_loaded lnet || module_loaded libcfs; then
1942 echo "$TESTSUITE: modules still loaded..." 1>&2
1951 if [[ "$1" == "--verbose" ]]; then
1966 PREV_RESULT=$(do_node $node "$TEST")
1968 RESULT=$(do_node $node "$TEST")
1969 if [[ "$RESULT" == "$FINAL" ]]; then
1970 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
1971 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
1975 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
1976 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
1980 [[ $WAIT -ge $MAX ]] && break
1981 [[ $((WAIT % print)) -eq 0 ]] &&
1982 echo "Waiting $((MAX - WAIT)) secs for update"
1983 WAIT=$((WAIT + sleep))
1986 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
1990 wait_update_facet() {
1993 wait_update $(facet_active_host $facet) "$@"
1997 do_nodes $(comma_list $(mdts_nodes)) \
1998 "lctl set_param -n osd*.*MDT*.force_sync 1"
1999 do_nodes $(comma_list $(osts_nodes)) \
2000 "lctl set_param -n osd*.*OS*.force_sync 1" 2>&1 |
2001 grep -v 'Found no match'
2004 wait_delete_completed_mds() {
2005 local MAX_WAIT=${1:-20}
2007 local stime=`date +%s`
2012 # find MDS with pending deletions
2013 for node in $(mdts_nodes); do
2014 changes=$(do_node $node "lctl get_param -n osc.*MDT*.sync_*" \
2015 2>/dev/null | calc_sum)
2016 if [ -z "$changes" ] || [ $changes -eq 0 ]; then
2019 mds2sync="$mds2sync $node"
2021 if [ "$mds2sync" == "" ]; then
2024 mds2sync=$(comma_list $mds2sync)
2026 # sync MDS transactions
2027 do_nodes $mds2sync "lctl set_param -n osd*.*MD*.force_sync 1"
2029 # wait till all changes are sent and commmitted by OSTs
2030 # for ldiskfs space is released upon execution, but DMU
2031 # do this upon commit
2034 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
2035 changes=$(do_nodes $mds2sync "lctl get_param -n osc.*MDT*.sync_*" \
2037 #echo "$node: $changes changes on all"
2038 if [ "$changes" -eq "0" ]; then
2040 #echo "delete took $((etime - stime)) seconds"
2048 echo "Delete is not completed in $((etime - stime)) seconds"
2049 do_nodes $mds2sync "lctl get_param osc.*MDT*.sync_*"
2055 # we can use "for" here because we are waiting the slowest
2056 for host in ${hostlist//,/ }; do
2057 check_network "$host" 900
2059 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2066 for facet in ${facetlist//,/ }; do
2067 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2069 wait_for_host $hostlist
2072 _wait_recovery_complete () {
2075 # Use default policy if $2 is not passed by caller.
2076 local MAX=${2:-$(max_recovery_time)}
2081 while [ $WAIT -lt $MAX ]; do
2082 STATUS=$(lctl get_param -n $param | grep status)
2084 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2087 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2089 echo "$param recovery not done in $MAX sec. $STATUS"
2093 wait_recovery_complete () {
2096 # with an assumption that at_max is the same on all nodes
2097 local MAX=${2:-$(max_recovery_time)}
2100 if [ "$FAILURE_MODE" = HARD ]; then
2101 facets=$(facets_on_host $(facet_active_host $facet))
2103 echo affected facets: $facets
2105 # we can use "for" here because we are waiting the slowest
2106 for facet in ${facets//,/ }; do
2107 local var_svc=${facet}_svc
2108 local param="*.${!var_svc}.recovery_status"
2110 local host=$(facet_active_host $facet)
2111 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2115 wait_mds_ost_sync () {
2116 # just because recovery is done doesn't mean we've finished
2117 # orphan cleanup. Wait for llogs to get synchronized.
2118 echo "Waiting for orphan cleanup..."
2119 # MAX value includes time needed for MDS-OST reconnection
2120 local MAX=$(( TIMEOUT * 2 ))
2121 local WAIT_TIMEOUT=${1:-$MAX}
2124 local list=$(comma_list $(mdts_nodes))
2125 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2126 if ! do_facet $SINGLEMDS \
2127 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2129 # old way, use mds_sync
2131 list=$(comma_list $(osts_nodes))
2132 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2135 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2136 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2137 local -a sync=($(do_nodes $list "$cmd"))
2140 for ((i=0; i<${#sync[@]}; i++)); do
2142 [ ${sync[$i]} -eq 1 ] && continue
2144 [ ${sync[$i]} -eq 0 ] && continue
2146 # there is a not finished MDS-OST synchronization
2150 sleep 2 # increase waiting time and cover statfs cache
2151 [ ${con} -eq 1 ] && return 0
2152 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2156 # show which nodes are not finished.
2157 do_nodes $list "$cmd"
2158 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2162 wait_destroy_complete () {
2163 echo "Waiting for local destroys to complete"
2164 # MAX value shouldn't be big as this mean server responsiveness
2165 # never increase this just to make test pass but investigate
2166 # why it takes so long time
2169 while [ $WAIT -lt $MAX ]; do
2170 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2174 for ((i=0; i<${#RPCs[@]}; i++)); do
2175 [ ${RPCs[$i]} -eq 0 ] && continue
2176 # there are still some destroy RPCs in flight
2181 [ ${con} -eq 1 ] && return 0 # done waiting
2182 echo "Waiting ${WAIT}s for local destroys to complete"
2185 echo "Local destroys weren't done in $MAX sec."
2189 wait_delete_completed() {
2190 wait_delete_completed_mds $1 || return $?
2191 wait_destroy_complete
2200 # conf-sanity 31 takes a long time cleanup
2201 while [ $WAIT -lt 300 ]; do
2202 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2203 [ -z "${running}" ] && return 0
2204 echo "waited $WAIT for${running}"
2205 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2207 WAIT=$((WAIT + INTERVAL))
2209 echo "service didn't stop after $WAIT seconds. Still running:"
2214 wait_remote_prog () {
2220 [ "$PDSH" = "no_dsh" ] && return 0
2222 while [ $WAIT -lt $2 ]; do
2223 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2224 [ -z "${running}" ] && return 0 || true
2225 echo "waited $WAIT for: "
2227 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2229 WAIT=$((WAIT + INTERVAL))
2231 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2232 [ -z "$pids" ] && return 0
2233 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2234 # FIXME: not portable
2235 for pid in $pids; do
2236 cat /proc/${pid}/status || true
2237 cat /proc/${pid}/wchan || true
2239 kill -9 $pid || true
2248 # not every config has many clients
2250 if [ ! -z "$CLIENTS" ]; then
2251 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
2253 stat -f $MOUNT > /dev/null
2259 # usually checked on particular client or locally
2261 if [ ! -z "$client" ]; then
2262 $PDSH $client "stat -f $MOUNT" > /dev/null
2264 stat -f $MOUNT > /dev/null
2272 client_reconnect() {
2273 uname -n >> $MOUNT/recon
2274 if [ -z "$CLIENTS" ]; then
2275 df $MOUNT; uname -n >> $MOUNT/recon
2277 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
2279 echo Connected clients:
2281 ls -l $MOUNT/recon > /dev/null
2285 affected_facets () {
2288 local host=$(facet_active_host $facet)
2289 local affected=$facet
2291 if [ "$FAILURE_MODE" = HARD ]; then
2292 affected=$(facets_up_on_host $host)
2306 #Because it will only get up facets, we need get affected
2307 #facets before shutdown
2308 #For HARD Failure mode, it needs make sure facets on the same
2309 #HOST will only be shutdown and reboot once
2310 for facet in ${facets//,/ }; do
2311 local affected_facet
2313 #check whether facet has been included in other affected facets
2314 for ((index=0; index<$total; index++)); do
2315 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2318 if [ $skip -eq 0 ]; then
2319 affecteds[$total]=$(affected_facets $facet)
2324 for ((index=0; index<$total; index++)); do
2325 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2326 local host=$(facet_active_host $facet)
2327 echo "Failing ${affecteds[index]} on $host"
2328 shutdown_facet $facet
2331 for ((index=0; index<$total; index++)); do
2332 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2333 echo reboot facets: ${affecteds[index]}
2337 change_active ${affecteds[index]}
2339 wait_for_facet ${affecteds[index]}
2340 # start mgs first if it is affected
2341 if ! combined_mgs_mds &&
2342 list_member ${affecteds[index]} mgs; then
2343 mount_facet mgs || error "Restart of mgs failed"
2345 # FIXME; has to be changed to mount all facets concurrently
2346 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2347 echo mount facets: ${affecteds[index]}
2348 mount_facets ${affecteds[index]}
2358 do_facet $facet "sync; sync; sync"
2361 # make sure there will be no seq change
2362 local clients=${CLIENTS:-$HOSTNAME}
2363 local f=fsa-\\\$\(hostname\)
2364 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2365 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2367 local svc=${facet}_svc
2368 do_facet $facet $LCTL --device ${!svc} notransno
2370 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2371 # in-memory state has to be cleared by either rebooting the host or
2372 # exporting and reimporting the pool.
2374 # Although the uberblocks are not updated when a pool is freezed,
2375 # transactions are still written to the disks. Modified blocks may be
2376 # cached in memory when tests try reading them back. The
2377 # export-and-reimport process also evicts any cached pool data from
2378 # memory to provide the correct "data loss" semantics.
2380 # In the test framework, the exporting and importing operations are
2381 # handled by stop() and mount_facet() separately, which are used
2382 # inside fail() and fail_abort().
2384 do_facet $facet $LCTL --device ${!svc} readonly
2385 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2386 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2389 replay_barrier_nodf() {
2390 local facet=$1 echo running=${running}
2391 do_facet $facet "sync; sync; sync"
2392 local svc=${facet}_svc
2393 echo Replay barrier on ${!svc}
2394 do_facet $facet $LCTL --device ${!svc} notransno
2395 do_facet $facet $LCTL --device ${!svc} readonly
2396 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2397 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2400 replay_barrier_nosync() {
2401 local facet=$1 echo running=${running}
2402 local svc=${facet}_svc
2403 echo Replay barrier on ${!svc}
2404 do_facet $facet $LCTL --device ${!svc} notransno
2405 do_facet $facet $LCTL --device ${!svc} readonly
2406 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2407 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2411 # Get Lustre client uuid for a given Lustre mount point.
2414 local mntpnt=${1:-$MOUNT}
2416 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2417 local uuid=$($LCTL get_param -n llite.$name.uuid)
2422 mds_evict_client() {
2423 local mntpnt=${1:-$MOUNT}
2424 local uuid=$(get_client_uuid $mntpnt)
2426 do_facet $SINGLEMDS \
2427 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2430 ost_evict_client() {
2431 local mntpnt=${1:-$MOUNT}
2432 local uuid=$(get_client_uuid $mntpnt)
2435 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2440 local clients=${CLIENTS:-$HOSTNAME}
2442 facet_failover $* || error "failover: $?"
2443 wait_clients_import_state "$clients" "$facets" FULL
2444 clients_up || error "post-failover df: $?"
2449 facet_failover $facet
2455 change_active $facet
2456 wait_for_facet $facet
2457 mount_facet $facet -o abort_recovery
2458 clients_up || echo "first df failed: $?"
2459 clients_up || error "post-failover df: $?"
2463 echo There is no lmc. This is mountconf, baby.
2467 host_nids_address() {
2471 if [ -n "$kind" ]; then
2472 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2474 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2480 if [ "$1" = "'*'" ]; then echo \'*\'; else
2486 if [ "$1" = "'*'" ]; then echo \'*\'; else
2487 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2489 if [ -z "$ID" ]; then
2490 echo "Could not get a ptl id for $1..."
2499 h2name_or_ip "$1" "tcp"
2504 if [ "$1" = "'*'" ]; then echo \'*\'; else
2505 if type __h2elan >/dev/null 2>&1; then
2508 ID=`echo $1 | sed 's/[^0-9]*//g'`
2516 h2name_or_ip "$1" "o2ib"
2520 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2521 # expressions format. As a bonus we can then just pass in those variables
2522 # to pdsh. What this function does is take a HOSTLIST type string and
2523 # expand it into a space deliminated list for us.
2531 [ -z "$hostlist" ] && return
2533 # Translate the case of [..],..,[..] to [..] .. [..]
2534 list="${hostlist/],/] }"
2536 [[ "$front" == *,* ]] && {
2539 list=${list/${old}/${new}}
2542 for item in $list; do
2543 # Test if we have any []'s at all
2544 if [ "$item" != "${item/\[/}" ]; then {
2545 # Expand the [*] into list
2549 if [ "$name" != "$item" ]; then
2550 group=${item#$name[*}
2553 for range in ${group//,/ }; do
2557 # Number of leading zeros
2560 end=$(echo $end | sed 's/0*//')
2561 [[ -z "$end" ]] && end=0
2562 [[ $padlen2 -gt $padlen ]] && {
2563 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2566 begin=$(echo $begin | sed 's/0*//')
2567 [ -z $begin ] && begin=0
2569 for num in $(seq -f "%0${padlen}g" $begin $end); do
2570 value="${name#*,}${num}${back}"
2571 [ "$value" != "${value/\[/}" ] && {
2572 value=$(hostlist_expand "$value")
2574 myList="$myList $value"
2579 myList="$myList $item"
2582 myList=${myList//,/ }
2583 myList=${myList:1} # Remove first character which is a space
2585 # Filter any duplicates without sorting
2587 myList="${list%% *}"
2589 while [[ "$list" != ${myList##* } ]]; do
2590 list=${list//${list%% *} /}
2591 myList="$myList ${list%% *}"
2593 myList="${myList%* }";
2595 # We can select an object at a offset in the list
2598 for item in $myList; do
2600 [ $cnt -eq $offset ] && {
2604 [ $(get_node_count $myList) -ne 1 ] && myList=""
2613 [ "$facet" == client ] && echo -n $HOSTNAME && return
2614 varname=${facet}_HOST
2615 if [ -z "${!varname}" ]; then
2616 if [ "${facet:0:3}" == "ost" ]; then
2617 local fh=${facet%failover}_HOST
2618 eval export ${facet}_HOST=${!fh}
2619 if [ -z "${!varname}" ]; then
2620 eval export ${facet}_HOST=${ost_HOST}
2622 elif [ "${facet:0:3}" == "mdt" -o \
2623 "${facet:0:3}" == "mds" -o \
2624 "${facet:0:3}" == "mgs" ]; then
2625 eval export ${facet}_HOST=${mds_HOST}
2631 facet_failover_host() {
2635 var=${facet}failover_HOST
2636 if [ -n "${!var}" ]; then
2641 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2642 "${facet:0:3}" == "mgs" ]; then
2644 eval export ${facet}failover_host=${mds_HOST}
2649 if [[ $facet == ost* ]]; then
2650 eval export ${facet}failover_host=${ost_HOST}
2658 local activevar=${facet}active
2660 if [ -f $TMP/${facet}active ] ; then
2661 source $TMP/${facet}active
2664 active=${!activevar}
2665 if [ -z "$active" ] ; then
2672 facet_active_host() {
2674 local active=`facet_active $facet`
2675 if [ "$facet" == client ]; then
2678 echo `facet_host $active`
2682 # Get the passive failover partner host of facet.
2683 facet_passive_host() {
2685 [[ $facet = client ]] && return
2687 local host=${facet}_HOST
2688 local failover_host=${facet}failover_HOST
2689 local active_host=$(facet_active_host $facet)
2691 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2693 if [[ $active_host = ${!host} ]]; then
2694 echo -n ${!failover_host}
2704 facetlist=$(exclude_items_from_list $facetlist mgs)
2706 for facet in ${facetlist//,/ }; do
2707 local failover=${facet}failover
2708 local host=`facet_host $failover`
2709 [ -z "$host" ] && return
2711 local curactive=`facet_active $facet`
2712 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2713 eval export ${facet}active=$facet
2715 eval export ${facet}active=$failover
2717 # save the active host for this facet
2718 local activevar=${facet}active
2719 echo "$activevar=${!activevar}" > $TMP/$activevar
2720 [[ $facet = mds1 ]] && combined_mgs_mds && \
2721 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2722 local TO=`facet_active_host $facet`
2723 echo "Failover $facet to $TO"
2729 # do not stripe off hostname if verbose, bug 19215
2730 if [ x$1 = x--verbose ]; then
2738 if [ "$HOST" = "$HOSTNAME" ]; then
2740 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2741 echo "cannot run remote command on $HOST with $myPDSH"
2745 echo "CMD: $HOST $@" >&2
2746 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2749 if [ "$myPDSH" = "rsh" ]; then
2750 # we need this because rsh does not return exit code of an executed command
2751 local command_status="$TMP/cs"
2752 rsh $HOST ":> $command_status"
2753 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2754 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2755 echo command failed >$command_status"
2756 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2761 # print HOSTNAME for myPDSH="no_dsh"
2762 if [[ $myPDSH = no_dsh ]]; then
2763 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2765 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2768 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2770 return ${PIPESTATUS[0]}
2774 do_node --verbose "$@"
2777 single_local_node () {
2778 [ "$1" = "$HOSTNAME" ]
2781 # Outputs environment variable assignments that should be passed to remote nodes
2785 local facets=$(get_facets)
2788 for var in ${!MODOPTS_*}; do
2790 echo -n " ${var}=\"$value\""
2793 for facet in ${facets//,/ }; do
2795 if [ -n "${!var}" ]; then
2796 echo -n " $var=${!var}"
2800 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2801 if [ -n "${!var}" ]; then
2802 echo -n " $var=${!var}"
2806 if [ -n "$FSTYPE" ]; then
2807 echo -n " FSTYPE=$FSTYPE"
2813 # do not stripe off hostname if verbose, bug 19215
2814 if [ x$1 = x--verbose ]; then
2822 if single_local_node $rnodes; then
2824 do_nodev $rnodes "$@"
2826 do_node $rnodes "$@"
2831 # This is part from do_node
2834 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2835 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2837 export FANOUT=$(get_node_count "${rnodes//,/ }")
2839 echo "CMD: $rnodes $@" >&2
2840 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2843 # do not replace anything from pdsh output if -N is used
2844 # -N Disable hostname: prefix on lines of output.
2845 if $verbose || [[ $myPDSH = *-N* ]]; then
2846 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2848 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2850 return ${PIPESTATUS[0]}
2856 local HOST=`facet_active_host $facet`
2857 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
2861 # Function: do_facet_random_file $FACET $FILE $SIZE
2862 # Creates FILE with random content on the given FACET of given SIZE
2864 do_facet_random_file() {
2868 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
2869 do_facet $facet "$cmd 2>/dev/null"
2872 do_facet_create_file() {
2876 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
2877 do_facet $facet "$cmd 2>/dev/null"
2881 do_nodes --verbose "$@"
2887 # make sure its not already running
2889 rm -f $TMP/${facet}active
2890 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
2891 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
2893 if [[ $(facet_fstype $facet) == zfs ]]; then
2895 # After formatting a ZFS target, "cachefile=none" property will
2896 # be set on the ZFS storage pool so that the pool is not
2897 # automatically imported on system startup. And then the pool
2898 # will be exported so as to leave the importing and exporting
2899 # operations handled by mount_facet() and stop() separately.
2901 refresh_partition_table $facet $(facet_vdevice $facet)
2902 disable_zpool_cache $facet
2907 # Device formatted as ost
2910 local DEVNAME=OSTDEV$num
2912 local fstype=$(facet_fstype ost$num)
2916 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2917 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2919 #try $OSTZFSDEVn - independent of vdev
2920 DEVNAME=OSTZFSDEV$num
2921 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
2923 error "unknown fstype!";;
2929 # Physical device location of data
2935 local fstype=$(facet_fstype ost$num)
2939 # vdevs are not supported by ldiskfs
2942 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
2943 # Device formated by zfs
2945 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2947 error "unknown fstype!";;
2953 # Logical device formated for lustre
2956 local DEVNAME=MDSDEV$num
2958 local fstype=$(facet_fstype mds$num)
2962 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
2963 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
2965 # try $MDSZFSDEVn - independent of vdev
2966 DEVNAME=MDSZFSDEV$num
2967 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
2969 error "unknown fstype!";;
2975 # Physical location of data
2979 local fstype=$(facet_fstype mds$num)
2983 # vdevs are not supported by ldiskfs
2986 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
2987 # Device formated by ZFS
2988 local DEVNAME=MDSDEV$num
2989 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
2991 error "unknown fstype!";;
2999 local fstype=$(facet_fstype mgs)
3003 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3004 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3005 DEVPTR=$(mdsdevname 1)
3010 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3011 ( [ -z "$MGSZFSDEV" ] &&
3012 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3013 DEVPTR=$(mdsdevname 1)
3015 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3018 error "unknown fstype!";;
3027 local fstype=$(facet_fstype mgs)
3031 # vdevs are not supported by ldiskfs
3034 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3035 ( [ -z "$MGSDEV" ] &&
3036 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3037 VDEVPTR=$(mdsvdevname 1)
3038 elif [ -n "$MGSDEV" ]; then
3042 error "unknown fstype!";;
3050 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3052 local var=${facet}_MOUNT
3053 eval mntpt=${!var:-${MOUNT%/*}/$facet}
3060 local dev=$(facet_device $facet)
3061 local mnt=$(facet_mntpt $facet)
3064 if ! do_facet $facet test -b $dev; then
3067 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3072 local dev=$(facet_device $facet)
3073 local mnt=$(facet_mntpt $facet)
3075 do_facet $facet umount -d $mnt
3079 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3084 local ds=$(facet_device $facet)
3085 local mnt=$(facet_mntpt $facet)
3090 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3091 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3092 do_facet $facet $ZFS set canmount=noauto $ds
3094 # The "legacy" mount method is used here because "zfs unmount $mnt"
3095 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3096 # targets are not available at the time, the stat(2) on $MOUNT will
3099 do_facet $facet $ZFS set mountpoint=legacy $ds
3100 do_facet $facet mount -t zfs $ds $mnt
3101 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3102 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3107 local ds=$(facet_device $facet)
3108 local mnt=$(facet_mntpt $facet)
3109 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3110 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3111 local mntpt=${!var_mntpt}
3112 local canmnt=${!var_canmnt}
3116 do_facet $facet umount $mnt
3117 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3118 do_facet $facet $ZFS set canmount=$canmnt $ds
3124 local fstype=$(facet_fstype $facet)
3126 mount_$fstype $facet
3131 local fstype=$(facet_fstype $facet)
3133 unmount_$fstype $facet
3140 # make sure we are using the primary server, so test-framework will
3141 # be able to clean up properly.
3142 activemds=`facet_active mds1`
3143 if [ $activemds != "mds1" ]; then
3147 local clients=$CLIENTS
3148 [ -z $clients ] && clients=$(hostname)
3150 zconf_umount_clients $clients $MOUNT "$*" || true
3151 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3153 [ "$CLIENTONLY" ] && return
3154 # The add fn does rm ${facet}active file, this would be enough
3155 # if we use do_facet <facet> only after the facet added, but
3156 # currently we use do_facet mds in local.sh
3157 for num in `seq $MDSCOUNT`; do
3159 rm -f ${TMP}/mds${num}active
3161 combined_mgs_mds && rm -f $TMP/mgsactive
3163 for num in `seq $OSTCOUNT`; do
3165 rm -f $TMP/ost${num}active
3168 if ! combined_mgs_mds ; then
3175 cleanup_echo_devs () {
3176 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3178 for dev in $devs; do
3179 $LCTL --device $dev cleanup
3180 $LCTL --device $dev detach
3185 nfs_client_mode && return
3194 combined_mgs_mds () {
3195 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3196 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3200 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3204 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3210 local fsname=${3:-"$FSNAME"}
3211 local type=$(facet_type $facet)
3212 local index=$(($(facet_number $facet) - 1))
3213 local fstype=$(facet_fstype $facet)
3214 local host=$(facet_host $facet)
3219 if [ $type == MGS ] && combined_mgs_mds; then
3223 if [ $type == MGS ] || ( [ $type == MDS ] &&
3224 [ "$dev" == $(mgsdevname) ] &&
3225 [ "$host" == "$(facet_host mgs)" ] ); then
3228 opts="--mgsnode=$MGSNID"
3231 if [ $type != MGS ]; then
3232 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3236 var=${facet}failover_HOST
3237 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3238 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3241 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3242 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3244 if [ $type == MDS ]; then
3245 opts+=${SECLEVEL:+" --param=mdt.sec_level"}
3246 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3247 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3248 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3249 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3251 if [ $fstype == ldiskfs ]; then
3252 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3253 if [ ! -z $EJOURNAL ]; then
3254 fs_mkfs_opts+=${MDSJOURNALSIZE:+" device=$EJOURNAL"}
3256 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3260 if [ $type == OST ]; then
3261 opts+=${SECLEVEL:+" --param=ost.sec_level"}
3262 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3264 if [ $fstype == ldiskfs ]; then
3265 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3269 opts+=" --backfstype=$fstype"
3272 if [ -n "${!var}" ]; then
3273 opts+=" --device-size=${!var}"
3276 var=$(upper $fstype)_MKFS_OPTS
3277 fs_mkfs_opts+=${!var:+" ${!var}"}
3279 var=${type}_FS_MKFS_OPTS
3280 fs_mkfs_opts+=${!var:+" ${!var}"}
3282 if [ -n "${fs_mkfs_opts## }" ]; then
3283 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3287 opts+=${!var:+" ${!var}"}
3300 # We need ldiskfs here, may as well load them all
3302 [ "$CLIENTONLY" ] && return
3303 echo Formatting mgs, mds, osts
3304 if ! combined_mgs_mds ; then
3305 echo "Format mgs: $(mgsdevname)"
3306 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3307 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} ||
3311 for num in $(seq $MDSCOUNT); do
3312 echo "Format mds$num: $(mdsdevname $num)"
3313 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3314 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3315 ${quiet:+>/dev/null} || exit 10
3318 for num in $(seq $OSTCOUNT); do
3319 echo "Format ost$num: $(ostdevname $num)"
3320 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3321 --reformat $(ostdevname $num) $(ostvdevname ${num}) \
3322 ${quiet:+>/dev/null} || exit 10
3327 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3331 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3335 # 0: success, the old identity set already.
3336 # 1: success, the old identity does not set.
3341 local j=`expr $num - 1`
3342 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3344 if [ -z "$MDT" ]; then
3348 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3351 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3353 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3356 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3358 if [ $old = "NONE" ]; then
3367 zconf_umount `hostname` $1 || error "umount failed"
3368 zconf_mount `hostname` $1 || error "mount failed"
3376 rm -f $TMP/${facet}active
3377 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3382 local mdt_count=${1:-$MDSCOUNT}
3383 local ost_count=${2:-$OSTCOUNT}
3386 for num in $(seq $mdt_count); do
3387 DEVNAME=$(mdsdevname $num)
3388 writeconf_facet mds$num $DEVNAME || rc=$?
3391 for num in $(seq $ost_count); do
3392 DEVNAME=$(ostdevname $num)
3393 writeconf_facet ost$num $DEVNAME || rc=$?
3399 nfs_client_mode && return
3401 sanity_mount_check ||
3402 error "environments are insane!"
3406 if [ -z "$CLIENTONLY" ]; then
3407 echo Setup mgs, mdt, osts
3408 echo $WRITECONF | grep -q "writeconf" && \
3410 if ! combined_mgs_mds ; then
3411 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3414 for num in `seq $MDSCOUNT`; do
3415 DEVNAME=$(mdsdevname $num)
3416 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3418 # We started mds, now we should set failover variables properly.
3419 # Set mds${num}failover_HOST if it is not set (the default failnode).
3420 local varname=mds${num}failover_HOST
3421 if [ -z "${!varname}" ]; then
3422 eval mds${num}failover_HOST=$(facet_host mds$num)
3425 if [ $IDENTITY_UPCALL != "default" ]; then
3426 switch_identity $num $IDENTITY_UPCALL
3429 for num in `seq $OSTCOUNT`; do
3430 DEVNAME=$(ostdevname $num)
3431 start ost$num $DEVNAME $OST_MOUNT_OPTS
3433 # We started ost$num, now we should set ost${num}failover variable properly.
3434 # Set ost${num}failover_HOST if it is not set (the default failnode).
3435 varname=ost${num}failover_HOST
3436 if [ -z "${!varname}" ]; then
3437 eval ost${num}failover_HOST=$(facet_host ost${num})
3445 # wait a while to allow sptlrpc configuration be propogated to targets,
3446 # only needed when mounting new target devices.
3451 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3453 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3456 if [ "$MOUNT_2" ]; then
3457 mount_client $MOUNT2
3458 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3463 # by remounting mdt before ost, initial connect from mdt to ost might
3464 # timeout because ost is not ready yet. wait some time to its fully
3465 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3466 # by a context negotiation rpc with $TIMEOUT.
3467 # FIXME better by monitoring import status.
3470 sleep $((TIMEOUT + 5))
3476 mounted_lustre_filesystems() {
3477 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3480 init_facet_vars () {
3481 [ "$CLIENTONLY" ] && return 0
3488 eval export ${facet}_dev=${device}
3489 eval export ${facet}_opt=\"$@\"
3491 local dev=${facet}_dev
3493 # We need to loop for the label
3494 # in case its not initialized yet.
3495 for wait_time in {0,1,3,5,10}; do
3497 if [ $wait_time -gt 0 ]; then
3498 echo "${!dev} not yet initialized,"\
3499 "waiting ${wait_time} seconds."
3503 local label=$(devicelabel ${facet} ${!dev})
3505 # Check to make sure the label does
3506 # not include ffff at the end of the label.
3507 # This indicates it has not been initialized yet.
3509 if [[ $label =~ [f|F]{4}$ ]]; then
3510 # label is not initialized, unset the result
3511 # and either try again or fail
3518 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3520 eval export ${facet}_svc=${label}
3522 local varname=${facet}failover_HOST
3523 if [ -z "${!varname}" ]; then
3524 eval export $varname=$(facet_host $facet)
3527 varname=${facet}_HOST
3528 if [ -z "${!varname}" ]; then
3529 eval export $varname=$(facet_host $facet)
3532 # ${facet}failover_dev is set in cfg file
3533 varname=${facet}failover_dev
3534 if [ -n "${!varname}" ] ; then
3535 eval export ${facet}failover_dev=${!varname}
3537 eval export ${facet}failover_dev=$device
3540 # get mount point of already mounted device
3541 # is facet_dev is already mounted then use the real
3542 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3543 # i.e. ${facet}_MOUNT if specified by user or default
3544 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3545 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3546 if [ -z $mntpt ]; then
3547 mntpt=$(facet_mntpt $facet)
3549 eval export ${facet}_MOUNT=$mntpt
3552 init_facets_vars () {
3555 if ! remote_mds_nodsh; then
3556 for num in $(seq $MDSCOUNT); do
3557 DEVNAME=`mdsdevname $num`
3558 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3562 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3564 if ! remote_ost_nodsh; then
3565 for num in $(seq $OSTCOUNT); do
3566 DEVNAME=$(ostdevname $num)
3567 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3572 osc_ensure_active () {
3577 while [ $period -lt $timeout ]; do
3578 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3579 if [ $count -eq 0 ]; then
3583 echo "There are $count OST are inactive, wait $period seconds, and try again"
3585 period=$((period+3))
3588 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3591 set_conf_param_and_check() {
3595 local ORIG=$(do_facet $myfacet "$TEST")
3596 if [ $# -gt 3 ]; then
3602 echo "Setting $PARAM from $ORIG to $FINAL"
3603 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3604 error "conf_param $PARAM failed"
3606 wait_update $(facet_host $myfacet) "$TEST" "$FINAL" ||
3607 error "check $PARAM failed!"
3610 init_param_vars () {
3612 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3614 log "Using TIMEOUT=$TIMEOUT"
3616 osc_ensure_active $SINGLEMDS $TIMEOUT
3617 osc_ensure_active client $TIMEOUT
3619 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
3620 local current_jobid_var=$($LCTL get_param -n jobid_var)
3622 if [ $JOBID_VAR = "existing" ]; then
3623 echo "keeping jobstats as $current_jobid_var"
3624 elif [ $current_jobid_var != $JOBID_VAR ]; then
3625 echo "seting jobstats to $JOBID_VAR"
3627 set_conf_param_and_check client \
3628 "$LCTL get_param -n jobid_var" \
3629 "$FSNAME.sys.jobid_var" $JOBID_VAR
3632 echo "jobstats not supported by server"
3635 if [ $QUOTA_AUTO -ne 0 ]; then
3636 if [ "$ENABLE_QUOTA" ]; then
3637 echo "enable quota as required"
3638 setup_quota $MOUNT || return 2
3640 echo "disable quota as required"
3641 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
3647 nfs_client_mode () {
3648 if [ "$NFSCLIENT" ]; then
3649 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
3650 local clients=$CLIENTS
3651 [ -z $clients ] && clients=$(hostname)
3653 # FIXME: remove hostname when 19215 fixed
3654 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
3655 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
3656 if [[ ${#nfsexport[@]} -eq 0 ]]; then
3657 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
3659 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
3665 check_config_client () {
3668 local mounted=$(mount | grep " $mntpt ")
3669 if [ "$CLIENTONLY" ]; then
3671 # CLIENTONLY should not depend on *_HOST settings
3672 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
3673 # in theory someone could create a new,
3674 # client-only config file that assumed lustre was already
3675 # configured and didn't set the MGSNID. If MGSNID is not set,
3676 # then we should use the mgs nid currently being used
3677 # as the default value. bug 18021
3678 [[ x$MGSNID = x ]] &&
3681 if [[ x$mgc != xMGC$MGSNID ]]; then
3682 if [ "$mgs_HOST" ]; then
3683 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
3684 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
3685 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
3691 local myMGS_host=$mgs_HOST
3692 if [ "$NETTYPE" = "ptl" ]; then
3693 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
3696 echo Checking config lustre mounted on $mntpt
3697 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
3698 mgshost=$(echo $mgshost | awk -F: '{print $1}')
3700 # if [ "$mgshost" != "$myMGS_host" ]; then
3701 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
3702 # Please use correct config or set mds_HOST correctly!"
3707 check_config_clients () {
3708 local clients=${CLIENTS:-$HOSTNAME}
3711 nfs_client_mode && return
3713 do_rpc_nodes "$clients" check_config_client $mntpt
3715 sanity_mount_check || error "environments are insane!"
3719 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3720 local cltimeout=$(lctl get_param -n timeout)
3721 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
3722 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
3729 [ -z $mntpt ] && return 1
3730 local mounted=$(mounted_lustre_filesystems)
3732 echo $mounted' ' | grep -w -q $mntpt' '
3736 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
3740 # empty lustre filesystem may have empty directories lost+found and .lustre
3742 # exclude .lustre & lost+found
3743 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
3744 -print | wc -l) = 1 ] || return 1
3745 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
3746 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
3747 # exclude .lustre/fid (LU-2780)
3748 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
3749 -print | wc -l) = 1 ] || return 1
3751 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
3756 check_and_setup_lustre() {
3757 nfs_client_mode && return
3759 local MOUNTED=$(mounted_lustre_filesystems)
3763 # both MOUNT and MOUNT2 are not mounted
3764 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
3765 [ "$REFORMAT" ] && formatall
3766 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
3768 is_mounted $MOUNT || error "NAME=$NAME not mounted"
3769 export I_MOUNTED=yes
3773 elif is_mounted $MOUNT2; then
3775 # MOUNT2 is mounted, while MOUNT_2 is not set
3776 if ! [ "$MOUNT_2" ]; then
3777 cleanup_mount $MOUNT2
3778 export I_UMOUNTED2=yes
3781 # MOUNT2 is mounted, MOUNT_2 is set
3783 # FIXME: what to do if check_config failed?
3785 # 1) remote client has mounted other Lustre fs ?
3786 # 2) it has insane env ?
3787 # let's try umount MOUNT2 on all clients and mount it again:
3788 if ! check_config_clients $MOUNT2; then
3789 cleanup_mount $MOUNT2
3790 restore_mount $MOUNT2
3791 export I_MOUNTED2=yes
3796 # MOUNT is mounted MOUNT2 is not mounted
3797 elif [ "$MOUNT_2" ]; then
3798 restore_mount $MOUNT2
3799 export I_MOUNTED2=yes
3803 # FIXME: what to do if check_config failed?
3805 # 1) remote client has mounted other Lustre fs?
3806 # 2) lustre is mounted on remote_clients atall ?
3807 check_config_clients $MOUNT
3811 set_default_debug_nodes $(comma_list $(nodes_list))
3814 if [ $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ] ; then
3816 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
3817 facets="$(get_facets OST)"
3818 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
3819 facets="$facets,$(get_facets MDS)"
3820 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
3821 facets="$facets,mgs"
3822 local nodes="$(facets_hosts ${facets})"
3823 if [ -n "$nodes" ] ; then
3824 do_nodes $nodes "$LCTL set_param \
3825 osd-ldiskfs.track_declares_assert=1 || true"
3834 if [ "$ONLY" == "setup" ]; then
3840 local clients=${CLIENTS:-$HOSTNAME}
3843 zconf_mount_clients $clients $mntpt
3847 local clients=${CLIENTS:-$HOSTNAME}
3850 zconf_umount_clients $clients $mntpt
3853 cleanup_and_setup_lustre() {
3854 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
3855 lctl set_param debug=0 || true
3857 if [ "$ONLY" == "cleanup" ]; then
3861 check_and_setup_lustre
3864 # Get all of the server target devices from a given server node and type.
3871 if [ "$type" == ost ]; then
3872 devs=$(get_osd_param $node "" mntdev)
3874 devs=$(do_node $node \
3875 "lctl get_param -n osd-*.$FSNAME-M*.mntdev")
3877 for dev in $devs; do
3879 *loop*) do_node $node "losetup $dev" | \
3880 sed -e "s/.*(//" -e "s/).*//" ;;
3886 # Get all of the server target devices.
3891 MDTDEV=$(get_mnt_devs $(mdts_nodes) mdt)
3895 for node in $(osts_nodes); do
3896 OSTDEVS[i]=$(get_mnt_devs $node ost)
3901 # Run e2fsck on MDT or OST device.
3907 df > /dev/null # update statfs data on disk
3908 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
3911 do_node $node $cmd || rc=$?
3912 [ $rc -le $FSCK_MAX_ERR ] || \
3913 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
3918 # Run resize2fs on MDT or OST device.
3927 do_facet $facet "$RESIZE2FS $opts $device $size"
3930 # verify a directory is shared among nodes.
3931 check_shared_dir() {
3933 local list=${2:-$(comma_list $(nodes_list))}
3935 [ -z "$dir" ] && return 1
3936 do_rpc_nodes "$list" check_logdir $dir
3937 check_write_access $dir "$list" || return 1
3941 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
3947 [[ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]] ||
3948 { skip "Lustre 2.2.0 lacks the patch for LU-1255"; exit 0; }
3950 check_shared_dir $SHARED_DIRECTORY ||
3951 error "$SHARED_DIRECTORY isn't a shared directory"
3953 export MDSDB=$SHARED_DIRECTORY/mdsdb
3954 export OSTDB=$SHARED_DIRECTORY/ostdb
3956 [ $MDSCOUNT -eq 1 ] || error "CMD is not supported"
3958 run_e2fsck $(mdts_nodes) $MDTDEV "-n --mdsdb $MDSDB"
3963 for node in $(osts_nodes); do
3964 for dev in ${OSTDEVS[i]}; do
3965 run_e2fsck $node $dev "-n --mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
3966 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
3967 ostidx=$((ostidx + 1))
3973 # Run lfsck on server node if lfsck can't be found on client (LU-2571)
3974 run_lfsck_remote() {
3975 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
3980 #Check if lustre is already mounted
3981 do_rpc_nodes $client is_mounted $MOUNT || mounted=false
3983 zconf_mount $client $MOUNT ||
3984 error "failed to mount Lustre on $client"
3988 do_node $node $cmd || rc=$?
3989 #Umount if necessary
3991 zconf_umount $client $MOUNT ||
3992 error "failed to unmount Lustre on $client"
3995 [ $rc -le $FSCK_MAX_ERR ] ||
3996 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
3997 echo "lfsck finished with rc=$rc"
4003 local facets="client $SINGLEMDS"
4009 for facet in $facets; do
4010 node=$(facet_active_host $facet)
4011 if check_progs_installed $node $LFSCK_BIN; then
4016 ! $found && error "None of \"$facets\" supports lfsck"
4018 run_lfsck_remote $node || rc=$?
4020 rm -rvf $MDSDB* $OSTDB* || true
4024 check_and_cleanup_lustre() {
4025 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
4031 if is_mounted $MOUNT; then
4032 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4033 error "remove sub-test dirs failed"
4034 [ "$ENABLE_QUOTA" ] && restore_quota || true
4037 if [ "$I_UMOUNTED2" = "yes" ]; then
4038 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4041 if [ "$I_MOUNTED2" = "yes" ]; then
4042 cleanup_mount $MOUNT2
4045 if [ "$I_MOUNTED" = "yes" ]; then
4046 cleanupall -f || error "cleanup failed"
4054 wait_for_function () {
4057 # suppress fn both stderr and stdout
4058 if [ "$1" = "--quiet" ]; then
4060 quiet=" > /dev/null 2>&1"
4072 eval $fn $quiet && return 0
4074 wait=$((wait + sleep))
4075 [ $wait -lt $max ] || return 1
4076 echo waiting $fn, $((max - wait)) secs left ...
4086 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4087 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4088 echo "Network not available!"
4092 echo `date +"%H:%M:%S (%s)"` network interface is UP
4100 # Convert a space-delimited list to a comma-delimited list. If the input is
4101 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4103 # echo is used to convert newlines to spaces, since it doesn't
4104 # introduce a trailing space as using "tr '\n' ' '" does
4105 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4111 echo $list | grep -qw $item
4114 # list, excluded are the comma separated lists
4115 exclude_items_from_list () {
4121 for item in ${excluded//,/ }; do
4122 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4124 echo $(comma_list $list)
4127 # list, expand are the comma separated lists
4129 local list=${1//,/ }
4130 local expand=${2//,/ }
4133 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4134 echo $(comma_list $expanded)
4137 testslist_filter () {
4138 local script=$LUSTRE/tests/${TESTSUITE}.sh
4140 [ -f $script ] || return 0
4142 local start_at=$START_AT
4143 local stop_at=$STOP_AT
4145 local var=${TESTSUITE//-/_}_START_AT
4146 [ x"${!var}" != x ] && start_at=${!var}
4147 var=${TESTSUITE//-/_}_STOP_AT
4148 [ x"${!var}" != x ] && stop_at=${!var}
4150 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4151 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4152 /^'${start_at}'$/ {flag = 0}
4153 {if (flag == 1) print $0}
4154 /^'${stop_at}'$/ { flag = 1 }'
4158 (cd `dirname $1`; echo $PWD/`basename $1`)
4162 local types=${1:-"OST MDS MGS"}
4166 for entry in $types; do
4167 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4168 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4171 MGS ) list="$list $name";;
4172 MDS|OST|AGT ) local count=${type}COUNT
4173 for ((i=1; i<=${!count}; i++)) do
4174 list="$list ${name}$i"
4176 * ) error "Invalid facet type"
4180 echo $(comma_list $list)
4183 ##################################
4184 # Adaptive Timeouts funcs
4187 # only check mds, we assume at_max is the same on all nodes
4188 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4189 if [ $at_max -eq 0 ]; then
4200 # suppose that all ost-s have the same $at value set
4201 [ $facet != "ost" ] || facet=ost1
4203 do_facet $facet "lctl get_param -n $at"
4221 if [ $facet == "ost" ]; then
4222 facet=$(get_facets OST)
4223 elif [ $facet == "mds" ]; then
4224 facet=$(get_facets MDS)
4226 hosts=$(expand_list $hosts $(facets_hosts $facet))
4229 do_nodes $hosts lctl set_param at_max=$at_max
4232 ##################################
4236 # OBD_FAIL_MDS_ALL_REQUEST_NET
4238 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4239 do_facet client "$1" || RC=$?
4240 do_facet $SINGLEMDS lctl set_param fail_loc=0
4245 # OBD_FAIL_MDS_ALL_REPLY_NET
4247 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
4248 do_facet client "$@" || RC=$?
4249 do_facet $SINGLEMDS lctl set_param fail_loc=0
4253 drop_reint_reply() {
4254 # OBD_FAIL_MDS_REINT_NET_REP
4256 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
4257 do_facet client "$@" || RC=$?
4258 do_facet $SINGLEMDS lctl set_param fail_loc=0
4262 drop_update_reply() {
4263 # OBD_FAIL_UPDATE_OBJ_NET_REP
4267 do_facet mds${index} lctl set_param fail_loc=0x1701
4268 do_facet client "$@" || RC=$?
4269 do_facet mds${index} lctl set_param fail_loc=0
4274 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4277 local timeout=${2:-0}
4278 # default is (obd_timeout / 4) if unspecified
4279 echo "timeout is $timeout/$2"
4280 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
4281 do_facet client "$1" || RC=$?
4282 do_facet client "sync"
4283 do_facet ost1 lctl set_param fail_loc=0
4287 drop_ldlm_cancel() {
4288 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4290 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4291 do_nodes $list lctl set_param fail_loc=0x304
4293 do_facet client "$@" || RC=$?
4295 do_nodes $list lctl set_param fail_loc=0
4299 drop_bl_callback() {
4300 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4302 do_facet client lctl set_param fail_loc=0x80000305
4303 do_facet client "$@" || RC=$?
4304 do_facet client lctl set_param fail_loc=0
4309 #define OBD_FAIL_LDLM_REPLY 0x30c
4311 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
4312 do_facet client "$@" || RC=$?
4313 do_facet $SINGLEMDS lctl set_param fail_loc=0
4321 echo "clearing fail_loc on $facet"
4322 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4325 set_nodes_failloc () {
4326 do_nodes $(comma_list $1) lctl set_param fail_val=0 fail_loc=$2
4329 cancel_lru_locks() {
4330 $LCTL mark "cancel_lru_locks $1 start"
4331 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
4332 $LCTL set_param -n $d=clear
4334 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
4335 $LCTL mark "cancel_lru_locks $1 stop"
4340 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4341 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4342 echo "$DEFAULT_LRU_SIZE"
4347 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4350 lru_resize_disable()
4352 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4357 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4358 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4359 echo there is still data in page cache $FILE ?
4360 lctl get_param -n $FILE
4368 DEBUGSAVE="$(lctl get_param -n debug)"
4372 [ -n "$DEBUGSAVE" ] && \
4373 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
4378 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4381 debug_size_restore() {
4382 [ -n "$DEBUG_SIZE_SAVED" ] && \
4383 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4387 start_full_debug_logging() {
4392 local DEBUG_SIZE=150
4394 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4395 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4398 stop_full_debug_logging() {
4403 # prints bash call stack
4406 for (( i=1; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4407 local s=${BASH_SOURCE[$i]}
4408 local l=${BASH_LINENO[$i-1]}
4409 local f=${FUNCNAME[$i]}
4410 echo " = $s:$l:$f()"
4414 ##################################
4416 ##################################
4419 local TYPE=${TYPE:-"FAIL"}
4422 # do not dump logs if $1=false
4423 if [ "x$1" = "xfalse" ]; then
4429 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4433 # We need to dump the logs on all nodes
4435 gather_logs $(comma_list $(nodes_list))
4439 [ "$TESTSUITELOG" ] &&
4440 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4441 if [ -z "$*" ]; then
4442 echo "error() without useful message, please fix" > $LOGDIR/err
4444 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4445 echo "$@" > $LOGDIR/ignore
4447 echo "$@" > $LOGDIR/err
4454 local log=$TESTSUITELOG
4456 [ -f "$log" ] && grep -q FAIL $log && status=1
4469 # use only if we are ignoring failures for this test, bugno required.
4470 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4471 # e.g. error_ignore bz5494 "your message" or
4472 # error_ignore LU-5494 "your message"
4474 local TYPE="IGNORE ($1)"
4479 error_and_remount() {
4481 remount_client $MOUNT
4486 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4491 log " SKIP: $TESTSUITE $TESTNAME $@"
4493 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4494 skip_logged $TESTNAME "$@"
4497 echo "$@" > $LOGDIR/skip
4500 [[ -n "$TESTSUITELOG" ]] &&
4501 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
4504 build_test_filter() {
4505 EXCEPT="$EXCEPT $(testslist_filter)"
4507 [ "$ONLY" ] && log "only running test `echo $ONLY`"
4511 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
4512 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
4513 [ "$EXCEPT_SLOW" ] && \
4514 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
4515 for E in $EXCEPT; do
4516 eval EXCEPT_${E}=true
4518 for E in $ALWAYS_EXCEPT; do
4519 eval EXCEPT_ALWAYS_${E}=true
4521 for E in $EXCEPT_SLOW; do
4522 eval EXCEPT_SLOW_${E}=true
4524 for G in $GRANT_CHECK_LIST; do
4525 eval GCHECK_ONLY_${G}=true
4530 if [[ $1 = [a-z]* ]]; then
4537 # print a newline if the last test was skipped
4538 export LAST_SKIPPED=
4539 export ALWAYS_SKIPPED=
4541 # Main entry into test-framework. This is called with the name and
4542 # description of a test. The name is used to find the function to run
4543 # the test using "test_$name".
4545 # This supports a variety of methods of specifying specific test to
4546 # run or not run. These need to be documented...
4551 export base=`basetest $1`
4552 if [ ! -z "$ONLY" ]; then
4554 if [ ${!testname}x != x ]; then
4555 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4556 run_one_logged $1 "$2"
4560 if [ ${!testname}x != x ]; then
4561 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4562 run_one_logged $1 "$2"
4572 if [ ${!testname}x != x ]; then
4573 TESTNAME=test_$1 skip "skipping excluded test $1"
4576 testname=EXCEPT_$base
4577 if [ ${!testname}x != x ]; then
4578 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
4581 testname=EXCEPT_ALWAYS_$1
4582 if [ ${!testname}x != x ]; then
4583 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
4586 testname=EXCEPT_ALWAYS_$base
4587 if [ ${!testname}x != x ]; then
4588 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
4591 testname=EXCEPT_SLOW_$1
4592 if [ ${!testname}x != x ]; then
4593 TESTNAME=test_$1 skip "skipping SLOW test $1"
4596 testname=EXCEPT_SLOW_$base
4597 if [ ${!testname}x != x ]; then
4598 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
4604 run_one_logged $1 "$2"
4611 module_loaded lnet || load_modules
4623 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
4628 strace -o $TMP/$1.strace -ttt $*
4630 log "FINISHED: $*: rc $RC"
4637 banner test complete, duration $duration sec
4638 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
4639 echo duration $duration >>$TESTSUITELOG
4643 # Set TEST_STATUS here. It will be used for logging the result.
4646 if [[ -f $LOGDIR/err ]]; then
4648 elif [[ -f $LOGDIR/skip ]]; then
4651 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
4655 local FFREE=$(do_node $SINGLEMDS \
4656 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
4657 local FTOTAL=$(do_node $SINGLEMDS \
4658 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
4660 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
4664 echo -n "Resetting fail_loc on all nodes..."
4665 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
4671 # Log a message (on all nodes) padded with "=" before and after.
4672 # Also appends a timestamp and prepends the testsuite name.
4675 EQUALS="===================================================================================================="
4677 msg="== ${TESTSUITE} $*"
4679 [[ $last != "=" && $last != " " ]] && msg="$msg "
4680 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
4681 # always include at least == after the message
4682 log "$msg== $(date +"%H:%M:%S (%s)")"
4686 # Run a single test function and cleanup after it.
4688 # This function should be run in a subshell so the test func can
4689 # exit() without stopping the whole script.
4694 export tfile=f${testnum}.${TESTSUITE}
4695 export tdir=d${testnum}.${TESTSUITE}
4696 export TESTNAME=test_$testnum
4697 local SAVE_UMASK=`umask`
4700 banner "test $testnum: $message"
4701 test_${testnum} || error "test_$testnum failed with $?"
4704 check_grant ${testnum} || error "check_grant $testnum failed with $?"
4705 check_catastrophe || error "LBUG/LASSERT detected"
4706 if [ "$PARALLEL" != "yes" ]; then
4707 ps auxww | grep -v grep | grep -q multiop &&
4708 error "multiop still running"
4718 # Wrapper around run_one to ensure:
4719 # - test runs in subshell
4720 # - output of test is saved to separate log file for error reporting
4721 # - test result is saved to data file
4724 local BEFORE=`date +%s`
4726 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
4727 local test_log=$LOGDIR/$name
4729 rm -rf $LOGDIR/ignore
4731 local SAVE_UMASK=`umask`
4735 log_sub_test_begin test_${1}
4736 (run_one $1 "$2") 2>&1 | tee -i $test_log
4737 local RC=${PIPESTATUS[0]}
4739 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
4740 echo "test_$1 returned $RC" | tee $LOGDIR/err
4742 duration=$((`date +%s` - $BEFORE))
4743 pass "$1" "(${duration}s)"
4745 if [[ -f $LOGDIR/err ]]; then
4746 TEST_ERROR=$(cat $LOGDIR/err)
4747 elif [[ -f $LOGDIR/ignore ]]; then
4748 TEST_ERROR=$(cat $LOGDIR/ignore)
4749 elif [[ -f $LOGDIR/skip ]]; then
4750 TEST_ERROR=$(cat $LOGDIR/skip)
4752 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
4754 if [[ "$TEST_STATUS" != "SKIP" ]] && [[ -f $TF_SKIP ]]; then
4758 if [ -f $LOGDIR/err ]; then
4759 $FAIL_ON_ERROR && exit $RC
4768 # Print information of skipped tests to result.yml
4771 log_sub_test_begin $1
4773 log_sub_test_end "SKIP" "0" "0" "$@"
4777 (cd `dirname $1`; echo $PWD/`basename $1`)
4782 export base=`basetest $1`
4783 [ "$CHECK_GRANT" == "no" ] && return 0
4785 testname=GCHECK_ONLY_${base}
4786 [ ${!testname}x == x ] && return 0
4788 echo -n "checking grant......"
4790 local clients=$CLIENTS
4791 [ -z $clients ] && clients=$(hostname)
4793 # sync all the data and make sure no pending data on server
4794 do_nodes $clients sync
4797 client_grant=`do_nodes $clients \
4798 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" | \
4799 awk '{total += $1} END{print total}'`
4802 server_grant=`do_nodes $(comma_list $(osts_nodes)) \
4803 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
4804 awk '{total += $1} END{print total}'`
4806 # check whether client grant == server grant
4807 if [ $client_grant -ne $server_grant ]; then
4808 echo "failed: client:${client_grant} server: ${server_grant}."
4809 do_nodes $(comma_list $(osts_nodes)) \
4810 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
4811 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
4814 echo "pass: client:${client_grant} server: ${server_grant}"
4819 ########################
4825 ost=`echo $1 | awk -F_ '{print $3}'`
4826 if [ -z $ost ]; then
4827 ost=`echo $1 | sed 's/-osc.*//'`
4832 ostuuid_from_index()
4834 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
4837 ostname_from_index() {
4838 local uuid=$(ostuuid_from_index $1)
4842 index_from_ostuuid()
4844 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
4847 mdtuuid_from_index()
4849 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
4853 # Return unique identifier for given hostname
4856 echo $host_name | md5sum | cut -d' ' -f1
4860 # Returns list of ip addresses for each interface
4862 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
4867 # Cache address list to avoid mutiple execution of local_addr_list
4868 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
4870 for i in $LOCAL_ADDR_LIST ; do
4871 [[ "$i" == "$addr" ]] && return 0
4878 local is_local="IS_LOCAL_$(host_id $host_name)"
4879 if [ -z "${!is_local-}" ] ; then
4881 local host_ip=$($LUSTRE/tests/resolveip $host_name)
4882 is_local_addr "$host_ip" && eval $is_local=1
4884 [[ "${!is_local}" == "1" ]]
4889 local_node $node && return 1
4896 for node in $(mdts_nodes); do
4897 remote_node $node && return 0
4904 [ "$CLIENTONLY" ] && return 0 || true
4905 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
4910 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
4911 MSKIPPED=1 && return 1
4918 for node in $(osts_nodes) ; do
4919 remote_node $node && return 0
4926 [ "$CLIENTONLY" ] && return 0 || true
4927 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
4932 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
4933 OSKIPPED=1 && return 1
4940 MGS=$(facet_host mgs)
4941 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
4946 remote_mds_nodsh || remote_ost_nodsh || \
4947 $(single_local_node $(comma_list $(nodes_list)))
4951 remote_ost && remote_mds
4954 # Get the active nodes for facets.
4962 for facet in ${facets//,/ }; do
4963 nodes="$nodes $(facet_active_host $facet)"
4966 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
4970 # Get all of the active MDS nodes.
4972 echo -n $(facets_nodes $(get_facets MDS))
4975 # Get all of the active OSS nodes.
4977 echo -n $(facets_nodes $(get_facets OST))
4980 # Get all of the active AGT (HSM agent) nodes.
4982 echo -n $(facets_nodes $(get_facets AGT))
4985 # Get all of the client nodes and active server nodes.
4987 local nodes=$HOSTNAME
4991 # CLIENTS (if specified) contains the local client
4992 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
4994 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
4995 nodes="$nodes $(facets_nodes $(get_facets))"
4998 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5002 # Get all of the remote client nodes and remote active server nodes.
5003 remote_nodes_list () {
5004 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5007 # Get all of the MDS nodes, including active and passive nodes.
5015 for i in $(seq $MDSCOUNT); do
5017 failover_host=mds${i}failover_HOST
5018 nodes="$nodes ${!host} ${!failover_host}"
5021 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5025 # Get all of the OSS nodes, including active and passive nodes.
5033 for i in $(seq $OSTCOUNT); do
5035 failover_host=ost${i}failover_HOST
5036 nodes="$nodes ${!host} ${!failover_host}"
5039 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5043 # Get all of the server nodes, including active and passive nodes.
5044 all_server_nodes () {
5049 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5051 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5055 # Get all of the client and server nodes, including active and passive nodes.
5057 local nodes=$HOSTNAME
5061 # CLIENTS (if specified) contains the local client
5062 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5064 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5065 nodes="$nodes $(all_server_nodes)"
5068 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5072 init_clients_lists () {
5073 # Sanity check: exclude the local client from RCLIENTS
5074 local clients=$(hostlist_expand "$RCLIENTS")
5075 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5077 # Sanity check: exclude the dup entries
5078 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5080 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5082 # Sanity check: exclude the dup entries from CLIENTS
5083 # for those configs which has SINGLCLIENT set to local client
5084 clients=$(for i in $clients; do echo $i; done | sort -u)
5086 CLIENTS=$(comma_list $clients)
5087 local -a remoteclients=($RCLIENTS)
5088 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5089 varname=CLIENT$((i + 2))
5090 eval $varname=${remoteclients[i]}
5093 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5096 get_random_entry () {
5099 rnodes=${rnodes//,/ }
5101 local -a nodes=($rnodes)
5102 local num=${#nodes[@]}
5103 local i=$((RANDOM * num * 2 / 65536))
5109 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
5114 lctl get_param version | grep -q patchless
5118 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5119 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5124 echo $nodes | wc -w || true
5128 local nodes=$(osts_nodes)
5129 local osscount=$(get_node_count "$nodes")
5130 [ ! "$OSTCOUNT" = "$osscount" ]
5134 local nodes=$(mdts_nodes)
5135 local mdtcount=$(get_node_count "$nodes")
5136 [ ! "$MDSCOUNT" = "$mdtcount" ]
5139 generate_machine_file() {
5140 local nodes=${1//,/ }
5141 local machinefile=$2
5143 for node in $nodes; do
5144 echo $node >>$machinefile || \
5145 { echo "can not generate machinefile $machinefile" && return 1; }
5150 local file=$1/stripe
5153 $LFS getstripe -v $file || error "getstripe $file failed"
5157 setstripe_nfsserver () {
5160 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5161 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
5163 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5165 do_nodev $nfsserver lfs setstripe "$@"
5168 # Check and add a test group.
5174 local gid=$(getent group $group_name | cut -d: -f3)
5175 if [[ -n "$gid" ]]; then
5176 [[ "$gid" -eq "$group_id" ]] || {
5177 error_noexit "inconsistent group ID:" \
5178 "new: $group_id, old: $gid"
5182 groupadd -g $group_id $group_name
5189 # Check and add a test user.
5202 local uid=$(getent passwd $user_name | cut -d: -f3)
5203 if [[ -n "$uid" ]]; then
5204 if [[ "$uid" -eq "$user_id" ]]; then
5205 local dir=$(getent passwd $user_name | cut -d: -f6)
5206 if [[ "$dir" != "$home" ]]; then
5208 usermod -d $home $user_name
5212 error_noexit "inconsistent user ID:" \
5213 "new: $user_id, old: $uid"
5218 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5225 check_runas_id_ret() {
5227 local myRUNAS_UID=$1
5228 local myRUNAS_GID=$2
5231 if [ -z "$myRUNAS" ]; then
5232 error_exit "myRUNAS command must be specified for check_runas_id"
5235 $myRUNAS krb5_login.sh || \
5236 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5238 mkdir $DIR/d0_runas_test
5240 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5241 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5242 rm -rf $DIR/d0_runas_test
5247 local myRUNAS_UID=$1
5248 local myRUNAS_GID=$2
5251 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5252 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5253 Please set RUNAS_ID to some UID which exists on MDS and client or
5254 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5257 # obtain the UID/GID for MPI_USER
5261 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5262 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5264 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5265 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5268 # obtain and cache Kerberos ticket-granting ticket
5269 refresh_krb5_tgt() {
5270 local myRUNAS_UID=$1
5271 local myRUNAS_GID=$2
5274 if [ -z "$myRUNAS" ]; then
5275 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5278 CLIENTS=${CLIENTS:-$HOSTNAME}
5279 do_nodes $CLIENTS "set -x
5280 if ! $myRUNAS krb5_login.sh; then
5281 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5286 # Run multiop in the background, but wait for it to print
5287 # "PAUSING" to its stdout before returning from this function.
5288 multiop_bg_pause() {
5289 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5293 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5296 echo "$MULTIOP_PROG $FILE v$ARGS"
5297 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5299 echo "TMPPIPE=${TMPPIPE}"
5300 read -t 60 multiop_output < $TMPPIPE
5301 if [ $? -ne 0 ]; then
5306 if [ "$multiop_output" != "PAUSING" ]; then
5307 echo "Incorrect multiop output: $multiop_output"
5322 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5328 inodes_available () {
5329 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
5333 mdsrate_inodes_available () {
5334 local min_inodes=$(inodes_available)
5335 echo $((min_inodes * 99 / 100))
5338 # reset llite stat counters
5339 clear_llite_stats(){
5340 lctl set_param -n llite.*.stats 0
5343 # sum llite stat items
5344 calc_llite_stats() {
5345 local res=$(lctl get_param -n llite.*.stats |
5346 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
5350 # reset osc stat counters
5352 lctl set_param -n osc.*.osc_stats 0
5355 # sum osc stat items
5357 local res=$(lctl get_param -n osc.*.osc_stats |
5358 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
5363 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
5366 calc_osc_kbytes () {
5367 df $MOUNT > /dev/null
5368 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5371 # save_lustre_params(comma separated facet list, parameter_mask)
5372 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5373 save_lustre_params() {
5379 for facet in ${facets//,/ }; do
5380 node=$(facet_active_host $facet)
5381 [[ *\ $node\ * = " $nodes " ]] && continue
5382 nodes="$nodes $node"
5384 do_node $node "$LCTL get_param $2 |
5385 while read s; do echo $facet \\\$s; done"
5389 # restore lustre parameters from input stream, produces by save_lustre_params
5390 restore_lustre_params() {
5395 while IFS=" =" read facet name val; do
5396 do_facet $facet "$LCTL set_param -n $name $val"
5400 check_catastrophe() {
5401 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
5402 local C=$CATASTROPHE
5403 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
5405 [ -z "$rnodes" ] && return 0
5408 data=$(do_nodes "$rnodes" "rc=\\\$([ -f $C ] &&
5409 echo \\\$(< $C) || echo 0);
5410 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
5413 if [ -n "$data" ]; then
5420 # CMD: determine mds index where directory inode presents
5423 local file=$dir/f0.get_mds_dir_tmpfile
5428 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
5429 local -a oldused=($iused)
5431 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
5433 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
5434 local -a newused=($iused)
5437 for ((i=0; i<${#newused[@]}; i++)); do
5438 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
5444 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
5447 mdsrate_cleanup () {
5449 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
5450 --nfiles $3 --dir $4 --filefmt $5 $6
5455 delayed_recovery_enabled () {
5456 local var=${SINGLEMDS}_svc
5457 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5460 ########################
5462 convert_facet2label() {
5465 if [ x$facet = xost ]; then
5469 local varsvc=${facet}_svc
5471 if [ -n ${!varsvc} ]; then
5474 error "No lablel for $facet!"
5478 get_clientosc_proc_path() {
5482 get_lustre_version () {
5483 local facet=${1:-"$SINGLEMDS"}
5484 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
5487 lustre_version_code() {
5488 local facet=${1:-"$SINGLEMDS"}
5489 version_code $(get_lustre_version $1)
5492 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5493 # used by MDT would not be changed.
5494 # mdt lov: fsname-mdtlov
5495 # mdt osc: fsname-OSTXXXX-osc
5496 mds_on_old_device() {
5497 local mds=${1:-"$SINGLEMDS"}
5499 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5500 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5501 > /dev/null 2>&1" && return 0
5506 get_mdtosc_proc_path() {
5508 local ost_label=${2:-"*OST*"}
5510 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5511 local mdt_label=$(convert_facet2label $mds_facet)
5512 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5514 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5515 mds_on_old_device $mds_facet; then
5516 echo "${ost_label}-osc"
5518 echo "${ost_label}-osc-${mdt_index}"
5522 get_osc_import_name() {
5525 local label=$(convert_facet2label $ost)
5527 if [ "${facet:0:3}" = "mds" ]; then
5528 get_mdtosc_proc_path $facet $label
5532 get_clientosc_proc_path $label
5536 _wait_import_state () {
5539 local maxtime=${3:-$(max_recovery_time)}
5543 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5544 while [ "${CONN_STATE}" != "${expected}" ]; do
5545 if [ "${expected}" == "DISCONN" ]; then
5546 # for disconn we can check after proc entry is removed
5547 [ "x${CONN_STATE}" == "x" ] && return 0
5548 # with AT enabled, we can have connect request timeout near of
5549 # reconnect timeout and test can't see real disconnect
5550 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
5552 [ $i -ge $maxtime ] && \
5553 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
5556 # Add uniq for multi-mount case
5557 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5561 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
5565 wait_import_state() {
5568 local maxtime=${3:-$(max_recovery_time)}
5571 for param in ${params//,/ }; do
5572 _wait_import_state $state $param $maxtime || return
5576 wait_import_state_mount() {
5577 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
5581 wait_import_state $*
5584 # One client request could be timed out because server was not ready
5585 # when request was sent by client.
5586 # The request timeout calculation details :
5588 # /* We give the server rq_timeout secs to process the req, and
5589 # add the network latency for our local timeout. */
5590 # request->rq_deadline = request->rq_sent + request->rq_timeout +
5591 # ptlrpc_at_get_net_latency(request) ;
5593 # ptlrpc_connect_import ()
5594 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5597 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
5598 # ptlrpc_at_get_net_latency(request) ->
5599 # at_get (max (iat_net_latency=0, at_min)) = at_min
5602 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
5603 # INITIAL_CONNECT_TIMEOUT + at_min
5605 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
5606 # because we can not get this value in runtime,
5607 # the value depends on configure options, and it is not stored in /proc.
5609 # #define CONNECTION_SWITCH_MIN 5U
5610 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5612 request_timeout () {
5615 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5616 local init_connect_timeout=$TIMEOUT
5617 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5619 local at_min=$(at_get $facet at_min)
5621 echo $(( init_connect_timeout + at_min ))
5624 _wait_osc_import_state() {
5628 local ost=$(get_osc_import_name $facet $ost_facet)
5630 local param="osc.${ost}.ost_server_uuid"
5633 # 1. wait the deadline of client 1st request (it could be skipped)
5634 # 2. wait the deadline of client 2nd request
5635 local maxtime=$(( 2 * $(request_timeout $facet)))
5637 #During setup time, the osc might not be setup, it need wait
5638 #until list_param can return valid value. And also if there
5639 #are mulitple osc entries we should list all of them before
5641 local params=$($LCTL list_param $param 2>/dev/null || true)
5642 while [ -z "$params" ]; do
5643 if [ $i -ge $maxtime ]; then
5644 echo "can't get $param by list_param in $maxtime secs"
5645 if [[ $facet != client* ]]; then
5646 echo "Go with $param directly"
5655 params=$($LCTL list_param $param 2>/dev/null || true)
5658 if ! do_rpc_nodes "$(facet_active_host $facet)" \
5659 wait_import_state $expected "$params" $maxtime; then
5660 error "import is not in ${expected} state"
5667 wait_osc_import_state() {
5673 if [[ $facet = mds ]]; then
5674 for num in $(seq $MDSCOUNT); do
5675 _wait_osc_import_state mds$num "$ost_facet" "$expected"
5678 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
5682 get_clientmdc_proc_path() {
5690 [ -z "$list" ] && return 0
5692 # Add paths to lustre tests for 32 and 64 bit systems.
5693 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
5694 local TESTPATH="$RLUSTRE/tests:"
5695 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
5696 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
5699 wait_clients_import_state () {
5706 if [ "$FAILURE_MODE" = HARD ]; then
5707 facets=$(facets_on_host $(facet_active_host $facet))
5710 for facet in ${facets//,/ }; do
5711 local label=$(convert_facet2label $facet)
5714 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
5715 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
5716 *) error "unknown facet!" ;;
5718 local params=$(expand_list $params $proc_path)
5721 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params; then
5722 error "import is not in ${expected} state"
5732 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
5733 $LCTL get_param obdfilter.*.kbytesavail))
5734 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
5735 $LCTL get_param -n obdfilter.*.tot_granted))
5736 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
5737 $LCTL get_param -n obdfilter.*.kbytestotal))
5738 for ((i=0; i<${#AVAILA[@]}; i++)); do
5739 local -a AVAIL1=(${AVAILA[$i]//=/ })
5740 local -a TOTAL=(${TOTALA[$i]//=/ })
5741 GRANT=$((${GRANTA[$i]}/1024))
5742 # allow 1% of total space in bavail because of delayed
5743 # allocation with ZFS which might release some free space after
5744 # txg commit. For small devices, we set a mininum of 8MB
5745 local LIMIT=$((${TOTAL} / 100 + 8000))
5746 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
5747 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
5748 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
5749 echo " FULL" || echo
5755 do_facet mgs lctl pool_list $1
5759 local fsname=${1%%.*}
5760 local poolname=${1##$fsname.}
5762 do_facet mgs lctl pool_new $1
5764 # get param should return err unless pool is created
5765 [[ $RC -ne 0 ]] && return $RC
5767 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
5768 2>/dev/null || echo foo" "" || RC=1
5769 if [[ $RC -eq 0 ]]; then
5772 error "pool_new failed $1"
5777 add_pool_to_list () {
5778 local fsname=${1%%.*}
5779 local poolname=${1##$fsname.}
5781 local listvar=${fsname}_CREATED_POOLS
5782 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
5785 remove_pool_from_list () {
5786 local fsname=${1%%.*}
5787 local poolname=${1##$fsname.}
5789 local listvar=${fsname}_CREATED_POOLS
5790 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
5793 destroy_pool_int() {
5795 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
5796 awk '$1 !~ /^Pool:/ {print $1}')
5797 for ost in $OSTS; do
5798 do_facet mgs lctl pool_remove $1 $ost
5800 do_facet mgs lctl pool_destroy $1
5803 # <fsname>.<poolname> or <poolname>
5805 local fsname=${1%%.*}
5806 local poolname=${1##$fsname.}
5808 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
5812 pool_list $fsname.$poolname || return $?
5814 destroy_pool_int $fsname.$poolname
5816 [[ $RC -ne 0 ]] && return $RC
5818 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
5819 2>/dev/null || echo foo" "foo" || RC=1
5821 if [[ $RC -eq 0 ]]; then
5822 remove_pool_from_list $fsname.$poolname
5824 error "destroy pool failed $1"
5830 local fsname=${1:-$FSNAME}
5832 local listvar=${fsname}_CREATED_POOLS
5836 [ x${!listvar} = x ] && return 0
5838 echo destroy the created pools: ${!listvar}
5839 for poolname in ${!listvar//,/ }; do
5840 destroy_pool $fsname.$poolname
5845 local fsname=${1:-$FSNAME}
5847 destroy_pools $fsname
5853 local ts=$(date +%s)
5856 if [[ ! -f "$YAML_LOG" ]]; then
5857 # init_logging is not performed before gather_logs,
5858 # so the $LOGDIR needs to be checked here
5859 check_shared_dir $LOGDIR && touch $LOGDIR/shared
5862 [ -f $LOGDIR/shared ] && docp=false
5864 # dump lustre logs, dmesg
5866 prefix="$TESTLOG_PREFIX.$TESTNAME"
5868 echo "Dumping lctl log to ${prefix}.*.${suffix}"
5870 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
5871 echo "Dumping logs only on local client."
5872 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
5873 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
5878 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
5879 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
5880 if [ ! -f $LOGDIR/shared ]; then
5881 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
5894 for i in $(seq 0 $num_mntpts); do
5895 cmd="ls -laf ${mntpt_root}$i/$dir"
5901 for pid in $pids; do
5908 # target_start_and_reset_recovery_timer()
5909 # service_time = at_est2timeout(service_time);
5910 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
5911 # INITIAL_CONNECT_TIMEOUT);
5912 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
5913 #define CONNECTION_SWITCH_INC 1
5914 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5915 #define CONNECTION_SWITCH_MIN 5U
5917 max_recovery_time () {
5918 local init_connect_timeout=$(( TIMEOUT / 20 ))
5919 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5921 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
5926 get_clients_mount_count () {
5927 local clients=${CLIENTS:-`hostname`}
5929 # we need to take into account the clients mounts and
5930 # exclude mds/ost mounts if any;
5931 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
5935 PROC_CLI="srpc_info"
5943 if [ $M -lt $N ]; then
5947 while [ $N -lt $M ]; do
5957 calc_connection_cnt() {
5960 # MDT->MDT = 2 * C(M, 2)
5964 comb_m2=$(combination $MDSCOUNT 2)
5966 local num_clients=$(get_clients_mount_count)
5968 local cnt_mdt2mdt=$((comb_m2 * 2))
5969 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
5970 local cnt_cli2ost=$((num_clients * OSTCOUNT))
5971 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
5972 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
5973 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
5974 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
5988 local cmd="$tgt.srpc.flavor"
5990 if [ $net == "any" ]; then
5995 if [ $dir != "any" ]; then
6000 log "Setting sptlrpc rule: $cmd"
6001 do_facet mgs "$LCTL conf_param $cmd"
6010 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
6011 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
6013 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
6015 if [ "x$bulkspec" != "x" ]; then
6016 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
6018 if [ "x$algs" != "x" ]; then
6019 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
6021 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
6022 if [ $bulk == "bulkn" ]; then
6023 bulk_count=`echo "$output" | grep "bulk flavor" \
6024 | grep "null/null" | wc -l`
6025 elif [ $bulk == "bulki" ]; then
6026 bulk_count=`echo "$output" | grep "bulk flavor" \
6027 | grep "/null" | grep -v "null/" | wc -l`
6029 bulk_count=`echo "$output" | grep "bulk flavor" \
6030 | grep -v "/null" | grep -v "null/" | wc -l`
6034 [ $bulk_count -lt $count ] && count=$bulk_count
6045 local clients=${CLIENTS:-`hostname`}
6047 for c in ${clients//,/ }; do
6048 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
6049 tmpcnt=`count_flvr "$output" $flavor`
6050 cnt=$((cnt + tmpcnt))
6060 local clients=${CLIENTS:-`hostname`}
6062 for c in ${clients//,/ }; do
6063 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
6064 tmpcnt=`count_flvr "$output" $flavor`
6065 cnt=$((cnt + tmpcnt))
6075 if [ $MDSCOUNT -le 1 ]; then
6080 for num in `seq $MDSCOUNT`; do
6081 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
6082 tmpcnt=`count_flvr "$output" $flavor`
6083 cnt=$((cnt + tmpcnt))
6094 for num in `seq $MDSCOUNT`; do
6095 mdtosc=$(get_mdtosc_proc_path mds$num)
6096 mdtosc=${mdtosc/-MDT*/-MDT\*}
6097 output=$(do_facet mds$num lctl get_param -n \
6098 osc.$mdtosc.$PROC_CLI 2>/dev/null)
6099 tmpcnt=`count_flvr "$output" $flavor`
6100 cnt=$((cnt + tmpcnt))
6109 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
6110 count_flvr "$output" $flavor
6115 local dir=$1 # from to
6116 local flavor=$2 # flavor expected
6119 if [ $dir == "cli2mdt" ]; then
6120 res=`flvr_cnt_cli2mdt $flavor`
6121 elif [ $dir == "cli2ost" ]; then
6122 res=`flvr_cnt_cli2ost $flavor`
6123 elif [ $dir == "mdt2mdt" ]; then
6124 res=`flvr_cnt_mdt2mdt $flavor`
6125 elif [ $dir == "mdt2ost" ]; then
6126 res=`flvr_cnt_mdt2ost $flavor`
6127 elif [ $dir == "all2ost" ]; then
6128 res1=`flvr_cnt_mdt2ost $flavor`
6129 res2=`flvr_cnt_cli2ost $flavor`
6130 res=$((res1 + res2))
6131 elif [ $dir == "all2mdt" ]; then
6132 res1=`flvr_cnt_mdt2mdt $flavor`
6133 res2=`flvr_cnt_cli2mdt $flavor`
6134 res=$((res1 + res2))
6135 elif [ $dir == "all2all" ]; then
6136 res1=`flvr_cnt_mdt2ost $flavor`
6137 res2=`flvr_cnt_cli2ost $flavor`
6138 res3=`flvr_cnt_mdt2mdt $flavor`
6139 res4=`flvr_cnt_cli2mdt $flavor`
6140 res=$((res1 + res2 + res3 + res4))
6148 local dir=$1 # from to
6149 local flavor=$2 # flavor expected
6150 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6154 for ((i=0;i<20;i++)); do
6155 echo -n "checking $dir..."
6156 res=$(do_check_flavor $dir $flavor)
6157 echo "found $res/$expect $flavor connections"
6158 [ $res -ge $expect ] && return 0
6162 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6166 restore_to_default_flavor()
6168 local proc="mgs.MGS.live.$FSNAME"
6170 echo "restoring to default flavor..."
6172 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6174 # remove all existing rules if any
6175 if [ $nrule -ne 0 ]; then
6176 echo "$nrule existing rules"
6177 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6178 echo "remove rule: $rule"
6179 spec=`echo $rule | awk -F = '{print $1}'`
6180 do_facet mgs "$LCTL conf_param -d $spec"
6184 # verify no rules left
6185 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6186 [ $nrule -ne 0 ] && error "still $nrule rules left"
6188 # wait for default flavor to be applied
6189 # currently default flavor for all connections are 'null'
6190 wait_flavor all2all null
6191 echo "now at default flavor settings"
6196 local flavor=${1:-null}
6198 echo "setting all flavor to $flavor"
6200 # FIXME need parameter to this fn
6201 # and remove global vars
6202 local cnt_all2all=$(calc_connection_cnt all2all)
6204 local res=$(do_check_flavor all2all $flavor)
6205 if [ $res -eq $cnt_all2all ]; then
6206 echo "already have total $res $flavor connections"
6210 echo "found $res $flavor out of total $cnt_all2all connections"
6211 restore_to_default_flavor
6213 [[ $flavor = null ]] && return 0
6215 set_rule $FSNAME any any $flavor
6216 wait_flavor all2all $flavor
6222 # Checking for shared logdir
6223 if [ ! -d $dir ]; then
6224 # Not found. Create local logdir
6227 touch $dir/check_file.$(hostname -s)
6232 check_write_access() {
6234 local list=${2:-$(comma_list $(nodes_list))}
6238 for node in ${list//,/ }; do
6239 file=$dir/check_file.$(short_nodename $node)
6240 if [[ ! -f "$file" ]]; then
6241 # Logdir not accessible/writable from this node.
6244 rm -f $file || return 1
6250 if [[ -n $YAML_LOG ]]; then
6253 local SAVE_UMASK=`umask`
6256 export YAML_LOG=${LOGDIR}/results.yml
6260 if [ ! -f $YAML_LOG ]; then # If the yaml log already exists then we will just append to it
6261 if check_shared_dir $LOGDIR; then
6262 touch $LOGDIR/shared
6263 echo "Logging to shared log directory: $LOGDIR"
6265 echo "Logging to local directory: $LOGDIR"
6268 yml_nodes_file $LOGDIR >> $YAML_LOG
6269 yml_results_file >> $YAML_LOG
6276 yml_log_test $1 >> $YAML_LOG
6280 yml_log_test_status $@ >> $YAML_LOG
6283 log_sub_test_begin() {
6284 yml_log_sub_test_begin "$@" >> $YAML_LOG
6287 log_sub_test_end() {
6288 yml_log_sub_test_end "$@" >> $YAML_LOG
6294 local llverdev_opts=$2
6295 local devname=$(basename $1)
6296 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6297 # loop devices aren't in /proc/partitions
6298 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6300 size=$(($size / 1024 / 1024)) # Gb
6302 local partial_arg=""
6303 # Run in partial (fast) mode if the size
6304 # of a partition > 1 GB
6305 [ $size -gt 1 ] && partial_arg="-p"
6307 llverdev --force $partial_arg $llverdev_opts $dev
6313 local llverfs_opts=$2
6314 local use_partial_arg=$3
6315 local partial_arg=""
6316 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6318 # Run in partial (fast) mode if the size
6319 # of a partition > 1 GB
6320 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6322 llverfs $partial_arg $llverfs_opts $dir
6325 #Remove objects from OST
6326 remove_ost_objects() {
6332 local mntpt=$(facet_mntpt $facet)
6333 local opts=$OST_MOUNT_OPTS
6337 echo "removing objects from $ostdev on $facet: $objids"
6338 if ! test -b $ostdev; then
6339 opts=$(csa_add "$opts" -o loop)
6341 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
6344 for i in $objids; do
6345 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
6347 umount -f $mntpt || return $?
6351 #Remove files from MDT
6352 remove_mdt_files() {
6357 local mntpt=$(facet_mntpt $facet)
6358 local opts=$MDS_MOUNT_OPTS
6360 echo "removing files from $mdtdev on $facet: $files"
6361 if [ $(facet_fstype $facet) == ldiskfs ] &&
6362 ! do_facet $facet test -b $mdtdev; then
6363 opts=$(csa_add "$opts" -o loop)
6365 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6369 rm $mntpt/ROOT/$f || { rc=$?; break; }
6371 umount -f $mntpt || return $?
6375 duplicate_mdt_files() {
6380 local mntpt=$(facet_mntpt $facet)
6381 local opts=$MDS_MOUNT_OPTS
6383 echo "duplicating files on $mdtdev on $facet: $files"
6384 mkdir -p $mntpt || return $?
6385 if [ $(facet_fstype $facet) == ldiskfs ] &&
6386 ! do_facet $facet test -b $mdtdev; then
6387 opts=$(csa_add "$opts" -o loop)
6389 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6400 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
6401 pushd $mntpt/ROOT > /dev/null || return $?
6404 touch $f.bad || return $?
6405 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
6407 [ $rc -eq 0 ] || return $rc
6408 setfattr --restore $tmp || return $?
6414 local devs=${1//,/ }
6417 local rslt=$TMP/sgpdd_survey
6419 # sgpdd-survey cleanups ${rslt}.* files
6421 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
6427 # returns the canonical name for an ldiskfs device
6432 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
6433 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
6434 echo dm-\\\${foo##*:};
6436 echo \\\$(basename \\\$dv);
6440 is_sanity_benchmark() {
6441 local benchmarks="dbench bonnie iozone fsx"
6443 for b in $benchmarks; do
6444 if [ "$b" == "$suite" ]; then
6452 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
6456 # Get the available size (KB) of a given obd target.
6463 [[ $facet != client ]] || return 0
6465 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
6470 # Get the page size (bytes) on a given facet node.
6476 size=$(do_facet $facet getconf PAGE_SIZE)
6477 [[ ${PIPESTATUS[0]} = 0 && -n "$size" ]] || size=4096
6482 # Get the block count of the filesystem.
6489 count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6490 awk '/^Block count:/ {print $3}')
6494 # Get the block size of the filesystem.
6500 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6501 awk '/^Block size:/ {print $3}')
6505 # Check whether the "large_xattr" feature is enabled or not.
6506 large_xattr_enabled() {
6507 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
6509 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6511 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
6512 grep -E -q '(ea_inode|large_xattr)'"
6513 return ${PIPESTATUS[0]}
6516 # Get the maximum xattr size supported by the filesystem.
6520 if large_xattr_enabled; then
6521 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
6524 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6525 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
6527 # maximum xattr size = size of block - size of header -
6528 # size of 1 entry - 4 null bytes
6529 size=$((block_size - 32 - 32 - 4))
6535 # Dump the value of the named xattr from a file.
6540 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
6543 # Generate a string with size of $size bytes.
6545 local size=${1:-1024} # in bytes
6547 echo "$(head -c $size < /dev/zero | tr '\0' y)"
6550 reformat_external_journal() {
6553 if [ ! -z ${EJOURNAL} ]; then
6554 local rcmd="do_facet $facet"
6556 echo "reformat external journal on $facet:${EJOURNAL}"
6557 ${rcmd} mke2fs -O journal_dev ${EJOURNAL} || return 1
6561 # MDT file-level backup/restore
6562 mds_backup_restore() {
6565 local devname=$(mdsdevname $(facet_number $facet))
6566 local mntpt=$(facet_mntpt brpt)
6567 local rcmd="do_facet $facet"
6568 local metaea=${TMP}/backup_restore.ea
6569 local metadata=${TMP}/backup_restore.tgz
6570 local opts=${MDS_MOUNT_OPTS}
6571 local svc=${facet}_svc
6573 if ! ${rcmd} test -b ${devname}; then
6574 opts=$(csa_add "$opts" -o loop)
6577 echo "file-level backup/restore on $facet:${devname}"
6579 # step 1: build mount point
6580 ${rcmd} mkdir -p $mntpt
6581 # step 2: cleanup old backup
6582 ${rcmd} rm -f $metaea $metadata
6584 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
6585 if [ ! -z $igif ]; then
6586 # step 3.5: rm .lustre
6587 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
6589 # step 4: backup metaea
6591 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
6593 # step 5: backup metadata
6595 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
6597 ${rcmd} umount -d $mntpt || return 4
6598 # step 7: reformat external journal if needed
6599 reformat_external_journal $facet || return 5
6600 # step 8: reformat dev
6601 echo "reformat new device"
6602 add $facet $(mkfs_opts $facet ${devname}) --backfstype ldiskfs \
6603 --reformat ${devname} $(mdsvdevname $(facet_number $facet)) \
6604 > /dev/null || exit 6
6606 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
6607 # step 10: restore metadata
6609 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
6610 # step 11: restore metaea
6612 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
6613 # step 12: remove recovery logs
6614 echo "remove recovery logs"
6615 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
6616 # step 13: umount dev
6617 ${rcmd} umount -d $mntpt || return 10
6618 # step 14: cleanup tmp backup
6619 ${rcmd} rm -f $metaea $metadata
6620 # step 15: reset device label - it's not virgin on
6621 ${rcmd} e2label $devname ${!svc}
6628 local devname=$(mdsdevname $(facet_number $facet))
6629 local mntpt=$(facet_mntpt brpt)
6630 local rcmd="do_facet $facet"
6631 local opts=${MDS_MOUNT_OPTS}
6633 if ! ${rcmd} test -b ${devname}; then
6634 opts=$(csa_add "$opts" -o loop)
6637 echo "removing OI files on $facet: idx=${idx}"
6639 # step 1: build mount point
6640 ${rcmd} mkdir -p $mntpt
6642 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
6643 if [ -z $idx ]; then
6644 # step 3: remove all OI files
6645 ${rcmd} rm -fv $mntpt/oi.16*
6646 elif [ $idx -lt 2 ]; then
6647 ${rcmd} rm -fv $mntpt/oi.16.${idx}
6651 # others, rm oi.16.[idx, idx * idx, idx ** ...]
6652 for ((i=${idx}; i<64; i=$((i * idx)))); do
6653 ${rcmd} rm -fv $mntpt/oi.16.${i}
6657 ${rcmd} umount -d $mntpt || return 2
6658 # OI files will be recreated when mounted as lustre next time.
6661 # generate maloo upload-able log file name
6662 # \param logname specify unique part of file name
6663 generate_logname() {
6664 local logname=${1:-"default_logname"}
6666 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
6669 # make directory on different MDTs
6681 *) error "Only creating single directory is supported";;
6684 child=$(basename $path)
6685 parent=$(dirname $path)
6687 if [ "$option" == "-p" -a -d $parent/$child ]; then
6691 if [ ! -d ${parent} ]; then
6692 if [ "$option" == "-p" ]; then
6699 if [ $MDSCOUNT -le 1 ]; then
6700 mkdir $option $parent/$child || rc=$?
6702 local mdt_idx=$($LFS getstripe -M $parent)
6703 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
6705 if [ "$mdt_idx" -ne 0 ]; then
6706 mkdir $option $parent/$child || rc=$?
6708 mdt_idx=$((test_num % MDSCOUNT))
6709 echo "mkdir $mdt_idx for $parent/$child"
6710 $LFS setdirstripe -i $mdt_idx $parent/$child || rc=$?
6716 # find the smallest and not in use file descriptor
6719 local max_fd=$(ulimit -n)
6721 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
6724 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"