3 trap 'print_summary && touch $TF_FAIL && \
4 echo "test-framework exiting on error"' ERR
8 export EJOURNAL=${EJOURNAL:-""}
9 export REFORMAT=${REFORMAT:-""}
10 export WRITECONF=${WRITECONF:-""}
11 export VERBOSE=${VERBOSE:-false}
12 export CATASTROPHE=${CATASTROPHE:-/proc/sys/lnet/catastrophe}
15 export GSS_PIPEFS=false
16 export IDENTITY_UPCALL=default
18 export JOBSTATS_AUTO=${JOBSTATS_AUTO:-1}
19 export JOBID_VAR=${JOBID_VAR:-"procname_uid"}
21 # LOAD_LLOOP: LU-409: only load llite_lloop module if kernel < 2.6.32 or
22 # LOAD_LLOOP is true. LOAD_LLOOP is false by default.
23 export LOAD_LLOOP=${LOAD_LLOOP:-false}
25 #export PDSH="pdsh -S -Rssh -w"
27 # function used by scripts run on remote nodes
28 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
29 . $LUSTRE/tests/functions.sh
30 . $LUSTRE/tests/yaml.sh
32 export LD_LIBRARY_PATH=${LUSTRE}/utils:${LD_LIBRARY_PATH}
34 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
36 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
38 if [ -f "$EXCEPT_LIST_FILE" ]; then
39 echo "Reading test skip list from $EXCEPT_LIST_FILE"
44 # check config files for options in decreasing order of preference
45 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
46 MODPROBECONF=/etc/modprobe.d/lustre.conf
47 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
48 MODPROBECONF=/etc/modprobe.d/Lustre
49 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
50 MODPROBECONF=/etc/modprobe.conf
54 [[ $DIR/ = $MOUNT/* ]] || \
55 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
56 [[ $DIR1/ = $MOUNT1/* ]] || \
57 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
58 [[ $DIR2/ = $MOUNT2/* ]] || \
59 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
61 [ -n "$failed" ] && exit 99 || true
65 echo "usage: $0 [-r] [-f cfgfile]"
73 [ "$TESTSUITE" == "lfsck" ] && return 0
74 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
76 local form="%-13s %-17s %-9s %s %s\n"
77 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
78 echo "------------------------------------------------------------------------------------"
79 for O in $DEFAULT_SUITES; do
80 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
81 [ "${!O}" = "no" ] && continue || true
82 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
83 local log=${TMP}/${o}.log
84 if is_sanity_benchmark $o; then
85 log=${TMP}/sanity-benchmark.log
90 local status=Unfinished
92 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
93 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | sort -nr -k 3 | head -5 | awk '{ print $2":"$3"s" }')
94 total=$(grep duration $log | awk '{ print $2}')
95 if [ "${!O}" = "done" ]; then
99 local durations=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | awk '{ print $2":"$3"|" }')
100 details=$(printf "%s\n%s %s %s\n" "$details" "DDETAILS" "$O" "$(echo $durations)")
103 printf "$form" $status "$O" "${total}" "E=$skipped"
104 printf "$form" "-" "-" "-" "S=$(echo $slow)"
107 for O in $DEFAULT_SUITES; do
108 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
109 if [ "${!O}" = "no" ]; then
110 printf "$form" "Skipped" "$O" ""
114 # print the detailed tests durations if DDETAILS=true
121 export LUSTRE=`absolute_path $LUSTRE`
122 export TESTSUITE=`basename $0 .sh`
123 export TEST_FAILED=false
124 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
126 export MKE2FS=${MKE2FS:-mke2fs}
127 export DEBUGFS=${DEBUGFS:-debugfs}
128 export TUNE2FS=${TUNE2FS:-tune2fs}
129 export E2LABEL=${E2LABEL:-e2label}
130 export DUMPE2FS=${DUMPE2FS:-dumpe2fs}
131 export E2FSCK=${E2FSCK:-e2fsck}
132 export LFSCK_BIN=${LFSCK_BIN:-lfsck}
134 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after each test suite
135 export FSCK_MAX_ERR=4 # File system errors left uncorrected
137 export ZFS=${ZFS:-zfs}
138 export ZPOOL=${ZPOOL:-zpool}
139 export ZDB=${ZDB:-zdb}
141 #[ -d /r ] && export ROOT=${ROOT:-/r}
142 export TMP=${TMP:-$ROOT/tmp}
143 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
144 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
145 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
147 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
148 if ! echo $PATH | grep -q $LUSTRE/utils; then
149 export PATH=$LUSTRE/utils:$PATH
151 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
152 export PATH=$LUSTRE/utils/gss:$PATH
154 if ! echo $PATH | grep -q $LUSTRE/tests; then
155 export PATH=$LUSTRE/tests:$PATH
157 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
158 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
160 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
161 [ ! -f "$LST" ] && export LST=$(which lst)
162 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
163 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
164 # Ubuntu, at least, has a truncate command in /usr/bin
165 # so fully path our truncate command.
166 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
167 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
168 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
169 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
170 export PATH=$LUSTRE/tests/racer:$PATH:
172 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
173 export PATH=$LUSTRE/tests/mpi:$PATH
175 export RSYNC_RSH=${RSYNC_RSH:-rsh}
177 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
178 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
179 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
180 [ ! -f "$LFS" ] && export LFS=$(which lfs)
181 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
182 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
184 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
185 if [ ! -f "$L_GETIDENTITY" ]; then
186 if `which l_getidentity > /dev/null 2>&1`; then
187 export L_GETIDENTITY=$(which l_getidentity)
189 export L_GETIDENTITY=NONE
192 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
193 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID=$(which ll_decode_filter_fid)
194 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
195 [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre)
196 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
197 [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre)
198 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
199 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
200 [ ! -f "$LUSTRE_RMMOD" ] &&
201 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
202 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
203 [ ! -f "$LFS_MIGRATE" ] &&
204 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
205 export NAME=${NAME:-local}
206 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
207 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
208 export LGSSD=$(which lgssd)
209 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
210 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
211 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
213 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
216 if [ "$ACCEPTOR_PORT" ]; then
217 export PORT_OPT="--port $ACCEPTOR_PORT"
222 echo "Using GSS/krb5 ptlrpc security flavor"
223 which lgss_keyring > /dev/null 2>&1 || \
224 error_exit "built with gss disabled! SEC=$SEC"
235 IDENTITY_UPCALL=false
238 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
240 # Paths on remote nodes, if different
241 export RLUSTRE=${RLUSTRE:-$LUSTRE}
242 export RPWD=${RPWD:-$PWD}
243 export I_MOUNTED=${I_MOUNTED:-"no"}
244 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mds.ko -a \
245 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mds.ko -a \
246 ! -f `dirname $0`/../mds/mds.ko ]; then
247 export CLIENTMODSONLY=yes
250 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
254 while getopts "rvwf:" opt $*; do
257 r) REFORMAT=--reformat;;
259 w) WRITECONF=writeconf;;
264 shift $((OPTIND - 1))
267 # print the durations of each test if "true"
268 DDETAILS=${DDETAILS:-false}
269 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
277 ncpts=$(do_facet $facet "lctl get_param -n " \
278 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
280 if [ $ncpts -eq 0 ]; then
288 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
289 eval set -- $(tr "[:punct:]" " " <<< $*)
291 echo -n $((($1 << 16) | ($2 << 8) | $3))
294 export LINUX_VERSION=$(uname -r | sed -e "s/[-.]/ /3" -e "s/ .*//")
295 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
298 /sbin/lsmod | grep -q "^\<$1\>"
301 # Load a module on the system where this is running.
303 # Synopsis: load_module module_name [module arguments for insmod/modprobe]
305 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
306 # will be used as the arguments. Otherwise arguments will be obtained from
307 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
314 BASE=`basename $module $EXT`
316 module_loaded ${BASE} && return
318 # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
320 if [ $# -eq 0 ]; then
321 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
322 # Bash until 4.x, so we resort to eval.
323 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
324 eval set -- \$$optvar
325 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
326 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
327 set -- $(grep -P "^options\\s+${BASE}" $MODPROBECONF)
328 # Get rid of "options $module"
329 (($# > 0)) && shift 2
331 # Ensure we have accept=all for lnet
332 if [ $(basename $module) = lnet ]; then
333 # OK, this is a bit wordy...
334 local arg accept_all_present=false
336 [ "$arg" = accept=all ] && accept_all_present=true
338 $accept_all_present || set -- "$@" accept=all
343 [ $# -gt 0 ] && echo "${module} options: '$*'"
345 # Note that insmod will ignore anything in modprobe.conf, which is why we're
346 # passing options on the command-line.
347 if [ "$BASE" == "lnet_selftest" ] && \
348 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
349 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
350 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
351 insmod ${LUSTRE}/${module}${EXT} "$@"
353 # must be testing a "make install" or "rpm" installation
354 # note failed to load ptlrpc_gss is considered not fatal
355 if [ "$BASE" == "ptlrpc_gss" ]; then
356 modprobe $BASE "$@" 2>/dev/null || echo "gss/krb5 is not supported"
363 llite_lloop_enabled() {
364 local n1=$(uname -r | cut -d. -f1)
365 local n2=$(uname -r | cut -d. -f2)
366 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
368 # load the llite_lloop module for < 2.6.32 kernels
369 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
370 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
377 load_modules_local() {
378 if [ "$USE_OFD" == yes ]; then
379 if module_loaded obdfilter; then
380 if ! $LUSTRE_RMMOD ldiskfs; then
381 echo "$HOSTNAME may still be using obdfilter.ko"
386 if module_loaded ofd; then
387 if ! $LUSTRE_RMMOD ldiskfs; then
388 echo "$HOSTNAME may still be using ofd.ko"
394 if [ -n "$MODPROBE" ]; then
396 echo "Using modprobe to load modules"
400 echo Loading modules from $LUSTRE
404 if [ -f /sys/devices/system/cpu/online ]; then
405 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
406 echo "detected $ncpus online CPUs by sysfs"
408 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
410 if [ $rc -eq 0 ]; then
411 echo "detected $ncpus online CPUs by getconf"
413 echo "Can't detect number of CPUs"
419 # if there is only one CPU core, libcfs can only create one partition
420 # if there is more than 4 CPU cores, libcfs should create multiple CPU
421 # partitions. So we just force libcfs to create 2 partitions for
422 # system with 2 or 4 cores
423 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
424 # force to enable multiple CPU partitions
425 echo "Force libcfs to create 2 CPU partitions"
428 echo "libcfs will create CPU partition based on online CPUs"
431 load_module ../libcfs/libcfs/libcfs cpu_npartitions=$ncpts
433 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
434 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
435 load_module ../lnet/lnet/lnet
436 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
437 load_module ../lnet/klnds/$LNETLND
438 load_module lvfs/lvfs
439 load_module obdclass/obdclass
440 load_module ptlrpc/ptlrpc
441 load_module ptlrpc/gss/ptlrpc_gss
449 load_module obdecho/obdecho
450 if ! client_only; then
451 SYMLIST=/proc/kallsyms
452 grep -q crc16 $SYMLIST || { modprobe crc16 2>/dev/null || true; }
453 grep -q -w jbd $SYMLIST || { modprobe jbd 2>/dev/null || true; }
454 grep -q -w jbd2 $SYMLIST || { modprobe jbd2 2>/dev/null || true; }
455 [ "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
456 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
457 load_module osd-zfs/osd_zfs
462 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
464 # This block shall be moved up beside osd-zfs as soon
465 # as osd-ldiskfs stops using mdd symbols.
467 grep -q exportfs_decode_fh $SYMLIST ||
468 { modprobe exportfs 2> /dev/null || true; }
469 load_module ../ldiskfs/ldiskfs/ldiskfs
470 load_module lvfs/fsfilt_ldiskfs
471 load_module osd-ldiskfs/osd_ldiskfs
477 if [ "$USE_OFD" == yes ]; then
480 load_module obdfilter/obdfilter
485 load_module llite/lustre
486 llite_lloop_enabled && load_module llite/llite_lloop
487 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
489 rm -f $OGDB/ogdb-$HOSTNAME
490 $LCTL modules > $OGDB/ogdb-$HOSTNAME
492 # 'mount' doesn't look in $PATH, just sbin
493 if [ -f $LUSTRE/utils/mount.lustre ] && \
494 ! grep -qe "/sbin/mount\.lustre " /proc/mounts; then
495 [ ! -f /sbin/mount.lustre ] && touch /sbin/mount.lustre
496 mount --bind $LUSTRE/utils/mount.lustre /sbin/mount.lustre || true
503 # load modules on remote nodes optionally
504 # lustre-tests have to be installed on these nodes
505 if $LOAD_MODULES_REMOTE ; then
506 local list=$(comma_list $(remote_nodes_list))
507 echo loading modules on $list
508 do_rpc_nodes $list load_modules_local
513 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
514 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
515 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
516 echo "$LEAK_LUSTRE" 1>&2
517 echo "$LEAK_PORTALS" 1>&2
518 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
519 echo "Memory leaks detected"
520 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
526 wait_exit_ST client # bug 12845
528 $LUSTRE_RMMOD ldiskfs || return 2
530 if $LOAD_MODULES_REMOTE ; then
531 local list=$(comma_list $(remote_nodes_list))
532 if [ ! -z $list ]; then
533 echo unloading modules on $list
534 do_rpc_nodes $list $LUSTRE_RMMOD ldiskfs
535 do_rpc_nodes $list check_mem_leak
539 if grep -qe "/sbin/mount\.lustre" /proc/mounts; then
540 umount /sbin/mount.lustre || true
541 [ -w /sbin/mount.lustre -a ! -s /sbin/mount.lustre ] && \
542 rm -f /sbin/mount.lustre || true
545 check_mem_leak || return 254
547 echo "modules unloaded."
551 check_gss_daemon_nodes() {
555 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
556 if [ \\\"\\\$num\\\" -ne 1 ]; then
557 echo \\\$num instance of $dname;
562 check_gss_daemon_facet() {
566 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
567 if [ $num -ne 1 ]; then
568 echo "$num instance of $dname on $facet"
577 echo Stopping $@ on $list
578 do_nodes $list "killall -2 $@ 2>/dev/null || true"
581 # start gss daemons on all nodes, or
582 # "daemon" on "list" if set
583 start_gss_daemons() {
587 if [ "$list" ] && [ "$daemon" ] ; then
588 echo "Starting gss daemon on nodes: $list"
589 do_nodes $list "$daemon" || return 8
593 local list=$(comma_list $(mdts_nodes))
595 echo "Starting gss daemon on mds: $list"
596 do_nodes $list "$LSVCGSSD -v" || return 1
598 do_nodes $list "$LGSSD -v" || return 2
601 list=$(comma_list $(osts_nodes))
602 echo "Starting gss daemon on ost: $list"
603 do_nodes $list "$LSVCGSSD -v" || return 3
604 # starting on clients
606 local clients=${CLIENTS:-`hostname`}
608 echo "Starting $LGSSD on clients $clients "
609 do_nodes $clients "$LGSSD -v" || return 4
612 # wait daemons entering "stable" status
616 # check daemons are running
618 list=$(comma_list $(mdts_nodes) $(osts_nodes))
619 check_gss_daemon_nodes $list lsvcgssd || return 5
621 list=$(comma_list $(mdts_nodes))
622 check_gss_daemon_nodes $list lgssd || return 6
625 check_gss_daemon_nodes $clients lgssd || return 7
630 local list=$(comma_list $(mdts_nodes))
632 send_sigint $list lsvcgssd lgssd
634 list=$(comma_list $(osts_nodes))
635 send_sigint $list lsvcgssd
637 list=${CLIENTS:-`hostname`}
638 send_sigint $list lgssd
643 if ! module_loaded ptlrpc_gss; then
644 load_module ptlrpc/gss/ptlrpc_gss
645 module_loaded ptlrpc_gss ||
646 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
648 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
650 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
651 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
659 # maybe cleanup credential cache?
666 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9]\+//' |
667 tr '[:lower:]' '[:upper:]'
673 if [ $facet == mgs ]; then
677 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
685 if [ -n "${!var}" ]; then
690 var=$(facet_type $facet)FSTYPE
691 if [ -n "${!var}" ]; then
696 if [ -n "$FSTYPE" ]; then
708 local facets=$(get_facets)
711 for facet in ${facets//,/ }; do
712 if [ $node == $(facet_host $facet) ] ||
713 [ $node == "$(facet_failover_host $facet)" ]; then
714 fstype=$(facet_fstype $facet)
715 if [[ $fstypes != *$fstype* ]]; then
716 fstypes+="${fstypes:+,}$fstype"
727 local fstype=$(facet_fstype $facet)
731 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
733 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
734 ${dev} 2>/dev/null");;
736 error "unknown fstype!";;
744 local device=$(mdsdevname $num)
745 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
751 local device=$(ostdevname $num)
752 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
757 # This and set_obdfilter_param() shall be used to access OSD parameters
758 # once existed under "obdfilter":
763 # writethrough_cache_enable
765 get_obdfilter_param() {
767 local device=${2:-$FSNAME-OST*}
770 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
771 osd-*.$device.$name 2>&1" | grep -v 'Found no match'
774 set_obdfilter_param() {
776 local device=${2:-$FSNAME-OST*}
780 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
781 osd-*.$device.$name=$value 2>&1" | grep -v 'Found no match'
785 local dz=${1:-$DEBUG_SIZE}
787 if [ -f /sys/devices/system/cpu/possible ]; then
788 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
790 local cpus=$(getconf _NPROCESSORS_CONF)
793 # bug 19944, adjust size to be -gt num_possible_cpus()
794 # promise 2MB for every cpu at least
795 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
798 lctl set_param debug_mb=$dz
801 set_default_debug () {
802 local debug=${1:-"$PTLDEBUG"}
803 local subsys=${2:-"$SUBSYSTEM"}
804 local debug_size=${3:-$DEBUG_SIZE}
806 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
807 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
809 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
812 set_default_debug_nodes () {
815 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
816 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
820 [[ -n $nodes ]] && do_rpc_nodes $nodes set_default_debug \
821 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
824 set_default_debug_facet () {
826 local node=$(facet_active_host $facet)
827 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
829 set_default_debug_nodes $node
834 local facets=${1:-$(get_facets)}
837 for facet in ${facets//,/ }; do
840 [ $RC -eq 0 ] && continue
842 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
843 skip "Restart of $facet failed!." && touch $LU482_FAILED
845 error "Restart of $facet failed!"
852 # Add argument "arg" (e.g., "loop") to the comma-separated list
853 # of arguments for option "opt" (e.g., "-o") on command
854 # line "opts" (e.g., "-o flock").
860 local opt_pattern="\([[:space:]]\+\|^\)$opt"
862 if echo "$opts" | grep -q $opt_pattern; then
863 opts=$(echo "$opts" | sed -e \
864 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
866 opts+="${opts:+ }$opt $arg"
874 local dev=$(facet_active $facet)_dev
875 local opt=${facet}_opt
876 local mntpt=$(facet_mntpt $facet)
877 local opts="${!opt} $@"
879 if [ $(facet_fstype $facet) == ldiskfs ] &&
880 ! do_facet $facet test -b ${!dev}; then
881 opts=$(csa_add "$opts" -o loop)
884 echo "Starting ${facet}: $opts ${!dev} $mntpt"
885 # for testing LU-482 error handling in mount_facets() and test_0a()
886 if [ -f $TMP/test-lu482-trigger ]; then
889 do_facet ${facet} "mkdir -p $mntpt; mount -t lustre $opts \
893 if [ $RC -ne 0 ]; then
894 echo "Start of ${!dev} on ${facet} failed ${RC}"
896 set_default_debug_facet $facet
898 label=$(devicelabel ${facet} ${!dev})
899 [ -z "$label" ] && echo no label for ${!dev} && exit 1
900 eval export ${facet}_svc=${label}
901 echo Started ${label}
906 # start facet device options
912 eval export ${facet}_dev=${device}
913 eval export ${facet}_opt=\"$@\"
915 local varname=${facet}failover_dev
916 if [ -n "${!varname}" ] ; then
917 eval export ${facet}failover_dev=${!varname}
919 eval export ${facet}failover_dev=$device
922 local mntpt=$(facet_mntpt $facet)
923 do_facet ${facet} mkdir -p $mntpt
924 eval export ${facet}_MOUNT=$mntpt
931 # When a ZFS OSD is made read-only by replay_barrier(), its pool is "freezed".
932 # Because stopping corresponding target may not clear this in-memory state, we
933 # need to zap the pool from memory by exporting and reimporting the pool.
935 # Although the uberblocks are not updated when a pool is freezed, transactions
936 # are still written to the disks. Modified blocks may be cached in memory when
937 # tests try reading them back. The export-and-reimport process also evicts any
938 # cached pool data from memory to provide the correct "data loss" semantics.
942 local fstype=$(facet_fstype $facet)
947 if [ "${fstype}" == "zfs" ]; then
948 _dev=$(facet_active $facet)_dev
949 dev=${!_dev} # expand _dev to its value, e.g. ${mds1_dev}
950 poolname="${dev%%/*}" # poolname is string before "/"
952 if [ "${poolname}" == "" ]; then
953 echo "invalid dataset name: $dev"
956 do_facet $facet "cp /etc/zfs/zpool.cache /tmp/zpool.cache.back"
957 do_facet $facet "$ZPOOL export ${poolname}"
958 do_facet $facet "$ZPOOL import -f -c /tmp/zpool.cache.back \
967 local HOST=`facet_active_host $facet`
968 [ -z $HOST ] && echo stop: no host for $facet && return 0
970 local mntpt=$(facet_mntpt $facet)
971 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
972 if [ ${running} -ne 0 ]; then
973 echo "Stopping $mntpt (opts:$@) on $HOST"
974 do_facet ${facet} umount -d $@ $mntpt
977 # umount should block, but we should wait for unrelated obd's
978 # like the MGS or MGC to also stop.
979 wait_exit_ST ${facet}
982 # save quota version (both administrative and operational quotas)
983 # add an additional parameter if mountpoint is ever different from $MOUNT
985 # XXX This function is kept for interoperability with old server (< 2.3.50),
986 # it should be removed whenever we drop the interoperability for such
988 quota_save_version() {
989 local fsname=${2:-$FSNAME}
991 local ver=$(tr -c -d "123" <<< $spec)
992 local type=$(tr -c -d "ug" <<< $spec)
994 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
996 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
998 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
1000 local osts=$(get_facets OST)
1001 for ost in ${osts//,/ }; do
1003 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1007 # client could mount several lustre
1009 # XXX This function is kept for interoperability with old server (< 2.3.50),
1010 # it should be removed whenever we drop the interoperability for such
1013 local fsname=${1:-$FSNAME}
1015 do_facet mgs lctl get_param mdd.${fsname}-MDT*.quota_type || rc=$?
1016 do_nodes $(comma_list $(osts_nodes)) \
1017 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1021 # XXX This function is kept for interoperability with old server (< 2.3.50),
1022 # it should be removed whenever we drop the interoperability for such
1024 restore_quota_old() {
1025 local mntpt=${1:-$MOUNT}
1026 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
1027 if [ ! "$old_QUOTA_TYPE" ] ||
1028 [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
1031 quota_save_version $old_QUOTA_TYPE
1034 # XXX This function is kept for interoperability with old server (< 2.3.50),
1035 # it should be removed whenever we drop the interoperability for such
1040 # no quota enforcement for now and accounting works out of the box
1043 # We need save the original quota_type params, and restore them after testing
1045 # Suppose that quota type the same on mds and ost
1046 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
1047 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
1048 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
1049 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
1050 export old_QUOTA_TYPE=$quota_type
1051 quota_save_version $QUOTA_TYPE
1053 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
1054 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
1057 local quota_usrs=$QUOTA_USERS
1059 # get_filesystem_size
1060 local disksz=$(lfs df $mntpt | grep "filesystem summary:" | awk '{print $3}')
1061 local blk_soft=$((disksz + 1024))
1062 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1064 local Inodes=$(lfs df -i $mntpt | grep "filesystem summary:" | awk '{print $3}')
1065 local i_soft=$Inodes
1066 local i_hard=$((i_soft + i_soft / 20))
1068 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
1069 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
1072 for usr in $quota_usrs; do
1073 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1075 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1077 eval $cmd || error "$cmd FAILED!"
1079 # display the quota status
1080 echo "Quota settings for $usr : "
1081 $LFS quota -v -u $usr $mntpt || true
1085 # get mdt quota type
1087 local varsvc=${SINGLEMDS}_svc
1088 do_facet $SINGLEMDS $LCTL get_param -n \
1089 osd-$FSTYPE.${!varsvc}.quota_slave.enabled
1092 # get ost quota type
1094 # All OSTs should have same quota type
1095 local varsvc=ost1_svc
1096 do_facet ost1 $LCTL get_param -n \
1097 osd-$FSTYPE.${!varsvc}.quota_slave.enabled
1100 # restore old quota type settings
1102 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1107 if [ "$old_MDT_QUOTA_TYPE" ]; then
1108 do_facet mgs $LCTL conf_param \
1109 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
1111 if [ "$old_OST_QUOTA_TYPE" ]; then
1112 do_facet mgs $LCTL conf_param \
1113 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
1118 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1123 # XXX remove it once all quota code landed
1124 echo "skip quota setup"
1129 # save old quota type & set new quota type
1130 local mdt_qtype=$(mdt_quota_type)
1131 local ost_qtype=$(ost_quota_type)
1133 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
1134 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
1136 export old_MDT_QUOTA_TYPE=$mdt_qtype
1137 export old_OST_QUOTA_TYPE=$ost_qtype
1139 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$QUOTA_TYPE ||
1140 error "set mdt quota type failed"
1141 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$QUOTA_TYPE ||
1142 error "set ost quota type failed"
1144 local quota_usrs=$QUOTA_USERS
1146 # get_filesystem_size
1147 local disksz=$(lfs df $mntpt | grep "filesystem summary:" |
1149 local blk_soft=$((disksz + 1024))
1150 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1152 local inodes=$(lfs df -i $mntpt | grep "filesystem summary:" |
1154 local i_soft=$inodes
1155 local i_hard=$((i_soft + i_soft / 20))
1157 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
1158 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
1159 "inode-hardlimit: $i_hard"
1162 for usr in $quota_usrs; do
1163 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1165 cmd="$LFS setquota -$type $usr -b $blk_soft"
1166 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1168 eval $cmd || error "$cmd FAILED!"
1170 # display the quota status
1171 echo "Quota settings for $usr : "
1172 $LFS quota -v -u $usr $mntpt || true
1179 local OPTIONS=${3:-$MOUNTOPT}
1181 local device=$MGSNID:/$FSNAME
1182 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1183 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
1187 echo "Starting client: $client: $OPTIONS $device $mnt"
1188 do_node $client mkdir -p $mnt
1189 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
1191 set_default_debug_nodes $client
1203 [ "$3" ] && force=-f
1204 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1205 if [ $running -ne 0 ]; then
1206 echo "Stopping client $client $mnt (opts:$force)"
1207 do_node $client lsof -t $mnt || need_kill=no
1208 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1209 pids=$(do_node $client lsof -t $mnt | sort -u);
1210 if [ -n $pids ]; then
1211 do_node $client kill -9 $pids || true
1215 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1216 if [ $busy -ne 0 ] ; then
1217 echo "$mnt is still busy, wait one second" && sleep 1
1218 do_node $client umount $force $mnt
1223 # nodes is comma list
1224 sanity_mount_check_nodes () {
1230 # FIXME: assume that all cluster nodes run the same os
1231 [ "$(uname)" = Linux ] || return 0
1234 for mnt in $mnts ; do
1235 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1236 mpts=\\\$(mount | grep -c $mnt' ');
1237 if [ \\\$running -ne \\\$mpts ]; then
1238 echo \\\$(hostname) env are INSANE!;
1241 [ $? -eq 0 ] || rc=1
1246 sanity_mount_check_servers () {
1247 [ "$CLIENTONLY" ] &&
1248 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1249 echo Checking servers environments
1251 # FIXME: modify get_facets to display all facets wo params
1252 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1256 for facet in ${facets//,/ }; do
1257 node=$(facet_host ${facet})
1258 mntpt=$(facet_mntpt $facet)
1259 sanity_mount_check_nodes $node $mntpt ||
1260 { error "server $node environments are insane!"; return 1; }
1264 sanity_mount_check_clients () {
1265 local clients=${1:-$CLIENTS}
1266 local mntpt=${2:-$MOUNT}
1267 local mntpt2=${3:-$MOUNT2}
1269 [ -z $clients ] && clients=$(hostname)
1270 echo Checking clients $clients environments
1272 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1273 error "clients environments are insane!"
1276 sanity_mount_check () {
1277 sanity_mount_check_servers || return 1
1278 sanity_mount_check_clients || return 2
1281 # mount clients if not mouted
1282 zconf_mount_clients() {
1285 local OPTIONS=${3:-$MOUNTOPT}
1287 local device=$MGSNID:/$FSNAME
1288 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1289 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
1293 echo "Starting client $clients: $OPTIONS $device $mnt"
1296 running=\\\$(mount | grep -c $mnt' ');
1298 if [ \\\$running -eq 0 ] ; then
1300 mount -t lustre $OPTIONS $device $mnt;
1303 exit \\\$rc" || return ${PIPESTATUS[0]}
1305 echo "Started clients $clients: "
1306 do_nodes $clients "mount | grep $mnt' '"
1308 set_default_debug_nodes $clients
1313 zconf_umount_clients() {
1318 [ "$3" ] && force=-f
1320 echo "Stopping clients: $clients $mnt (opts:$force)"
1321 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1322 if [ \\\$running -ne 0 ] ; then
1323 echo Stopping client \\\$(hostname) $mnt opts:$force;
1324 lsof $mnt || need_kill=no;
1325 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1326 pids=\\\$(lsof -t $mnt | sort -u);
1327 if [ -n \\\"\\\$pids\\\" ]; then
1331 while umount $force $mnt 2>&1 | grep -q "busy"; do
1332 echo "$mnt is still busy, wait one second" && sleep 1;
1339 echo + $POWER_DOWN $node
1343 shutdown_node_hard () {
1345 local attempts=$SHUTDOWN_ATTEMPTS
1347 for i in $(seq $attempts) ; do
1350 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1351 echo "waiting for $host to fail attempts=$attempts"
1352 [ $i -lt $attempts ] || \
1353 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1359 local mnt=${2:-$MOUNT}
1362 if [ "$FAILURE_MODE" = HARD ]; then
1363 shutdown_node_hard $client
1365 zconf_umount_clients $client $mnt -f
1371 local facets="$(get_facets OST),$(get_facets MDS)"
1374 combined_mgs_mds || facets="$facets,mgs"
1376 for facet in ${facets//,/ }; do
1377 if [ $(facet_active_host $facet) == $host ]; then
1378 affected="$affected $facet"
1382 echo $(comma_list $affected)
1387 local host=${2:-$(facet_host $facet)}
1389 local label=$(convert_facet2label $facet)
1390 do_node $host $LCTL dl | awk '{print $4}' | grep -q -x $label
1393 facets_up_on_host () {
1395 local facets=$(facets_on_host $host)
1398 for facet in ${facets//,/ }; do
1399 if $(facet_up $facet $host); then
1400 affected_up="$affected_up $facet"
1404 echo $(comma_list $affected_up)
1410 if [ "$FAILURE_MODE" = HARD ]; then
1411 shutdown_node_hard $(facet_active_host $facet)
1419 echo + $POWER_UP $node
1432 if [ "$FAILURE_MODE" = HARD ]; then
1433 reboot_node $(facet_active_host $facet)
1435 refresh_disk ${facet}
1442 if [ "$FAILURE_MODE" = HARD ]; then
1452 for facet in ${facets//,/ }; do
1453 hosts=$(expand_list $hosts $(facet_host $facet) )
1459 _check_progs_installed () {
1463 for prog in $progs; do
1464 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1465 echo $prog missing on $(hostname)
1472 check_progs_installed () {
1476 do_rpc_nodes $nodes _check_progs_installed $@
1479 # recovery-scale functions
1481 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1484 start_client_load() {
1487 local var=$(node_var_name $client)_load
1488 eval export ${var}=$load
1490 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1491 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1492 END_RUN_FILE=$END_RUN_FILE \
1493 LOAD_PID_FILE=$LOAD_PID_FILE \
1494 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1495 TESTNAME=$TESTNAME \
1496 DBENCH_LIB=$DBENCH_LIB \
1497 DBENCH_SRC=$DBENCH_SRC \
1500 log "Started client load: ${load} on $client"
1502 # get the children process IDs
1503 local pids=$(ps --ppid $ppid -o pid= | xargs)
1504 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1508 start_client_loads () {
1509 local -a clients=(${1//,/ })
1510 local numloads=${#CLIENT_LOADS[@]}
1513 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1514 testnum=$((nodenum % numloads))
1515 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1517 # bug 22169: wait the background threads to start
1521 # only for remote client
1522 check_client_load () {
1524 local var=$(node_var_name $client)_load
1525 local TESTLOAD=run_${!var}.sh
1527 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1529 # bug 18914: try to connect several times not only when
1530 # check ps, but while check_catastrophe also
1533 while [ $RC = 254 -a $tries -gt 0 ]; do
1537 if ! check_catastrophe $client; then
1539 if [ $RC -eq 254 ]; then
1540 # FIXME: not sure how long we shuold sleep here
1544 echo "check catastrophe failed: RC=$RC "
1548 # We can continue try to connect if RC=254
1549 # Just print the warning about this
1550 if [ $RC = 254 ]; then
1551 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1554 # see if the load is still on the client
1557 while [ $RC = 254 -a $tries -gt 0 ]; do
1561 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1566 if [ $RC = 254 ]; then
1567 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1568 # see if we can diagnose a bit why this is
1573 check_client_loads () {
1574 local clients=${1//,/ }
1578 for client in $clients; do
1579 check_client_load $client
1581 if [ "$rc" != 0 ]; then
1582 log "Client load failed on node $client, rc=$rc"
1588 restart_client_loads () {
1589 local clients=${1//,/ }
1590 local expectedfail=${2:-""}
1594 for client in $clients; do
1595 check_client_load $client
1597 if [ "$rc" != 0 -a "$expectedfail" ]; then
1598 local var=$(node_var_name $client)_load
1599 start_client_load $client ${!var}
1600 echo "Restarted client load ${!var}: on $client. Checking ..."
1601 check_client_load $client
1603 if [ "$rc" != 0 ]; then
1604 log "Client load failed to restart on node $client, rc=$rc"
1605 # failure one client load means test fail
1606 # we do not need to check other
1615 # Start vmstat and save its process ID in a file.
1620 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1623 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1624 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1627 # Display the nodes on which client loads failed.
1628 print_end_run_file() {
1632 [ -s $file ] || return 0
1634 echo "Found the END_RUN_FILE file: $file"
1637 # A client load will stop if it finds the END_RUN_FILE file.
1638 # That does not mean the client load actually failed though.
1639 # The first node in END_RUN_FILE is the one we are interested in.
1642 if [ -n "$node" ]; then
1643 local var=$(node_var_name $node)_load
1645 local prefix=$TESTLOG_PREFIX
1646 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
1647 local stdout_log=$prefix.run_${!var}_stdout.$node.log
1648 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
1650 echo "Client load ${!var} failed on node $node:"
1656 # Stop the process which had its PID saved in a file.
1661 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1663 do_nodes $nodes "test -f $pid_file &&
1664 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
1667 # Stop all client loads.
1668 stop_client_loads() {
1669 local nodes=${1:-$CLIENTS}
1672 # stop the client loads
1673 stop_process $nodes $pid_file
1675 # clean up the processes that started them
1676 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
1678 # End recovery-scale functions
1680 # verify that lustre actually cleaned up properly
1682 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
1683 error "LBUG/LASSERT detected"
1684 BUSY=`dmesg | grep -i destruct || true`
1685 if [ "$BUSY" ]; then
1687 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
1691 check_mem_leak || exit 204
1693 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
1694 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
1696 if module_loaded lnet || module_loaded libcfs; then
1697 echo "$0: modules still loaded..." 1>&2
1715 RESULT=$(do_node $node "$TEST")
1716 if [ "$RESULT" == "$FINAL" ]; then
1717 [ -z "$RESULT" -o $WAIT -le $sleep ] ||
1718 echo "Updated after ${WAIT}s: wanted '$FINAL' got '$RESULT'"
1721 [ $WAIT -ge $MAX ] && break
1722 [ $((WAIT % print)) -eq 0 ] &&
1723 echo "Waiting $((MAX - WAIT)) secs for update"
1724 WAIT=$((WAIT + sleep))
1727 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
1731 wait_update_facet() {
1734 wait_update $(facet_active_host $facet) "$@"
1738 do_node $(osts_nodes) "lctl set_param -n osd*.*OS*.force_sync 1" 2>&1 |
1739 grep -v 'Found no match'
1742 wait_delete_completed_mds() {
1743 local MAX_WAIT=${1:-20}
1745 local stime=`date +%s`
1750 # find MDS with pending deletions
1751 for node in $(mdts_nodes); do
1752 changes=$(do_node $node "lctl get_param -n osc.*MDT*.sync_*" \
1753 2>/dev/null | calc_sum)
1754 if [ -z "$changes" ] || [ $changes -eq 0 ]; then
1757 mds2sync="$mds2sync $node"
1759 if [ "$mds2sync" == "" ]; then
1762 mds2sync=$(comma_list $mds2sync)
1764 # sync MDS transactions
1765 do_nodes $mds2sync "lctl set_param -n osd*.*MD*.force_sync 1"
1767 # wait till all changes are sent and commmitted by OSTs
1768 # for ldiskfs space is released upon execution, but DMU
1769 # do this upon commit
1772 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
1773 changes=$(do_nodes $mds2sync "lctl get_param -n osc.*MDT*.sync_*" \
1775 #echo "$node: $changes changes on all"
1776 if [ "$changes" -eq "0" ]; then
1778 #echo "delete took $((etime - stime)) seconds"
1786 echo "Delete is not completed in $((etime - stime)) seconds"
1787 do_nodes $mds2sync "lctl get_param osc.*MDT*.sync_*"
1793 # we can use "for" here because we are waiting the slowest
1794 for host in ${hostlist//,/ }; do
1795 check_network "$host" 900
1797 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
1804 for facet in ${facetlist//,/ }; do
1805 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
1807 wait_for_host $hostlist
1810 _wait_recovery_complete () {
1813 # Use default policy if $2 is not passed by caller.
1814 local MAX=${2:-$(max_recovery_time)}
1819 while [ $WAIT -lt $MAX ]; do
1820 STATUS=$(lctl get_param -n $param | grep status)
1822 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
1825 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
1827 echo "$param recovery not done in $MAX sec. $STATUS"
1831 wait_recovery_complete () {
1834 # with an assumption that at_max is the same on all nodes
1835 local MAX=${2:-$(max_recovery_time)}
1838 if [ "$FAILURE_MODE" = HARD ]; then
1839 facets=$(facets_on_host $(facet_active_host $facet))
1841 echo affected facets: $facets
1843 # we can use "for" here because we are waiting the slowest
1844 for facet in ${facets//,/ }; do
1845 local var_svc=${facet}_svc
1846 local param="*.${!var_svc}.recovery_status"
1848 local host=$(facet_active_host $facet)
1849 do_rpc_nodes $host _wait_recovery_complete $param $MAX
1853 wait_mds_ost_sync () {
1854 # just because recovery is done doesn't mean we've finished
1855 # orphan cleanup. Wait for llogs to get synchronized.
1856 echo "Waiting for orphan cleanup..."
1857 # MAX value includes time needed for MDS-OST reconnection
1858 local MAX=$(( TIMEOUT * 2 ))
1860 while [ $WAIT -lt $MAX ]; do
1861 local -a sync=($(do_nodes $(comma_list $(osts_nodes)) \
1862 "$LCTL get_param -n obdfilter.*.mds_sync"))
1865 for ((i=0; i<${#sync[@]}; i++)); do
1866 [ ${sync[$i]} -eq 0 ] && continue
1867 # there is a not finished MDS-OST synchronization
1871 sleep 2 # increase waiting time and cover statfs cache
1872 [ ${con} -eq 1 ] && return 0
1873 echo "Waiting $WAIT secs for $facet mds-ost sync done."
1876 echo "$facet recovery not done in $MAX sec. $STATUS"
1880 wait_destroy_complete () {
1881 echo "Waiting for local destroys to complete"
1882 # MAX value shouldn't be big as this mean server responsiveness
1883 # never increase this just to make test pass but investigate
1884 # why it takes so long time
1887 while [ $WAIT -lt $MAX ]; do
1888 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
1892 for ((i=0; i<${#RPCs[@]}; i++)); do
1893 [ ${RPCs[$i]} -eq 0 ] && continue
1894 # there are still some destroy RPCs in flight
1899 [ ${con} -eq 1 ] && return 0 # done waiting
1900 echo "Waiting ${WAIT}s for local destroys to complete"
1903 echo "Local destroys weren't done in $MAX sec."
1907 wait_delete_completed() {
1908 wait_delete_completed_mds $1 || return $?
1909 wait_destroy_complete
1918 # conf-sanity 31 takes a long time cleanup
1919 while [ $WAIT -lt 300 ]; do
1920 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
1921 [ -z "${running}" ] && return 0
1922 echo "waited $WAIT for${running}"
1923 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
1925 WAIT=$((WAIT + INTERVAL))
1927 echo "service didn't stop after $WAIT seconds. Still running:"
1932 wait_remote_prog () {
1938 [ "$PDSH" = "no_dsh" ] && return 0
1940 while [ $WAIT -lt $2 ]; do
1941 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
1942 [ -z "${running}" ] && return 0 || true
1943 echo "waited $WAIT for: "
1945 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
1947 WAIT=$((WAIT + INTERVAL))
1949 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
1950 [ -z "$pids" ] && return 0
1951 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
1952 # FIXME: not portable
1953 for pid in $pids; do
1954 cat /proc/${pid}/status || true
1955 cat /proc/${pid}/wchan || true
1957 kill -9 $pid || true
1966 # not every config has many clients
1968 if [ ! -z "$CLIENTS" ]; then
1969 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
1971 stat -f $MOUNT > /dev/null
1977 # usually checked on particular client or locally
1979 if [ ! -z "$client" ]; then
1980 $PDSH $client "stat -f $MOUNT" > /dev/null
1982 stat -f $MOUNT > /dev/null
1990 client_reconnect() {
1991 uname -n >> $MOUNT/recon
1992 if [ -z "$CLIENTS" ]; then
1993 df $MOUNT; uname -n >> $MOUNT/recon
1995 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
1997 echo Connected clients:
1999 ls -l $MOUNT/recon > /dev/null
2003 affected_facets () {
2006 local host=$(facet_active_host $facet)
2007 local affected=$facet
2009 if [ "$FAILURE_MODE" = HARD ]; then
2010 affected=$(facets_up_on_host $host)
2018 local host=$(facet_active_host $facet)
2020 echo "Failing $facet on node $host"
2022 local affected=$(affected_facets $facet)
2024 shutdown_facet $facet
2026 echo affected facets: $affected
2028 [ -n "$sleep_time" ] && sleep $sleep_time
2032 change_active $affected
2034 wait_for_facet $affected
2035 # start mgs first if it is affected
2036 if ! combined_mgs_mds && list_member $affected mgs; then
2037 mount_facet mgs || error "Restart of mgs failed"
2039 # FIXME; has to be changed to mount all facets concurrently
2040 affected=$(exclude_items_from_list $affected mgs)
2041 mount_facets $affected
2050 do_facet $facet "sync; sync; sync"
2053 # make sure there will be no seq change
2054 local clients=${CLIENTS:-$HOSTNAME}
2055 do_nodes $clients "f=${MOUNT}/fsa-\\\$(hostname); mcreate \\\$f; rm \\\$f"
2057 local svc=${facet}_svc
2058 do_facet $facet $LCTL --device %${!svc} notransno
2059 do_facet $facet $LCTL --device %${!svc} readonly
2060 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2061 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2064 replay_barrier_nodf() {
2065 local facet=$1 echo running=${running}
2066 do_facet $facet "sync; sync; sync"
2067 local svc=${facet}_svc
2068 echo Replay barrier on ${!svc}
2069 do_facet $facet $LCTL --device %${!svc} notransno
2070 do_facet $facet $LCTL --device %${!svc} readonly
2071 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2072 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2075 replay_barrier_nosync() {
2076 local facet=$1 echo running=${running}
2077 local svc=${facet}_svc
2078 echo Replay barrier on ${!svc}
2079 do_facet $facet $LCTL --device %${!svc} notransno
2080 do_facet $facet $LCTL --device %${!svc} readonly
2081 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
2082 $LCTL mark "local REPLAY BARRIER on ${!svc}"
2085 mds_evict_client() {
2086 UUID=`lctl get_param -n mdc.${mds1_svc}-mdc-*.uuid`
2087 do_facet mds1 "lctl set_param -n mdt.${mds1_svc}.evict_client $UUID"
2090 ost_evict_client() {
2091 UUID=`lctl get_param -n devices| grep ${ost1_svc}-osc- | egrep -v 'MDT' | awk '{print $5}'`
2092 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
2096 facet_failover $* || error "failover: $?"
2097 clients_up || error "post-failover df: $?"
2102 facet_failover $facet
2108 refresh_disk ${facet}
2109 change_active $facet
2110 wait_for_facet $facet
2111 mount_facet $facet -o abort_recovery
2112 clients_up || echo "first df failed: $?"
2113 clients_up || error "post-failover df: $?"
2117 echo There is no lmc. This is mountconf, baby.
2121 host_nids_address() {
2125 if [ -n "$kind" ]; then
2126 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
2128 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
2134 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
2140 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
2141 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
2142 if [ -z "$ID" ]; then
2143 echo "Could not get a ptl id for $1..."
2152 h2name_or_ip "$1" "tcp"
2157 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
2158 if type __h2elan >/dev/null 2>&1; then
2161 ID=`echo $1 | sed 's/[^0-9]*//g'`
2169 h2name_or_ip "$1" "o2ib"
2173 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2174 # expressions format. As a bonus we can then just pass in those variables
2175 # to pdsh. What this function does is take a HOSTLIST type string and
2176 # expand it into a space deliminated list for us.
2184 [ -z "$hostlist" ] && return
2186 # Translate the case of [..],..,[..] to [..] .. [..]
2187 list="${hostlist/],/] }"
2189 [[ "$front" == *,* ]] && {
2192 list=${list/${old}/${new}}
2195 for item in $list; do
2196 # Test if we have any []'s at all
2197 if [ "$item" != "${item/\[/}" ]; then {
2198 # Expand the [*] into list
2202 if [ "$name" != "$item" ]; then
2203 group=${item#$name[*}
2206 for range in ${group//,/ }; do
2210 # Number of leading zeros
2213 end=$(echo $end | sed 's/0*//')
2214 [[ -z "$end" ]] && end=0
2215 [[ $padlen2 -gt $padlen ]] && {
2216 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2219 begin=$(echo $begin | sed 's/0*//')
2220 [ -z $begin ] && begin=0
2222 for num in $(seq -f "%0${padlen}g" $begin $end); do
2223 value="${name#*,}${num}${back}"
2224 [ "$value" != "${value/\[/}" ] && {
2225 value=$(hostlist_expand "$value")
2227 myList="$myList $value"
2232 myList="$myList $item"
2235 myList=${myList//,/ }
2236 myList=${myList:1} # Remove first character which is a space
2238 # Filter any duplicates without sorting
2240 myList="${list%% *}"
2242 while [[ "$list" != ${myList##* } ]]; do
2243 list=${list//${list%% *} /}
2244 myList="$myList ${list%% *}"
2246 myList="${myList%* }";
2248 # We can select an object at a offset in the list
2251 for item in $myList; do
2253 [ $cnt -eq $offset ] && {
2257 [ $(get_node_count $myList) -ne 1 ] && myList=""
2265 [ "$facet" == client ] && echo -n $HOSTNAME && return
2266 varname=${facet}_HOST
2267 if [ -z "${!varname}" ]; then
2268 if [ "${facet:0:3}" == "ost" ]; then
2269 eval ${facet}_HOST=${ost_HOST}
2275 facet_failover_host() {
2279 var=${facet}failover_HOST
2280 if [ -n "${!var}" ]; then
2285 if [[ $facet == ost* ]]; then
2286 var=ostfailover_HOST
2287 if [ -n "${!var}" ]; then
2296 local activevar=${facet}active
2298 if [ -f $TMP/${facet}active ] ; then
2299 source $TMP/${facet}active
2302 active=${!activevar}
2303 if [ -z "$active" ] ; then
2310 facet_active_host() {
2312 local active=`facet_active $facet`
2313 if [ "$facet" == client ]; then
2316 echo `facet_host $active`
2324 facetlist=$(exclude_items_from_list $facetlist mgs)
2326 for facet in ${facetlist//,/ }; do
2327 local failover=${facet}failover
2328 local host=`facet_host $failover`
2329 [ -z "$host" ] && return
2331 local curactive=`facet_active $facet`
2332 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2333 eval export ${facet}active=$facet
2335 eval export ${facet}active=$failover
2337 # save the active host for this facet
2338 local activevar=${facet}active
2339 echo "$activevar=${!activevar}" > $TMP/$activevar
2340 [[ $facet = mds1 ]] && combined_mgs_mds && \
2341 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2342 local TO=`facet_active_host $facet`
2343 echo "Failover $facet to $TO"
2349 # do not stripe off hostname if verbose, bug 19215
2350 if [ x$1 = x--verbose ]; then
2358 if [ "$HOST" = "$HOSTNAME" ]; then
2360 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2361 echo "cannot run remote command on $HOST with $myPDSH"
2365 echo "CMD: $HOST $@" >&2
2366 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2369 if [ "$myPDSH" = "rsh" ]; then
2370 # we need this because rsh does not return exit code of an executed command
2371 local command_status="$TMP/cs"
2372 rsh $HOST ":> $command_status"
2373 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2374 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2375 echo command failed >$command_status"
2376 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2381 # print HOSTNAME for myPDSH="no_dsh"
2382 if [[ $myPDSH = no_dsh ]]; then
2383 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2385 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2388 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2390 return ${PIPESTATUS[0]}
2394 do_node --verbose "$@"
2397 single_local_node () {
2398 [ "$1" = "$HOSTNAME" ]
2401 # Outputs environment variable assignments that should be passed to remote nodes
2405 local facets=$(get_facets)
2408 for var in ${!MODOPTS_*}; do
2410 echo -n " ${var}=\"$value\""
2413 echo -n " USE_OFD=$USE_OFD"
2415 for facet in ${facets//,/ }; do
2417 if [ -n "${!var}" ]; then
2418 echo -n " $var=${!var}"
2422 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2423 if [ -n "${!var}" ]; then
2424 echo -n " $var=${!var}"
2428 if [ -n "$FSTYPE" ]; then
2429 echo -n " FSTYPE=$FSTYPE"
2435 # do not stripe off hostname if verbose, bug 19215
2436 if [ x$1 = x--verbose ]; then
2444 if single_local_node $rnodes; then
2446 do_nodev $rnodes "$@"
2448 do_node $rnodes "$@"
2453 # This is part from do_node
2456 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2457 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2459 export FANOUT=$(get_node_count "${rnodes//,/ }")
2461 echo "CMD: $rnodes $@" >&2
2462 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2465 # do not replace anything from pdsh output if -N is used
2466 # -N Disable hostname: prefix on lines of output.
2467 if $verbose || [[ $myPDSH = *-N* ]]; then
2468 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2470 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2472 return ${PIPESTATUS[0]}
2478 local HOST=`facet_active_host $facet`
2479 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
2483 # Function: do_facet_random_file $FACET $FILE $SIZE
2484 # Creates FILE with random content on the given FACET of given SIZE
2486 do_facet_random_file() {
2490 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
2491 do_facet $facet "$cmd 2>/dev/null"
2494 do_facet_create_file() {
2498 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
2499 do_facet $facet "$cmd 2>/dev/null"
2503 do_nodes --verbose "$@"
2509 # make sure its not already running
2511 rm -f $TMP/${facet}active
2512 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
2513 do_facet ${facet} $MKFS $*
2520 local fstype=$(facet_fstype ost$num)
2524 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2525 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2527 #dataset name is independent of vdev device names
2528 eval DEVPTR=${FSNAME}-ost${num}/ost${num};;
2530 error "unknown fstype!";;
2540 local fstype=$(facet_fstype ost$num)
2544 # vdevs are not supported by ldiskfs
2547 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2548 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2550 error "unknown fstype!";;
2560 local fstype=$(facet_fstype mds$num)
2564 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
2565 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
2567 #dataset name is independent of vdev device names
2568 eval DEVPTR=${FSNAME}-mdt${num}/mdt${num};;
2570 error "unknown fstype!";;
2580 local fstype=$(facet_fstype mds$num)
2584 # vdevs are not supported by ldiskfs
2587 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
2588 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
2590 error "unknown fstype!";;
2599 local fstype=$(facet_fstype mds$num)
2603 #if $MGSDEV isn't defined, default is $MDSDEV1
2604 eval DEVPTR=${!DEVNAME:=${MDSDEV1}};;
2606 #dataset name is independent of vdev device names
2607 eval DEVPTR=${FSNAME}-mgs/mgs;;
2609 error "unknown fstype!";;
2618 local fstype=$(facet_fstype mds$num)
2622 # vdevs are not supported by ldiskfs
2625 #if $MGSDEV isn't defined, default is $MGSDEV1
2626 eval VDEVPTR=${!DEVNAME:=${MDSDEV1}};;
2628 error "unknown fstype!";;
2636 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
2638 local var=${facet}_MOUNT
2639 eval mntpt=${!var:-${MOUNT%/*}/$facet}
2648 # make sure we are using the primary server, so test-framework will
2649 # be able to clean up properly.
2650 activemds=`facet_active mds1`
2651 if [ $activemds != "mds1" ]; then
2655 local clients=$CLIENTS
2656 [ -z $clients ] && clients=$(hostname)
2658 zconf_umount_clients $clients $MOUNT "$*" || true
2659 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
2661 [ "$CLIENTONLY" ] && return
2662 # The add fn does rm ${facet}active file, this would be enough
2663 # if we use do_facet <facet> only after the facet added, but
2664 # currently we use do_facet mds in local.sh
2665 for num in `seq $MDSCOUNT`; do
2667 rm -f ${TMP}/mds${num}active
2669 combined_mgs_mds && rm -f $TMP/mgsactive
2671 for num in `seq $OSTCOUNT`; do
2673 rm -f $TMP/ost${num}active
2676 if ! combined_mgs_mds ; then
2683 cleanup_echo_devs () {
2684 local devs=$($LCTL dl | grep echo | awk '{print $4}')
2686 for dev in $devs; do
2687 $LCTL --device $dev cleanup
2688 $LCTL --device $dev detach
2693 nfs_client_mode && return
2702 combined_mgs_mds () {
2703 [[ $MDSDEV1 = $MGSDEV ]] && [[ $mds1_HOST = $mgs_HOST ]]
2707 echo -n "$1" | tr '[:upper:]' '[:lower:]'
2711 echo -n "$1" | tr '[:lower:]' '[:upper:]'
2716 local type=$(facet_type $facet)
2717 local index=$(($(facet_number $facet) - 1))
2718 local fstype=$(facet_fstype $facet)
2723 if [ $type == MGS ] && combined_mgs_mds; then
2727 if [ $type == MGS ] || ( [ $type == MDS ] && combined_mgs_mds ); then
2730 opts="--mgsnode=$MGSNID"
2733 if [ $type != MGS ]; then
2734 opts+=" --fsname=$FSNAME --$(lower ${type/MDS/MDT}) --index=$index"
2737 var=${facet}failover_HOST
2738 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
2739 opts+=" --failnode=$(h2$NETTYPE ${!var})"
2742 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
2743 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
2745 if [ $type == MDS ]; then
2746 opts+=${SECLEVEL:+" --param=mdt.sec_level"}
2747 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
2748 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
2749 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
2750 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
2752 if [ $fstype == ldiskfs ]; then
2753 opts+=${IAMDIR:+" --iam-dir"}
2755 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
2756 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
2760 if [ $type == OST ]; then
2761 opts+=${SECLEVEL:+" --param=ost.sec_level"}
2762 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
2764 if [ $fstype == ldiskfs ]; then
2765 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
2769 opts+=" --backfstype=$fstype"
2772 if [ -n "${!var}" ]; then
2773 opts+=" --device-size=${!var}"
2776 var=$(upper $fstype)_MKFS_OPTS
2777 fs_mkfs_opts+=${!var:+" ${!var}"}
2779 var=${type}_FS_MKFS_OPTS
2780 fs_mkfs_opts+=${!var:+" ${!var}"}
2782 if [ -n "${fs_mkfs_opts## }" ]; then
2783 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
2787 opts+=${!var:+" ${!var}"}
2800 # We need ldiskfs here, may as well load them all
2802 [ "$CLIENTONLY" ] && return
2803 echo Formatting mgs, mds, osts
2804 if ! combined_mgs_mds ; then
2805 echo "Format mgs: $(mgsdevname)"
2806 add mgs $(mkfs_opts mgs) --reformat $(mgsdevname) \
2807 $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
2810 for num in `seq $MDSCOUNT`; do
2811 echo "Format mds$num: $(mdsdevname $num)"
2812 add mds$num $(mkfs_opts mds$num) --reformat \
2813 $(mdsdevname $num) $(mdsvdevname $num) \
2814 ${quiet:+>/dev/null} || exit 10
2817 for num in `seq $OSTCOUNT`; do
2818 echo "Format ost$num: $(ostdevname $num)"
2819 add ost$num $(mkfs_opts ost$num) --reformat \
2820 $(ostdevname $num) $(ostvdevname ${num}) \
2821 ${quiet:+>/dev/null} || exit 10
2826 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
2830 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
2834 # 0: success, the old identity set already.
2835 # 1: success, the old identity does not set.
2840 local j=`expr $num - 1`
2841 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
2843 if [ -z "$MDT" ]; then
2847 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
2850 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
2852 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
2855 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
2857 if [ $old = "NONE" ]; then
2866 zconf_umount `hostname` $1 || error "umount failed"
2867 zconf_mount `hostname` $1 || error "mount failed"
2870 writeconf_facet () {
2874 do_facet $facet "$TUNEFS --writeconf $dev"
2878 for num in `seq $MDSCOUNT`; do
2879 DEVNAME=$(mdsdevname $num)
2880 writeconf_facet mds$num $DEVNAME
2883 for num in `seq $OSTCOUNT`; do
2884 DEVNAME=$(ostdevname $num)
2885 writeconf_facet ost$num $DEVNAME
2890 nfs_client_mode && return
2892 sanity_mount_check ||
2893 error "environments are insane!"
2897 if [ -z "$CLIENTONLY" ]; then
2898 echo Setup mgs, mdt, osts
2899 echo $WRITECONF | grep -q "writeconf" && \
2901 if ! combined_mgs_mds ; then
2902 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
2905 for num in `seq $MDSCOUNT`; do
2906 DEVNAME=$(mdsdevname $num)
2907 start mds$num $DEVNAME $MDS_MOUNT_OPTS
2909 # We started mds, now we should set failover variables properly.
2910 # Set mds${num}failover_HOST if it is not set (the default failnode).
2911 local varname=mds${num}failover_HOST
2912 if [ -z "${!varname}" ]; then
2913 eval mds${num}failover_HOST=$(facet_host mds$num)
2916 if [ $IDENTITY_UPCALL != "default" ]; then
2917 switch_identity $num $IDENTITY_UPCALL
2920 for num in `seq $OSTCOUNT`; do
2921 DEVNAME=$(ostdevname $num)
2922 start ost$num $DEVNAME $OST_MOUNT_OPTS
2924 # We started ost$num, now we should set ost${num}failover variable properly.
2925 # Set ost${num}failover_HOST if it is not set (the default failnode).
2926 varname=ost${num}failover_HOST
2927 if [ -z "${!varname}" ]; then
2928 eval ost${num}failover_HOST=$(facet_host ost${num})
2936 # wait a while to allow sptlrpc configuration be propogated to targets,
2937 # only needed when mounting new target devices.
2942 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
2944 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
2947 if [ "$MOUNT_2" ]; then
2948 mount_client $MOUNT2
2949 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
2954 # by remounting mdt before ost, initial connect from mdt to ost might
2955 # timeout because ost is not ready yet. wait some time to its fully
2956 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
2957 # by a context negotiation rpc with $TIMEOUT.
2958 # FIXME better by monitoring import status.
2961 sleep $((TIMEOUT + 5))
2967 mounted_lustre_filesystems() {
2968 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
2971 init_facet_vars () {
2972 [ "$CLIENTONLY" ] && return 0
2979 eval export ${facet}_dev=${device}
2980 eval export ${facet}_opt=\"$@\"
2982 local dev=${facet}_dev
2983 local label=$(devicelabel ${facet} ${!dev})
2984 [ -z "$label" ] && echo no label for ${!dev} && exit 1
2986 eval export ${facet}_svc=${label}
2988 local varname=${facet}failover_HOST
2989 if [ -z "${!varname}" ]; then
2990 eval $varname=$(facet_host $facet)
2993 # ${facet}failover_dev is set in cfg file
2994 varname=${facet}failover_dev
2995 if [ -n "${!varname}" ] ; then
2996 eval export ${facet}failover_dev=${!varname}
2998 eval export ${facet}failover_dev=$device
3001 # get mount point of already mounted device
3002 # is facet_dev is already mounted then use the real
3003 # mount point of this facet; otherwise use $(facet_mntpt $facet)
3004 # i.e. ${facet}_MOUNT if specified by user or default
3005 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
3006 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
3007 if [ -z $mntpt ]; then
3008 mntpt=$(facet_mntpt $facet)
3010 eval export ${facet}_MOUNT=$mntpt
3013 init_facets_vars () {
3016 if ! remote_mds_nodsh; then
3017 for num in `seq $MDSCOUNT`; do
3018 DEVNAME=`mdsdevname $num`
3019 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
3023 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
3025 remote_ost_nodsh && return
3027 for num in `seq $OSTCOUNT`; do
3028 DEVNAME=`ostdevname $num`
3029 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
3033 osc_ensure_active () {
3038 while [ $period -lt $timeout ]; do
3039 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
3040 if [ $count -eq 0 ]; then
3044 echo "There are $count OST are inactive, wait $period seconds, and try again"
3046 period=$((period+3))
3049 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
3052 init_param_vars () {
3054 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3056 log "Using TIMEOUT=$TIMEOUT"
3058 osc_ensure_active $SINGLEMDS $TIMEOUT
3059 osc_ensure_active client $TIMEOUT
3062 if [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ]; then
3064 elif [ $JOBSTATS_AUTO -ne 0 ]; then
3065 echo "enable jobstats, set job scheduler as $JOBID_VAR"
3066 jobid_var=$JOBID_VAR
3068 jobid_var=`$LCTL get_param -n jobid_var`
3069 if [ $jobid_var != "disable" ]; then
3070 echo "disable jobstats as required"
3077 if [ $jobid_var == $JOBID_VAR -o $jobid_var == "disable" ]; then
3078 do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$jobid_var
3079 wait_update $HOSTNAME "$LCTL get_param -n jobid_var" \
3080 $jobid_var || return 1
3083 if [ $QUOTA_AUTO -ne 0 ]; then
3084 if [ "$ENABLE_QUOTA" ]; then
3085 echo "enable quota as required"
3086 setup_quota $MOUNT || return 2
3088 echo "disable quota as required"
3089 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
3095 nfs_client_mode () {
3096 if [ "$NFSCLIENT" ]; then
3097 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
3098 local clients=$CLIENTS
3099 [ -z $clients ] && clients=$(hostname)
3101 # FIXME: remove hostname when 19215 fixed
3102 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
3103 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
3104 if [[ ${#nfsexport[@]} -eq 0 ]]; then
3105 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
3107 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
3113 check_config_client () {
3116 local mounted=$(mount | grep " $mntpt ")
3117 if [ "$CLIENTONLY" ]; then
3119 # CLIENTONLY should not depend on *_HOST settings
3120 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
3121 # in theory someone could create a new,
3122 # client-only config file that assumed lustre was already
3123 # configured and didn't set the MGSNID. If MGSNID is not set,
3124 # then we should use the mgs nid currently being used
3125 # as the default value. bug 18021
3126 [[ x$MGSNID = x ]] &&
3129 if [[ x$mgc != xMGC$MGSNID ]]; then
3130 if [ "$mgs_HOST" ]; then
3131 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
3132 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
3133 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
3139 local myMGS_host=$mgs_HOST
3140 if [ "$NETTYPE" = "ptl" ]; then
3141 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
3144 echo Checking config lustre mounted on $mntpt
3145 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
3146 mgshost=$(echo $mgshost | awk -F: '{print $1}')
3148 # if [ "$mgshost" != "$myMGS_host" ]; then
3149 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
3150 # Please use correct config or set mds_HOST correctly!"
3155 check_config_clients () {
3156 local clients=${CLIENTS:-$HOSTNAME}
3159 nfs_client_mode && return
3161 do_rpc_nodes $clients check_config_client $mntpt
3163 sanity_mount_check ||
3164 error "environments are insane!"
3168 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3169 local cltimeout=$(lctl get_param -n timeout)
3170 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
3171 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
3178 [ -z $mntpt ] && return 1
3179 local mounted=$(mounted_lustre_filesystems)
3181 echo $mounted' ' | grep -w -q $mntpt' '
3185 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
3189 # empty lustre filesystem may have empty directories lost+found and .lustre
3191 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
3192 -print | wc -l) = 1 ] || return 1
3193 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found && return 0
3194 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre && return 0
3198 check_and_setup_lustre() {
3199 nfs_client_mode && return
3201 local MOUNTED=$(mounted_lustre_filesystems)
3205 # both MOUNT and MOUNT2 are not mounted
3206 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
3207 [ "$REFORMAT" ] && formatall
3208 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
3210 is_mounted $MOUNT || error "NAME=$NAME not mounted"
3211 export I_MOUNTED=yes
3215 elif is_mounted $MOUNT2; then
3217 # MOUNT2 is mounted, while MOUNT_2 is not set
3218 if ! [ "$MOUNT_2" ]; then
3219 cleanup_mount $MOUNT2
3220 export I_UMOUNTED2=yes
3223 # MOUNT2 is mounted, MOUNT_2 is set
3225 # FIXME: what to do if check_config failed?
3227 # 1) remote client has mounted other Lustre fs ?
3228 # 2) it has insane env ?
3229 # let's try umount MOUNT2 on all clients and mount it again:
3230 if ! check_config_clients $MOUNT2; then
3231 cleanup_mount $MOUNT2
3232 restore_mount $MOUNT2
3233 export I_MOUNTED2=yes
3238 # MOUNT is mounted MOUNT2 is not mounted
3239 elif [ "$MOUNT_2" ]; then
3240 restore_mount $MOUNT2
3241 export I_MOUNTED2=yes
3245 # FIXME: what to do if check_config failed?
3247 # 1) remote client has mounted other Lustre fs?
3248 # 2) lustre is mounted on remote_clients atall ?
3249 check_config_clients $MOUNT
3253 set_default_debug_nodes $(comma_list $(nodes_list))
3261 if [ "$ONLY" == "setup" ]; then
3267 local clients=${CLIENTS:-$HOSTNAME}
3270 zconf_mount_clients $clients $mntpt
3274 local clients=${CLIENTS:-$HOSTNAME}
3277 zconf_umount_clients $clients $mntpt
3280 cleanup_and_setup_lustre() {
3281 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
3282 lctl set_param debug=0 || true
3284 if [ "$ONLY" == "cleanup" ]; then
3288 check_and_setup_lustre
3291 # Get all of the server target devices from a given server node and type.
3298 if [ "$type" == ost ]; then
3299 devs=$(get_obdfilter_param $node "" mntdev)
3301 devs=$(do_node $node \
3302 "lctl get_param -n osd-*.$FSNAME-M*.mntdev")
3304 for dev in $devs; do
3306 *loop*) do_node $node "losetup $dev" | \
3307 sed -e "s/.*(//" -e "s/).*//" ;;
3313 # Get all of the server target devices.
3318 MDTDEV=$(get_mnt_devs $(mdts_nodes) mdt)
3322 for node in $(osts_nodes); do
3323 OSTDEVS[i]=$(get_mnt_devs $node ost)
3328 # Run e2fsck on MDT or OST device.
3334 df > /dev/null # update statfs data on disk
3335 local cmd="$E2FSCK -d -v -t -t -f -n $extra_opts $target_dev"
3338 do_node $node $cmd || rc=$?
3339 [ $rc -le $FSCK_MAX_ERR ] || \
3340 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
3344 # verify a directory is shared among nodes.
3345 check_shared_dir() {
3348 [ -z "$dir" ] && return 1
3349 do_rpc_nodes $(comma_list $(nodes_list)) check_logdir $dir
3350 check_write_access $dir || return 1
3354 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
3360 [[ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]] ||
3361 { skip "Lustre 2.2.0 lacks the patch for LU-1255"; exit 0; }
3363 check_shared_dir $SHARED_DIRECTORY ||
3364 error "$SHARED_DIRECTORY isn't a shared directory"
3366 export MDSDB=$SHARED_DIRECTORY/mdsdb
3367 export OSTDB=$SHARED_DIRECTORY/ostdb
3369 [ $MDSCOUNT -eq 1 ] || error "CMD is not supported"
3371 run_e2fsck $(mdts_nodes) $MDTDEV "--mdsdb $MDSDB"
3376 for node in $(osts_nodes); do
3377 for dev in ${OSTDEVS[i]}; do
3378 run_e2fsck $node $dev "--mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
3379 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
3380 ostidx=$((ostidx + 1))
3387 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
3391 [ $rc -le $FSCK_MAX_ERR ] || \
3392 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
3393 echo "lfsck finished with rc=$rc"
3395 rm -rvf $MDSDB* $OSTDB* || true
3399 check_and_cleanup_lustre() {
3400 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
3406 if is_mounted $MOUNT; then
3407 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
3408 error "remove sub-test dirs failed"
3409 [ "$ENABLE_QUOTA" ] && restore_quota || true
3412 if [ "$I_UMOUNTED2" = "yes" ]; then
3413 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
3416 if [ "$I_MOUNTED2" = "yes" ]; then
3417 cleanup_mount $MOUNT2
3420 if [ "$I_MOUNTED" = "yes" ]; then
3421 cleanupall -f || error "cleanup failed"
3429 wait_for_function () {
3432 # suppress fn both stderr and stdout
3433 if [ "$1" = "--quiet" ]; then
3435 quiet=" > /dev/null 2>&1"
3447 eval $fn $quiet && return 0
3449 wait=$((wait + sleep))
3450 [ $wait -lt $max ] || return 1
3451 echo waiting $fn, $((max - wait)) secs left ...
3461 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
3462 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
3463 echo "Network not available!"
3467 echo `date +"%H:%M:%S (%s)"` network interface is UP
3476 # the sed converts spaces to commas, but leaves the last space
3477 # alone, so the line doesn't end with a comma.
3478 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
3484 echo $list | grep -qw $item
3487 # list, excluded are the comma separated lists
3488 exclude_items_from_list () {
3494 for item in ${excluded//,/ }; do
3495 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
3497 echo $(comma_list $list)
3500 # list, expand are the comma separated lists
3502 local list=${1//,/ }
3503 local expand=${2//,/ }
3506 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
3507 echo $(comma_list $expanded)
3510 testslist_filter () {
3511 local script=$LUSTRE/tests/${TESTSUITE}.sh
3513 [ -f $script ] || return 0
3515 local start_at=$START_AT
3516 local stop_at=$STOP_AT
3518 local var=${TESTSUITE//-/_}_START_AT
3519 [ x"${!var}" != x ] && start_at=${!var}
3520 var=${TESTSUITE//-/_}_STOP_AT
3521 [ x"${!var}" != x ] && stop_at=${!var}
3523 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
3524 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
3525 /^'${start_at}'$/ {flag = 0}
3526 {if (flag == 1) print $0}
3527 /^'${stop_at}'$/ { flag = 1 }'
3531 (cd `dirname $1`; echo $PWD/`basename $1`)
3535 local types=${1:-"OST MDS MGS"}
3539 for entry in $types; do
3540 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
3541 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
3544 MGS ) list="$list $name";;
3545 MDS|OST ) local count=${type}COUNT
3546 for ((i=1; i<=${!count}; i++)) do
3547 list="$list ${name}$i"
3549 * ) error "Invalid facet type"
3553 echo $(comma_list $list)
3556 ##################################
3557 # Adaptive Timeouts funcs
3560 # only check mds, we assume at_max is the same on all nodes
3561 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
3562 if [ $at_max -eq 0 ]; then
3573 # suppose that all ost-s have the same $at value set
3574 [ $facet != "ost" ] || facet=ost1
3576 do_facet $facet "lctl get_param -n $at"
3594 if [ $facet == "ost" ]; then
3595 facet=$(get_facets OST)
3596 elif [ $facet == "mds" ]; then
3597 facet=$(get_facets MDS)
3599 hosts=$(expand_list $hosts $(facets_hosts $facet))
3602 do_nodes $hosts lctl set_param at_max=$at_max
3605 ##################################
3609 # OBD_FAIL_MDS_ALL_REQUEST_NET
3611 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
3612 do_facet client "$1" || RC=$?
3613 do_facet $SINGLEMDS lctl set_param fail_loc=0
3618 # OBD_FAIL_MDS_ALL_REPLY_NET
3620 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
3621 do_facet client "$@" || RC=$?
3622 do_facet $SINGLEMDS lctl set_param fail_loc=0
3626 drop_reint_reply() {
3627 # OBD_FAIL_MDS_REINT_NET_REP
3629 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
3630 do_facet client "$@" || RC=$?
3631 do_facet $SINGLEMDS lctl set_param fail_loc=0
3636 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
3638 do_facet ost1 lctl set_param fail_loc=0x214
3639 do_facet client "$1" || RC=$?
3640 do_facet client "sync"
3641 do_facet ost1 lctl set_param fail_loc=0
3645 drop_ldlm_cancel() {
3646 #define OBD_FAIL_LDLM_CANCEL 0x304
3648 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
3649 do_nodes $list lctl set_param fail_loc=0x304
3651 do_facet client "$@" || RC=$?
3653 do_nodes $list lctl set_param fail_loc=0
3657 drop_bl_callback() {
3658 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
3660 do_facet client lctl set_param fail_loc=0x305
3661 do_facet client "$@" || RC=$?
3662 do_facet client lctl set_param fail_loc=0
3667 #define OBD_FAIL_LDLM_REPLY 0x30c
3669 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
3670 do_facet client "$@" || RC=$?
3671 do_facet $SINGLEMDS lctl set_param fail_loc=0
3679 echo "clearing fail_loc on $facet"
3680 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
3683 set_nodes_failloc () {
3684 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
3687 cancel_lru_locks() {
3688 $LCTL mark "cancel_lru_locks $1 start"
3689 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
3690 $LCTL set_param -n $d=clear
3692 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
3693 $LCTL mark "cancel_lru_locks $1 stop"
3698 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
3699 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
3700 echo "$DEFAULT_LRU_SIZE"
3705 lctl set_param ldlm.namespaces.*$1*.lru_size=0
3708 lru_resize_disable()
3710 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
3715 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
3716 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
3717 echo there is still data in page cache $FILE ?
3718 lctl get_param -n $FILE
3726 DEBUGSAVE="$(lctl get_param -n debug)"
3730 [ -n "$DEBUGSAVE" ] && \
3731 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
3736 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
3739 debug_size_restore() {
3740 [ -n "$DEBUG_SIZE_SAVED" ] && \
3741 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
3745 start_full_debug_logging() {
3750 local DEBUG_SIZE=150
3752 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
3753 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
3756 stop_full_debug_logging() {
3761 # prints bash call stack
3764 for (( i=1; i < ${#BASH_LINENO[*]} ; i++ )) ; do
3765 local s=${BASH_SOURCE[$i]}
3766 local l=${BASH_LINENO[$i-1]}
3767 local f=${FUNCNAME[$i]}
3768 echo " = $s:$l:$f()"
3772 ##################################
3774 ##################################
3777 local TYPE=${TYPE:-"FAIL"}
3780 # do not dump logs if $1=false
3781 if [ "x$1" = "xfalse" ]; then
3786 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
3790 # We need to dump the logs on all nodes
3792 gather_logs $(comma_list $(nodes_list))
3796 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
3797 echo "$@" > $LOGDIR/err
3802 local log=$TESTSUITELOG
3804 [ -f "$log" ] && grep -q FAIL $log && status=1
3817 # use only if we are ignoring failures for this test, bugno required.
3818 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
3819 # e.g. error_ignore 5494 "your message"
3821 local TYPE="IGNORE (bz$1)"
3826 error_and_remount() {
3828 remount_client $MOUNT
3833 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
3838 log " SKIP: $TESTSUITE $TESTNAME $@"
3840 if [[ -n "$ALWAYS_SKIPPED" ]]; then
3841 skip_logged $TESTNAME "$@"
3844 echo "$@" > $LOGDIR/skip
3847 [[ -n "$TESTSUITELOG" ]] &&
3848 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
3851 build_test_filter() {
3852 EXCEPT="$EXCEPT $(testslist_filter)"
3854 [ "$ONLY" ] && log "only running test `echo $ONLY`"
3858 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
3859 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
3860 [ "$EXCEPT_SLOW" ] && \
3861 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
3862 for E in $EXCEPT; do
3863 eval EXCEPT_${E}=true
3865 for E in $ALWAYS_EXCEPT; do
3866 eval EXCEPT_ALWAYS_${E}=true
3868 for E in $EXCEPT_SLOW; do
3869 eval EXCEPT_SLOW_${E}=true
3871 for G in $GRANT_CHECK_LIST; do
3872 eval GCHECK_ONLY_${G}=true
3877 if [[ $1 = [a-z]* ]]; then
3884 # print a newline if the last test was skipped
3885 export LAST_SKIPPED=
3886 export ALWAYS_SKIPPED=
3888 # Main entry into test-framework. This is called with the name and
3889 # description of a test. The name is used to find the function to run
3890 # the test using "test_$name".
3892 # This supports a variety of methods of specifying specific test to
3893 # run or not run. These need to be documented...
3898 export base=`basetest $1`
3899 if [ ! -z "$ONLY" ]; then
3901 if [ ${!testname}x != x ]; then
3902 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
3903 run_one_logged $1 "$2"
3907 if [ ${!testname}x != x ]; then
3908 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
3909 run_one_logged $1 "$2"
3920 if [ ${!testname}x != x ]; then
3921 TESTNAME=test_$1 skip "skipping excluded test $1"
3924 testname=EXCEPT_$base
3925 if [ ${!testname}x != x ]; then
3926 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
3929 testname=EXCEPT_ALWAYS_$1
3930 if [ ${!testname}x != x ]; then
3931 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
3934 testname=EXCEPT_ALWAYS_$base
3935 if [ ${!testname}x != x ]; then
3936 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
3939 testname=EXCEPT_SLOW_$1
3940 if [ ${!testname}x != x ]; then
3941 TESTNAME=test_$1 skip "skipping SLOW test $1"
3944 testname=EXCEPT_SLOW_$base
3945 if [ ${!testname}x != x ]; then
3946 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
3952 run_one_logged $1 "$2"
3963 module_loaded lnet || load_modules
3975 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
3980 strace -o $TMP/$1.strace -ttt $*
3982 log "FINISHED: $*: rc $RC"
3987 equals_msg $1 test complete, duration $2 sec
3988 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
3989 echo duration $2 >>$TESTSUITELOG
3993 # Set TEST_STATUS here. It will be used for logging the result.
3996 if [[ -f $LOGDIR/err ]]; then
3998 elif [[ -f $LOGDIR/skip ]]; then
4001 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
4005 local FFREE=$(do_node $SINGLEMDS \
4006 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
4007 local FTOTAL=$(do_node $SINGLEMDS \
4008 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
4010 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
4014 echo -n "Resetting fail_loc on all nodes..."
4015 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
4021 # Log a message (on all nodes) padded with "=" before and after.
4022 # Also appends a timestamp and prepends the testsuite name.
4025 EQUALS="===================================================================================================="
4027 msg="== ${TESTSUITE} $*"
4029 [[ $last != "=" && $last != " " ]] && msg="$msg "
4030 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
4031 # always include at least == after the message
4032 log "$msg== $(date +"%H:%M:%S (%s)")"
4036 # Run a single test function and cleanup after it.
4038 # This function should be run in a subshell so the test func can
4039 # exit() without stopping the whole script.
4044 tfile=f.${TESTSUITE}.${testnum}
4045 export tdir=d0.${TESTSUITE}/d${base}
4046 export TESTNAME=test_$testnum
4047 local SAVE_UMASK=`umask`
4050 banner "test $testnum: $message"
4051 test_${testnum} || error "test_$testnum failed with $?"
4054 check_grant ${testnum} || error "check_grant $testnum failed with $?"
4055 check_catastrophe || error "LBUG/LASSERT detected"
4056 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
4064 # Wrapper around run_one to ensure:
4065 # - test runs in subshell
4066 # - output of test is saved to separate log file for error reporting
4067 # - test result is saved to data file
4070 local BEFORE=`date +%s`
4072 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
4073 local test_log=$LOGDIR/$name
4076 local SAVE_UMASK=`umask`
4080 log_sub_test_begin test_${1}
4081 (run_one $1 "$2") 2>&1 | tee -i $test_log
4082 local RC=${PIPESTATUS[0]}
4084 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] && \
4085 echo "test_$1 returned $RC" | tee $LOGDIR/err
4087 duration=$((`date +%s` - $BEFORE))
4088 pass "$1" "(${duration}s)"
4090 if [[ -f $LOGDIR/err ]]; then
4091 TEST_ERROR=$(cat $LOGDIR/err)
4092 elif [[ -f $LOGDIR/skip ]]; then
4093 TEST_ERROR=$(cat $LOGDIR/skip)
4095 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
4097 if [ -f $LOGDIR/err ]; then
4098 $FAIL_ON_ERROR && exit $RC
4107 # Print information of skipped tests to result.yml
4110 log_sub_test_begin $1
4112 log_sub_test_end "SKIP" "0" "0" "$@"
4116 (cd `dirname $1`; echo $PWD/`basename $1`)
4121 export base=`basetest $1`
4122 [ "$CHECK_GRANT" == "no" ] && return 0
4124 testname=GCHECK_ONLY_${base}
4125 [ ${!testname}x == x ] && return 0
4127 echo -n "checking grant......"
4129 local clients=$CLIENTS
4130 [ -z $clients ] && clients=$(hostname)
4132 # sync all the data and make sure no pending data on server
4133 do_nodes $clients sync
4136 client_grant=`do_nodes $clients \
4137 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" | \
4138 awk '{total += $1} END{print total}'`
4141 server_grant=`do_nodes $(comma_list $(osts_nodes)) \
4142 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
4143 awk '{total += $1} END{print total}'`
4145 # check whether client grant == server grant
4146 if [ $client_grant -ne $server_grant ]; then
4147 echo "failed: client:${client_grant} server: ${server_grant}."
4148 do_nodes $(comma_list $(osts_nodes)) \
4149 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
4150 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
4153 echo "pass: client:${client_grant} server: ${server_grant}"
4158 ########################
4164 ost=`echo $1 | awk -F_ '{print $3}'`
4165 if [ -z $ost ]; then
4166 ost=`echo $1 | sed 's/-osc.*//'`
4171 ostuuid_from_index()
4173 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
4176 ostname_from_index() {
4177 local uuid=$(ostuuid_from_index $1)
4181 index_from_ostuuid()
4183 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
4186 mdtuuid_from_index()
4188 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
4193 [ "$node" != "$(hostname)" ]
4199 for node in $(mdts_nodes); do
4200 remote_node $node && return 0
4207 [ "$CLIENTONLY" ] && return 0 || true
4208 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
4213 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
4214 MSKIPPED=1 && return 1
4221 for node in $(osts_nodes) ; do
4222 remote_node $node && return 0
4229 [ "$CLIENTONLY" ] && return 0 || true
4230 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
4235 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
4236 OSKIPPED=1 && return 1
4243 MGS=$(facet_host mgs)
4244 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
4249 remote_mds_nodsh || remote_ost_nodsh || \
4250 $(single_local_node $(comma_list $(nodes_list)))
4256 for num in `seq $MDSCOUNT`; do
4257 MDSNODES="$MDSNODES $(facet_host mds$num)"
4259 NODES_sort=$(for i in $MDSNODES; do echo $i; done | sort -u)
4265 remote_ost && remote_mds
4273 for facet in ${facets//,/ }; do
4274 if [ "$FAILURE_MODE" = HARD ]; then
4275 nodes="$nodes $(facet_active_host $facet)"
4277 nodes="$nodes $(facet_host $facet)"
4280 NODES_sort=$(for i in $nodes; do echo $i; done | sort -u)
4286 local facets=$(get_facets OST)
4287 local nodes=$(facets_nodes $facets)
4293 # FIXME. We need a list of clients
4294 local myNODES=$HOSTNAME
4297 # CLIENTS (if specified) contains the local client
4298 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
4300 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
4301 myNODES="$myNODES $(facets_nodes $(get_facets))"
4304 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
4309 remote_nodes_list () {
4310 local rnodes=$(nodes_list)
4311 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
4315 init_clients_lists () {
4316 # Sanity check: exclude the local client from RCLIENTS
4317 local clients=$(hostlist_expand "$RCLIENTS")
4318 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
4320 # Sanity check: exclude the dup entries
4321 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
4323 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
4325 # Sanity check: exclude the dup entries from CLIENTS
4326 # for those configs which has SINGLCLIENT set to local client
4327 clients=$(for i in $clients; do echo $i; done | sort -u)
4329 CLIENTS=$(comma_list $clients)
4330 local -a remoteclients=($RCLIENTS)
4331 for ((i=0; $i<${#remoteclients[@]}; i++)); do
4332 varname=CLIENT$((i + 2))
4333 eval $varname=${remoteclients[i]}
4336 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
4339 get_random_entry () {
4342 rnodes=${rnodes//,/ }
4344 local -a nodes=($rnodes)
4345 local num=${#nodes[@]}
4346 local i=$((RANDOM * num * 2 / 65536))
4352 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
4357 lctl get_param version | grep -q patchless
4361 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
4362 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
4367 echo $nodes | wc -w || true
4371 local nodes=$(osts_nodes)
4372 local osscount=$(get_node_count "$nodes")
4373 [ ! "$OSTCOUNT" = "$osscount" ]
4377 local nodes=$(mdts_nodes)
4378 local mdtcount=$(get_node_count "$nodes")
4379 [ ! "$MDSCOUNT" = "$mdtcount" ]
4382 generate_machine_file() {
4383 local nodes=${1//,/ }
4384 local machinefile=$2
4386 for node in $nodes; do
4387 echo $node >>$machinefile || \
4388 { echo "can not generate machinefile $machinefile" && return 1; }
4393 local file=$1/stripe
4395 $LFS getstripe -v $file || error
4399 setstripe_nfsserver () {
4402 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
4403 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
4405 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
4407 do_nodev $nfsserver lfs setstripe "$@"
4410 # Check and add a test group.
4416 local gid=$(getent group $group_name | cut -d: -f3)
4417 if [[ -n "$gid" ]]; then
4418 [[ "$gid" -eq "$group_id" ]] || {
4419 error_noexit "inconsistent group ID:" \
4420 "new: $group_id, old: $gid"
4424 groupadd -g $group_id $group_name
4431 # Check and add a test user.
4444 local uid=$(getent passwd $user_name | cut -d: -f3)
4445 if [[ -n "$uid" ]]; then
4446 if [[ "$uid" -eq "$user_id" ]]; then
4447 local dir=$(getent passwd $user_name | cut -d: -f6)
4448 if [[ "$dir" != "$home" ]]; then
4450 usermod -d $home $user_name
4454 error_noexit "inconsistent user ID:" \
4455 "new: $user_id, old: $uid"
4460 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
4467 check_runas_id_ret() {
4469 local myRUNAS_UID=$1
4470 local myRUNAS_GID=$2
4473 if [ -z "$myRUNAS" ]; then
4474 error_exit "myRUNAS command must be specified for check_runas_id"
4477 $myRUNAS krb5_login.sh || \
4478 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
4480 mkdir $DIR/d0_runas_test
4482 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
4483 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
4484 rm -rf $DIR/d0_runas_test
4489 local myRUNAS_UID=$1
4490 local myRUNAS_GID=$2
4493 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
4494 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
4495 Please set RUNAS_ID to some UID which exists on MDS and client or
4496 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
4499 # obtain the UID/GID for MPI_USER
4503 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
4504 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
4506 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
4507 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
4510 # obtain and cache Kerberos ticket-granting ticket
4511 refresh_krb5_tgt() {
4512 local myRUNAS_UID=$1
4513 local myRUNAS_GID=$2
4516 if [ -z "$myRUNAS" ]; then
4517 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
4520 CLIENTS=${CLIENTS:-$HOSTNAME}
4521 do_nodes $CLIENTS "set -x
4522 if ! $myRUNAS krb5_login.sh; then
4523 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
4528 # Run multiop in the background, but wait for it to print
4529 # "PAUSING" to its stdout before returning from this function.
4530 multiop_bg_pause() {
4531 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
4535 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
4538 echo "$MULTIOP_PROG $FILE v$ARGS"
4539 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
4541 echo "TMPPIPE=${TMPPIPE}"
4542 read -t 60 multiop_output < $TMPPIPE
4543 if [ $? -ne 0 ]; then
4548 if [ "$multiop_output" != "PAUSING" ]; then
4549 echo "Incorrect multiop output: $multiop_output"
4564 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
4570 inodes_available () {
4571 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
4575 mdsrate_inodes_available () {
4576 local min_inodes=$(inodes_available)
4577 echo $((min_inodes * 99 / 100))
4580 # reset llite stat counters
4581 clear_llite_stats(){
4582 lctl set_param -n llite.*.stats 0
4585 # sum llite stat items
4586 calc_llite_stats() {
4587 local res=$(lctl get_param -n llite.*.stats |
4588 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
4592 # reset osc stat counters
4594 lctl set_param -n osc.*.osc_stats 0
4597 # sum osc stat items
4599 local res=$(lctl get_param -n osc.*.osc_stats |
4600 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
4605 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
4608 calc_osc_kbytes () {
4609 df $MOUNT > /dev/null
4610 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
4613 # save_lustre_params(node, parameter_mask)
4614 # generate a stream of formatted strings (<node> <param name>=<param value>)
4615 save_lustre_params() {
4617 do_nodesv $1 "lctl get_param $2 | while read s; do echo \\\$s; done"
4620 # restore lustre parameters from input stream, produces by save_lustre_params
4621 restore_lustre_params() {
4625 while IFS=" =" read node name val; do
4626 do_node ${node//:/} "lctl set_param -n $name $val"
4630 check_catastrophe() {
4631 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
4632 local C=$CATASTROPHE
4633 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
4635 if [ $rnodes ]; then
4636 do_nodes $rnodes "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
4637 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
4642 # CMD: determine mds index where directory inode presents
4645 local file=$dir/f0.get_mds_dir_tmpfile
4650 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
4651 local -a oldused=($iused)
4653 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
4655 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
4656 local -a newused=($iused)
4659 for ((i=0; i<${#newused[@]}; i++)); do
4660 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
4666 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
4669 mdsrate_cleanup () {
4671 mpi_run -np $1 -machinefile $2 ${MDSRATE} --unlink --nfiles $3 --dir $4 --filefmt $5 $6
4676 delayed_recovery_enabled () {
4677 local var=${SINGLEMDS}_svc
4678 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
4681 ########################
4683 convert_facet2label() {
4686 if [ x$facet = xost ]; then
4690 local varsvc=${facet}_svc
4692 if [ -n ${!varsvc} ]; then
4695 error "No lablel for $facet!"
4699 get_clientosc_proc_path() {
4700 echo "${1}-osc-[^M]*"
4703 get_lustre_version () {
4704 local facet=${1:-"$SINGLEMDS"}
4705 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
4708 lustre_version_code() {
4709 local facet=${1:-"$SINGLEMDS"}
4710 version_code $(get_lustre_version $1)
4713 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
4714 # used by MDT would not be changed.
4715 # mdt lov: fsname-mdtlov
4716 # mdt osc: fsname-OSTXXXX-osc
4717 mds_on_old_device() {
4718 local mds=${1:-"$SINGLEMDS"}
4720 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
4721 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
4722 > /dev/null 2>&1" && return 0
4727 get_mdtosc_proc_path() {
4729 local ost_label=${2:-"*OST*"}
4731 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
4732 local mdt_label=$(convert_facet2label $mds_facet)
4733 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
4735 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
4736 mds_on_old_device $mds_facet; then
4737 echo "${ost_label}-osc"
4739 echo "${ost_label}-osc-${mdt_index}"
4743 get_osc_import_name() {
4746 local label=$(convert_facet2label $ost)
4748 if [ "${facet:0:3}" = "mds" ]; then
4749 get_mdtosc_proc_path $facet $label
4753 get_clientosc_proc_path $label
4757 _wait_import_state () {
4760 local maxtime=${3:-$(max_recovery_time)}
4764 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
4765 while [ "${CONN_STATE}" != "${expected}" ]; do
4766 if [ "${expected}" == "DISCONN" ]; then
4767 # for disconn we can check after proc entry is removed
4768 [ "x${CONN_STATE}" == "x" ] && return 0
4769 # with AT enabled, we can have connect request timeout near of
4770 # reconnect timeout and test can't see real disconnect
4771 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
4773 [ $i -ge $maxtime ] && \
4774 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
4777 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
4781 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
4785 wait_import_state() {
4788 local maxtime=${3:-$(max_recovery_time)}
4791 for param in ${params//,/ }; do
4792 _wait_import_state $state $param $maxtime || return
4796 # One client request could be timed out because server was not ready
4797 # when request was sent by client.
4798 # The request timeout calculation details :
4800 # /* We give the server rq_timeout secs to process the req, and
4801 # add the network latency for our local timeout. */
4802 # request->rq_deadline = request->rq_sent + request->rq_timeout +
4803 # ptlrpc_at_get_net_latency(request) ;
4805 # ptlrpc_connect_import ()
4806 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
4809 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
4810 # ptlrpc_at_get_net_latency(request) ->
4811 # at_get (max (iat_net_latency=0, at_min)) = at_min
4814 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
4815 # INITIAL_CONNECT_TIMEOUT + at_min
4817 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
4818 # because we can not get this value in runtime,
4819 # the value depends on configure options, and it is not stored in /proc.
4821 # #define CONNECTION_SWITCH_MIN 5U
4822 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
4824 request_timeout () {
4827 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
4828 local init_connect_timeout=$TIMEOUT
4829 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
4831 local at_min=$(at_get $facet at_min)
4833 echo $(( init_connect_timeout + at_min ))
4836 wait_osc_import_state() {
4840 local ost=$(get_osc_import_name $facet $ost_facet)
4842 local param="osc.${ost}.ost_server_uuid"
4844 # 1. wait the deadline of client 1st request (it could be skipped)
4845 # 2. wait the deadline of client 2nd request
4846 local maxtime=$(( 2 * $(request_timeout $facet)))
4848 if ! do_rpc_nodes $(facet_host $facet) \
4849 _wait_import_state $expected $param $maxtime; then
4850 error "import is not in ${expected} state"
4857 get_clientmdc_proc_path() {
4865 # Add paths to lustre tests for 32 and 64 bit systems.
4866 local RPATH="PATH=$RLUSTRE/tests:/usr/lib/lustre/tests:/usr/lib64/lustre/tests:$PATH"
4867 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
4870 wait_clients_import_state () {
4877 if [ "$FAILURE_MODE" = HARD ]; then
4878 facets=$(facets_on_host $(facet_active_host $facet))
4881 for facet in ${facets//,/ }; do
4882 local label=$(convert_facet2label $facet)
4885 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
4886 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
4887 *) error "unknown facet!" ;;
4889 local params=$(expand_list $params $proc_path)
4892 if ! do_rpc_nodes $list wait_import_state $expected $params; then
4893 error "import is not in ${expected} state"
4903 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
4904 $LCTL get_param obdfilter.*.kbytesavail))
4905 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
4906 $LCTL get_param -n obdfilter.*.tot_granted))
4907 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
4908 $LCTL get_param -n obdfilter.*.kbytestotal))
4909 for ((i=0; i<${#AVAILA[@]}; i++)); do
4910 local -a AVAIL1=(${AVAILA[$i]//=/ })
4911 local -a TOTAL=(${TOTALA[$i]//=/ })
4912 GRANT=$((${GRANTA[$i]}/1024))
4913 # allow 1% of total space in bavail because of delayed
4914 # allocation with ZFS which might release some free space after
4915 # txg commit. For small devices, we set a mininum of 8MB
4916 local LIMIT=$((${TOTAL} / 100 + 8000))
4917 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
4918 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
4919 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
4920 echo " FULL" || echo
4926 do_facet mgs lctl pool_list $1
4930 local fsname=${1%%.*}
4931 local poolname=${1##$fsname.}
4933 do_facet mgs lctl pool_new $1
4935 # get param should return err unless pool is created
4936 [[ $RC -ne 0 ]] && return $RC
4938 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4939 2>/dev/null || echo foo" "" || RC=1
4940 if [[ $RC -eq 0 ]]; then
4943 error "pool_new failed $1"
4948 add_pool_to_list () {
4949 local fsname=${1%%.*}
4950 local poolname=${1##$fsname.}
4952 local listvar=${fsname}_CREATED_POOLS
4953 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
4956 remove_pool_from_list () {
4957 local fsname=${1%%.*}
4958 local poolname=${1##$fsname.}
4960 local listvar=${fsname}_CREATED_POOLS
4961 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
4964 destroy_pool_int() {
4966 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
4967 awk '$1 !~ /^Pool:/ {print $1}')
4968 for ost in $OSTS; do
4969 do_facet mgs lctl pool_remove $1 $ost
4971 do_facet mgs lctl pool_destroy $1
4974 # <fsname>.<poolname> or <poolname>
4976 local fsname=${1%%.*}
4977 local poolname=${1##$fsname.}
4979 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
4983 pool_list $fsname.$poolname || return $?
4985 destroy_pool_int $fsname.$poolname
4987 [[ $RC -ne 0 ]] && return $RC
4989 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4990 2>/dev/null || echo foo" "foo" || RC=1
4992 if [[ $RC -eq 0 ]]; then
4993 remove_pool_from_list $fsname.$poolname
4995 error "destroy pool failed $1"
5001 local fsname=${1:-$FSNAME}
5003 local listvar=${fsname}_CREATED_POOLS
5007 [ x${!listvar} = x ] && return 0
5009 echo destroy the created pools: ${!listvar}
5010 for poolname in ${!listvar//,/ }; do
5011 destroy_pool $fsname.$poolname
5016 local fsname=${1:-$FSNAME}
5018 destroy_pools $fsname
5024 local ts=$(date +%s)
5027 if [[ ! -f "$YAML_LOG" ]]; then
5028 # init_logging is not performed before gather_logs,
5029 # so the $LOGDIR needs to be checked here
5030 check_shared_dir $LOGDIR && touch $LOGDIR/shared
5033 [ -f $LOGDIR/shared ] && docp=false
5035 # dump lustre logs, dmesg
5037 prefix="$TESTLOG_PREFIX.$TESTNAME"
5039 echo "Dumping lctl log to ${prefix}.*.${suffix}"
5041 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
5042 echo "Dumping logs only on local client."
5043 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
5044 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
5049 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
5050 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
5051 if [ ! -f $LOGDIR/shared ]; then
5052 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
5065 for i in $(seq 0 $num_mntpts); do
5066 cmd="ls -laf ${mntpt_root}$i/$dir"
5072 for pid in $pids; do
5079 # target_start_and_reset_recovery_timer()
5080 # service_time = at_est2timeout(service_time);
5081 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
5082 # INITIAL_CONNECT_TIMEOUT);
5083 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
5084 #define CONNECTION_SWITCH_INC 1
5085 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
5086 #define CONNECTION_SWITCH_MIN 5U
5088 max_recovery_time () {
5089 local init_connect_timeout=$(( TIMEOUT / 20 ))
5090 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
5092 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
5097 get_clients_mount_count () {
5098 local clients=${CLIENTS:-`hostname`}
5100 # we need to take into account the clients mounts and
5101 # exclude mds/ost mounts if any;
5102 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
5106 PROC_CLI="srpc_info"
5114 if [ $M -lt $N ]; then
5118 while [ $N -lt $M ]; do
5128 calc_connection_cnt() {
5131 # MDT->MDT = 2 * C(M, 2)
5135 comb_m2=$(combination $MDSCOUNT 2)
5137 local num_clients=$(get_clients_mount_count)
5139 local cnt_mdt2mdt=$((comb_m2 * 2))
5140 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
5141 local cnt_cli2ost=$((num_clients * OSTCOUNT))
5142 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
5143 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
5144 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
5145 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
5159 local cmd="$tgt.srpc.flavor"
5161 if [ $net == "any" ]; then
5166 if [ $dir != "any" ]; then
5171 log "Setting sptlrpc rule: $cmd"
5172 do_facet mgs "$LCTL conf_param $cmd"
5181 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
5182 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
5184 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
5186 if [ "x$bulkspec" != "x" ]; then
5187 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
5189 if [ "x$algs" != "x" ]; then
5190 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
5192 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
5193 if [ $bulk == "bulkn" ]; then
5194 bulk_count=`echo "$output" | grep "bulk flavor" \
5195 | grep "null/null" | wc -l`
5196 elif [ $bulk == "bulki" ]; then
5197 bulk_count=`echo "$output" | grep "bulk flavor" \
5198 | grep "/null" | grep -v "null/" | wc -l`
5200 bulk_count=`echo "$output" | grep "bulk flavor" \
5201 | grep -v "/null" | grep -v "null/" | wc -l`
5205 [ $bulk_count -lt $count ] && count=$bulk_count
5216 local clients=${CLIENTS:-`hostname`}
5218 for c in ${clients//,/ }; do
5219 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
5220 tmpcnt=`count_flvr "$output" $flavor`
5221 cnt=$((cnt + tmpcnt))
5231 local clients=${CLIENTS:-`hostname`}
5233 for c in ${clients//,/ }; do
5234 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
5235 tmpcnt=`count_flvr "$output" $flavor`
5236 cnt=$((cnt + tmpcnt))
5246 if [ $MDSCOUNT -le 1 ]; then
5251 for num in `seq $MDSCOUNT`; do
5252 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
5253 tmpcnt=`count_flvr "$output" $flavor`
5254 cnt=$((cnt + tmpcnt))
5265 for num in `seq $MDSCOUNT`; do
5266 mdtosc=$(get_mdtosc_proc_path mds$num)
5267 mdtosc=${mdtosc/-MDT*/-MDT\*}
5268 output=$(do_facet mds$num lctl get_param -n \
5269 osc.$mdtosc.$PROC_CLI 2>/dev/null)
5270 tmpcnt=`count_flvr "$output" $flavor`
5271 cnt=$((cnt + tmpcnt))
5280 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
5281 count_flvr "$output" $flavor
5286 local dir=$1 # from to
5287 local flavor=$2 # flavor expected
5290 if [ $dir == "cli2mdt" ]; then
5291 res=`flvr_cnt_cli2mdt $flavor`
5292 elif [ $dir == "cli2ost" ]; then
5293 res=`flvr_cnt_cli2ost $flavor`
5294 elif [ $dir == "mdt2mdt" ]; then
5295 res=`flvr_cnt_mdt2mdt $flavor`
5296 elif [ $dir == "mdt2ost" ]; then
5297 res=`flvr_cnt_mdt2ost $flavor`
5298 elif [ $dir == "all2ost" ]; then
5299 res1=`flvr_cnt_mdt2ost $flavor`
5300 res2=`flvr_cnt_cli2ost $flavor`
5301 res=$((res1 + res2))
5302 elif [ $dir == "all2mdt" ]; then
5303 res1=`flvr_cnt_mdt2mdt $flavor`
5304 res2=`flvr_cnt_cli2mdt $flavor`
5305 res=$((res1 + res2))
5306 elif [ $dir == "all2all" ]; then
5307 res1=`flvr_cnt_mdt2ost $flavor`
5308 res2=`flvr_cnt_cli2ost $flavor`
5309 res3=`flvr_cnt_mdt2mdt $flavor`
5310 res4=`flvr_cnt_cli2mdt $flavor`
5311 res=$((res1 + res2 + res3 + res4))
5319 local dir=$1 # from to
5320 local flavor=$2 # flavor expected
5321 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
5325 for ((i=0;i<20;i++)); do
5326 echo -n "checking $dir..."
5327 res=$(do_check_flavor $dir $flavor)
5328 echo "found $res/$expect $flavor connections"
5329 [ $res -ge $expect ] && return 0
5333 echo "Error checking $flavor of $dir: expect $expect, actual $res"
5337 restore_to_default_flavor()
5339 local proc="mgs.MGS.live.$FSNAME"
5341 echo "restoring to default flavor..."
5343 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
5345 # remove all existing rules if any
5346 if [ $nrule -ne 0 ]; then
5347 echo "$nrule existing rules"
5348 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
5349 echo "remove rule: $rule"
5350 spec=`echo $rule | awk -F = '{print $1}'`
5351 do_facet mgs "$LCTL conf_param -d $spec"
5355 # verify no rules left
5356 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
5357 [ $nrule -ne 0 ] && error "still $nrule rules left"
5359 # wait for default flavor to be applied
5360 # currently default flavor for all connections are 'null'
5361 wait_flavor all2all null
5362 echo "now at default flavor settings"
5367 local flavor=${1:-null}
5369 echo "setting all flavor to $flavor"
5371 # FIXME need parameter to this fn
5372 # and remove global vars
5373 local cnt_all2all=$(calc_connection_cnt all2all)
5375 local res=$(do_check_flavor all2all $flavor)
5376 if [ $res -eq $cnt_all2all ]; then
5377 echo "already have total $res $flavor connections"
5381 echo "found $res $flavor out of total $cnt_all2all connections"
5382 restore_to_default_flavor
5384 [[ $flavor = null ]] && return 0
5386 set_rule $FSNAME any any $flavor
5387 wait_flavor all2all $flavor
5393 # Checking for shared logdir
5394 if [ ! -d $dir ]; then
5395 # Not found. Create local logdir
5398 touch $dir/check_file.$(hostname -s)
5403 check_write_access() {
5408 for node in $(nodes_list); do
5409 file=$dir/check_file.$(short_hostname $node)
5410 if [[ ! -f "$file" ]]; then
5411 # Logdir not accessible/writable from this node.
5414 rm -f $file || return 1
5420 if [[ -n $YAML_LOG ]]; then
5423 local SAVE_UMASK=`umask`
5426 export YAML_LOG=${LOGDIR}/results.yml
5430 if [ ! -f $YAML_LOG ]; then # If the yaml log already exists then we will just append to it
5431 if check_shared_dir $LOGDIR; then
5432 touch $LOGDIR/shared
5433 echo "Logging to shared log directory: $LOGDIR"
5435 echo "Logging to local directory: $LOGDIR"
5438 yml_nodes_file $LOGDIR >> $YAML_LOG
5439 yml_results_file >> $YAML_LOG
5446 yml_log_test $1 >> $YAML_LOG
5450 yml_log_test_status $@ >> $YAML_LOG
5453 log_sub_test_begin() {
5454 yml_log_sub_test_begin "$@" >> $YAML_LOG
5457 log_sub_test_end() {
5458 yml_log_sub_test_end "$@" >> $YAML_LOG
5464 local llverdev_opts=$2
5465 local devname=$(basename $1)
5466 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
5467 # loop devices aren't in /proc/partitions
5468 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
5470 size=$(($size / 1024 / 1024)) # Gb
5472 local partial_arg=""
5473 # Run in partial (fast) mode if the size
5474 # of a partition > 1 GB
5475 [ $size -gt 1 ] && partial_arg="-p"
5477 llverdev --force $partial_arg $llverdev_opts $dev
5483 local llverfs_opts=$2
5484 local partial_arg=""
5485 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
5487 # Run in partial (fast) mode if the size
5488 # of a partition > 1 GB
5489 [ $size -gt 1 ] && partial_arg="-p"
5491 llverfs $partial_arg $llverfs_opts $dir
5494 remove_mdt_files() {
5499 local mntpt=$(facet_mntpt $facet)
5500 local opts=$MDS_MOUNT_OPTS
5502 echo "removing files from $mdtdev on $facet: $files"
5503 if [ $(facet_fstype $facet) == ldiskfs ] &&
5504 ! do_facet $facet test -b ${!dev}; then
5505 opts=$(csa_add "$opts" -o loop)
5507 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
5511 rm $mntpt/ROOT/$f || { rc=$?; break; }
5513 umount -f $mntpt || return $?
5517 duplicate_mdt_files() {
5522 local mntpt=$(facet_mntpt $facet)
5523 local opts=$MDS_MOUNT_OPTS
5525 echo "duplicating files on $mdtdev on $facet: $files"
5526 mkdir -p $mntpt || return $?
5527 if [ $(facet_fstype $facet) == ldiskfs ] &&
5528 ! do_facet $facet test -b ${!dev}; then
5529 opts=$(csa_add "$opts" -o loop)
5531 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
5542 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
5543 pushd $mntpt/ROOT > /dev/null || return $?
5546 touch $f.bad || return $?
5547 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
5549 [ $rc -eq 0 ] || return $rc
5550 setfattr --restore $tmp || return $?
5556 local devs=${1//,/ }
5559 local rslt=$TMP/sgpdd_survey
5561 # sgpdd-survey cleanups ${rslt}.* files
5563 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
5569 # returns the canonical name for an ldiskfs device
5574 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
5575 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
5576 echo dm-\\\${foo##*:};
5578 echo \\\$(basename \\\$dv);
5582 is_sanity_benchmark() {
5583 local benchmarks="dbench bonnie iozone fsx"
5585 for b in $benchmarks; do
5586 if [ "$b" == "$suite" ]; then
5594 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
5597 # Get the block size of the filesystem.
5603 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
5604 awk '/^Block size:/ {print $3}')
5608 # Check whether the "large_xattr" feature is enabled or not.
5609 large_xattr_enabled() {
5610 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
5612 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 | grep -q large_xattr"
5613 return ${PIPESTATUS[0]}
5616 # Get the maximum xattr size supported by the filesystem.
5620 if large_xattr_enabled; then
5621 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
5624 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
5625 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
5627 # maximum xattr size = size of block - size of header -
5628 # size of 1 entry - 4 null bytes
5629 size=$((block_size - 32 - 32 - 4))
5635 # Dump the value of the named xattr from a file.
5640 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
5643 # Generate a string with size of $size bytes.
5645 local size=${1:-1024} # in bytes
5647 echo "$(head -c $size < /dev/zero | tr '\0' y)"
5650 reformat_external_journal() {
5651 if [ ! -z ${EJOURNAL} ]; then
5652 local rcmd="do_facet ${SINGLEMDS}"
5654 echo "reformat external journal on ${SINGLEMDS}:${EJOURNAL}"
5655 ${rcmd} mke2fs -O journal_dev ${EJOURNAL} || return 1
5659 # MDT file-level backup/restore
5660 mds_backup_restore() {
5661 local devname=$(mdsdevname ${SINGLEMDS//mds/})
5662 local mntpt=$(facet_mntpt brpt)
5663 local rcmd="do_facet ${SINGLEMDS}"
5664 local metaea=${TMP}/backup_restore.ea
5665 local metadata=${TMP}/backup_restore.tgz
5666 local opts=${MDS_MOUNT_OPTS}
5668 if ! ${rcmd} test -b ${devname}; then
5669 opts=$(csa_add "$opts" -o loop)
5672 echo "file-level backup/restore on ${SINGLEMDS}:${devname}"
5674 # step 1: build mount point
5675 ${rcmd} mkdir -p $mntpt
5676 # step 2: cleanup old backup
5677 ${rcmd} rm -f $metaea $metadata
5679 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
5680 # step 4: backup metaea
5682 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
5684 # step 5: backup metadata
5686 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
5688 ${rcmd} umount -d $mntpt || return 4
5689 # step 7: reformat external journal if needed
5690 reformat_external_journal || return 5
5691 # step 8: reformat dev
5692 echo "reformat new device"
5693 add ${SINGLEMDS} $(mkfs_opts ${SINGLEMDS}) --backfstype ldiskfs \
5694 --reformat $devname > /dev/null || return 6
5696 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
5697 # step 10: restore metadata
5699 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
5700 # step 11: restore metaea
5702 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
5703 # step 12: remove recovery logs
5704 echo "remove recovery logs"
5705 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
5706 # step 13: umount dev
5707 ${rcmd} umount -d $mntpt || return 10
5708 # step 14: cleanup tmp backup
5709 ${rcmd} rm -f $metaea $metadata
5714 local devname=$(mdsdevname ${SINGLEMDS//mds/})
5715 local mntpt=$(facet_mntpt brpt)
5716 local rcmd="do_facet ${SINGLEMDS}"
5718 local opts=${MDS_MOUNT_OPTS}
5720 if ! ${rcmd} test -b ${devname}; then
5721 opts=$(csa_add "$opts" -o loop)
5724 echo "remove OI files: idx=${idx}"
5726 # step 1: build mount point
5727 ${rcmd} mkdir -p $mntpt
5729 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
5730 if [ -z $idx ]; then
5731 # step 3: remove all OI files
5732 ${rcmd} rm -fv $mntpt/oi.16*
5733 elif [ $idx -lt 2 ]; then
5734 ${rcmd} rm -fv $mntpt/oi.16.${idx}
5738 # others, rm oi.16.[idx, idx * idx, idx ** ...]
5739 for ((i=${idx}; i<64; i=$((i * idx)))); do
5740 ${rcmd} rm -fv $mntpt/oi.16.${i}
5744 ${rcmd} umount -d $mntpt || return 2
5745 # OI files will be recreated when mounted as lustre next time.