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
528 load_module llite/lustre
529 llite_lloop_enabled && load_module llite/llite_lloop
530 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
532 rm -f $OGDB/ogdb-$HOSTNAME
533 $LCTL modules > $OGDB/ogdb-$HOSTNAME
535 # 'mount' doesn't look in $PATH, just sbin
536 if [ -f $LUSTRE/utils/mount.lustre ] && \
537 ! grep -qe "/sbin/mount\.lustre " /proc/mounts; then
538 [ ! -f /sbin/mount.lustre ] && touch /sbin/mount.lustre
539 mount --bind $LUSTRE/utils/mount.lustre /sbin/mount.lustre || true
546 # load modules on remote nodes optionally
547 # lustre-tests have to be installed on these nodes
548 if $LOAD_MODULES_REMOTE; then
549 local list=$(comma_list $(remote_nodes_list))
550 if [ -n "$list" ]; then
551 echo "loading modules on: '$list'"
552 do_rpc_nodes "$list" load_modules_local
558 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
559 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
560 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
561 echo "$LEAK_LUSTRE" 1>&2
562 echo "$LEAK_PORTALS" 1>&2
563 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
564 echo "Memory leaks detected"
565 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
571 wait_exit_ST client # bug 12845
573 $LUSTRE_RMMOD ldiskfs || return 2
575 if $LOAD_MODULES_REMOTE; then
576 local list=$(comma_list $(remote_nodes_list))
577 if [ -n "$list" ]; then
578 echo "unloading modules on: '$list'"
579 do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
580 do_rpc_nodes "$list" check_mem_leak
584 if grep -qe "/sbin/mount\.lustre" /proc/mounts; then
585 umount /sbin/mount.lustre || true
586 [ -w /sbin/mount.lustre -a ! -s /sbin/mount.lustre ] && \
587 rm -f /sbin/mount.lustre || true
590 check_mem_leak || return 254
592 echo "modules unloaded."
597 local facet=${1:-$SINGLEMDS}
598 local fstype=$(facet_fstype $facet)
601 ldiskfs) size=50;; # largest seen is 44, leave some headroom
602 zfs) size=400;; # largest seen is 384
608 check_gss_daemon_nodes() {
612 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
613 if [ \\\"\\\$num\\\" -ne 1 ]; then
614 echo \\\$num instance of $dname;
619 check_gss_daemon_facet() {
623 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
624 if [ $num -ne 1 ]; then
625 echo "$num instance of $dname on $facet"
634 echo Stopping $@ on $list
635 do_nodes $list "killall -2 $@ 2>/dev/null || true"
638 # start gss daemons on all nodes, or
639 # "daemon" on "list" if set
640 start_gss_daemons() {
644 if [ "$list" ] && [ "$daemon" ] ; then
645 echo "Starting gss daemon on nodes: $list"
646 do_nodes $list "$daemon" || return 8
650 local list=$(comma_list $(mdts_nodes))
652 echo "Starting gss daemon on mds: $list"
653 do_nodes $list "$LSVCGSSD -v" || return 1
655 do_nodes $list "$LGSSD -v" || return 2
658 list=$(comma_list $(osts_nodes))
659 echo "Starting gss daemon on ost: $list"
660 do_nodes $list "$LSVCGSSD -v" || return 3
661 # starting on clients
663 local clients=${CLIENTS:-`hostname`}
665 echo "Starting $LGSSD on clients $clients "
666 do_nodes $clients "$LGSSD -v" || return 4
669 # wait daemons entering "stable" status
673 # check daemons are running
675 list=$(comma_list $(mdts_nodes) $(osts_nodes))
676 check_gss_daemon_nodes $list lsvcgssd || return 5
678 list=$(comma_list $(mdts_nodes))
679 check_gss_daemon_nodes $list lgssd || return 6
682 check_gss_daemon_nodes $clients lgssd || return 7
687 local list=$(comma_list $(mdts_nodes))
689 send_sigint $list lsvcgssd lgssd
691 list=$(comma_list $(osts_nodes))
692 send_sigint $list lsvcgssd
694 list=${CLIENTS:-`hostname`}
695 send_sigint $list lgssd
700 if ! module_loaded ptlrpc_gss; then
701 load_module ptlrpc/gss/ptlrpc_gss
702 module_loaded ptlrpc_gss ||
703 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
705 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
707 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
708 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
716 # maybe cleanup credential cache?
722 local var=${facet}_svc
730 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
731 tr '[:lower:]' '[:upper:]'
737 if [ $facet == mgs ]; then
741 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
749 if [ -n "${!var}" ]; then
754 var=$(facet_type $facet)FSTYPE
755 if [ -n "${!var}" ]; then
760 if [ -n "$FSTYPE" ]; then
765 if [[ $facet == mgs ]] && combined_mgs_mds; then
777 local facets=$(get_facets)
780 for facet in ${facets//,/ }; do
781 if [ $node == $(facet_host $facet) ] ||
782 [ $node == "$(facet_failover_host $facet)" ]; then
783 fstype=$(facet_fstype $facet)
784 if [[ $fstypes != *$fstype* ]]; then
785 fstypes+="${fstypes:+,}$fstype"
796 local fstype=$(facet_fstype $facet)
800 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
802 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
803 ${dev} 2>/dev/null");;
805 error "unknown fstype!";;
813 local device=$(mdsdevname $num)
814 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
820 local device=$(ostdevname $num)
821 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
826 # Get the device of a facet.
833 mgs) device=$(mgsdevname) ;;
834 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
835 ost*) device=$(ostdevname $(facet_number $facet)) ;;
836 fs2mds) device=$(mdsdevname 1_2) ;;
837 fs2ost) device=$(ostdevname 1_2) ;;
838 fs3ost) device=$(ostdevname 2_2) ;;
846 # Get the virtual device of a facet.
853 mgs) device=$(mgsvdevname) ;;
854 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
855 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
856 fs2mds) device=$(mdsvdevname 1_2) ;;
857 fs2ost) device=$(ostvdevname 1_2) ;;
858 fs3ost) device=$(ostvdevname 2_2) ;;
866 # Re-read the partition table on failover partner host.
867 # After a ZFS storage pool is created on a shared device, the partition table
868 # on the device may change. However, the operating system on the failover
869 # host may not notice the change automatically. Without the up-to-date partition
870 # block devices, 'zpool import ..' cannot find the labels, whose positions are
871 # relative to partition rather than disk beginnings.
873 # This function performs partprobe on the failover host to make it re-read the
876 refresh_partition_table() {
881 host=$(facet_passive_host $facet)
882 if [[ -n "$host" ]]; then
883 do_node $host "$PARTPROBE $device"
888 # Get ZFS storage pool name.
895 device=$(facet_device $facet)
896 # poolname is string before "/"
897 poolname="${device%%/*}"
903 # Create ZFS storage pool.
910 local opts=${@:-"-o cachefile=none"}
912 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
913 $ZPOOL create -f $opts $poolname $vdev"
917 # Create ZFS file system.
923 local opts=${@:-"-o mountpoint=legacy"}
925 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
926 $ZFS create $opts $dataset"
930 # Export ZFS storage pool.
931 # Before exporting the pool, all datasets within the pool should be unmounted.
939 poolname=$(zpool_name $facet)
941 if [[ -n "$poolname" ]]; then
942 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
943 grep -q ^$poolname/ /proc/mounts ||
944 $ZPOOL export $opts $poolname"
949 # Destroy ZFS storage pool.
950 # Destroy the given pool and free up any devices for other use. This command
951 # tries to unmount any active datasets before destroying the pool.
952 # -f Force any active datasets contained within the pool to be unmounted.
956 local poolname=${2:-$(zpool_name $facet)}
958 if [[ -n "$poolname" ]]; then
959 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
960 $ZPOOL destroy -f $poolname"
965 # Import ZFS storage pool.
966 # Force importing, even if the pool appears to be potentially active.
971 local opts=${@:-"-o cachefile=none"}
974 poolname=$(zpool_name $facet)
976 if [[ -n "$poolname" ]]; then
977 opts+=" -d $(dirname $(facet_vdevice $facet))"
978 do_facet $facet "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
979 $ZPOOL import -f $opts $poolname"
984 # Set the "cachefile=none" property on ZFS storage pool so that the pool
985 # is not automatically imported on system startup.
987 # In a failover environment, this will provide resource level fencing which
988 # will ensure that the same ZFS storage pool will not be imported concurrently
989 # on different nodes.
991 disable_zpool_cache() {
995 poolname=$(zpool_name $facet)
997 if [[ -n "$poolname" ]]; then
998 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1003 # This and set_osd_param() shall be used to access OSD parameters
1004 # once existed under "obdfilter":
1009 # writethrough_cache_enable
1013 local device=${2:-$FSNAME-OST*}
1016 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
1017 osd-*.$device.$name 2>&1" | grep -v 'Found no match'
1022 local device=${2:-$FSNAME-OST*}
1026 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
1027 osd-*.$device.$name=$value 2>&1" | grep -v 'Found no match'
1031 local dz=${1:-$DEBUG_SIZE}
1033 if [ -f /sys/devices/system/cpu/possible ]; then
1034 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1036 local cpus=$(getconf _NPROCESSORS_CONF)
1039 # bug 19944, adjust size to be -gt num_possible_cpus()
1040 # promise 2MB for every cpu at least
1041 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1044 lctl set_param debug_mb=$dz
1047 set_default_debug () {
1048 local debug=${1:-"$PTLDEBUG"}
1049 local subsys=${2:-"$SUBSYSTEM"}
1050 local debug_size=${3:-$DEBUG_SIZE}
1052 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1053 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1055 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1058 set_default_debug_nodes () {
1061 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1062 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1066 do_rpc_nodes "$nodes" set_default_debug \
1067 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
1070 set_default_debug_facet () {
1072 local node=$(facet_active_host $facet)
1073 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
1075 set_default_debug_nodes $node
1080 local facets=${1:-$(get_facets)}
1083 for facet in ${facets//,/ }; do
1086 [ $RC -eq 0 ] && continue
1088 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1089 skip "Restart of $facet failed!." && touch $LU482_FAILED
1091 error "Restart of $facet failed!"
1098 # Add argument "arg" (e.g., "loop") to the comma-separated list
1099 # of arguments for option "opt" (e.g., "-o") on command
1100 # line "opts" (e.g., "-o flock").
1106 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1108 if echo "$opts" | grep -q $opt_pattern; then
1109 opts=$(echo "$opts" | sed -e \
1110 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1112 opts+="${opts:+ }$opt $arg"
1120 local dev=$(facet_active $facet)_dev
1121 local opt=${facet}_opt
1122 local mntpt=$(facet_mntpt $facet)
1123 local opts="${!opt} $@"
1125 if [ $(facet_fstype $facet) == ldiskfs ] &&
1126 ! do_facet $facet test -b ${!dev}; then
1127 opts=$(csa_add "$opts" -o loop)
1130 if [[ $(facet_fstype $facet) == zfs ]]; then
1131 # import ZFS storage pool
1132 import_zpool $facet || return ${PIPESTATUS[0]}
1135 echo "Starting ${facet}: $opts ${!dev} $mntpt"
1136 # for testing LU-482 error handling in mount_facets() and test_0a()
1137 if [ -f $TMP/test-lu482-trigger ]; then
1140 do_facet ${facet} "mkdir -p $mntpt; mount -t lustre $opts \
1144 if [ $RC -ne 0 ]; then
1145 echo "Start of ${!dev} on ${facet} failed ${RC}"
1147 set_default_debug_facet $facet
1149 label=$(devicelabel ${facet} ${!dev})
1150 [ -z "$label" ] && echo no label for ${!dev} && exit 1
1151 eval export ${facet}_svc=${label}
1152 echo Started ${label}
1157 # start facet device options
1163 eval export ${facet}_dev=${device}
1164 eval export ${facet}_opt=\"$@\"
1166 local varname=${facet}failover_dev
1167 if [ -n "${!varname}" ] ; then
1168 eval export ${facet}failover_dev=${!varname}
1170 eval export ${facet}failover_dev=$device
1173 local mntpt=$(facet_mntpt $facet)
1174 do_facet ${facet} mkdir -p $mntpt
1175 eval export ${facet}_MOUNT=$mntpt
1176 mount_facet ${facet}
1185 local HOST=`facet_active_host $facet`
1186 [ -z $HOST ] && echo stop: no host for $facet && return 0
1188 local mntpt=$(facet_mntpt $facet)
1189 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
1190 if [ ${running} -ne 0 ]; then
1191 echo "Stopping $mntpt (opts:$@) on $HOST"
1192 do_facet ${facet} umount -d $@ $mntpt
1195 # umount should block, but we should wait for unrelated obd's
1196 # like the MGS or MGC to also stop.
1197 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
1199 if [[ $(facet_fstype $facet) == zfs ]]; then
1200 # export ZFS storage pool
1205 # save quota version (both administrative and operational quotas)
1206 # add an additional parameter if mountpoint is ever different from $MOUNT
1208 # XXX This function is kept for interoperability with old server (< 2.3.50),
1209 # it should be removed whenever we drop the interoperability for such
1211 quota_save_version() {
1212 local fsname=${2:-$FSNAME}
1214 local ver=$(tr -c -d "123" <<< $spec)
1215 local type=$(tr -c -d "ug" <<< $spec)
1217 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
1219 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
1221 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1223 local osts=$(get_facets OST)
1224 for ost in ${osts//,/ }; do
1226 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1230 # client could mount several lustre
1232 # XXX This function is kept for interoperability with old server (< 2.3.50),
1233 # it should be removed whenever we drop the interoperability for such
1236 local fsname=${1:-$FSNAME}
1238 do_facet $SINGLEMDS lctl get_param mdd.${fsname}-MDT*.quota_type ||
1240 do_nodes $(comma_list $(osts_nodes)) \
1241 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1245 # XXX This function is kept for interoperability with old server (< 2.3.50),
1246 # it should be removed whenever we drop the interoperability for such
1248 restore_quota_old() {
1249 local mntpt=${1:-$MOUNT}
1250 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
1251 if [ ! "$old_QUOTA_TYPE" ] ||
1252 [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
1255 quota_save_version $old_QUOTA_TYPE
1258 # XXX This function is kept for interoperability with old server (< 2.3.50),
1259 # it should be removed whenever we drop the interoperability for such
1264 # no quota enforcement for now and accounting works out of the box
1267 # We need save the original quota_type params, and restore them after testing
1269 # Suppose that quota type the same on mds and ost
1270 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
1271 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
1272 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
1273 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
1274 export old_QUOTA_TYPE=$quota_type
1275 quota_save_version $QUOTA_TYPE
1277 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
1278 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
1281 local quota_usrs=$QUOTA_USERS
1283 # get_filesystem_size
1284 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1285 local blk_soft=$((disksz + 1024))
1286 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1288 local Inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1289 local i_soft=$Inodes
1290 local i_hard=$((i_soft + i_soft / 20))
1292 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
1293 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
1296 for usr in $quota_usrs; do
1297 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1299 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1301 eval $cmd || error "$cmd FAILED!"
1303 # display the quota status
1304 echo "Quota settings for $usr : "
1305 $LFS quota -v -u $usr $mntpt || true
1309 # get mdt quota type
1311 local varsvc=${SINGLEMDS}_svc
1312 do_facet $SINGLEMDS $LCTL get_param -n \
1313 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
1316 # get ost quota type
1318 # All OSTs should have same quota type
1319 local varsvc=ost1_svc
1320 do_facet ost1 $LCTL get_param -n \
1321 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
1324 # restore old quota type settings
1326 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1331 if [ "$old_MDT_QUOTA_TYPE" ]; then
1332 do_facet mgs $LCTL conf_param \
1333 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1335 if [ "$old_OST_QUOTA_TYPE" ]; then
1336 do_facet mgs $LCTL conf_param \
1337 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1341 # Handle the case when there is a space in the lfs df
1342 # "filesystem summary" line the same as when there is no space.
1343 # This will allow fixing the "lfs df" summary line in the future.
1345 $LFS df $* | sed -e 's/filesystem /filesystem_/'
1348 # Get free inodes on the MDT specified by mdt index, free indoes on
1349 # the whole filesystem will be returned when index == -1.
1355 if [ $index -eq -1 ]; then
1358 mdt_uuid=$(mdtuuid_from_index $index)
1361 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
1366 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1373 # save old quota type & set new quota type
1374 local mdt_qtype=$(mdt_quota_type)
1375 local ost_qtype=$(ost_quota_type)
1377 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1378 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1380 export old_MDT_QUOTA_TYPE=$mdt_qtype
1381 export old_OST_QUOTA_TYPE=$ost_qtype
1383 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1384 error "set mdt quota type failed"
1385 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1386 error "set ost quota type failed"
1388 local quota_usrs=$QUOTA_USERS
1390 # get_filesystem_size
1391 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
1392 local blk_soft=$((disksz + 1024))
1393 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1395 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
1396 local i_soft=$inodes
1397 local i_hard=$((i_soft + i_soft / 20))
1399 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1400 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1401 "inode-hardlimit: $i_hard"
1404 for usr in $quota_usrs; do
1405 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1407 cmd="$LFS setquota -$type $usr -b $blk_soft"
1408 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1410 eval $cmd || error "$cmd FAILED!"
1412 # display the quota status
1413 echo "Quota settings for $usr : "
1414 $LFS quota -v -u $usr $mntpt || true
1421 local OPTIONS=${3:-$MOUNTOPT}
1423 local device=$MGSNID:/$FSNAME
1424 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1425 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
1429 echo "Starting client: $client: $OPTIONS $device $mnt"
1430 do_node $client mkdir -p $mnt
1431 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
1433 set_default_debug_nodes $client
1445 [ "$3" ] && force=-f
1446 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1447 if [ $running -ne 0 ]; then
1448 echo "Stopping client $client $mnt (opts:$force)"
1449 do_node $client lsof -t $mnt || need_kill=no
1450 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1451 pids=$(do_node $client lsof -t $mnt | sort -u);
1452 if [ -n $pids ]; then
1453 do_node $client kill -9 $pids || true
1457 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1458 if [ $busy -ne 0 ] ; then
1459 echo "$mnt is still busy, wait one second" && sleep 1
1460 do_node $client umount $force $mnt
1465 # nodes is comma list
1466 sanity_mount_check_nodes () {
1472 # FIXME: assume that all cluster nodes run the same os
1473 [ "$(uname)" = Linux ] || return 0
1476 for mnt in $mnts ; do
1477 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1478 mpts=\\\$(mount | grep -c $mnt' ');
1479 if [ \\\$running -ne \\\$mpts ]; then
1480 echo \\\$(hostname) env are INSANE!;
1483 [ $? -eq 0 ] || rc=1
1488 sanity_mount_check_servers () {
1489 [ "$CLIENTONLY" ] &&
1490 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1491 echo Checking servers environments
1493 # FIXME: modify get_facets to display all facets wo params
1494 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1498 for facet in ${facets//,/ }; do
1499 node=$(facet_host ${facet})
1500 mntpt=$(facet_mntpt $facet)
1501 sanity_mount_check_nodes $node $mntpt ||
1502 { error "server $node environments are insane!"; return 1; }
1506 sanity_mount_check_clients () {
1507 local clients=${1:-$CLIENTS}
1508 local mntpt=${2:-$MOUNT}
1509 local mntpt2=${3:-$MOUNT2}
1511 [ -z $clients ] && clients=$(hostname)
1512 echo Checking clients $clients environments
1514 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1515 error "clients environments are insane!"
1518 sanity_mount_check () {
1519 sanity_mount_check_servers || return 1
1520 sanity_mount_check_clients || return 2
1523 # mount clients if not mouted
1524 zconf_mount_clients() {
1527 local OPTIONS=${3:-$MOUNTOPT}
1529 local device=$MGSNID:/$FSNAME
1530 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1531 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
1535 echo "Starting client $clients: $OPTIONS $device $mnt"
1538 running=\\\$(mount | grep -c $mnt' ');
1540 if [ \\\$running -eq 0 ] ; then
1542 mount -t lustre $OPTIONS $device $mnt;
1545 exit \\\$rc" || return ${PIPESTATUS[0]}
1547 echo "Started clients $clients: "
1548 do_nodes $clients "mount | grep $mnt' '"
1550 set_default_debug_nodes $clients
1555 zconf_umount_clients() {
1560 [ "$3" ] && force=-f
1562 echo "Stopping clients: $clients $mnt (opts:$force)"
1563 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1564 if [ \\\$running -ne 0 ] ; then
1565 echo Stopping client \\\$(hostname) $mnt opts:$force;
1566 lsof $mnt || need_kill=no;
1567 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1568 pids=\\\$(lsof -t $mnt | sort -u);
1569 if [ -n \\\"\\\$pids\\\" ]; then
1573 while umount $force $mnt 2>&1 | grep -q "busy"; do
1574 echo "$mnt is still busy, wait one second" && sleep 1;
1581 echo + $POWER_DOWN $node
1585 shutdown_node_hard () {
1587 local attempts=$SHUTDOWN_ATTEMPTS
1589 for i in $(seq $attempts) ; do
1592 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1593 echo "waiting for $host to fail attempts=$attempts"
1594 [ $i -lt $attempts ] || \
1595 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1601 local mnt=${2:-$MOUNT}
1604 if [ "$FAILURE_MODE" = HARD ]; then
1605 shutdown_node_hard $client
1607 zconf_umount_clients $client $mnt -f
1613 local facets="$(get_facets OST),$(get_facets MDS)"
1616 combined_mgs_mds || facets="$facets,mgs"
1618 for facet in ${facets//,/ }; do
1619 if [ $(facet_active_host $facet) == $host ]; then
1620 affected="$affected $facet"
1624 echo $(comma_list $affected)
1629 local host=${2:-$(facet_host $facet)}
1631 local label=$(convert_facet2label $facet)
1632 do_node $host $LCTL dl | awk '{print $4}' | grep -q -x $label
1635 facets_up_on_host () {
1637 local facets=$(facets_on_host $host)
1640 for facet in ${facets//,/ }; do
1641 if $(facet_up $facet $host); then
1642 affected_up="$affected_up $facet"
1646 echo $(comma_list $affected_up)
1652 if [ "$FAILURE_MODE" = HARD ]; then
1653 shutdown_node_hard $(facet_active_host $facet)
1661 echo + $POWER_UP $node
1674 if [ "$FAILURE_MODE" = HARD ]; then
1675 reboot_node $(facet_active_host $facet)
1683 if [ "$FAILURE_MODE" = HARD ]; then
1693 for facet in ${facets//,/ }; do
1694 hosts=$(expand_list $hosts $(facet_host $facet) )
1700 _check_progs_installed () {
1704 for prog in $progs; do
1705 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1706 echo $prog missing on $(hostname)
1713 check_progs_installed () {
1717 do_rpc_nodes "$nodes" _check_progs_installed $@
1720 # recovery-scale functions
1722 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1725 start_client_load() {
1728 local var=$(node_var_name $client)_load
1729 eval export ${var}=$load
1731 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1732 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1733 END_RUN_FILE=$END_RUN_FILE \
1734 LOAD_PID_FILE=$LOAD_PID_FILE \
1735 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1736 TESTNAME=$TESTNAME \
1737 DBENCH_LIB=$DBENCH_LIB \
1738 DBENCH_SRC=$DBENCH_SRC \
1739 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
1743 log "Started client load: ${load} on $client"
1745 # get the children process IDs
1746 local pids=$(ps --ppid $ppid -o pid= | xargs)
1747 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1751 start_client_loads () {
1752 local -a clients=(${1//,/ })
1753 local numloads=${#CLIENT_LOADS[@]}
1756 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1757 testnum=$((nodenum % numloads))
1758 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1760 # bug 22169: wait the background threads to start
1764 # only for remote client
1765 check_client_load () {
1767 local var=$(node_var_name $client)_load
1768 local TESTLOAD=run_${!var}.sh
1770 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1772 # bug 18914: try to connect several times not only when
1773 # check ps, but while check_catastrophe also
1776 while [ $RC = 254 -a $tries -gt 0 ]; do
1780 if ! check_catastrophe $client; then
1782 if [ $RC -eq 254 ]; then
1783 # FIXME: not sure how long we shuold sleep here
1787 echo "check catastrophe failed: RC=$RC "
1791 # We can continue try to connect if RC=254
1792 # Just print the warning about this
1793 if [ $RC = 254 ]; then
1794 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1797 # see if the load is still on the client
1800 while [ $RC = 254 -a $tries -gt 0 ]; do
1804 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1809 if [ $RC = 254 ]; then
1810 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1811 # see if we can diagnose a bit why this is
1816 check_client_loads () {
1817 local clients=${1//,/ }
1821 for client in $clients; do
1822 check_client_load $client
1824 if [ "$rc" != 0 ]; then
1825 log "Client load failed on node $client, rc=$rc"
1831 restart_client_loads () {
1832 local clients=${1//,/ }
1833 local expectedfail=${2:-""}
1837 for client in $clients; do
1838 check_client_load $client
1840 if [ "$rc" != 0 -a "$expectedfail" ]; then
1841 local var=$(node_var_name $client)_load
1842 start_client_load $client ${!var}
1843 echo "Restarted client load ${!var}: on $client. Checking ..."
1844 check_client_load $client
1846 if [ "$rc" != 0 ]; then
1847 log "Client load failed to restart on node $client, rc=$rc"
1848 # failure one client load means test fail
1849 # we do not need to check other
1858 # Start vmstat and save its process ID in a file.
1863 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1866 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1867 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1870 # Display the nodes on which client loads failed.
1871 print_end_run_file() {
1875 [ -s $file ] || return 0
1877 echo "Found the END_RUN_FILE file: $file"
1880 # A client load will stop if it finds the END_RUN_FILE file.
1881 # That does not mean the client load actually failed though.
1882 # The first node in END_RUN_FILE is the one we are interested in.
1885 if [ -n "$node" ]; then
1886 local var=$(node_var_name $node)_load
1888 local prefix=$TESTLOG_PREFIX
1889 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
1890 local stdout_log=$prefix.run_${!var}_stdout.$node.log
1891 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
1893 echo "Client load ${!var} failed on node $node:"
1899 # Stop the process which had its PID saved in a file.
1904 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1906 do_nodes $nodes "test -f $pid_file &&
1907 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
1910 # Stop all client loads.
1911 stop_client_loads() {
1912 local nodes=${1:-$CLIENTS}
1915 # stop the client loads
1916 stop_process $nodes $pid_file
1918 # clean up the processes that started them
1919 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
1921 # End recovery-scale functions
1923 # verify that lustre actually cleaned up properly
1925 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
1926 error "LBUG/LASSERT detected"
1927 BUSY=`dmesg | grep -i destruct || true`
1928 if [ "$BUSY" ]; then
1930 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
1934 check_mem_leak || exit 204
1936 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl &&
1937 echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
1940 if module_loaded lnet || module_loaded libcfs; then
1941 echo "$TESTSUITE: modules still loaded..." 1>&2
1950 if [[ "$1" == "--verbose" ]]; then
1965 PREV_RESULT=$(do_node $node "$TEST")
1967 RESULT=$(do_node $node "$TEST")
1968 if [[ "$RESULT" == "$FINAL" ]]; then
1969 [[ -z "$RESULT" || $WAIT -le $sleep ]] ||
1970 echo "Updated after ${WAIT}s: wanted '$FINAL'"\
1974 if [[ $verbose && "$RESULT" != "$PREV_RESULT" ]]; then
1975 echo "Changed after ${WAIT}s: from '$PREV_RESULT'"\
1979 [[ $WAIT -ge $MAX ]] && break
1980 [[ $((WAIT % print)) -eq 0 ]] &&
1981 echo "Waiting $((MAX - WAIT)) secs for update"
1982 WAIT=$((WAIT + sleep))
1985 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
1989 wait_update_facet() {
1992 wait_update $(facet_active_host $facet) "$@"
1996 do_nodes $(comma_list $(mdts_nodes)) \
1997 "lctl set_param -n osd*.*MDT*.force_sync 1"
1998 do_nodes $(comma_list $(osts_nodes)) \
1999 "lctl set_param -n osd*.*OS*.force_sync 1" 2>&1 |
2000 grep -v 'Found no match'
2003 wait_delete_completed_mds() {
2004 local MAX_WAIT=${1:-20}
2006 local stime=`date +%s`
2011 # find MDS with pending deletions
2012 for node in $(mdts_nodes); do
2013 changes=$(do_node $node "lctl get_param -n osc.*MDT*.sync_*" \
2014 2>/dev/null | calc_sum)
2015 if [ -z "$changes" ] || [ $changes -eq 0 ]; then
2018 mds2sync="$mds2sync $node"
2020 if [ "$mds2sync" == "" ]; then
2023 mds2sync=$(comma_list $mds2sync)
2025 # sync MDS transactions
2026 do_nodes $mds2sync "lctl set_param -n osd*.*MD*.force_sync 1"
2028 # wait till all changes are sent and commmitted by OSTs
2029 # for ldiskfs space is released upon execution, but DMU
2030 # do this upon commit
2033 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
2034 changes=$(do_nodes $mds2sync "lctl get_param -n osc.*MDT*.sync_*" \
2036 #echo "$node: $changes changes on all"
2037 if [ "$changes" -eq "0" ]; then
2039 #echo "delete took $((etime - stime)) seconds"
2047 echo "Delete is not completed in $((etime - stime)) seconds"
2048 do_nodes $mds2sync "lctl get_param osc.*MDT*.sync_*"
2054 # we can use "for" here because we are waiting the slowest
2055 for host in ${hostlist//,/ }; do
2056 check_network "$host" 900
2058 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
2065 for facet in ${facetlist//,/ }; do
2066 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
2068 wait_for_host $hostlist
2071 _wait_recovery_complete () {
2074 # Use default policy if $2 is not passed by caller.
2075 local MAX=${2:-$(max_recovery_time)}
2080 while [ $WAIT -lt $MAX ]; do
2081 STATUS=$(lctl get_param -n $param | grep status)
2083 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
2086 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
2088 echo "$param recovery not done in $MAX sec. $STATUS"
2092 wait_recovery_complete () {
2095 # with an assumption that at_max is the same on all nodes
2096 local MAX=${2:-$(max_recovery_time)}
2099 if [ "$FAILURE_MODE" = HARD ]; then
2100 facets=$(facets_on_host $(facet_active_host $facet))
2102 echo affected facets: $facets
2104 # we can use "for" here because we are waiting the slowest
2105 for facet in ${facets//,/ }; do
2106 local var_svc=${facet}_svc
2107 local param="*.${!var_svc}.recovery_status"
2109 local host=$(facet_active_host $facet)
2110 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
2114 wait_mds_ost_sync () {
2115 # just because recovery is done doesn't mean we've finished
2116 # orphan cleanup. Wait for llogs to get synchronized.
2117 echo "Waiting for orphan cleanup..."
2118 # MAX value includes time needed for MDS-OST reconnection
2119 local MAX=$(( TIMEOUT * 2 ))
2120 local WAIT_TIMEOUT=${1:-$MAX}
2123 local list=$(comma_list $(mdts_nodes))
2124 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
2125 if ! do_facet $SINGLEMDS \
2126 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
2128 # old way, use mds_sync
2130 list=$(comma_list $(osts_nodes))
2131 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
2134 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
2135 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
2136 local -a sync=($(do_nodes $list "$cmd"))
2139 for ((i=0; i<${#sync[@]}; i++)); do
2141 [ ${sync[$i]} -eq 1 ] && continue
2143 [ ${sync[$i]} -eq 0 ] && continue
2145 # there is a not finished MDS-OST synchronization
2149 sleep 2 # increase waiting time and cover statfs cache
2150 [ ${con} -eq 1 ] && return 0
2151 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
2155 # show which nodes are not finished.
2156 do_nodes $list "$cmd"
2157 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
2161 wait_destroy_complete () {
2162 echo "Waiting for local destroys to complete"
2163 # MAX value shouldn't be big as this mean server responsiveness
2164 # never increase this just to make test pass but investigate
2165 # why it takes so long time
2168 while [ $WAIT -lt $MAX ]; do
2169 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
2173 for ((i=0; i<${#RPCs[@]}; i++)); do
2174 [ ${RPCs[$i]} -eq 0 ] && continue
2175 # there are still some destroy RPCs in flight
2180 [ ${con} -eq 1 ] && return 0 # done waiting
2181 echo "Waiting ${WAIT}s for local destroys to complete"
2184 echo "Local destroys weren't done in $MAX sec."
2188 wait_delete_completed() {
2189 wait_delete_completed_mds $1 || return $?
2190 wait_destroy_complete
2199 # conf-sanity 31 takes a long time cleanup
2200 while [ $WAIT -lt 300 ]; do
2201 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
2202 [ -z "${running}" ] && return 0
2203 echo "waited $WAIT for${running}"
2204 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
2206 WAIT=$((WAIT + INTERVAL))
2208 echo "service didn't stop after $WAIT seconds. Still running:"
2213 wait_remote_prog () {
2219 [ "$PDSH" = "no_dsh" ] && return 0
2221 while [ $WAIT -lt $2 ]; do
2222 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
2223 [ -z "${running}" ] && return 0 || true
2224 echo "waited $WAIT for: "
2226 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
2228 WAIT=$((WAIT + INTERVAL))
2230 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
2231 [ -z "$pids" ] && return 0
2232 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
2233 # FIXME: not portable
2234 for pid in $pids; do
2235 cat /proc/${pid}/status || true
2236 cat /proc/${pid}/wchan || true
2238 kill -9 $pid || true
2247 # not every config has many clients
2249 if [ ! -z "$CLIENTS" ]; then
2250 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
2252 stat -f $MOUNT > /dev/null
2258 # usually checked on particular client or locally
2260 if [ ! -z "$client" ]; then
2261 $PDSH $client "stat -f $MOUNT" > /dev/null
2263 stat -f $MOUNT > /dev/null
2271 client_reconnect() {
2272 uname -n >> $MOUNT/recon
2273 if [ -z "$CLIENTS" ]; then
2274 df $MOUNT; uname -n >> $MOUNT/recon
2276 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
2278 echo Connected clients:
2280 ls -l $MOUNT/recon > /dev/null
2284 affected_facets () {
2287 local host=$(facet_active_host $facet)
2288 local affected=$facet
2290 if [ "$FAILURE_MODE" = HARD ]; then
2291 affected=$(facets_up_on_host $host)
2305 #Because it will only get up facets, we need get affected
2306 #facets before shutdown
2307 #For HARD Failure mode, it needs make sure facets on the same
2308 #HOST will only be shutdown and reboot once
2309 for facet in ${facets//,/ }; do
2310 local affected_facet
2312 #check whether facet has been included in other affected facets
2313 for ((index=0; index<$total; index++)); do
2314 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
2317 if [ $skip -eq 0 ]; then
2318 affecteds[$total]=$(affected_facets $facet)
2323 for ((index=0; index<$total; index++)); do
2324 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2325 local host=$(facet_active_host $facet)
2326 echo "Failing ${affecteds[index]} on $host"
2327 shutdown_facet $facet
2330 for ((index=0; index<$total; index++)); do
2331 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
2332 echo reboot facets: ${affecteds[index]}
2336 change_active ${affecteds[index]}
2338 wait_for_facet ${affecteds[index]}
2339 # start mgs first if it is affected
2340 if ! combined_mgs_mds &&
2341 list_member ${affecteds[index]} mgs; then
2342 mount_facet mgs || error "Restart of mgs failed"
2344 # FIXME; has to be changed to mount all facets concurrently
2345 affected=$(exclude_items_from_list ${affecteds[index]} mgs)
2346 echo mount facets: ${affecteds[index]}
2347 mount_facets ${affecteds[index]}
2357 do_facet $facet "sync; sync; sync"
2360 # make sure there will be no seq change
2361 local clients=${CLIENTS:-$HOSTNAME}
2362 local f=fsa-\\\$\(hostname\)
2363 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
2364 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
2366 local svc=${facet}_svc
2367 do_facet $facet $LCTL --device ${!svc} notransno
2369 # If a ZFS OSD is made read-only here, its pool is "freezed". This
2370 # in-memory state has to be cleared by either rebooting the host or
2371 # exporting and reimporting the pool.
2373 # Although the uberblocks are not updated when a pool is freezed,
2374 # transactions are still written to the disks. Modified blocks may be
2375 # cached in memory when tests try reading them back. The
2376 # export-and-reimport process also evicts any cached pool data from
2377 # memory to provide the correct "data loss" semantics.
2379 # In the test framework, the exporting and importing operations are
2380 # handled by stop() and mount_facet() separately, which are used
2381 # inside fail() and fail_abort().
2383 do_facet $facet $LCTL --device ${!svc} readonly
2384 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2385 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2388 replay_barrier_nodf() {
2389 local facet=$1 echo running=${running}
2390 do_facet $facet "sync; sync; sync"
2391 local svc=${facet}_svc
2392 echo Replay barrier on ${!svc}
2393 do_facet $facet $LCTL --device ${!svc} notransno
2394 do_facet $facet $LCTL --device ${!svc} readonly
2395 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2396 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2399 replay_barrier_nosync() {
2400 local facet=$1 echo running=${running}
2401 local svc=${facet}_svc
2402 echo Replay barrier on ${!svc}
2403 do_facet $facet $LCTL --device ${!svc} notransno
2404 do_facet $facet $LCTL --device ${!svc} readonly
2405 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2406 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2410 # Get Lustre client uuid for a given Lustre mount point.
2413 local mntpnt=${1:-$MOUNT}
2415 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
2416 local uuid=$($LCTL get_param -n llite.$name.uuid)
2421 mds_evict_client() {
2422 local mntpnt=${1:-$MOUNT}
2423 local uuid=$(get_client_uuid $mntpnt)
2425 do_facet $SINGLEMDS \
2426 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
2429 ost_evict_client() {
2430 local mntpnt=${1:-$MOUNT}
2431 local uuid=$(get_client_uuid $mntpnt)
2434 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
2439 local clients=${CLIENTS:-$HOSTNAME}
2441 facet_failover $* || error "failover: $?"
2442 wait_clients_import_state "$clients" "$facets" FULL
2443 clients_up || error "post-failover df: $?"
2448 facet_failover $facet
2454 change_active $facet
2455 wait_for_facet $facet
2456 mount_facet $facet -o abort_recovery
2457 clients_up || echo "first df failed: $?"
2458 clients_up || error "post-failover df: $?"
2462 echo There is no lmc. This is mountconf, baby.
2466 host_nids_address() {
2470 if [ -n "$kind" ]; then
2471 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2473 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2479 if [ "$1" = "'*'" ]; then echo \'*\'; else
2485 if [ "$1" = "'*'" ]; then echo \'*\'; else
2486 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | \
2488 if [ -z "$ID" ]; then
2489 echo "Could not get a ptl id for $1..."
2498 h2name_or_ip "$1" "tcp"
2503 if [ "$1" = "'*'" ]; then echo \'*\'; else
2504 if type __h2elan >/dev/null 2>&1; then
2507 ID=`echo $1 | sed 's/[^0-9]*//g'`
2515 h2name_or_ip "$1" "o2ib"
2519 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2520 # expressions format. As a bonus we can then just pass in those variables
2521 # to pdsh. What this function does is take a HOSTLIST type string and
2522 # expand it into a space deliminated list for us.
2530 [ -z "$hostlist" ] && return
2532 # Translate the case of [..],..,[..] to [..] .. [..]
2533 list="${hostlist/],/] }"
2535 [[ "$front" == *,* ]] && {
2538 list=${list/${old}/${new}}
2541 for item in $list; do
2542 # Test if we have any []'s at all
2543 if [ "$item" != "${item/\[/}" ]; then {
2544 # Expand the [*] into list
2548 if [ "$name" != "$item" ]; then
2549 group=${item#$name[*}
2552 for range in ${group//,/ }; do
2556 # Number of leading zeros
2559 end=$(echo $end | sed 's/0*//')
2560 [[ -z "$end" ]] && end=0
2561 [[ $padlen2 -gt $padlen ]] && {
2562 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2565 begin=$(echo $begin | sed 's/0*//')
2566 [ -z $begin ] && begin=0
2568 for num in $(seq -f "%0${padlen}g" $begin $end); do
2569 value="${name#*,}${num}${back}"
2570 [ "$value" != "${value/\[/}" ] && {
2571 value=$(hostlist_expand "$value")
2573 myList="$myList $value"
2578 myList="$myList $item"
2581 myList=${myList//,/ }
2582 myList=${myList:1} # Remove first character which is a space
2584 # Filter any duplicates without sorting
2586 myList="${list%% *}"
2588 while [[ "$list" != ${myList##* } ]]; do
2589 list=${list//${list%% *} /}
2590 myList="$myList ${list%% *}"
2592 myList="${myList%* }";
2594 # We can select an object at a offset in the list
2597 for item in $myList; do
2599 [ $cnt -eq $offset ] && {
2603 [ $(get_node_count $myList) -ne 1 ] && myList=""
2612 [ "$facet" == client ] && echo -n $HOSTNAME && return
2613 varname=${facet}_HOST
2614 if [ -z "${!varname}" ]; then
2615 if [ "${facet:0:3}" == "ost" ]; then
2616 local fh=${facet%failover}_HOST
2617 eval export ${facet}_HOST=${!fh}
2618 if [ -z "${!varname}" ]; then
2619 eval export ${facet}_HOST=${ost_HOST}
2621 elif [ "${facet:0:3}" == "mdt" -o \
2622 "${facet:0:3}" == "mds" -o \
2623 "${facet:0:3}" == "mgs" ]; then
2624 eval export ${facet}_HOST=${mds_HOST}
2630 facet_failover_host() {
2634 var=${facet}failover_HOST
2635 if [ -n "${!var}" ]; then
2640 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
2641 "${facet:0:3}" == "mgs" ]; then
2643 eval export ${facet}failover_host=${mds_HOST}
2648 if [[ $facet == ost* ]]; then
2649 eval export ${facet}failover_host=${ost_HOST}
2657 local activevar=${facet}active
2659 if [ -f $TMP/${facet}active ] ; then
2660 source $TMP/${facet}active
2663 active=${!activevar}
2664 if [ -z "$active" ] ; then
2671 facet_active_host() {
2673 local active=`facet_active $facet`
2674 if [ "$facet" == client ]; then
2677 echo `facet_host $active`
2681 # Get the passive failover partner host of facet.
2682 facet_passive_host() {
2684 [[ $facet = client ]] && return
2686 local host=${facet}_HOST
2687 local failover_host=${facet}failover_HOST
2688 local active_host=$(facet_active_host $facet)
2690 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
2692 if [[ $active_host = ${!host} ]]; then
2693 echo -n ${!failover_host}
2703 facetlist=$(exclude_items_from_list $facetlist mgs)
2705 for facet in ${facetlist//,/ }; do
2706 local failover=${facet}failover
2707 local host=`facet_host $failover`
2708 [ -z "$host" ] && return
2710 local curactive=`facet_active $facet`
2711 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2712 eval export ${facet}active=$facet
2714 eval export ${facet}active=$failover
2716 # save the active host for this facet
2717 local activevar=${facet}active
2718 echo "$activevar=${!activevar}" > $TMP/$activevar
2719 [[ $facet = mds1 ]] && combined_mgs_mds && \
2720 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2721 local TO=`facet_active_host $facet`
2722 echo "Failover $facet to $TO"
2728 # do not stripe off hostname if verbose, bug 19215
2729 if [ x$1 = x--verbose ]; then
2737 if [ "$HOST" = "$HOSTNAME" ]; then
2739 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2740 echo "cannot run remote command on $HOST with $myPDSH"
2744 echo "CMD: $HOST $@" >&2
2745 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2748 if [ "$myPDSH" = "rsh" ]; then
2749 # we need this because rsh does not return exit code of an executed command
2750 local command_status="$TMP/cs"
2751 rsh $HOST ":> $command_status"
2752 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2753 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2754 echo command failed >$command_status"
2755 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2760 # print HOSTNAME for myPDSH="no_dsh"
2761 if [[ $myPDSH = no_dsh ]]; then
2762 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2764 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2767 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2769 return ${PIPESTATUS[0]}
2773 do_node --verbose "$@"
2776 single_local_node () {
2777 [ "$1" = "$HOSTNAME" ]
2780 # Outputs environment variable assignments that should be passed to remote nodes
2784 local facets=$(get_facets)
2787 for var in ${!MODOPTS_*}; do
2789 echo -n " ${var}=\"$value\""
2792 for facet in ${facets//,/ }; do
2794 if [ -n "${!var}" ]; then
2795 echo -n " $var=${!var}"
2799 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2800 if [ -n "${!var}" ]; then
2801 echo -n " $var=${!var}"
2805 if [ -n "$FSTYPE" ]; then
2806 echo -n " FSTYPE=$FSTYPE"
2812 # do not stripe off hostname if verbose, bug 19215
2813 if [ x$1 = x--verbose ]; then
2821 if single_local_node $rnodes; then
2823 do_nodev $rnodes "$@"
2825 do_node $rnodes "$@"
2830 # This is part from do_node
2833 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2834 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2836 export FANOUT=$(get_node_count "${rnodes//,/ }")
2838 echo "CMD: $rnodes $@" >&2
2839 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2842 # do not replace anything from pdsh output if -N is used
2843 # -N Disable hostname: prefix on lines of output.
2844 if $verbose || [[ $myPDSH = *-N* ]]; then
2845 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2847 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2849 return ${PIPESTATUS[0]}
2855 local HOST=`facet_active_host $facet`
2856 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
2860 # Function: do_facet_random_file $FACET $FILE $SIZE
2861 # Creates FILE with random content on the given FACET of given SIZE
2863 do_facet_random_file() {
2867 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
2868 do_facet $facet "$cmd 2>/dev/null"
2871 do_facet_create_file() {
2875 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
2876 do_facet $facet "$cmd 2>/dev/null"
2880 do_nodes --verbose "$@"
2886 # make sure its not already running
2888 rm -f $TMP/${facet}active
2889 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
2890 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
2892 if [[ $(facet_fstype $facet) == zfs ]]; then
2894 # After formatting a ZFS target, "cachefile=none" property will
2895 # be set on the ZFS storage pool so that the pool is not
2896 # automatically imported on system startup. And then the pool
2897 # will be exported so as to leave the importing and exporting
2898 # operations handled by mount_facet() and stop() separately.
2900 refresh_partition_table $facet $(facet_vdevice $facet)
2901 disable_zpool_cache $facet
2906 # Device formatted as ost
2909 local DEVNAME=OSTDEV$num
2911 local fstype=$(facet_fstype ost$num)
2915 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2916 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2918 #try $OSTZFSDEVn - independent of vdev
2919 DEVNAME=OSTZFSDEV$num
2920 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
2922 error "unknown fstype!";;
2928 # Physical device location of data
2934 local fstype=$(facet_fstype ost$num)
2938 # vdevs are not supported by ldiskfs
2941 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
2942 # Device formated by zfs
2944 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2946 error "unknown fstype!";;
2952 # Logical device formated for lustre
2955 local DEVNAME=MDSDEV$num
2957 local fstype=$(facet_fstype mds$num)
2961 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
2962 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
2964 # try $MDSZFSDEVn - independent of vdev
2965 DEVNAME=MDSZFSDEV$num
2966 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
2968 error "unknown fstype!";;
2974 # Physical location of data
2978 local fstype=$(facet_fstype mds$num)
2982 # vdevs are not supported by ldiskfs
2985 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
2986 # Device formated by ZFS
2987 local DEVNAME=MDSDEV$num
2988 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
2990 error "unknown fstype!";;
2998 local fstype=$(facet_fstype mgs)
3002 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3003 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
3004 DEVPTR=$(mdsdevname 1)
3009 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3010 ( [ -z "$MGSZFSDEV" ] &&
3011 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
3012 DEVPTR=$(mdsdevname 1)
3014 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
3017 error "unknown fstype!";;
3026 local fstype=$(facet_fstype mgs)
3030 # vdevs are not supported by ldiskfs
3033 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
3034 ( [ -z "$MGSDEV" ] &&
3035 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
3036 VDEVPTR=$(mdsvdevname 1)
3037 elif [ -n "$MGSDEV" ]; then
3041 error "unknown fstype!";;
3049 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
3051 local var=${facet}_MOUNT
3052 eval mntpt=${!var:-${MOUNT%/*}/$facet}
3059 local dev=$(facet_device $facet)
3060 local mnt=$(facet_mntpt $facet)
3063 if ! do_facet $facet test -b $dev; then
3066 do_facet $facet mount -t ldiskfs $opts $dev $mnt
3071 local dev=$(facet_device $facet)
3072 local mnt=$(facet_mntpt $facet)
3074 do_facet $facet umount -d $mnt
3078 echo -n "$1" | tr -c '[:alnum:]\n' '_'
3083 local ds=$(facet_device $facet)
3084 local mnt=$(facet_mntpt $facet)
3089 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
3090 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
3091 do_facet $facet $ZFS set canmount=noauto $ds
3093 # The "legacy" mount method is used here because "zfs unmount $mnt"
3094 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
3095 # targets are not available at the time, the stat(2) on $MOUNT will
3098 do_facet $facet $ZFS set mountpoint=legacy $ds
3099 do_facet $facet mount -t zfs $ds $mnt
3100 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
3101 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
3106 local ds=$(facet_device $facet)
3107 local mnt=$(facet_mntpt $facet)
3108 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
3109 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
3110 local mntpt=${!var_mntpt}
3111 local canmnt=${!var_canmnt}
3115 do_facet $facet umount $mnt
3116 do_facet $facet $ZFS set mountpoint=$mntpt $ds
3117 do_facet $facet $ZFS set canmount=$canmnt $ds
3123 local fstype=$(facet_fstype $facet)
3125 mount_$fstype $facet
3130 local fstype=$(facet_fstype $facet)
3132 unmount_$fstype $facet
3139 # make sure we are using the primary server, so test-framework will
3140 # be able to clean up properly.
3141 activemds=`facet_active mds1`
3142 if [ $activemds != "mds1" ]; then
3146 local clients=$CLIENTS
3147 [ -z $clients ] && clients=$(hostname)
3149 zconf_umount_clients $clients $MOUNT "$*" || true
3150 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
3152 [ "$CLIENTONLY" ] && return
3153 # The add fn does rm ${facet}active file, this would be enough
3154 # if we use do_facet <facet> only after the facet added, but
3155 # currently we use do_facet mds in local.sh
3156 for num in `seq $MDSCOUNT`; do
3158 rm -f ${TMP}/mds${num}active
3160 combined_mgs_mds && rm -f $TMP/mgsactive
3162 for num in `seq $OSTCOUNT`; do
3164 rm -f $TMP/ost${num}active
3167 if ! combined_mgs_mds ; then
3174 cleanup_echo_devs () {
3175 local devs=$($LCTL dl | grep echo | awk '{print $4}')
3177 for dev in $devs; do
3178 $LCTL --device $dev cleanup
3179 $LCTL --device $dev detach
3184 nfs_client_mode && return
3193 combined_mgs_mds () {
3194 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
3195 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
3199 echo -n "$1" | tr '[:upper:]' '[:lower:]'
3203 echo -n "$1" | tr '[:lower:]' '[:upper:]'
3209 local fsname=${3:-"$FSNAME"}
3210 local type=$(facet_type $facet)
3211 local index=$(($(facet_number $facet) - 1))
3212 local fstype=$(facet_fstype $facet)
3213 local host=$(facet_host $facet)
3218 if [ $type == MGS ] && combined_mgs_mds; then
3222 if [ $type == MGS ] || ( [ $type == MDS ] &&
3223 [ "$dev" == $(mgsdevname) ] &&
3224 [ "$host" == "$(facet_host mgs)" ] ); then
3227 opts="--mgsnode=$MGSNID"
3230 if [ $type != MGS ]; then
3231 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
3235 var=${facet}failover_HOST
3236 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
3237 opts+=" --failnode=$(h2$NETTYPE ${!var})"
3240 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
3241 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
3243 if [ $type == MDS ]; then
3244 opts+=${SECLEVEL:+" --param=mdt.sec_level"}
3245 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
3246 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
3247 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
3248 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
3250 if [ $fstype == ldiskfs ]; then
3251 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
3252 if [ ! -z $EJOURNAL ]; then
3253 fs_mkfs_opts+=${MDSJOURNALSIZE:+" device=$EJOURNAL"}
3255 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
3259 if [ $type == OST ]; then
3260 opts+=${SECLEVEL:+" --param=ost.sec_level"}
3261 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
3263 if [ $fstype == ldiskfs ]; then
3264 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
3268 opts+=" --backfstype=$fstype"
3271 if [ -n "${!var}" ]; then
3272 opts+=" --device-size=${!var}"
3275 var=$(upper $fstype)_MKFS_OPTS
3276 fs_mkfs_opts+=${!var:+" ${!var}"}
3278 var=${type}_FS_MKFS_OPTS
3279 fs_mkfs_opts+=${!var:+" ${!var}"}
3281 if [ -n "${fs_mkfs_opts## }" ]; then
3282 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
3286 opts+=${!var:+" ${!var}"}
3299 # We need ldiskfs here, may as well load them all
3301 [ "$CLIENTONLY" ] && return
3302 echo Formatting mgs, mds, osts
3303 if ! combined_mgs_mds ; then
3304 echo "Format mgs: $(mgsdevname)"
3305 add mgs $(mkfs_opts mgs $(mgsdevname)) --reformat \
3306 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} ||
3310 for num in $(seq $MDSCOUNT); do
3311 echo "Format mds$num: $(mdsdevname $num)"
3312 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
3313 --reformat $(mdsdevname $num) $(mdsvdevname $num) \
3314 ${quiet:+>/dev/null} || exit 10
3317 for num in $(seq $OSTCOUNT); do
3318 echo "Format ost$num: $(ostdevname $num)"
3319 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
3320 --reformat $(ostdevname $num) $(ostvdevname ${num}) \
3321 ${quiet:+>/dev/null} || exit 10
3326 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
3330 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
3334 # 0: success, the old identity set already.
3335 # 1: success, the old identity does not set.
3340 local j=`expr $num - 1`
3341 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
3343 if [ -z "$MDT" ]; then
3347 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
3350 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
3352 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
3355 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
3357 if [ $old = "NONE" ]; then
3366 zconf_umount `hostname` $1 || error "umount failed"
3367 zconf_mount `hostname` $1 || error "mount failed"
3375 rm -f $TMP/${facet}active
3376 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
3381 local mdt_count=${1:-$MDSCOUNT}
3382 local ost_count=${2:-$OSTCOUNT}
3385 for num in $(seq $mdt_count); do
3386 DEVNAME=$(mdsdevname $num)
3387 writeconf_facet mds$num $DEVNAME || rc=$?
3390 for num in $(seq $ost_count); do
3391 DEVNAME=$(ostdevname $num)
3392 writeconf_facet ost$num $DEVNAME || rc=$?
3398 nfs_client_mode && return
3400 sanity_mount_check ||
3401 error "environments are insane!"
3405 if [ -z "$CLIENTONLY" ]; then
3406 echo Setup mgs, mdt, osts
3407 echo $WRITECONF | grep -q "writeconf" && \
3409 if ! combined_mgs_mds ; then
3410 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
3413 for num in `seq $MDSCOUNT`; do
3414 DEVNAME=$(mdsdevname $num)
3415 start mds$num $DEVNAME $MDS_MOUNT_OPTS
3417 # We started mds, now we should set failover variables properly.
3418 # Set mds${num}failover_HOST if it is not set (the default failnode).
3419 local varname=mds${num}failover_HOST
3420 if [ -z "${!varname}" ]; then
3421 eval mds${num}failover_HOST=$(facet_host mds$num)
3424 if [ $IDENTITY_UPCALL != "default" ]; then
3425 switch_identity $num $IDENTITY_UPCALL
3428 for num in `seq $OSTCOUNT`; do
3429 DEVNAME=$(ostdevname $num)
3430 start ost$num $DEVNAME $OST_MOUNT_OPTS
3432 # We started ost$num, now we should set ost${num}failover variable properly.
3433 # Set ost${num}failover_HOST if it is not set (the default failnode).
3434 varname=ost${num}failover_HOST
3435 if [ -z "${!varname}" ]; then
3436 eval ost${num}failover_HOST=$(facet_host ost${num})
3444 # wait a while to allow sptlrpc configuration be propogated to targets,
3445 # only needed when mounting new target devices.
3450 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
3452 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
3455 if [ "$MOUNT_2" ]; then
3456 mount_client $MOUNT2
3457 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
3462 # by remounting mdt before ost, initial connect from mdt to ost might
3463 # timeout because ost is not ready yet. wait some time to its fully
3464 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
3465 # by a context negotiation rpc with $TIMEOUT.
3466 # FIXME better by monitoring import status.
3469 sleep $((TIMEOUT + 5))
3475 mounted_lustre_filesystems() {
3476 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
3479 init_facet_vars () {
3480 [ "$CLIENTONLY" ] && return 0
3487 eval export ${facet}_dev=${device}
3488 eval export ${facet}_opt=\"$@\"
3490 local dev=${facet}_dev
3492 # We need to loop for the label
3493 # in case its not initialized yet.
3494 for wait_time in {0,1,3,5,10}; do
3496 if [ $wait_time -gt 0 ]; then
3497 echo "${!dev} not yet initialized,"\
3498 "waiting ${wait_time} seconds."
3502 local label=$(devicelabel ${facet} ${!dev})
3504 # Check to make sure the label does
3505 # not include ffff at the end of the label.
3506 # This indicates it has not been initialized yet.
3508 if [[ $label =~ [f|F]{4}$ ]]; then
3509 # label is not initialized, unset the result
3510 # and either try again or fail
3517 [ -z "$label" ] && echo no label for ${!dev} && exit 1
3519 eval export ${facet}_svc=${label}
3521 local varname=${facet}failover_HOST
3522 if [ -z "${!varname}" ]; then
3523 eval export $varname=$(facet_host $facet)
3526 varname=${facet}_HOST
3527 if [ -z "${!varname}" ]; then
3528 eval export $varname=$(facet_host $facet)
3531 # ${facet}failover_dev is set in cfg file
3532 varname=${facet}failover_dev
3533 if [ -n "${!varname}" ] ; then
3534 eval export ${facet}failover_dev=${!varname}
3536 eval export ${facet}failover_dev=$device
3539 # get mount point of already mounted device
3540 # is facet_dev is already mounted then use the real
3541 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3542 # i.e. ${facet}_MOUNT if specified by user or default
3543 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3544 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3545 if [ -z $mntpt ]; then
3546 mntpt=$(facet_mntpt $facet)
3548 eval export ${facet}_MOUNT=$mntpt
3551 init_facets_vars () {
3554 if ! remote_mds_nodsh; then
3555 for num in $(seq $MDSCOUNT); do
3556 DEVNAME=`mdsdevname $num`
3557 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3561 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3563 if ! remote_ost_nodsh; then
3564 for num in $(seq $OSTCOUNT); do
3565 DEVNAME=$(ostdevname $num)
3566 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3571 osc_ensure_active () {
3576 while [ $period -lt $timeout ]; do
3577 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3578 if [ $count -eq 0 ]; then
3582 echo "There are $count OST are inactive, wait $period seconds, and try again"
3584 period=$((period+3))
3587 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3590 set_conf_param_and_check() {
3594 local ORIG=$(do_facet $myfacet "$TEST")
3595 if [ $# -gt 3 ]; then
3601 echo "Setting $PARAM from $ORIG to $FINAL"
3602 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
3603 error "conf_param $PARAM failed"
3605 wait_update $(facet_host $myfacet) "$TEST" "$FINAL" ||
3606 error "check $PARAM failed!"
3609 init_param_vars () {
3611 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3613 log "Using TIMEOUT=$TIMEOUT"
3615 osc_ensure_active $SINGLEMDS $TIMEOUT
3616 osc_ensure_active client $TIMEOUT
3618 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
3619 local current_jobid_var=$($LCTL get_param -n jobid_var)
3621 if [ $JOBID_VAR = "existing" ]; then
3622 echo "keeping jobstats as $current_jobid_var"
3623 elif [ $current_jobid_var != $JOBID_VAR ]; then
3624 echo "seting jobstats to $JOBID_VAR"
3626 set_conf_param_and_check client \
3627 "$LCTL get_param -n jobid_var" \
3628 "$FSNAME.sys.jobid_var" $JOBID_VAR
3631 echo "jobstats not supported by server"
3634 if [ $QUOTA_AUTO -ne 0 ]; then
3635 if [ "$ENABLE_QUOTA" ]; then
3636 echo "enable quota as required"
3637 setup_quota $MOUNT || return 2
3639 echo "disable quota as required"
3640 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
3646 nfs_client_mode () {
3647 if [ "$NFSCLIENT" ]; then
3648 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
3649 local clients=$CLIENTS
3650 [ -z $clients ] && clients=$(hostname)
3652 # FIXME: remove hostname when 19215 fixed
3653 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
3654 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
3655 if [[ ${#nfsexport[@]} -eq 0 ]]; then
3656 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
3658 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
3664 check_config_client () {
3667 local mounted=$(mount | grep " $mntpt ")
3668 if [ "$CLIENTONLY" ]; then
3670 # CLIENTONLY should not depend on *_HOST settings
3671 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
3672 # in theory someone could create a new,
3673 # client-only config file that assumed lustre was already
3674 # configured and didn't set the MGSNID. If MGSNID is not set,
3675 # then we should use the mgs nid currently being used
3676 # as the default value. bug 18021
3677 [[ x$MGSNID = x ]] &&
3680 if [[ x$mgc != xMGC$MGSNID ]]; then
3681 if [ "$mgs_HOST" ]; then
3682 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
3683 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
3684 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
3690 local myMGS_host=$mgs_HOST
3691 if [ "$NETTYPE" = "ptl" ]; then
3692 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
3695 echo Checking config lustre mounted on $mntpt
3696 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
3697 mgshost=$(echo $mgshost | awk -F: '{print $1}')
3699 # if [ "$mgshost" != "$myMGS_host" ]; then
3700 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
3701 # Please use correct config or set mds_HOST correctly!"
3706 check_config_clients () {
3707 local clients=${CLIENTS:-$HOSTNAME}
3710 nfs_client_mode && return
3712 do_rpc_nodes "$clients" check_config_client $mntpt
3714 sanity_mount_check || error "environments are insane!"
3718 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3719 local cltimeout=$(lctl get_param -n timeout)
3720 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
3721 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
3728 [ -z $mntpt ] && return 1
3729 local mounted=$(mounted_lustre_filesystems)
3731 echo $mounted' ' | grep -w -q $mntpt' '
3735 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
3739 # empty lustre filesystem may have empty directories lost+found and .lustre
3741 # exclude .lustre & lost+found
3742 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
3743 -print | wc -l) = 1 ] || return 1
3744 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
3745 if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.4.0) ]; then
3746 # exclude .lustre/fid (LU-2780)
3747 [ $(find $1/.lustre -maxdepth 1 -name fid -prune -o \
3748 -print | wc -l) = 1 ] || return 1
3750 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
3755 check_and_setup_lustre() {
3756 nfs_client_mode && return
3758 local MOUNTED=$(mounted_lustre_filesystems)
3762 # both MOUNT and MOUNT2 are not mounted
3763 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
3764 [ "$REFORMAT" ] && formatall
3765 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
3767 is_mounted $MOUNT || error "NAME=$NAME not mounted"
3768 export I_MOUNTED=yes
3772 elif is_mounted $MOUNT2; then
3774 # MOUNT2 is mounted, while MOUNT_2 is not set
3775 if ! [ "$MOUNT_2" ]; then
3776 cleanup_mount $MOUNT2
3777 export I_UMOUNTED2=yes
3780 # MOUNT2 is mounted, MOUNT_2 is set
3782 # FIXME: what to do if check_config failed?
3784 # 1) remote client has mounted other Lustre fs ?
3785 # 2) it has insane env ?
3786 # let's try umount MOUNT2 on all clients and mount it again:
3787 if ! check_config_clients $MOUNT2; then
3788 cleanup_mount $MOUNT2
3789 restore_mount $MOUNT2
3790 export I_MOUNTED2=yes
3795 # MOUNT is mounted MOUNT2 is not mounted
3796 elif [ "$MOUNT_2" ]; then
3797 restore_mount $MOUNT2
3798 export I_MOUNTED2=yes
3802 # FIXME: what to do if check_config failed?
3804 # 1) remote client has mounted other Lustre fs?
3805 # 2) lustre is mounted on remote_clients atall ?
3806 check_config_clients $MOUNT
3810 set_default_debug_nodes $(comma_list $(nodes_list))
3813 if [ $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ] ; then
3815 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
3816 facets="$(get_facets OST)"
3817 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
3818 facets="$facets,$(get_facets MDS)"
3819 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
3820 facets="$facets,mgs"
3821 local nodes="$(facets_hosts ${facets})"
3822 if [ -n "$nodes" ] ; then
3823 do_nodes $nodes "$LCTL set_param \
3824 osd-ldiskfs.track_declares_assert=1 || true"
3833 if [ "$ONLY" == "setup" ]; then
3839 local clients=${CLIENTS:-$HOSTNAME}
3842 zconf_mount_clients $clients $mntpt
3846 local clients=${CLIENTS:-$HOSTNAME}
3849 zconf_umount_clients $clients $mntpt
3852 cleanup_and_setup_lustre() {
3853 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
3854 lctl set_param debug=0 || true
3856 if [ "$ONLY" == "cleanup" ]; then
3860 check_and_setup_lustre
3863 # Get all of the server target devices from a given server node and type.
3870 if [ "$type" == ost ]; then
3871 devs=$(get_osd_param $node "" mntdev)
3873 devs=$(do_node $node \
3874 "lctl get_param -n osd-*.$FSNAME-M*.mntdev")
3876 for dev in $devs; do
3878 *loop*) do_node $node "losetup $dev" | \
3879 sed -e "s/.*(//" -e "s/).*//" ;;
3885 # Get all of the server target devices.
3890 MDTDEV=$(get_mnt_devs $(mdts_nodes) mdt)
3894 for node in $(osts_nodes); do
3895 OSTDEVS[i]=$(get_mnt_devs $node ost)
3900 # Run e2fsck on MDT or OST device.
3906 df > /dev/null # update statfs data on disk
3907 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
3910 do_node $node $cmd || rc=$?
3911 [ $rc -le $FSCK_MAX_ERR ] || \
3912 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
3917 # Run resize2fs on MDT or OST device.
3926 do_facet $facet "$RESIZE2FS $opts $device $size"
3929 # verify a directory is shared among nodes.
3930 check_shared_dir() {
3932 local list=${2:-$(comma_list $(nodes_list))}
3934 [ -z "$dir" ] && return 1
3935 do_rpc_nodes "$list" check_logdir $dir
3936 check_write_access $dir "$list" || return 1
3940 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
3946 [[ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]] ||
3947 { skip "Lustre 2.2.0 lacks the patch for LU-1255"; exit 0; }
3949 check_shared_dir $SHARED_DIRECTORY ||
3950 error "$SHARED_DIRECTORY isn't a shared directory"
3952 export MDSDB=$SHARED_DIRECTORY/mdsdb
3953 export OSTDB=$SHARED_DIRECTORY/ostdb
3955 [ $MDSCOUNT -eq 1 ] || error "CMD is not supported"
3957 run_e2fsck $(mdts_nodes) $MDTDEV "-n --mdsdb $MDSDB"
3962 for node in $(osts_nodes); do
3963 for dev in ${OSTDEVS[i]}; do
3964 run_e2fsck $node $dev "-n --mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
3965 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
3966 ostidx=$((ostidx + 1))
3972 # Run lfsck on server node if lfsck can't be found on client (LU-2571)
3973 run_lfsck_remote() {
3974 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
3979 #Check if lustre is already mounted
3980 do_rpc_nodes $client is_mounted $MOUNT || mounted=false
3982 zconf_mount $client $MOUNT ||
3983 error "failed to mount Lustre on $client"
3987 do_node $node $cmd || rc=$?
3988 #Umount if necessary
3990 zconf_umount $client $MOUNT ||
3991 error "failed to unmount Lustre on $client"
3994 [ $rc -le $FSCK_MAX_ERR ] ||
3995 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
3996 echo "lfsck finished with rc=$rc"
4002 local facets="client $SINGLEMDS"
4008 for facet in $facets; do
4009 node=$(facet_active_host $facet)
4010 if check_progs_installed $node $LFSCK_BIN; then
4015 ! $found && error "None of \"$facets\" supports lfsck"
4017 run_lfsck_remote $node || rc=$?
4019 rm -rvf $MDSDB* $OSTDB* || true
4023 check_and_cleanup_lustre() {
4024 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
4030 if is_mounted $MOUNT; then
4031 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
4032 error "remove sub-test dirs failed"
4033 [ "$ENABLE_QUOTA" ] && restore_quota || true
4036 if [ "$I_UMOUNTED2" = "yes" ]; then
4037 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
4040 if [ "$I_MOUNTED2" = "yes" ]; then
4041 cleanup_mount $MOUNT2
4044 if [ "$I_MOUNTED" = "yes" ]; then
4045 cleanupall -f || error "cleanup failed"
4053 wait_for_function () {
4056 # suppress fn both stderr and stdout
4057 if [ "$1" = "--quiet" ]; then
4059 quiet=" > /dev/null 2>&1"
4071 eval $fn $quiet && return 0
4073 wait=$((wait + sleep))
4074 [ $wait -lt $max ] || return 1
4075 echo waiting $fn, $((max - wait)) secs left ...
4085 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
4086 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
4087 echo "Network not available!"
4091 echo `date +"%H:%M:%S (%s)"` network interface is UP
4099 # Convert a space-delimited list to a comma-delimited list. If the input is
4100 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
4102 # echo is used to convert newlines to spaces, since it doesn't
4103 # introduce a trailing space as using "tr '\n' ' '" does
4104 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
4110 echo $list | grep -qw $item
4113 # list, excluded are the comma separated lists
4114 exclude_items_from_list () {
4120 for item in ${excluded//,/ }; do
4121 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
4123 echo $(comma_list $list)
4126 # list, expand are the comma separated lists
4128 local list=${1//,/ }
4129 local expand=${2//,/ }
4132 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
4133 echo $(comma_list $expanded)
4136 testslist_filter () {
4137 local script=$LUSTRE/tests/${TESTSUITE}.sh
4139 [ -f $script ] || return 0
4141 local start_at=$START_AT
4142 local stop_at=$STOP_AT
4144 local var=${TESTSUITE//-/_}_START_AT
4145 [ x"${!var}" != x ] && start_at=${!var}
4146 var=${TESTSUITE//-/_}_STOP_AT
4147 [ x"${!var}" != x ] && stop_at=${!var}
4149 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
4150 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
4151 /^'${start_at}'$/ {flag = 0}
4152 {if (flag == 1) print $0}
4153 /^'${stop_at}'$/ { flag = 1 }'
4157 (cd `dirname $1`; echo $PWD/`basename $1`)
4161 local types=${1:-"OST MDS MGS"}
4165 for entry in $types; do
4166 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
4167 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
4170 MGS ) list="$list $name";;
4171 MDS|OST|AGT ) local count=${type}COUNT
4172 for ((i=1; i<=${!count}; i++)) do
4173 list="$list ${name}$i"
4175 * ) error "Invalid facet type"
4179 echo $(comma_list $list)
4182 ##################################
4183 # Adaptive Timeouts funcs
4186 # only check mds, we assume at_max is the same on all nodes
4187 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
4188 if [ $at_max -eq 0 ]; then
4199 # suppose that all ost-s have the same $at value set
4200 [ $facet != "ost" ] || facet=ost1
4202 do_facet $facet "lctl get_param -n $at"
4220 if [ $facet == "ost" ]; then
4221 facet=$(get_facets OST)
4222 elif [ $facet == "mds" ]; then
4223 facet=$(get_facets MDS)
4225 hosts=$(expand_list $hosts $(facets_hosts $facet))
4228 do_nodes $hosts lctl set_param at_max=$at_max
4231 ##################################
4235 # OBD_FAIL_MDS_ALL_REQUEST_NET
4237 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
4238 do_facet client "$1" || RC=$?
4239 do_facet $SINGLEMDS lctl set_param fail_loc=0
4244 # OBD_FAIL_MDS_ALL_REPLY_NET
4246 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
4247 do_facet client "$@" || RC=$?
4248 do_facet $SINGLEMDS lctl set_param fail_loc=0
4252 drop_reint_reply() {
4253 # OBD_FAIL_MDS_REINT_NET_REP
4255 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
4256 do_facet client "$@" || RC=$?
4257 do_facet $SINGLEMDS lctl set_param fail_loc=0
4261 drop_update_reply() {
4262 # OBD_FAIL_UPDATE_OBJ_NET_REP
4266 do_facet mds${index} lctl set_param fail_loc=0x1701
4267 do_facet client "$@" || RC=$?
4268 do_facet mds${index} lctl set_param fail_loc=0
4273 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4276 local timeout=${2:-0}
4277 # default is (obd_timeout / 4) if unspecified
4278 echo "timeout is $timeout/$2"
4279 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
4280 do_facet client "$1" || RC=$?
4281 do_facet client "sync"
4282 do_facet ost1 lctl set_param fail_loc=0
4286 drop_ldlm_cancel() {
4287 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
4289 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
4290 do_nodes $list lctl set_param fail_loc=0x304
4292 do_facet client "$@" || RC=$?
4294 do_nodes $list lctl set_param fail_loc=0
4298 drop_bl_callback() {
4299 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
4301 do_facet client lctl set_param fail_loc=0x80000305
4302 do_facet client "$@" || RC=$?
4303 do_facet client lctl set_param fail_loc=0
4308 #define OBD_FAIL_LDLM_REPLY 0x30c
4310 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
4311 do_facet client "$@" || RC=$?
4312 do_facet $SINGLEMDS lctl set_param fail_loc=0
4320 echo "clearing fail_loc on $facet"
4321 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
4324 set_nodes_failloc () {
4325 do_nodes $(comma_list $1) lctl set_param fail_val=0 fail_loc=$2
4328 cancel_lru_locks() {
4329 $LCTL mark "cancel_lru_locks $1 start"
4330 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
4331 $LCTL set_param -n $d=clear
4333 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
4334 $LCTL mark "cancel_lru_locks $1 stop"
4339 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
4340 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
4341 echo "$DEFAULT_LRU_SIZE"
4346 lctl set_param ldlm.namespaces.*$1*.lru_size=0
4349 lru_resize_disable()
4351 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
4356 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
4357 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
4358 echo there is still data in page cache $FILE ?
4359 lctl get_param -n $FILE
4367 DEBUGSAVE="$(lctl get_param -n debug)"
4371 [ -n "$DEBUGSAVE" ] && \
4372 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
4377 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
4380 debug_size_restore() {
4381 [ -n "$DEBUG_SIZE_SAVED" ] && \
4382 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
4386 start_full_debug_logging() {
4391 local DEBUG_SIZE=150
4393 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
4394 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
4397 stop_full_debug_logging() {
4402 # prints bash call stack
4405 for (( i=1; i < ${#BASH_LINENO[*]} ; i++ )) ; do
4406 local s=${BASH_SOURCE[$i]}
4407 local l=${BASH_LINENO[$i-1]}
4408 local f=${FUNCNAME[$i]}
4409 echo " = $s:$l:$f()"
4413 ##################################
4415 ##################################
4418 local TYPE=${TYPE:-"FAIL"}
4421 # do not dump logs if $1=false
4422 if [ "x$1" = "xfalse" ]; then
4428 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
4432 # We need to dump the logs on all nodes
4434 gather_logs $(comma_list $(nodes_list))
4438 [ "$TESTSUITELOG" ] &&
4439 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
4440 if [ -z "$*" ]; then
4441 echo "error() without useful message, please fix" > $LOGDIR/err
4443 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
4444 echo "$@" > $LOGDIR/ignore
4446 echo "$@" > $LOGDIR/err
4453 local log=$TESTSUITELOG
4455 [ -f "$log" ] && grep -q FAIL $log && status=1
4468 # use only if we are ignoring failures for this test, bugno required.
4469 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
4470 # e.g. error_ignore bz5494 "your message" or
4471 # error_ignore LU-5494 "your message"
4473 local TYPE="IGNORE ($1)"
4478 error_and_remount() {
4480 remount_client $MOUNT
4485 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
4490 log " SKIP: $TESTSUITE $TESTNAME $@"
4492 if [[ -n "$ALWAYS_SKIPPED" ]]; then
4493 skip_logged $TESTNAME "$@"
4496 echo "$@" > $LOGDIR/skip
4499 [[ -n "$TESTSUITELOG" ]] &&
4500 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
4503 build_test_filter() {
4504 EXCEPT="$EXCEPT $(testslist_filter)"
4506 [ "$ONLY" ] && log "only running test `echo $ONLY`"
4510 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
4511 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
4512 [ "$EXCEPT_SLOW" ] && \
4513 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
4514 for E in $EXCEPT; do
4515 eval EXCEPT_${E}=true
4517 for E in $ALWAYS_EXCEPT; do
4518 eval EXCEPT_ALWAYS_${E}=true
4520 for E in $EXCEPT_SLOW; do
4521 eval EXCEPT_SLOW_${E}=true
4523 for G in $GRANT_CHECK_LIST; do
4524 eval GCHECK_ONLY_${G}=true
4529 if [[ $1 = [a-z]* ]]; then
4536 # print a newline if the last test was skipped
4537 export LAST_SKIPPED=
4538 export ALWAYS_SKIPPED=
4540 # Main entry into test-framework. This is called with the name and
4541 # description of a test. The name is used to find the function to run
4542 # the test using "test_$name".
4544 # This supports a variety of methods of specifying specific test to
4545 # run or not run. These need to be documented...
4550 export base=`basetest $1`
4551 if [ ! -z "$ONLY" ]; then
4553 if [ ${!testname}x != x ]; then
4554 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4555 run_one_logged $1 "$2"
4559 if [ ${!testname}x != x ]; then
4560 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
4561 run_one_logged $1 "$2"
4571 if [ ${!testname}x != x ]; then
4572 TESTNAME=test_$1 skip "skipping excluded test $1"
4575 testname=EXCEPT_$base
4576 if [ ${!testname}x != x ]; then
4577 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
4580 testname=EXCEPT_ALWAYS_$1
4581 if [ ${!testname}x != x ]; then
4582 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
4585 testname=EXCEPT_ALWAYS_$base
4586 if [ ${!testname}x != x ]; then
4587 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
4590 testname=EXCEPT_SLOW_$1
4591 if [ ${!testname}x != x ]; then
4592 TESTNAME=test_$1 skip "skipping SLOW test $1"
4595 testname=EXCEPT_SLOW_$base
4596 if [ ${!testname}x != x ]; then
4597 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
4603 run_one_logged $1 "$2"
4610 module_loaded lnet || load_modules
4622 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
4627 strace -o $TMP/$1.strace -ttt $*
4629 log "FINISHED: $*: rc $RC"
4636 banner test complete, duration $duration sec
4637 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
4638 echo duration $duration >>$TESTSUITELOG
4642 # Set TEST_STATUS here. It will be used for logging the result.
4645 if [[ -f $LOGDIR/err ]]; then
4647 elif [[ -f $LOGDIR/skip ]]; then
4650 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
4654 local FFREE=$(do_node $SINGLEMDS \
4655 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
4656 local FTOTAL=$(do_node $SINGLEMDS \
4657 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
4659 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
4663 echo -n "Resetting fail_loc on all nodes..."
4664 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
4670 # Log a message (on all nodes) padded with "=" before and after.
4671 # Also appends a timestamp and prepends the testsuite name.
4674 EQUALS="===================================================================================================="
4676 msg="== ${TESTSUITE} $*"
4678 [[ $last != "=" && $last != " " ]] && msg="$msg "
4679 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
4680 # always include at least == after the message
4681 log "$msg== $(date +"%H:%M:%S (%s)")"
4685 # Run a single test function and cleanup after it.
4687 # This function should be run in a subshell so the test func can
4688 # exit() without stopping the whole script.
4693 tfile=f.${TESTSUITE}.${testnum}
4694 export tdir=d0.${TESTSUITE}/d${base}
4695 export TESTNAME=test_$testnum
4696 local SAVE_UMASK=`umask`
4699 banner "test $testnum: $message"
4700 test_${testnum} || error "test_$testnum failed with $?"
4703 check_grant ${testnum} || error "check_grant $testnum failed with $?"
4704 check_catastrophe || error "LBUG/LASSERT detected"
4705 if [ "$PARALLEL" != "yes" ]; then
4706 ps auxww | grep -v grep | grep -q multiop &&
4707 error "multiop still running"
4716 # Wrapper around run_one to ensure:
4717 # - test runs in subshell
4718 # - output of test is saved to separate log file for error reporting
4719 # - test result is saved to data file
4722 local BEFORE=`date +%s`
4724 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
4725 local test_log=$LOGDIR/$name
4727 rm -rf $LOGDIR/ignore
4729 local SAVE_UMASK=`umask`
4733 log_sub_test_begin test_${1}
4734 (run_one $1 "$2") 2>&1 | tee -i $test_log
4735 local RC=${PIPESTATUS[0]}
4737 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
4738 echo "test_$1 returned $RC" | tee $LOGDIR/err
4740 duration=$((`date +%s` - $BEFORE))
4741 pass "$1" "(${duration}s)"
4743 if [[ -f $LOGDIR/err ]]; then
4744 TEST_ERROR=$(cat $LOGDIR/err)
4745 elif [[ -f $LOGDIR/ignore ]]; then
4746 TEST_ERROR=$(cat $LOGDIR/ignore)
4747 elif [[ -f $LOGDIR/skip ]]; then
4748 TEST_ERROR=$(cat $LOGDIR/skip)
4750 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
4752 if [ -f $LOGDIR/err ]; then
4753 $FAIL_ON_ERROR && exit $RC
4762 # Print information of skipped tests to result.yml
4765 log_sub_test_begin $1
4767 log_sub_test_end "SKIP" "0" "0" "$@"
4771 (cd `dirname $1`; echo $PWD/`basename $1`)
4776 export base=`basetest $1`
4777 [ "$CHECK_GRANT" == "no" ] && return 0
4779 testname=GCHECK_ONLY_${base}
4780 [ ${!testname}x == x ] && return 0
4782 echo -n "checking grant......"
4784 local clients=$CLIENTS
4785 [ -z $clients ] && clients=$(hostname)
4787 # sync all the data and make sure no pending data on server
4788 do_nodes $clients sync
4791 client_grant=`do_nodes $clients \
4792 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" | \
4793 awk '{total += $1} END{print total}'`
4796 server_grant=`do_nodes $(comma_list $(osts_nodes)) \
4797 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
4798 awk '{total += $1} END{print total}'`
4800 # check whether client grant == server grant
4801 if [ $client_grant -ne $server_grant ]; then
4802 echo "failed: client:${client_grant} server: ${server_grant}."
4803 do_nodes $(comma_list $(osts_nodes)) \
4804 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
4805 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
4808 echo "pass: client:${client_grant} server: ${server_grant}"
4813 ########################
4819 ost=`echo $1 | awk -F_ '{print $3}'`
4820 if [ -z $ost ]; then
4821 ost=`echo $1 | sed 's/-osc.*//'`
4826 ostuuid_from_index()
4828 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
4831 ostname_from_index() {
4832 local uuid=$(ostuuid_from_index $1)
4836 index_from_ostuuid()
4838 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
4841 mdtuuid_from_index()
4843 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
4847 # Return unique identifier for given hostname
4850 echo $host_name | md5sum | cut -d' ' -f1
4854 # Returns list of ip addresses for each interface
4856 ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
4861 # Cache address list to avoid mutiple execution of local_addr_list
4862 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
4864 for i in $LOCAL_ADDR_LIST ; do
4865 [[ "$i" == "$addr" ]] && return 0
4872 local is_local="IS_LOCAL_$(host_id $host_name)"
4873 if [ -z "${!is_local-}" ] ; then
4875 local host_ip=$($LUSTRE/tests/resolveip $host_name)
4876 is_local_addr "$host_ip" && eval $is_local=1
4878 [[ "${!is_local}" == "1" ]]
4883 local_node $node && return 1
4890 for node in $(mdts_nodes); do
4891 remote_node $node && return 0
4898 [ "$CLIENTONLY" ] && return 0 || true
4899 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
4904 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
4905 MSKIPPED=1 && return 1
4912 for node in $(osts_nodes) ; do
4913 remote_node $node && return 0
4920 [ "$CLIENTONLY" ] && return 0 || true
4921 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
4926 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
4927 OSKIPPED=1 && return 1
4934 MGS=$(facet_host mgs)
4935 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
4940 remote_mds_nodsh || remote_ost_nodsh || \
4941 $(single_local_node $(comma_list $(nodes_list)))
4945 remote_ost && remote_mds
4948 # Get the active nodes for facets.
4956 for facet in ${facets//,/ }; do
4957 nodes="$nodes $(facet_active_host $facet)"
4960 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
4964 # Get all of the active MDS nodes.
4966 echo -n $(facets_nodes $(get_facets MDS))
4969 # Get all of the active OSS nodes.
4971 echo -n $(facets_nodes $(get_facets OST))
4974 # Get all of the active AGT (HSM agent) nodes.
4976 echo -n $(facets_nodes $(get_facets AGT))
4979 # Get all of the client nodes and active server nodes.
4981 local nodes=$HOSTNAME
4985 # CLIENTS (if specified) contains the local client
4986 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
4988 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
4989 nodes="$nodes $(facets_nodes $(get_facets))"
4992 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
4996 # Get all of the remote client nodes and remote active server nodes.
4997 remote_nodes_list () {
4998 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
5001 # Get all of the MDS nodes, including active and passive nodes.
5009 for i in $(seq $MDSCOUNT); do
5011 failover_host=mds${i}failover_HOST
5012 nodes="$nodes ${!host} ${!failover_host}"
5015 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5019 # Get all of the OSS nodes, including active and passive nodes.
5027 for i in $(seq $OSTCOUNT); do
5029 failover_host=ost${i}failover_HOST
5030 nodes="$nodes ${!host} ${!failover_host}"
5033 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5037 # Get all of the server nodes, including active and passive nodes.
5038 all_server_nodes () {
5043 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
5045 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5049 # Get all of the client and server nodes, including active and passive nodes.
5051 local nodes=$HOSTNAME
5055 # CLIENTS (if specified) contains the local client
5056 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
5058 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
5059 nodes="$nodes $(all_server_nodes)"
5062 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
5066 init_clients_lists () {
5067 # Sanity check: exclude the local client from RCLIENTS
5068 local clients=$(hostlist_expand "$RCLIENTS")
5069 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
5071 # Sanity check: exclude the dup entries
5072 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
5074 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
5076 # Sanity check: exclude the dup entries from CLIENTS
5077 # for those configs which has SINGLCLIENT set to local client
5078 clients=$(for i in $clients; do echo $i; done | sort -u)
5080 CLIENTS=$(comma_list $clients)
5081 local -a remoteclients=($RCLIENTS)
5082 for ((i=0; $i<${#remoteclients[@]}; i++)); do
5083 varname=CLIENT$((i + 2))
5084 eval $varname=${remoteclients[i]}
5087 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
5090 get_random_entry () {
5093 rnodes=${rnodes//,/ }
5095 local -a nodes=($rnodes)
5096 local num=${#nodes[@]}
5097 local i=$((RANDOM * num * 2 / 65536))
5103 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
5108 lctl get_param version | grep -q patchless
5112 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
5113 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
5118 echo $nodes | wc -w || true
5122 local nodes=$(osts_nodes)
5123 local osscount=$(get_node_count "$nodes")
5124 [ ! "$OSTCOUNT" = "$osscount" ]
5128 local nodes=$(mdts_nodes)
5129 local mdtcount=$(get_node_count "$nodes")
5130 [ ! "$MDSCOUNT" = "$mdtcount" ]
5133 generate_machine_file() {
5134 local nodes=${1//,/ }
5135 local machinefile=$2
5137 for node in $nodes; do
5138 echo $node >>$machinefile || \
5139 { echo "can not generate machinefile $machinefile" && return 1; }
5144 local file=$1/stripe
5147 $LFS getstripe -v $file || error "getstripe $file failed"
5151 setstripe_nfsserver () {
5154 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
5155 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
5157 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
5159 do_nodev $nfsserver lfs setstripe "$@"
5162 # Check and add a test group.
5168 local gid=$(getent group $group_name | cut -d: -f3)
5169 if [[ -n "$gid" ]]; then
5170 [[ "$gid" -eq "$group_id" ]] || {
5171 error_noexit "inconsistent group ID:" \
5172 "new: $group_id, old: $gid"
5176 groupadd -g $group_id $group_name
5183 # Check and add a test user.
5196 local uid=$(getent passwd $user_name | cut -d: -f3)
5197 if [[ -n "$uid" ]]; then
5198 if [[ "$uid" -eq "$user_id" ]]; then
5199 local dir=$(getent passwd $user_name | cut -d: -f6)
5200 if [[ "$dir" != "$home" ]]; then
5202 usermod -d $home $user_name
5206 error_noexit "inconsistent user ID:" \
5207 "new: $user_id, old: $uid"
5212 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
5219 check_runas_id_ret() {
5221 local myRUNAS_UID=$1
5222 local myRUNAS_GID=$2
5225 if [ -z "$myRUNAS" ]; then
5226 error_exit "myRUNAS command must be specified for check_runas_id"
5229 $myRUNAS krb5_login.sh || \
5230 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
5232 mkdir $DIR/d0_runas_test
5234 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
5235 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
5236 rm -rf $DIR/d0_runas_test
5241 local myRUNAS_UID=$1
5242 local myRUNAS_GID=$2
5245 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
5246 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
5247 Please set RUNAS_ID to some UID which exists on MDS and client or
5248 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
5251 # obtain the UID/GID for MPI_USER
5255 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
5256 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
5258 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
5259 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
5262 # obtain and cache Kerberos ticket-granting ticket
5263 refresh_krb5_tgt() {
5264 local myRUNAS_UID=$1
5265 local myRUNAS_GID=$2
5268 if [ -z "$myRUNAS" ]; then
5269 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
5272 CLIENTS=${CLIENTS:-$HOSTNAME}
5273 do_nodes $CLIENTS "set -x
5274 if ! $myRUNAS krb5_login.sh; then
5275 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
5280 # Run multiop in the background, but wait for it to print
5281 # "PAUSING" to its stdout before returning from this function.
5282 multiop_bg_pause() {
5283 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
5287 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
5290 echo "$MULTIOP_PROG $FILE v$ARGS"
5291 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
5293 echo "TMPPIPE=${TMPPIPE}"
5294 read -t 60 multiop_output < $TMPPIPE
5295 if [ $? -ne 0 ]; then
5300 if [ "$multiop_output" != "PAUSING" ]; then
5301 echo "Incorrect multiop output: $multiop_output"
5316 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
5322 inodes_available () {
5323 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
5327 mdsrate_inodes_available () {
5328 local min_inodes=$(inodes_available)
5329 echo $((min_inodes * 99 / 100))
5332 # reset llite stat counters
5333 clear_llite_stats(){
5334 lctl set_param -n llite.*.stats 0
5337 # sum llite stat items
5338 calc_llite_stats() {
5339 local res=$(lctl get_param -n llite.*.stats |
5340 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
5344 # reset osc stat counters
5346 lctl set_param -n osc.*.osc_stats 0
5349 # sum osc stat items
5351 local res=$(lctl get_param -n osc.*.osc_stats |
5352 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
5357 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
5360 calc_osc_kbytes () {
5361 df $MOUNT > /dev/null
5362 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
5365 # save_lustre_params(comma separated facet list, parameter_mask)
5366 # generate a stream of formatted strings (<facet> <param name>=<param value>)
5367 save_lustre_params() {
5373 for facet in ${facets//,/ }; do
5374 node=$(facet_active_host $facet)
5375 [[ *\ $node\ * = " $nodes " ]] && continue
5376 nodes="$nodes $node"
5378 do_node $node "$LCTL get_param $2 |
5379 while read s; do echo $facet \\\$s; done"
5383 # restore lustre parameters from input stream, produces by save_lustre_params
5384 restore_lustre_params() {
5389 while IFS=" =" read facet name val; do
5390 do_facet $facet "$LCTL set_param -n $name $val"
5394 check_catastrophe() {
5395 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
5396 local C=$CATASTROPHE
5397 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
5399 [ -z "$rnodes" ] && return 0
5402 data=$(do_nodes "$rnodes" "rc=\\\$([ -f $C ] &&
5403 echo \\\$(< $C) || echo 0);
5404 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
5407 if [ -n "$data" ]; then
5414 # CMD: determine mds index where directory inode presents
5417 local file=$dir/f0.get_mds_dir_tmpfile
5422 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
5423 local -a oldused=($iused)
5425 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
5427 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
5428 local -a newused=($iused)
5431 for ((i=0; i<${#newused[@]}; i++)); do
5432 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
5438 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
5441 mdsrate_cleanup () {
5443 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
5444 --nfiles $3 --dir $4 --filefmt $5 $6
5449 delayed_recovery_enabled () {
5450 local var=${SINGLEMDS}_svc
5451 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
5454 ########################
5456 convert_facet2label() {
5459 if [ x$facet = xost ]; then
5463 local varsvc=${facet}_svc
5465 if [ -n ${!varsvc} ]; then
5468 error "No lablel for $facet!"
5472 get_clientosc_proc_path() {
5476 get_lustre_version () {
5477 local facet=${1:-"$SINGLEMDS"}
5478 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
5481 lustre_version_code() {
5482 local facet=${1:-"$SINGLEMDS"}
5483 version_code $(get_lustre_version $1)
5486 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
5487 # used by MDT would not be changed.
5488 # mdt lov: fsname-mdtlov
5489 # mdt osc: fsname-OSTXXXX-osc
5490 mds_on_old_device() {
5491 local mds=${1:-"$SINGLEMDS"}
5493 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
5494 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
5495 > /dev/null 2>&1" && return 0
5500 get_mdtosc_proc_path() {
5502 local ost_label=${2:-"*OST*"}
5504 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
5505 local mdt_label=$(convert_facet2label $mds_facet)
5506 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
5508 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
5509 mds_on_old_device $mds_facet; then
5510 echo "${ost_label}-osc"
5512 echo "${ost_label}-osc-${mdt_index}"
5516 get_osc_import_name() {
5519 local label=$(convert_facet2label $ost)
5521 if [ "${facet:0:3}" = "mds" ]; then
5522 get_mdtosc_proc_path $facet $label
5526 get_clientosc_proc_path $label
5530 _wait_import_state () {
5533 local maxtime=${3:-$(max_recovery_time)}
5537 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5538 while [ "${CONN_STATE}" != "${expected}" ]; do
5539 if [ "${expected}" == "DISCONN" ]; then
5540 # for disconn we can check after proc entry is removed
5541 [ "x${CONN_STATE}" == "x" ] && return 0
5542 # with AT enabled, we can have connect request timeout near of
5543 # reconnect timeout and test can't see real disconnect
5544 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
5546 [ $i -ge $maxtime ] && \
5547 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
5550 # Add uniq for multi-mount case
5551 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
5555 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
5559 wait_import_state() {
5562 local maxtime=${3:-$(max_recovery_time)}
5565 for param in ${params//,/ }; do
5566 _wait_import_state $state $param $maxtime || return
5570 wait_import_state_mount() {
5571 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
5575 wait_import_state $*
5578 # One client request could be timed out because server was not ready
5579 # when request was sent by client.
5580 # The request timeout calculation details :
5582 # /* We give the server rq_timeout secs to process the req, and
5583 # add the network latency for our local timeout. */
5584 # request->rq_deadline = request->rq_sent + request->rq_timeout +
5585 # ptlrpc_at_get_net_latency(request) ;
5587 # ptlrpc_connect_import ()
5588 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5591 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
5592 # ptlrpc_at_get_net_latency(request) ->
5593 # at_get (max (iat_net_latency=0, at_min)) = at_min
5596 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
5597 # INITIAL_CONNECT_TIMEOUT + at_min
5599 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
5600 # because we can not get this value in runtime,
5601 # the value depends on configure options, and it is not stored in /proc.
5603 # #define CONNECTION_SWITCH_MIN 5U
5604 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5606 request_timeout () {
5609 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
5610 local init_connect_timeout=$TIMEOUT
5611 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5613 local at_min=$(at_get $facet at_min)
5615 echo $(( init_connect_timeout + at_min ))
5618 _wait_osc_import_state() {
5622 local ost=$(get_osc_import_name $facet $ost_facet)
5624 local param="osc.${ost}.ost_server_uuid"
5627 # 1. wait the deadline of client 1st request (it could be skipped)
5628 # 2. wait the deadline of client 2nd request
5629 local maxtime=$(( 2 * $(request_timeout $facet)))
5631 #During setup time, the osc might not be setup, it need wait
5632 #until list_param can return valid value. And also if there
5633 #are mulitple osc entries we should list all of them before
5635 local params=$($LCTL list_param $param 2>/dev/null || true)
5636 while [ -z "$params" ]; do
5637 if [ $i -ge $maxtime ]; then
5638 echo "can't get $param by list_param in $maxtime secs"
5639 if [[ $facet != client* ]]; then
5640 echo "Go with $param directly"
5649 params=$($LCTL list_param $param 2>/dev/null || true)
5652 if ! do_rpc_nodes "$(facet_active_host $facet)" \
5653 wait_import_state $expected "$params" $maxtime; then
5654 error "import is not in ${expected} state"
5661 wait_osc_import_state() {
5667 if [[ $facet = mds ]]; then
5668 for num in $(seq $MDSCOUNT); do
5669 _wait_osc_import_state mds$num "$ost_facet" "$expected"
5672 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
5676 get_clientmdc_proc_path() {
5684 [ -z "$list" ] && return 0
5686 # Add paths to lustre tests for 32 and 64 bit systems.
5687 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
5688 local TESTPATH="$RLUSTRE/tests:"
5689 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
5690 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
5693 wait_clients_import_state () {
5700 if [ "$FAILURE_MODE" = HARD ]; then
5701 facets=$(facets_on_host $(facet_active_host $facet))
5704 for facet in ${facets//,/ }; do
5705 local label=$(convert_facet2label $facet)
5708 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
5709 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
5710 *) error "unknown facet!" ;;
5712 local params=$(expand_list $params $proc_path)
5715 if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params; then
5716 error "import is not in ${expected} state"
5726 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
5727 $LCTL get_param obdfilter.*.kbytesavail))
5728 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
5729 $LCTL get_param -n obdfilter.*.tot_granted))
5730 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
5731 $LCTL get_param -n obdfilter.*.kbytestotal))
5732 for ((i=0; i<${#AVAILA[@]}; i++)); do
5733 local -a AVAIL1=(${AVAILA[$i]//=/ })
5734 local -a TOTAL=(${TOTALA[$i]//=/ })
5735 GRANT=$((${GRANTA[$i]}/1024))
5736 # allow 1% of total space in bavail because of delayed
5737 # allocation with ZFS which might release some free space after
5738 # txg commit. For small devices, we set a mininum of 8MB
5739 local LIMIT=$((${TOTAL} / 100 + 8000))
5740 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
5741 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
5742 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
5743 echo " FULL" || echo
5749 do_facet mgs lctl pool_list $1
5753 local fsname=${1%%.*}
5754 local poolname=${1##$fsname.}
5756 do_facet mgs lctl pool_new $1
5758 # get param should return err unless pool is created
5759 [[ $RC -ne 0 ]] && return $RC
5761 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
5762 2>/dev/null || echo foo" "" || RC=1
5763 if [[ $RC -eq 0 ]]; then
5766 error "pool_new failed $1"
5771 add_pool_to_list () {
5772 local fsname=${1%%.*}
5773 local poolname=${1##$fsname.}
5775 local listvar=${fsname}_CREATED_POOLS
5776 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
5779 remove_pool_from_list () {
5780 local fsname=${1%%.*}
5781 local poolname=${1##$fsname.}
5783 local listvar=${fsname}_CREATED_POOLS
5784 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
5787 destroy_pool_int() {
5789 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
5790 awk '$1 !~ /^Pool:/ {print $1}')
5791 for ost in $OSTS; do
5792 do_facet mgs lctl pool_remove $1 $ost
5794 do_facet mgs lctl pool_destroy $1
5797 # <fsname>.<poolname> or <poolname>
5799 local fsname=${1%%.*}
5800 local poolname=${1##$fsname.}
5802 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
5806 pool_list $fsname.$poolname || return $?
5808 destroy_pool_int $fsname.$poolname
5810 [[ $RC -ne 0 ]] && return $RC
5812 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
5813 2>/dev/null || echo foo" "foo" || RC=1
5815 if [[ $RC -eq 0 ]]; then
5816 remove_pool_from_list $fsname.$poolname
5818 error "destroy pool failed $1"
5824 local fsname=${1:-$FSNAME}
5826 local listvar=${fsname}_CREATED_POOLS
5830 [ x${!listvar} = x ] && return 0
5832 echo destroy the created pools: ${!listvar}
5833 for poolname in ${!listvar//,/ }; do
5834 destroy_pool $fsname.$poolname
5839 local fsname=${1:-$FSNAME}
5841 destroy_pools $fsname
5847 local ts=$(date +%s)
5850 if [[ ! -f "$YAML_LOG" ]]; then
5851 # init_logging is not performed before gather_logs,
5852 # so the $LOGDIR needs to be checked here
5853 check_shared_dir $LOGDIR && touch $LOGDIR/shared
5856 [ -f $LOGDIR/shared ] && docp=false
5858 # dump lustre logs, dmesg
5860 prefix="$TESTLOG_PREFIX.$TESTNAME"
5862 echo "Dumping lctl log to ${prefix}.*.${suffix}"
5864 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
5865 echo "Dumping logs only on local client."
5866 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
5867 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
5872 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
5873 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
5874 if [ ! -f $LOGDIR/shared ]; then
5875 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
5888 for i in $(seq 0 $num_mntpts); do
5889 cmd="ls -laf ${mntpt_root}$i/$dir"
5895 for pid in $pids; do
5902 # target_start_and_reset_recovery_timer()
5903 # service_time = at_est2timeout(service_time);
5904 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
5905 # INITIAL_CONNECT_TIMEOUT);
5906 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
5907 #define CONNECTION_SWITCH_INC 1
5908 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5909 #define CONNECTION_SWITCH_MIN 5U
5911 max_recovery_time () {
5912 local init_connect_timeout=$(( TIMEOUT / 20 ))
5913 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5915 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
5920 get_clients_mount_count () {
5921 local clients=${CLIENTS:-`hostname`}
5923 # we need to take into account the clients mounts and
5924 # exclude mds/ost mounts if any;
5925 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
5929 PROC_CLI="srpc_info"
5937 if [ $M -lt $N ]; then
5941 while [ $N -lt $M ]; do
5951 calc_connection_cnt() {
5954 # MDT->MDT = 2 * C(M, 2)
5958 comb_m2=$(combination $MDSCOUNT 2)
5960 local num_clients=$(get_clients_mount_count)
5962 local cnt_mdt2mdt=$((comb_m2 * 2))
5963 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
5964 local cnt_cli2ost=$((num_clients * OSTCOUNT))
5965 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
5966 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
5967 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
5968 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
5982 local cmd="$tgt.srpc.flavor"
5984 if [ $net == "any" ]; then
5989 if [ $dir != "any" ]; then
5994 log "Setting sptlrpc rule: $cmd"
5995 do_facet mgs "$LCTL conf_param $cmd"
6004 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
6005 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
6007 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
6009 if [ "x$bulkspec" != "x" ]; then
6010 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
6012 if [ "x$algs" != "x" ]; then
6013 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
6015 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
6016 if [ $bulk == "bulkn" ]; then
6017 bulk_count=`echo "$output" | grep "bulk flavor" \
6018 | grep "null/null" | wc -l`
6019 elif [ $bulk == "bulki" ]; then
6020 bulk_count=`echo "$output" | grep "bulk flavor" \
6021 | grep "/null" | grep -v "null/" | wc -l`
6023 bulk_count=`echo "$output" | grep "bulk flavor" \
6024 | grep -v "/null" | grep -v "null/" | wc -l`
6028 [ $bulk_count -lt $count ] && count=$bulk_count
6039 local clients=${CLIENTS:-`hostname`}
6041 for c in ${clients//,/ }; do
6042 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
6043 tmpcnt=`count_flvr "$output" $flavor`
6044 cnt=$((cnt + tmpcnt))
6054 local clients=${CLIENTS:-`hostname`}
6056 for c in ${clients//,/ }; do
6057 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
6058 tmpcnt=`count_flvr "$output" $flavor`
6059 cnt=$((cnt + tmpcnt))
6069 if [ $MDSCOUNT -le 1 ]; then
6074 for num in `seq $MDSCOUNT`; do
6075 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
6076 tmpcnt=`count_flvr "$output" $flavor`
6077 cnt=$((cnt + tmpcnt))
6088 for num in `seq $MDSCOUNT`; do
6089 mdtosc=$(get_mdtosc_proc_path mds$num)
6090 mdtosc=${mdtosc/-MDT*/-MDT\*}
6091 output=$(do_facet mds$num lctl get_param -n \
6092 osc.$mdtosc.$PROC_CLI 2>/dev/null)
6093 tmpcnt=`count_flvr "$output" $flavor`
6094 cnt=$((cnt + tmpcnt))
6103 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
6104 count_flvr "$output" $flavor
6109 local dir=$1 # from to
6110 local flavor=$2 # flavor expected
6113 if [ $dir == "cli2mdt" ]; then
6114 res=`flvr_cnt_cli2mdt $flavor`
6115 elif [ $dir == "cli2ost" ]; then
6116 res=`flvr_cnt_cli2ost $flavor`
6117 elif [ $dir == "mdt2mdt" ]; then
6118 res=`flvr_cnt_mdt2mdt $flavor`
6119 elif [ $dir == "mdt2ost" ]; then
6120 res=`flvr_cnt_mdt2ost $flavor`
6121 elif [ $dir == "all2ost" ]; then
6122 res1=`flvr_cnt_mdt2ost $flavor`
6123 res2=`flvr_cnt_cli2ost $flavor`
6124 res=$((res1 + res2))
6125 elif [ $dir == "all2mdt" ]; then
6126 res1=`flvr_cnt_mdt2mdt $flavor`
6127 res2=`flvr_cnt_cli2mdt $flavor`
6128 res=$((res1 + res2))
6129 elif [ $dir == "all2all" ]; then
6130 res1=`flvr_cnt_mdt2ost $flavor`
6131 res2=`flvr_cnt_cli2ost $flavor`
6132 res3=`flvr_cnt_mdt2mdt $flavor`
6133 res4=`flvr_cnt_cli2mdt $flavor`
6134 res=$((res1 + res2 + res3 + res4))
6142 local dir=$1 # from to
6143 local flavor=$2 # flavor expected
6144 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
6148 for ((i=0;i<20;i++)); do
6149 echo -n "checking $dir..."
6150 res=$(do_check_flavor $dir $flavor)
6151 echo "found $res/$expect $flavor connections"
6152 [ $res -ge $expect ] && return 0
6156 echo "Error checking $flavor of $dir: expect $expect, actual $res"
6160 restore_to_default_flavor()
6162 local proc="mgs.MGS.live.$FSNAME"
6164 echo "restoring to default flavor..."
6166 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6168 # remove all existing rules if any
6169 if [ $nrule -ne 0 ]; then
6170 echo "$nrule existing rules"
6171 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
6172 echo "remove rule: $rule"
6173 spec=`echo $rule | awk -F = '{print $1}'`
6174 do_facet mgs "$LCTL conf_param -d $spec"
6178 # verify no rules left
6179 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
6180 [ $nrule -ne 0 ] && error "still $nrule rules left"
6182 # wait for default flavor to be applied
6183 # currently default flavor for all connections are 'null'
6184 wait_flavor all2all null
6185 echo "now at default flavor settings"
6190 local flavor=${1:-null}
6192 echo "setting all flavor to $flavor"
6194 # FIXME need parameter to this fn
6195 # and remove global vars
6196 local cnt_all2all=$(calc_connection_cnt all2all)
6198 local res=$(do_check_flavor all2all $flavor)
6199 if [ $res -eq $cnt_all2all ]; then
6200 echo "already have total $res $flavor connections"
6204 echo "found $res $flavor out of total $cnt_all2all connections"
6205 restore_to_default_flavor
6207 [[ $flavor = null ]] && return 0
6209 set_rule $FSNAME any any $flavor
6210 wait_flavor all2all $flavor
6216 # Checking for shared logdir
6217 if [ ! -d $dir ]; then
6218 # Not found. Create local logdir
6221 touch $dir/check_file.$(hostname -s)
6226 check_write_access() {
6228 local list=${2:-$(comma_list $(nodes_list))}
6232 for node in ${list//,/ }; do
6233 file=$dir/check_file.$(short_nodename $node)
6234 if [[ ! -f "$file" ]]; then
6235 # Logdir not accessible/writable from this node.
6238 rm -f $file || return 1
6244 if [[ -n $YAML_LOG ]]; then
6247 local SAVE_UMASK=`umask`
6250 export YAML_LOG=${LOGDIR}/results.yml
6254 if [ ! -f $YAML_LOG ]; then # If the yaml log already exists then we will just append to it
6255 if check_shared_dir $LOGDIR; then
6256 touch $LOGDIR/shared
6257 echo "Logging to shared log directory: $LOGDIR"
6259 echo "Logging to local directory: $LOGDIR"
6262 yml_nodes_file $LOGDIR >> $YAML_LOG
6263 yml_results_file >> $YAML_LOG
6270 yml_log_test $1 >> $YAML_LOG
6274 yml_log_test_status $@ >> $YAML_LOG
6277 log_sub_test_begin() {
6278 yml_log_sub_test_begin "$@" >> $YAML_LOG
6281 log_sub_test_end() {
6282 yml_log_sub_test_end "$@" >> $YAML_LOG
6288 local llverdev_opts=$2
6289 local devname=$(basename $1)
6290 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
6291 # loop devices aren't in /proc/partitions
6292 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
6294 size=$(($size / 1024 / 1024)) # Gb
6296 local partial_arg=""
6297 # Run in partial (fast) mode if the size
6298 # of a partition > 1 GB
6299 [ $size -gt 1 ] && partial_arg="-p"
6301 llverdev --force $partial_arg $llverdev_opts $dev
6307 local llverfs_opts=$2
6308 local use_partial_arg=$3
6309 local partial_arg=""
6310 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
6312 # Run in partial (fast) mode if the size
6313 # of a partition > 1 GB
6314 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
6316 llverfs $partial_arg $llverfs_opts $dir
6319 #Remove objects from OST
6320 remove_ost_objects() {
6326 local mntpt=$(facet_mntpt $facet)
6327 local opts=$OST_MOUNT_OPTS
6331 echo "removing objects from $ostdev on $facet: $objids"
6332 if ! test -b $ostdev; then
6333 opts=$(csa_add "$opts" -o loop)
6335 mount -t $(facet_fstype $facet) $opts $ostdev $mntpt ||
6338 for i in $objids; do
6339 rm $mntpt/O/$group/d$((i % 32))/$i || { rc=$?; break; }
6341 umount -f $mntpt || return $?
6345 #Remove files from MDT
6346 remove_mdt_files() {
6351 local mntpt=$(facet_mntpt $facet)
6352 local opts=$MDS_MOUNT_OPTS
6354 echo "removing files from $mdtdev on $facet: $files"
6355 if [ $(facet_fstype $facet) == ldiskfs ] &&
6356 ! do_facet $facet test -b $mdtdev; then
6357 opts=$(csa_add "$opts" -o loop)
6359 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6363 rm $mntpt/ROOT/$f || { rc=$?; break; }
6365 umount -f $mntpt || return $?
6369 duplicate_mdt_files() {
6374 local mntpt=$(facet_mntpt $facet)
6375 local opts=$MDS_MOUNT_OPTS
6377 echo "duplicating files on $mdtdev on $facet: $files"
6378 mkdir -p $mntpt || return $?
6379 if [ $(facet_fstype $facet) == ldiskfs ] &&
6380 ! do_facet $facet test -b $mdtdev; then
6381 opts=$(csa_add "$opts" -o loop)
6383 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
6394 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
6395 pushd $mntpt/ROOT > /dev/null || return $?
6398 touch $f.bad || return $?
6399 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
6401 [ $rc -eq 0 ] || return $rc
6402 setfattr --restore $tmp || return $?
6408 local devs=${1//,/ }
6411 local rslt=$TMP/sgpdd_survey
6413 # sgpdd-survey cleanups ${rslt}.* files
6415 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
6421 # returns the canonical name for an ldiskfs device
6426 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
6427 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
6428 echo dm-\\\${foo##*:};
6430 echo \\\$(basename \\\$dv);
6434 is_sanity_benchmark() {
6435 local benchmarks="dbench bonnie iozone fsx"
6437 for b in $benchmarks; do
6438 if [ "$b" == "$suite" ]; then
6446 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
6450 # Get the available size (KB) of a given obd target.
6457 [[ $facet != client ]] || return 0
6459 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
6464 # Get the page size (bytes) on a given facet node.
6470 size=$(do_facet $facet getconf PAGE_SIZE)
6471 [[ ${PIPESTATUS[0]} = 0 && -n "$size" ]] || size=4096
6476 # Get the block count of the filesystem.
6483 count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6484 awk '/^Block count:/ {print $3}')
6488 # Get the block size of the filesystem.
6494 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
6495 awk '/^Block size:/ {print $3}')
6499 # Check whether the "large_xattr" feature is enabled or not.
6500 large_xattr_enabled() {
6501 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
6503 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6505 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
6506 grep -E -q '(ea_inode|large_xattr)'"
6507 return ${PIPESTATUS[0]}
6510 # Get the maximum xattr size supported by the filesystem.
6514 if large_xattr_enabled; then
6515 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
6518 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6519 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
6521 # maximum xattr size = size of block - size of header -
6522 # size of 1 entry - 4 null bytes
6523 size=$((block_size - 32 - 32 - 4))
6529 # Dump the value of the named xattr from a file.
6534 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
6537 # Generate a string with size of $size bytes.
6539 local size=${1:-1024} # in bytes
6541 echo "$(head -c $size < /dev/zero | tr '\0' y)"
6544 reformat_external_journal() {
6547 if [ ! -z ${EJOURNAL} ]; then
6548 local rcmd="do_facet $facet"
6550 echo "reformat external journal on $facet:${EJOURNAL}"
6551 ${rcmd} mke2fs -O journal_dev ${EJOURNAL} || return 1
6555 # MDT file-level backup/restore
6556 mds_backup_restore() {
6559 local devname=$(mdsdevname $(facet_number $facet))
6560 local mntpt=$(facet_mntpt brpt)
6561 local rcmd="do_facet $facet"
6562 local metaea=${TMP}/backup_restore.ea
6563 local metadata=${TMP}/backup_restore.tgz
6564 local opts=${MDS_MOUNT_OPTS}
6565 local svc=${facet}_svc
6567 if ! ${rcmd} test -b ${devname}; then
6568 opts=$(csa_add "$opts" -o loop)
6571 echo "file-level backup/restore on $facet:${devname}"
6573 # step 1: build mount point
6574 ${rcmd} mkdir -p $mntpt
6575 # step 2: cleanup old backup
6576 ${rcmd} rm -f $metaea $metadata
6578 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
6579 if [ ! -z $igif ]; then
6580 # step 3.5: rm .lustre
6581 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
6583 # step 4: backup metaea
6585 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
6587 # step 5: backup metadata
6589 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
6591 ${rcmd} umount -d $mntpt || return 4
6592 # step 7: reformat external journal if needed
6593 reformat_external_journal $facet || return 5
6594 # step 8: reformat dev
6595 echo "reformat new device"
6596 add $facet $(mkfs_opts $facet ${devname}) --backfstype ldiskfs \
6597 --reformat ${devname} $(mdsvdevname $(facet_number $facet)) \
6598 > /dev/null || exit 6
6600 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
6601 # step 10: restore metadata
6603 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
6604 # step 11: restore metaea
6606 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
6607 # step 12: remove recovery logs
6608 echo "remove recovery logs"
6609 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
6610 # step 13: umount dev
6611 ${rcmd} umount -d $mntpt || return 10
6612 # step 14: cleanup tmp backup
6613 ${rcmd} rm -f $metaea $metadata
6614 # step 15: reset device label - it's not virgin on
6615 ${rcmd} e2label $devname ${!svc}
6622 local devname=$(mdsdevname $(facet_number $facet))
6623 local mntpt=$(facet_mntpt brpt)
6624 local rcmd="do_facet $facet"
6625 local opts=${MDS_MOUNT_OPTS}
6627 if ! ${rcmd} test -b ${devname}; then
6628 opts=$(csa_add "$opts" -o loop)
6631 echo "removing OI files on $facet: idx=${idx}"
6633 # step 1: build mount point
6634 ${rcmd} mkdir -p $mntpt
6636 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
6637 if [ -z $idx ]; then
6638 # step 3: remove all OI files
6639 ${rcmd} rm -fv $mntpt/oi.16*
6640 elif [ $idx -lt 2 ]; then
6641 ${rcmd} rm -fv $mntpt/oi.16.${idx}
6645 # others, rm oi.16.[idx, idx * idx, idx ** ...]
6646 for ((i=${idx}; i<64; i=$((i * idx)))); do
6647 ${rcmd} rm -fv $mntpt/oi.16.${i}
6651 ${rcmd} umount -d $mntpt || return 2
6652 # OI files will be recreated when mounted as lustre next time.
6655 # generate maloo upload-able log file name
6656 # \param logname specify unique part of file name
6657 generate_logname() {
6658 local logname=${1:-"default_logname"}
6660 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
6663 # make directory on different MDTs
6675 *) error "Only creating single directory is supported";;
6678 child=$(basename $path)
6679 parent=$(dirname $path)
6681 if [ "$option" == "-p" -a -d $parent/$child ]; then
6685 if [ ! -d ${parent} ]; then
6686 if [ "$option" == "-p" ]; then
6693 if [ $MDSCOUNT -le 1 ]; then
6694 mkdir $option $parent/$child || rc=$?
6696 local mdt_idx=$($LFS getstripe -M $parent)
6697 local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
6699 if [ "$mdt_idx" -ne 0 ]; then
6700 mkdir $option $parent/$child || rc=$?
6702 mdt_idx=$((test_num % MDSCOUNT))
6703 echo "mkdir $mdt_idx for $parent/$child"
6704 $LFS setdirstripe -i $mdt_idx $parent/$child || rc=$?
6710 # find the smallest and not in use file descriptor
6713 local max_fd=$(ulimit -n)
6715 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
6718 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"