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 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
34 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
36 if [ -f "$EXCEPT_LIST_FILE" ]; then
37 echo "Reading test skip list from $EXCEPT_LIST_FILE"
42 # check config files for options in decreasing order of preference
43 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
44 MODPROBECONF=/etc/modprobe.d/lustre.conf
45 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
46 MODPROBECONF=/etc/modprobe.d/Lustre
47 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
48 MODPROBECONF=/etc/modprobe.conf
52 [[ $DIR/ = $MOUNT/* ]] || \
53 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
54 [[ $DIR1/ = $MOUNT1/* ]] || \
55 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
56 [[ $DIR2/ = $MOUNT2/* ]] || \
57 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
59 [ -n "$failed" ] && exit 99 || true
63 echo "usage: $0 [-r] [-f cfgfile]"
71 [ "$TESTSUITE" == "lfsck" ] && return 0
72 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
74 local form="%-13s %-17s %-9s %s %s\n"
75 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
76 echo "------------------------------------------------------------------------------------"
77 for O in $DEFAULT_SUITES; do
78 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
79 [ "${!O}" = "no" ] && continue || true
80 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
81 local log=${TMP}/${o}.log
82 if is_sanity_benchmark $o; then
83 log=${TMP}/sanity-benchmark.log
88 local status=Unfinished
90 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
91 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | sort -nr -k 3 | head -5 | awk '{ print $2":"$3"s" }')
92 total=$(grep duration $log | awk '{ print $2}')
93 if [ "${!O}" = "done" ]; then
97 local durations=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | awk '{ print $2":"$3"|" }')
98 details=$(printf "%s\n%s %s %s\n" "$details" "DDETAILS" "$O" "$(echo $durations)")
101 printf "$form" $status "$O" "${total}" "E=$skipped"
102 printf "$form" "-" "-" "-" "S=$(echo $slow)"
105 for O in $DEFAULT_SUITES; do
106 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
107 if [ "${!O}" = "no" ]; then
108 printf "$form" "Skipped" "$O" ""
112 # print the detailed tests durations if DDETAILS=true
119 export LUSTRE=`absolute_path $LUSTRE`
120 export TESTSUITE=`basename $0 .sh`
121 export TEST_FAILED=false
122 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
124 export MKE2FS=${MKE2FS:-mke2fs}
125 export DEBUGFS=${DEBUGFS:-debugfs}
126 export TUNE2FS=${TUNE2FS:-tune2fs}
127 export E2LABEL=${E2LABEL:-e2label}
128 export DUMPE2FS=${DUMPE2FS:-dumpe2fs}
129 export E2FSCK=${E2FSCK:-e2fsck}
130 export LFSCK_BIN=${LFSCK_BIN:-lfsck}
132 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after each test suite
133 export FSCK_MAX_ERR=4 # File system errors left uncorrected
135 export ZFS=${ZFS:-zfs}
136 export ZPOOL=${ZPOOL:-zpool}
137 export ZDB=${ZDB:-zdb}
139 #[ -d /r ] && export ROOT=${ROOT:-/r}
140 export TMP=${TMP:-$ROOT/tmp}
141 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
142 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
143 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
145 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
146 if ! echo $PATH | grep -q $LUSTRE/utils; then
147 export PATH=$LUSTRE/utils:$PATH
149 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
150 export PATH=$LUSTRE/utils/gss:$PATH
152 if ! echo $PATH | grep -q $LUSTRE/tests; then
153 export PATH=$LUSTRE/tests:$PATH
155 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
156 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
158 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
159 [ ! -f "$LST" ] && export LST=$(which lst)
160 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
161 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
162 # Ubuntu, at least, has a truncate command in /usr/bin
163 # so fully path our truncate command.
164 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
165 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
166 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
167 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
168 export PATH=$LUSTRE/tests/racer:$PATH:
170 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
171 export PATH=$LUSTRE/tests/mpi:$PATH
173 export RSYNC_RSH=${RSYNC_RSH:-rsh}
175 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
176 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
177 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
178 [ ! -f "$LFS" ] && export LFS=$(which lfs)
179 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
180 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
182 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
183 if [ ! -f "$L_GETIDENTITY" ]; then
184 if `which l_getidentity > /dev/null 2>&1`; then
185 export L_GETIDENTITY=$(which l_getidentity)
187 export L_GETIDENTITY=NONE
190 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
191 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID=$(which ll_decode_filter_fid)
192 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
193 [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre)
194 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
195 [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre)
196 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
197 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
198 [ ! -f "$LUSTRE_RMMOD" ] &&
199 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
200 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
201 [ ! -f "$LFS_MIGRATE" ] &&
202 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
203 export NAME=${NAME:-local}
204 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
205 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] && \
206 export LGSSD=$(which lgssd)
207 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
208 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
209 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
211 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
214 if [ "$ACCEPTOR_PORT" ]; then
215 export PORT_OPT="--port $ACCEPTOR_PORT"
220 echo "Using GSS/krb5 ptlrpc security flavor"
221 which lgss_keyring > /dev/null 2>&1 || \
222 error_exit "built with gss disabled! SEC=$SEC"
233 IDENTITY_UPCALL=false
236 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
238 # Paths on remote nodes, if different
239 export RLUSTRE=${RLUSTRE:-$LUSTRE}
240 export RPWD=${RPWD:-$PWD}
241 export I_MOUNTED=${I_MOUNTED:-"no"}
242 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mds.ko -a \
243 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mds.ko -a \
244 ! -f `dirname $0`/../mds/mds.ko ]; then
245 export CLIENTMODSONLY=yes
248 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
252 while getopts "rvwf:" opt $*; do
255 r) REFORMAT=--reformat;;
257 w) WRITECONF=writeconf;;
262 shift $((OPTIND - 1))
265 # print the durations of each test if "true"
266 DDETAILS=${DDETAILS:-false}
267 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
275 ncpts=$(do_facet $facet "lctl get_param -n " \
276 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
278 if [ $ncpts -eq 0 ]; then
286 # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
287 eval set -- $(tr "[:punct:]" " " <<< $*)
289 echo -n $((($1 << 16) | ($2 << 8) | $3))
292 export LINUX_VERSION=$(uname -r | sed -e "s/[-.]/ /3" -e "s/ .*//")
293 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
296 /sbin/lsmod | grep -q "^\<$1\>"
299 # Load a module on the system where this is running.
301 # Synopsis: load_module module_name [module arguments for insmod/modprobe]
303 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
304 # will be used as the arguments. Otherwise arguments will be obtained from
305 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
312 BASE=`basename $module $EXT`
314 module_loaded ${BASE} && return
316 # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
318 if [ $# -eq 0 ]; then
319 # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
320 # Bash until 4.x, so we resort to eval.
321 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
322 eval set -- \$$optvar
323 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
324 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
325 set -- $(grep -P "^options\\s+${BASE}" $MODPROBECONF)
326 # Get rid of "options $module"
327 (($# > 0)) && shift 2
329 # Ensure we have accept=all for lnet
330 if [ $(basename $module) = lnet ]; then
331 # OK, this is a bit wordy...
332 local arg accept_all_present=false
334 [ "$arg" = accept=all ] && accept_all_present=true
336 $accept_all_present || set -- "$@" accept=all
341 [ $# -gt 0 ] && echo "${module} options: '$*'"
343 # Note that insmod will ignore anything in modprobe.conf, which is why we're
344 # passing options on the command-line.
345 if [ "$BASE" == "lnet_selftest" ] && \
346 [ -f ${LUSTRE}/../lnet/selftest/${module}${EXT} ]; then
347 insmod ${LUSTRE}/../lnet/selftest/${module}${EXT}
348 elif [ -f ${LUSTRE}/${module}${EXT} ]; then
349 insmod ${LUSTRE}/${module}${EXT} "$@"
351 # must be testing a "make install" or "rpm" installation
352 # note failed to load ptlrpc_gss is considered not fatal
353 if [ "$BASE" == "ptlrpc_gss" ]; then
354 modprobe $BASE "$@" 2>/dev/null || echo "gss/krb5 is not supported"
361 llite_lloop_enabled() {
362 local n1=$(uname -r | cut -d. -f1)
363 local n2=$(uname -r | cut -d. -f2)
364 local n3=$(uname -r | cut -d- -f1 | cut -d. -f3)
366 # load the llite_lloop module for < 2.6.32 kernels
367 if [[ $n1 -lt 2 ]] || [[ $n1 -eq 2 && $n2 -lt 6 ]] || \
368 [[ $n1 -eq 2 && $n2 -eq 6 && $n3 -lt 32 ]] || \
375 load_modules_local() {
376 if [ "$USE_OFD" == yes ]; then
377 if module_loaded obdfilter; then
378 if ! $LUSTRE_RMMOD ldiskfs; then
379 echo "$HOSTNAME may still be using obdfilter.ko"
384 if module_loaded ofd; then
385 if ! $LUSTRE_RMMOD ldiskfs; then
386 echo "$HOSTNAME may still be using ofd.ko"
392 if [ -n "$MODPROBE" ]; then
394 echo "Using modprobe to load modules"
398 echo Loading modules from $LUSTRE
402 if [ -f /sys/devices/system/cpu/online ]; then
403 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
404 echo "detected $ncpus online CPUs by sysfs"
406 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
408 if [ $rc -eq 0 ]; then
409 echo "detected $ncpus online CPUs by getconf"
411 echo "Can't detect number of CPUs"
417 # if there is only one CPU core, libcfs can only create one partition
418 # if there is more than 4 CPU cores, libcfs should create multiple CPU
419 # partitions. So we just force libcfs to create 2 partitions for
420 # system with 2 or 4 cores
421 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
422 # force to enable multiple CPU partitions
423 echo "Force libcfs to create 2 CPU partitions"
426 echo "libcfs will create CPU partition based on online CPUs"
429 load_module ../libcfs/libcfs/libcfs cpu_npartitions=$ncpts
431 [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
432 [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
433 load_module ../lnet/lnet/lnet
434 LNETLND=${LNETLND:-"socklnd/ksocklnd"}
435 load_module ../lnet/klnds/$LNETLND
436 load_module lvfs/lvfs
437 load_module obdclass/obdclass
438 load_module ptlrpc/ptlrpc
439 load_module ptlrpc/gss/ptlrpc_gss
447 load_module obdecho/obdecho
448 if ! client_only; then
449 SYMLIST=/proc/kallsyms
450 grep -q crc16 $SYMLIST || { modprobe crc16 2>/dev/null || true; }
451 grep -q -w jbd $SYMLIST || { modprobe jbd 2>/dev/null || true; }
452 grep -q -w jbd2 $SYMLIST || { modprobe jbd2 2>/dev/null || true; }
453 [ "$LQUOTA" != "no" ] && load_module quota/lquota $LQUOTAOPTS
454 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
455 load_module osd-zfs/osd_zfs
460 if [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
462 # This block shall be moved up beside osd-zfs as soon
463 # as osd-ldiskfs stops using mdd symbols.
465 grep -q exportfs_decode_fh $SYMLIST ||
466 { modprobe exportfs 2> /dev/null || true; }
467 load_module ../ldiskfs/ldiskfs/ldiskfs
468 load_module lvfs/fsfilt_ldiskfs
469 load_module osd-ldiskfs/osd_ldiskfs
474 if [ "$USE_OFD" == yes ]; then
477 load_module obdfilter/obdfilter
482 load_module llite/lustre
483 llite_lloop_enabled && load_module llite/llite_lloop
484 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
486 rm -f $OGDB/ogdb-$HOSTNAME
487 $LCTL modules > $OGDB/ogdb-$HOSTNAME
489 # 'mount' doesn't look in $PATH, just sbin
490 if [ -f $LUSTRE/utils/mount.lustre ] && \
491 ! grep -qe "/sbin/mount\.lustre " /proc/mounts; then
492 [ ! -f /sbin/mount.lustre ] && touch /sbin/mount.lustre
493 mount --bind $LUSTRE/utils/mount.lustre /sbin/mount.lustre || true
500 # load modules on remote nodes optionally
501 # lustre-tests have to be installed on these nodes
502 if $LOAD_MODULES_REMOTE ; then
503 local list=$(comma_list $(remote_nodes_list))
504 echo loading modules on $list
505 do_rpc_nodes $list load_modules_local
510 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
511 LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
512 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
513 echo "$LEAK_LUSTRE" 1>&2
514 echo "$LEAK_PORTALS" 1>&2
515 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
516 echo "Memory leaks detected"
517 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
523 wait_exit_ST client # bug 12845
525 $LUSTRE_RMMOD ldiskfs || return 2
527 if $LOAD_MODULES_REMOTE ; then
528 local list=$(comma_list $(remote_nodes_list))
529 if [ ! -z $list ]; then
530 echo unloading modules on $list
531 do_rpc_nodes $list $LUSTRE_RMMOD ldiskfs
532 do_rpc_nodes $list check_mem_leak
536 if grep -qe "/sbin/mount\.lustre" /proc/mounts; then
537 umount /sbin/mount.lustre || true
538 [ -w /sbin/mount.lustre -a ! -s /sbin/mount.lustre ] && \
539 rm -f /sbin/mount.lustre || true
542 check_mem_leak || return 254
544 echo "modules unloaded."
548 check_gss_daemon_nodes() {
552 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
553 if [ \\\"\\\$num\\\" -ne 1 ]; then
554 echo \\\$num instance of $dname;
559 check_gss_daemon_facet() {
563 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
564 if [ $num -ne 1 ]; then
565 echo "$num instance of $dname on $facet"
574 echo Stopping $@ on $list
575 do_nodes $list "killall -2 $@ 2>/dev/null || true"
578 # start gss daemons on all nodes, or
579 # "daemon" on "list" if set
580 start_gss_daemons() {
584 if [ "$list" ] && [ "$daemon" ] ; then
585 echo "Starting gss daemon on nodes: $list"
586 do_nodes $list "$daemon" || return 8
590 local list=$(comma_list $(mdts_nodes))
592 echo "Starting gss daemon on mds: $list"
593 do_nodes $list "$LSVCGSSD -v" || return 1
595 do_nodes $list "$LGSSD -v" || return 2
598 list=$(comma_list $(osts_nodes))
599 echo "Starting gss daemon on ost: $list"
600 do_nodes $list "$LSVCGSSD -v" || return 3
601 # starting on clients
603 local clients=${CLIENTS:-`hostname`}
605 echo "Starting $LGSSD on clients $clients "
606 do_nodes $clients "$LGSSD -v" || return 4
609 # wait daemons entering "stable" status
613 # check daemons are running
615 list=$(comma_list $(mdts_nodes) $(osts_nodes))
616 check_gss_daemon_nodes $list lsvcgssd || return 5
618 list=$(comma_list $(mdts_nodes))
619 check_gss_daemon_nodes $list lgssd || return 6
622 check_gss_daemon_nodes $clients lgssd || return 7
627 local list=$(comma_list $(mdts_nodes))
629 send_sigint $list lsvcgssd lgssd
631 list=$(comma_list $(osts_nodes))
632 send_sigint $list lsvcgssd
634 list=${CLIENTS:-`hostname`}
635 send_sigint $list lgssd
640 if ! module_loaded ptlrpc_gss; then
641 load_module ptlrpc/gss/ptlrpc_gss
642 module_loaded ptlrpc_gss ||
643 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
645 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
647 if [ -n "$LGSS_KEYRING_DEBUG" ]; then
648 echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
656 # maybe cleanup credential cache?
663 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9]\+//' |
664 tr '[:lower:]' '[:upper:]'
670 if [ $facet == mgs ]; then
674 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
682 if [ -n "${!var}" ]; then
687 var=$(facet_type $facet)FSTYPE
688 if [ -n "${!var}" ]; then
693 if [ -n "$FSTYPE" ]; then
705 local facets=$(get_facets)
708 for facet in ${facets//,/ }; do
709 if [ $node == $(facet_host $facet) ] ||
710 [ $node == "$(facet_failover_host $facet)" ]; then
711 fstype=$(facet_fstype $facet)
712 if [[ $fstypes != *$fstype* ]]; then
713 fstypes+="${fstypes:+,}$fstype"
724 local fstype=$(facet_fstype $facet)
728 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
730 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
731 ${dev} 2>/dev/null");;
733 error "unknown fstype!";;
741 local device=$(mdsdevname $num)
742 local label=$(devicelabel mds$num ${device} | grep -v "CMD: ")
748 local device=$(ostdevname $num)
749 local label=$(devicelabel ost$num ${device} | grep -v "CMD: ")
754 # This and set_obdfilter_param() shall be used to access OSD parameters
755 # once existed under "obdfilter":
760 # writethrough_cache_enable
762 get_obdfilter_param() {
764 local device=${2:-$FSNAME-OST*}
767 do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
768 osd-*.$device.$name 2>&1" | grep -v 'Found no match'
771 set_obdfilter_param() {
773 local device=${2:-$FSNAME-OST*}
777 do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
778 osd-*.$device.$name=$value 2>&1" | grep -v 'Found no match'
782 local dz=${1:-$DEBUG_SIZE}
784 if [ -f /sys/devices/system/cpu/possible ]; then
785 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
787 local cpus=$(getconf _NPROCESSORS_CONF)
790 # bug 19944, adjust size to be -gt num_possible_cpus()
791 # promise 2MB for every cpu at least
792 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
795 lctl set_param debug_mb=$dz
798 set_default_debug () {
799 local debug=${1:-"$PTLDEBUG"}
800 local subsys=${2:-"$SUBSYSTEM"}
801 local debug_size=${3:-$DEBUG_SIZE}
803 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
804 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
806 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
809 set_default_debug_nodes () {
812 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
813 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
817 [[ -n $nodes ]] && do_rpc_nodes $nodes set_default_debug \
818 \\\"$PTLDEBUG\\\" \\\"$SUBSYSTEM\\\" $DEBUG_SIZE || true
821 set_default_debug_facet () {
823 local node=$(facet_active_host $facet)
824 [ -z "$node" ] && echo "No host defined for facet $facet" && exit 1
826 set_default_debug_nodes $node
831 local facets=${1:-$(get_facets)}
834 for facet in ${facets//,/ }; do
837 [ $RC -eq 0 ] && continue
839 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
840 skip "Restart of $facet failed!." && touch $LU482_FAILED
842 error "Restart of $facet failed!"
849 # Add argument "arg" (e.g., "loop") to the comma-separated list
850 # of arguments for option "opt" (e.g., "-o") on command
851 # line "opts" (e.g., "-o flock").
857 local opt_pattern="\([[:space:]]\+\|^\)$opt"
859 if echo "$opts" | grep -q $opt_pattern; then
860 opts=$(echo "$opts" | sed -e \
861 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
863 opts+="${opts:+ }$opt $arg"
871 local dev=$(facet_active $facet)_dev
872 local opt=${facet}_opt
873 local mntpt=$(facet_mntpt $facet)
874 local opts="${!opt} $@"
876 if [ $(facet_fstype $facet) == ldiskfs ] &&
877 ! do_facet $facet test -b ${!dev}; then
878 opts=$(csa_add "$opts" -o loop)
881 echo "Starting ${facet}: $opts ${!dev} $mntpt"
882 # for testing LU-482 error handling in mount_facets() and test_0a()
883 if [ -f $TMP/test-lu482-trigger ]; then
886 do_facet ${facet} "mkdir -p $mntpt; mount -t lustre $opts \
890 if [ $RC -ne 0 ]; then
891 echo "Start of ${!dev} on ${facet} failed ${RC}"
893 set_default_debug_facet $facet
895 label=$(devicelabel ${facet} ${!dev})
896 [ -z "$label" ] && echo no label for ${!dev} && exit 1
897 eval export ${facet}_svc=${label}
898 echo Started ${label}
903 # start facet device options
909 eval export ${facet}_dev=${device}
910 eval export ${facet}_opt=\"$@\"
912 local varname=${facet}failover_dev
913 if [ -n "${!varname}" ] ; then
914 eval export ${facet}failover_dev=${!varname}
916 eval export ${facet}failover_dev=$device
919 local mntpt=$(facet_mntpt $facet)
920 do_facet ${facet} mkdir -p $mntpt
921 eval export ${facet}_MOUNT=$mntpt
928 # When a ZFS OSD is made read-only by replay_barrier(), its pool is "freezed".
929 # Because stopping corresponding target may not clear this in-memory state, we
930 # need to zap the pool from memory by exporting and reimporting the pool.
932 # Although the uberblocks are not updated when a pool is freezed, transactions
933 # are still written to the disks. Modified blocks may be cached in memory when
934 # tests try reading them back. The export-and-reimport process also evicts any
935 # cached pool data from memory to provide the correct "data loss" semantics.
939 local fstype=$(facet_fstype $facet)
944 if [ "${fstype}" == "zfs" ]; then
945 _dev=$(facet_active $facet)_dev
946 dev=${!_dev} # expand _dev to its value, e.g. ${mds1_dev}
947 poolname="${dev%%/*}" # poolname is string before "/"
949 if [ "${poolname}" == "" ]; then
950 echo "invalid dataset name: $dev"
953 do_facet $facet "cp /etc/zfs/zpool.cache /tmp/zpool.cache.back"
954 do_facet $facet "$ZPOOL export ${poolname}"
955 do_facet $facet "$ZPOOL import -f -c /tmp/zpool.cache.back \
964 local HOST=`facet_active_host $facet`
965 [ -z $HOST ] && echo stop: no host for $facet && return 0
967 local mntpt=$(facet_mntpt $facet)
968 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts") || true
969 if [ ${running} -ne 0 ]; then
970 echo "Stopping $mntpt (opts:$@) on $HOST"
971 do_facet ${facet} umount -d $@ $mntpt
974 # umount should block, but we should wait for unrelated obd's
975 # like the MGS or MGC to also stop.
976 wait_exit_ST ${facet}
979 # save quota version (both administrative and operational quotas)
980 # add an additional parameter if mountpoint is ever different from $MOUNT
981 quota_save_version() {
982 local fsname=${2:-$FSNAME}
984 local ver=$(tr -c -d "123" <<< $spec)
985 local type=$(tr -c -d "ug" <<< $spec)
987 [ -n "$ver" -a "$ver" != "3" ] && error "wrong quota version specifier"
989 [ -n "$type" ] && { $LFS quotacheck -$type $MOUNT || error "quotacheck has failed"; }
991 do_facet mgs "lctl conf_param ${fsname}-MDT*.mdd.quota_type=$spec"
993 local osts=$(get_facets OST)
994 for ost in ${osts//,/ }; do
996 do_facet mgs "lctl conf_param ${!varsvc}.ost.quota_type=$spec"
1000 # client could mount several lustre
1002 local fsname=${1:-$FSNAME}
1004 do_facet mgs lctl get_param mdd.${fsname}-MDT*.quota_type || rc=$?
1005 do_nodes $(comma_list $(osts_nodes)) \
1006 lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
1010 restore_quota_type () {
1011 local mntpt=${1:-$MOUNT}
1012 local quota_type=$(quota_type $FSNAME | grep MDT | cut -d "=" -f2)
1013 if [ ! "$old_QUOTA_TYPE" ] || [ "$quota_type" = "$old_QUOTA_TYPE" ]; then
1016 quota_save_version $old_QUOTA_TYPE
1022 if [ "$USE_OFD" = "yes" ]; then
1023 $LFS quotacheck $mntpt || error "quotacheck failed"
1027 # We need save the original quota_type params, and restore them after testing
1029 # Suppose that quota type the same on mds and ost
1030 local quota_type=$(quota_type | grep MDT | cut -d "=" -f2)
1031 [ ${PIPESTATUS[0]} -eq 0 ] || error "quota_type failed!"
1032 echo "[HOST:$HOSTNAME] [old_quota_type:$quota_type] [new_quota_type:$QUOTA_TYPE]"
1033 if [ "$quota_type" != "$QUOTA_TYPE" ]; then
1034 export old_QUOTA_TYPE=$quota_type
1035 quota_save_version $QUOTA_TYPE
1037 qtype=$(tr -c -d "ug" <<< $QUOTA_TYPE)
1038 $LFS quotacheck -$qtype $mntpt || error "quotacheck has failed for $type"
1041 local quota_usrs=$QUOTA_USERS
1043 # get_filesystem_size
1044 local disksz=$(lfs df $mntpt | grep "filesystem summary:" | awk '{print $3}')
1045 local blk_soft=$((disksz + 1024))
1046 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
1048 local Inodes=$(lfs df -i $mntpt | grep "filesystem summary:" | awk '{print $3}')
1049 local i_soft=$Inodes
1050 local i_hard=$((i_soft + i_soft / 20))
1052 echo "Total disk size: $disksz block-softlimit: $blk_soft block-hardlimit:
1053 $blk_hard inode-softlimit: $i_soft inode-hardlimit: $i_hard"
1056 for usr in $quota_usrs; do
1057 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
1059 cmd="$LFS setquota -$type $usr -b $blk_soft -B $blk_hard -i $i_soft -I $i_hard $mntpt"
1061 eval $cmd || error "$cmd FAILED!"
1063 # display the quota status
1064 echo "Quota settings for $usr : "
1065 $LFS quota -v -u $usr $mntpt || true
1072 local OPTIONS=${3:-$MOUNTOPT}
1074 local device=$MGSNID:/$FSNAME
1075 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1076 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
1080 echo "Starting client: $client: $OPTIONS $device $mnt"
1081 do_node $client mkdir -p $mnt
1082 do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
1084 set_default_debug_nodes $client
1096 [ "$3" ] && force=-f
1097 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
1098 if [ $running -ne 0 ]; then
1099 echo "Stopping client $client $mnt (opts:$force)"
1100 do_node $client lsof -t $mnt || need_kill=no
1101 if [ "x$force" != "x" -a "x$need_kill" != "xno" ]; then
1102 pids=$(do_node $client lsof -t $mnt | sort -u);
1103 if [ -n $pids ]; then
1104 do_node $client kill -9 $pids || true
1108 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") || true
1109 if [ $busy -ne 0 ] ; then
1110 echo "$mnt is still busy, wait one second" && sleep 1
1111 do_node $client umount $force $mnt
1116 # nodes is comma list
1117 sanity_mount_check_nodes () {
1123 # FIXME: assume that all cluster nodes run the same os
1124 [ "$(uname)" = Linux ] || return 0
1127 for mnt in $mnts ; do
1128 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
1129 mpts=\\\$(mount | grep -c $mnt' ');
1130 if [ \\\$running -ne \\\$mpts ]; then
1131 echo \\\$(hostname) env are INSANE!;
1134 [ $? -eq 0 ] || rc=1
1139 sanity_mount_check_servers () {
1140 [ "$CLIENTONLY" ] &&
1141 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
1142 echo Checking servers environments
1144 # FIXME: modify get_facets to display all facets wo params
1145 local facets="$(get_facets OST),$(get_facets MDS),mgs"
1149 for facet in ${facets//,/ }; do
1150 node=$(facet_host ${facet})
1151 mntpt=$(facet_mntpt $facet)
1152 sanity_mount_check_nodes $node $mntpt ||
1153 { error "server $node environments are insane!"; return 1; }
1157 sanity_mount_check_clients () {
1158 local clients=${1:-$CLIENTS}
1159 local mntpt=${2:-$MOUNT}
1160 local mntpt2=${3:-$MOUNT2}
1162 [ -z $clients ] && clients=$(hostname)
1163 echo Checking clients $clients environments
1165 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
1166 error "clients environments are insane!"
1169 sanity_mount_check () {
1170 sanity_mount_check_servers || return 1
1171 sanity_mount_check_clients || return 2
1174 # mount clients if not mouted
1175 zconf_mount_clients() {
1178 local OPTIONS=${3:-$MOUNTOPT}
1180 local device=$MGSNID:/$FSNAME
1181 if [ -z "$mnt" -o -z "$FSNAME" ]; then
1182 echo Bad zconf mount command: opt=$OPTIONS dev=$device mnt=$mnt
1186 echo "Starting client $clients: $OPTIONS $device $mnt"
1189 running=\\\$(mount | grep -c $mnt' ');
1191 if [ \\\$running -eq 0 ] ; then
1193 mount -t lustre $OPTIONS $device $mnt;
1196 exit \\\$rc" || return ${PIPESTATUS[0]}
1198 echo "Started clients $clients: "
1199 do_nodes $clients "mount | grep $mnt' '"
1201 set_default_debug_nodes $clients
1206 zconf_umount_clients() {
1211 [ "$3" ] && force=-f
1213 echo "Stopping clients: $clients $mnt (opts:$force)"
1214 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
1215 if [ \\\$running -ne 0 ] ; then
1216 echo Stopping client \\\$(hostname) $mnt opts:$force;
1217 lsof $mnt || need_kill=no;
1218 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
1219 pids=\\\$(lsof -t $mnt | sort -u);
1220 if [ -n \\\"\\\$pids\\\" ]; then
1224 while umount $force $mnt 2>&1 | grep -q "busy"; do
1225 echo "$mnt is still busy, wait one second" && sleep 1;
1232 echo + $POWER_DOWN $node
1236 shutdown_node_hard () {
1238 local attempts=$SHUTDOWN_ATTEMPTS
1240 for i in $(seq $attempts) ; do
1243 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
1244 echo "waiting for $host to fail attempts=$attempts"
1245 [ $i -lt $attempts ] || \
1246 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
1252 local mnt=${2:-$MOUNT}
1255 if [ "$FAILURE_MODE" = HARD ]; then
1256 shutdown_node_hard $client
1258 zconf_umount_clients $client $mnt -f
1264 local facets="$(get_facets OST),$(get_facets MDS)"
1267 combined_mgs_mds || facets="$facets,mgs"
1269 for facet in ${facets//,/ }; do
1270 if [ $(facet_active_host $facet) == $host ]; then
1271 affected="$affected $facet"
1275 echo $(comma_list $affected)
1280 local host=${2:-$(facet_host $facet)}
1282 local label=$(convert_facet2label $facet)
1283 do_node $host lctl dl | awk '{print $4}' | grep -q $label
1286 facets_up_on_host () {
1288 local facets=$(facets_on_host $host)
1291 for facet in ${facets//,/ }; do
1292 if $(facet_up $facet $host); then
1293 affected_up="$affected_up $facet"
1297 echo $(comma_list $affected_up)
1303 if [ "$FAILURE_MODE" = HARD ]; then
1304 shutdown_node_hard $(facet_active_host $facet)
1312 echo + $POWER_UP $node
1325 if [ "$FAILURE_MODE" = HARD ]; then
1326 reboot_node $(facet_active_host $facet)
1328 refresh_disk ${facet}
1335 if [ "$FAILURE_MODE" = HARD ]; then
1345 for facet in ${facets//,/ }; do
1346 hosts=$(expand_list $hosts $(facet_host $facet) )
1352 _check_progs_installed () {
1356 for prog in $progs; do
1357 if ! [ "$(which $prog)" -o "${!prog}" ]; then
1358 echo $prog missing on $(hostname)
1365 check_progs_installed () {
1369 do_rpc_nodes $nodes _check_progs_installed $@
1372 # recovery-scale functions
1374 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
1377 start_client_load() {
1380 local var=$(node_var_name $client)_load
1381 eval export ${var}=$load
1383 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
1384 BREAK_ON_ERROR=$BREAK_ON_ERROR \
1385 END_RUN_FILE=$END_RUN_FILE \
1386 LOAD_PID_FILE=$LOAD_PID_FILE \
1387 TESTLOG_PREFIX=$TESTLOG_PREFIX \
1388 TESTNAME=$TESTNAME \
1389 DBENCH_LIB=$DBENCH_LIB \
1390 DBENCH_SRC=$DBENCH_SRC \
1393 log "Started client load: ${load} on $client"
1395 # get the children process IDs
1396 local pids=$(ps --ppid $ppid -o pid= | xargs)
1397 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
1401 start_client_loads () {
1402 local -a clients=(${1//,/ })
1403 local numloads=${#CLIENT_LOADS[@]}
1406 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
1407 testnum=$((nodenum % numloads))
1408 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[testnum]}
1410 # bug 22169: wait the background threads to start
1414 # only for remote client
1415 check_client_load () {
1417 local var=$(node_var_name $client)_load
1418 local TESTLOAD=run_${!var}.sh
1420 ps auxww | grep -v grep | grep $client | grep -q "$TESTLOAD" || return 1
1422 # bug 18914: try to connect several times not only when
1423 # check ps, but while check_catastrophe also
1426 while [ $RC = 254 -a $tries -gt 0 ]; do
1430 if ! check_catastrophe $client; then
1432 if [ $RC -eq 254 ]; then
1433 # FIXME: not sure how long we shuold sleep here
1437 echo "check catastrophe failed: RC=$RC "
1441 # We can continue try to connect if RC=254
1442 # Just print the warning about this
1443 if [ $RC = 254 ]; then
1444 echo "got a return status of $RC from do_node while checking catastrophe on $client"
1447 # see if the load is still on the client
1450 while [ $RC = 254 -a $tries -gt 0 ]; do
1454 if ! do_node $client "ps auxwww | grep -v grep | grep -q $TESTLOAD"; then
1459 if [ $RC = 254 ]; then
1460 echo "got a return status of $RC from do_node while checking (catastrophe and 'ps') the client load on $client"
1461 # see if we can diagnose a bit why this is
1466 check_client_loads () {
1467 local clients=${1//,/ }
1471 for client in $clients; do
1472 check_client_load $client
1474 if [ "$rc" != 0 ]; then
1475 log "Client load failed on node $client, rc=$rc"
1481 restart_client_loads () {
1482 local clients=${1//,/ }
1483 local expectedfail=${2:-""}
1487 for client in $clients; do
1488 check_client_load $client
1490 if [ "$rc" != 0 -a "$expectedfail" ]; then
1491 local var=$(node_var_name $client)_load
1492 start_client_load $client ${!var}
1493 echo "Restarted client load ${!var}: on $client. Checking ..."
1494 check_client_load $client
1496 if [ "$rc" != 0 ]; then
1497 log "Client load failed to restart on node $client, rc=$rc"
1498 # failure one client load means test fail
1499 # we do not need to check other
1508 # Start vmstat and save its process ID in a file.
1513 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1516 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
1517 2>/dev/null </dev/null & echo \\\$! > $pid_file"
1520 # Display the nodes on which client loads failed.
1521 print_end_run_file() {
1525 [ -s $file ] || return 0
1527 echo "Found the END_RUN_FILE file: $file"
1530 # A client load will stop if it finds the END_RUN_FILE file.
1531 # That does not mean the client load actually failed though.
1532 # The first node in END_RUN_FILE is the one we are interested in.
1535 if [ -n "$node" ]; then
1536 local var=$(node_var_name $node)_load
1538 local prefix=$TESTLOG_PREFIX
1539 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
1540 local stdout_log=$prefix.run_${!var}_stdout.$node.log
1541 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
1543 echo "Client load ${!var} failed on node $node:"
1549 # Stop the process which had its PID saved in a file.
1554 [ -z "$nodes" -o -z "$pid_file" ] && return 0
1556 do_nodes $nodes "test -f $pid_file &&
1557 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
1560 # Stop all client loads.
1561 stop_client_loads() {
1562 local nodes=${1:-$CLIENTS}
1565 # stop the client loads
1566 stop_process $nodes $pid_file
1568 # clean up the processes that started them
1569 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
1571 # End recovery-scale functions
1573 # verify that lustre actually cleaned up properly
1575 [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
1576 error "LBUG/LASSERT detected"
1577 BUSY=`dmesg | grep -i destruct || true`
1578 if [ "$BUSY" ]; then
1580 [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
1584 check_mem_leak || exit 204
1586 [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl && \
1587 echo "$0: lustre didn't clean up..." 1>&2 && return 202 || true
1589 if module_loaded lnet || module_loaded libcfs; then
1590 echo "$0: modules still loaded..." 1>&2
1608 RESULT=$(do_node $node "$TEST")
1609 if [ "$RESULT" == "$FINAL" ]; then
1610 [ -z "$RESULT" -o $WAIT -le $sleep ] ||
1611 echo "Updated after ${WAIT}s: wanted '$FINAL' got '$RESULT'"
1614 [ $WAIT -ge $MAX ] && break
1615 [ $((WAIT % print)) -eq 0 ] &&
1616 echo "Waiting $((MAX - WAIT)) secs for update"
1617 WAIT=$((WAIT + sleep))
1620 echo "Update not seen after ${MAX}s: wanted '$FINAL' got '$RESULT'"
1624 wait_update_facet () {
1626 wait_update $(facet_active_host $facet) "$@"
1630 do_node $(osts_nodes) "lctl set_param -n osd*.*OS*.force_sync 1" 2>&1 |
1631 grep -v 'Found no match'
1634 wait_delete_completed () {
1635 local TOTALPREV=`lctl get_param -n osc.*.kbytesavail | \
1636 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1640 while [ "$WAIT" -ne "$MAX_WAIT" ]; do
1642 TOTAL=`lctl get_param -n osc.*.kbytesavail | \
1643 awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1644 [ "$TOTAL" -eq "$TOTALPREV" ] && return 0
1645 echo "Waiting delete completed ... prev: $TOTALPREV current: $TOTAL "
1649 echo "Delete is not completed in $MAX_WAIT sec"
1656 # we can use "for" here because we are waiting the slowest
1657 for host in ${hostlist//,/ }; do
1658 check_network "$host" 900
1660 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
1667 for facet in ${facetlist//,/ }; do
1668 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
1670 wait_for_host $hostlist
1673 _wait_recovery_complete () {
1676 # Use default policy if $2 is not passed by caller.
1677 local MAX=${2:-$(max_recovery_time)}
1682 while [ $WAIT -lt $MAX ]; do
1683 STATUS=$(lctl get_param -n $param | grep status)
1685 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
1688 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
1690 echo "$param recovery not done in $MAX sec. $STATUS"
1694 wait_recovery_complete () {
1697 # with an assumption that at_max is the same on all nodes
1698 local MAX=${2:-$(max_recovery_time)}
1701 if [ "$FAILURE_MODE" = HARD ]; then
1702 facets=$(facets_on_host $(facet_active_host $facet))
1704 echo affected facets: $facets
1706 # we can use "for" here because we are waiting the slowest
1707 for facet in ${facets//,/ }; do
1708 local var_svc=${facet}_svc
1709 local param="*.${!var_svc}.recovery_status"
1711 local host=$(facet_active_host $facet)
1712 do_rpc_nodes $host _wait_recovery_complete $param $MAX
1716 wait_mds_ost_sync () {
1717 # just because recovery is done doesn't mean we've finished
1718 # orphan cleanup. Wait for llogs to get synchronized.
1719 echo "Waiting for orphan cleanup..."
1720 # MAX value includes time needed for MDS-OST reconnection
1721 local MAX=$(( TIMEOUT * 2 ))
1723 while [ $WAIT -lt $MAX ]; do
1724 local -a sync=($(do_nodes $(comma_list $(osts_nodes)) \
1725 "$LCTL get_param -n obdfilter.*.mds_sync"))
1728 for ((i=0; i<${#sync[@]}; i++)); do
1729 [ ${sync[$i]} -eq 0 ] && continue
1730 # there is a not finished MDS-OST synchronization
1734 sleep 2 # increase waiting time and cover statfs cache
1735 [ ${con} -eq 1 ] && return 0
1736 echo "Waiting $WAIT secs for $facet mds-ost sync done."
1739 echo "$facet recovery not done in $MAX sec. $STATUS"
1743 wait_destroy_complete () {
1744 echo "Waiting for destroy to be done..."
1745 # MAX value shouldn't be big as this mean server responsiveness
1746 # never increase this just to make test pass but investigate
1747 # why it takes so long time
1750 while [ $WAIT -lt $MAX ]; do
1751 local -a RPCs=($($LCTL get_param -n osc.*.destroys_in_flight))
1753 for ((i=0; i<${#RPCs[@]}; i++)); do
1754 [ ${RPCs[$i]} -eq 0 ] && continue
1755 # there are still some destroy RPCs in flight
1760 [ ${con} -eq 1 ] && return 0 # done waiting
1761 echo "Waiting $WAIT secs for destroys to be done."
1764 echo "Destroys weren't done in $MAX sec."
1774 # conf-sanity 31 takes a long time cleanup
1775 while [ $WAIT -lt 300 ]; do
1776 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null && lctl dl | grep ' ST '") || true
1777 [ -z "${running}" ] && return 0
1778 echo "waited $WAIT for${running}"
1779 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
1781 WAIT=$((WAIT + INTERVAL))
1783 echo "service didn't stop after $WAIT seconds. Still running:"
1788 wait_remote_prog () {
1794 [ "$PDSH" = "no_dsh" ] && return 0
1796 while [ $WAIT -lt $2 ]; do
1797 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
1798 [ -z "${running}" ] && return 0 || true
1799 echo "waited $WAIT for: "
1801 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
1803 WAIT=$((WAIT + INTERVAL))
1805 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
1806 [ -z "$pids" ] && return 0
1807 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
1808 # FIXME: not portable
1809 for pid in $pids; do
1810 cat /proc/${pid}/status || true
1811 cat /proc/${pid}/wchan || true
1813 kill -9 $pid || true
1822 # not every config has many clients
1824 if [ ! -z "$CLIENTS" ]; then
1825 $PDSH $CLIENTS "stat -f $MOUNT" > /dev/null
1827 stat -f $MOUNT > /dev/null
1833 # usually checked on particular client or locally
1835 if [ ! -z "$client" ]; then
1836 $PDSH $client "stat -f $MOUNT" > /dev/null
1838 stat -f $MOUNT > /dev/null
1846 client_reconnect() {
1847 uname -n >> $MOUNT/recon
1848 if [ -z "$CLIENTS" ]; then
1849 df $MOUNT; uname -n >> $MOUNT/recon
1851 do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
1853 echo Connected clients:
1855 ls -l $MOUNT/recon > /dev/null
1859 affected_facets () {
1862 local host=$(facet_active_host $facet)
1863 local affected=$facet
1865 if [ "$FAILURE_MODE" = HARD ]; then
1866 affected=$(facets_up_on_host $host)
1874 local host=$(facet_active_host $facet)
1876 echo "Failing $facet on node $host"
1878 local affected=$(affected_facets $facet)
1880 shutdown_facet $facet
1882 echo affected facets: $affected
1884 [ -n "$sleep_time" ] && sleep $sleep_time
1888 change_active $affected
1890 wait_for_facet $affected
1891 # start mgs first if it is affected
1892 if ! combined_mgs_mds && list_member $affected mgs; then
1893 mount_facet mgs || error "Restart of mgs failed"
1895 # FIXME; has to be changed to mount all facets concurrently
1896 affected=$(exclude_items_from_list $affected mgs)
1897 mount_facets $affected
1906 do_facet $facet "sync; sync; sync"
1909 # make sure there will be no seq change
1910 local clients=${CLIENTS:-$HOSTNAME}
1911 do_nodes $clients "f=${MOUNT}/fsa-\\\$(hostname); mcreate \\\$f; rm \\\$f"
1913 local svc=${facet}_svc
1914 do_facet $facet $LCTL --device %${!svc} notransno
1915 do_facet $facet $LCTL --device %${!svc} readonly
1916 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1917 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1920 replay_barrier_nodf() {
1921 local facet=$1 echo running=${running}
1922 do_facet $facet "sync; sync; sync"
1923 local svc=${facet}_svc
1924 echo Replay barrier on ${!svc}
1925 do_facet $facet $LCTL --device %${!svc} notransno
1926 do_facet $facet $LCTL --device %${!svc} readonly
1927 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1928 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1931 replay_barrier_nosync() {
1932 local facet=$1 echo running=${running}
1933 local svc=${facet}_svc
1934 echo Replay barrier on ${!svc}
1935 do_facet $facet $LCTL --device %${!svc} notransno
1936 do_facet $facet $LCTL --device %${!svc} readonly
1937 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
1938 $LCTL mark "local REPLAY BARRIER on ${!svc}"
1941 mds_evict_client() {
1942 UUID=`lctl get_param -n mdc.${mds1_svc}-mdc-*.uuid`
1943 do_facet mds1 "lctl set_param -n mdt.${mds1_svc}.evict_client $UUID"
1946 ost_evict_client() {
1947 UUID=`lctl get_param -n devices| grep ${ost1_svc}-osc- | egrep -v 'MDT' | awk '{print $5}'`
1948 do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.evict_client $UUID"
1952 facet_failover $* || error "failover: $?"
1953 clients_up || error "post-failover df: $?"
1958 facet_failover $facet
1964 refresh_disk ${facet}
1965 change_active $facet
1966 wait_for_facet $facet
1967 mount_facet $facet -o abort_recovery
1968 clients_up || echo "first df failed: $?"
1969 clients_up || error "post-failover df: $?"
1973 echo There is no lmc. This is mountconf, baby.
1977 host_nids_address() {
1981 if [ -n "$kind" ]; then
1982 nids=$(do_nodes $nodes "$LCTL list_nids | grep $kind | cut -f 1 -d '@'")
1984 nids=$(do_nodes $nodes "$LCTL list_nids all | cut -f 1 -d '@'")
1990 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1996 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
1997 ID=`xtprocadmin -n $1 2>/dev/null | egrep -v 'NID' | awk '{print $1}'`
1998 if [ -z "$ID" ]; then
1999 echo "Could not get a ptl id for $1..."
2008 h2name_or_ip "$1" "tcp"
2013 if [ "$1" = "client" -o "$1" = "'*'" ]; then echo \'*\'; else
2014 if type __h2elan >/dev/null 2>&1; then
2017 ID=`echo $1 | sed 's/[^0-9]*//g'`
2025 h2name_or_ip "$1" "o2ib"
2029 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
2030 # expressions format. As a bonus we can then just pass in those variables
2031 # to pdsh. What this function does is take a HOSTLIST type string and
2032 # expand it into a space deliminated list for us.
2040 [ -z "$hostlist" ] && return
2042 # Translate the case of [..],..,[..] to [..] .. [..]
2043 list="${hostlist/],/] }"
2045 [[ "$front" == *,* ]] && {
2048 list=${list/${old}/${new}}
2051 for item in $list; do
2052 # Test if we have any []'s at all
2053 if [ "$item" != "${item/\[/}" ]; then {
2054 # Expand the [*] into list
2058 if [ "$name" != "$item" ]; then
2059 group=${item#$name[*}
2062 for range in ${group//,/ }; do
2066 # Number of leading zeros
2069 end=$(echo $end | sed 's/0*//')
2070 [[ -z "$end" ]] && end=0
2071 [[ $padlen2 -gt $padlen ]] && {
2072 [[ $padlen2 -eq ${#end} ]] && padlen2=0
2075 begin=$(echo $begin | sed 's/0*//')
2076 [ -z $begin ] && begin=0
2078 for num in $(seq -f "%0${padlen}g" $begin $end); do
2079 value="${name#*,}${num}${back}"
2080 [ "$value" != "${value/\[/}" ] && {
2081 value=$(hostlist_expand "$value")
2083 myList="$myList $value"
2088 myList="$myList $item"
2091 myList=${myList//,/ }
2092 myList=${myList:1} # Remove first character which is a space
2094 # Filter any duplicates without sorting
2096 myList="${list%% *}"
2098 while [[ "$list" != ${myList##* } ]]; do
2099 list=${list//${list%% *} /}
2100 myList="$myList ${list%% *}"
2102 myList="${myList%* }";
2104 # We can select an object at a offset in the list
2107 for item in $myList; do
2109 [ $cnt -eq $offset ] && {
2113 [ $(get_node_count $myList) -ne 1 ] && myList=""
2121 [ "$facet" == client ] && echo -n $HOSTNAME && return
2122 varname=${facet}_HOST
2123 if [ -z "${!varname}" ]; then
2124 if [ "${facet:0:3}" == "ost" ]; then
2125 eval ${facet}_HOST=${ost_HOST}
2131 facet_failover_host() {
2135 var=${facet}failover_HOST
2136 if [ -n "${!var}" ]; then
2141 if [[ $facet == ost* ]]; then
2142 var=ostfailover_HOST
2143 if [ -n "${!var}" ]; then
2152 local activevar=${facet}active
2154 if [ -f $TMP/${facet}active ] ; then
2155 source $TMP/${facet}active
2158 active=${!activevar}
2159 if [ -z "$active" ] ; then
2166 facet_active_host() {
2168 local active=`facet_active $facet`
2169 if [ "$facet" == client ]; then
2172 echo `facet_host $active`
2180 facetlist=$(exclude_items_from_list $facetlist mgs)
2182 for facet in ${facetlist//,/ }; do
2183 local failover=${facet}failover
2184 local host=`facet_host $failover`
2185 [ -z "$host" ] && return
2187 local curactive=`facet_active $facet`
2188 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
2189 eval export ${facet}active=$facet
2191 eval export ${facet}active=$failover
2193 # save the active host for this facet
2194 local activevar=${facet}active
2195 echo "$activevar=${!activevar}" > $TMP/$activevar
2196 [[ $facet = mds1 ]] && combined_mgs_mds && \
2197 echo "mgsactive=${!activevar}" > $TMP/mgsactive
2198 local TO=`facet_active_host $facet`
2199 echo "Failover $facet to $TO"
2205 # do not stripe off hostname if verbose, bug 19215
2206 if [ x$1 = x--verbose ]; then
2214 if [ "$HOST" = "$HOSTNAME" ]; then
2216 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
2217 echo "cannot run remote command on $HOST with $myPDSH"
2221 echo "CMD: $HOST $@" >&2
2222 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2225 if [ "$myPDSH" = "rsh" ]; then
2226 # we need this because rsh does not return exit code of an executed command
2227 local command_status="$TMP/cs"
2228 rsh $HOST ":> $command_status"
2229 rsh $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;
2230 cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\") ||
2231 echo command failed >$command_status"
2232 [ -n "$($myPDSH $HOST cat $command_status)" ] && return 1 || true
2237 # print HOSTNAME for myPDSH="no_dsh"
2238 if [[ $myPDSH = no_dsh ]]; then
2239 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
2241 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")"
2244 $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed "s/^${HOST}: //"
2246 return ${PIPESTATUS[0]}
2250 do_node --verbose "$@"
2253 single_local_node () {
2254 [ "$1" = "$HOSTNAME" ]
2257 # Outputs environment variable assignments that should be passed to remote nodes
2261 local facets=$(get_facets)
2264 for var in ${!MODOPTS_*}; do
2266 echo -n " ${var}=\"$value\""
2269 echo -n " USE_OFD=$USE_OFD"
2271 for facet in ${facets//,/ }; do
2273 if [ -n "${!var}" ]; then
2274 echo -n " $var=${!var}"
2278 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
2279 if [ -n "${!var}" ]; then
2280 echo -n " $var=${!var}"
2284 if [ -n "$FSTYPE" ]; then
2285 echo -n " FSTYPE=$FSTYPE"
2291 # do not stripe off hostname if verbose, bug 19215
2292 if [ x$1 = x--verbose ]; then
2300 if single_local_node $rnodes; then
2302 do_nodev $rnodes "$@"
2304 do_node $rnodes "$@"
2309 # This is part from do_node
2312 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
2313 echo "cannot run remote command on $rnodes with $myPDSH" && return 128
2315 export FANOUT=$(get_node_count "${rnodes//,/ }")
2317 echo "CMD: $rnodes $@" >&2
2318 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
2321 # do not replace anything from pdsh output if -N is used
2322 # -N Disable hostname: prefix on lines of output.
2323 if $verbose || [[ $myPDSH = *-N* ]]; then
2324 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
2326 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
2328 return ${PIPESTATUS[0]}
2334 local HOST=`facet_active_host $facet`
2335 [ -z $HOST ] && echo No host defined for facet ${facet} && exit 1
2339 # Function: do_facet_random_file $FACET $FILE $SIZE
2340 # Creates FILE with random content on the given FACET of given SIZE
2342 do_facet_random_file() {
2346 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
2347 do_facet $facet "$cmd 2>/dev/null"
2350 do_facet_create_file() {
2354 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
2355 do_facet $facet "$cmd 2>/dev/null"
2359 do_nodes --verbose "$@"
2365 # make sure its not already running
2367 rm -f $TMP/${facet}active
2368 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
2369 do_facet ${facet} $MKFS $*
2376 local fstype=$(facet_fstype ost$num)
2380 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2381 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2383 #dataset name is independent of vdev device names
2384 eval DEVPTR=${FSNAME}-ost${num}/ost${num};;
2386 error "unknown fstype!";;
2396 local fstype=$(facet_fstype ost$num)
2400 # vdevs are not supported by ldiskfs
2403 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
2404 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
2406 error "unknown fstype!";;
2416 local fstype=$(facet_fstype mds$num)
2420 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
2421 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
2423 #dataset name is independent of vdev device names
2424 eval DEVPTR=${FSNAME}-mdt${num}/mdt${num};;
2426 error "unknown fstype!";;
2436 local fstype=$(facet_fstype mds$num)
2440 # vdevs are not supported by ldiskfs
2443 #if $MDSDEVn isn't defined, default is $MDSDEVBASE + num
2444 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
2446 error "unknown fstype!";;
2455 local fstype=$(facet_fstype mds$num)
2459 #if $MGSDEV isn't defined, default is $MDSDEV1
2460 eval DEVPTR=${!DEVNAME:=${MDSDEV1}};;
2462 #dataset name is independent of vdev device names
2463 eval DEVPTR=${FSNAME}-mgs/mgs;;
2465 error "unknown fstype!";;
2474 local fstype=$(facet_fstype mds$num)
2478 # vdevs are not supported by ldiskfs
2481 #if $MGSDEV isn't defined, default is $MGSDEV1
2482 eval VDEVPTR=${!DEVNAME:=${MDSDEV1}};;
2484 error "unknown fstype!";;
2492 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
2494 local var=${facet}_MOUNT
2495 eval mntpt=${!var:-${MOUNT%/*}/$facet}
2504 # make sure we are using the primary server, so test-framework will
2505 # be able to clean up properly.
2506 activemds=`facet_active mds1`
2507 if [ $activemds != "mds1" ]; then
2511 local clients=$CLIENTS
2512 [ -z $clients ] && clients=$(hostname)
2514 zconf_umount_clients $clients $MOUNT "$*" || true
2515 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
2517 [ "$CLIENTONLY" ] && return
2518 # The add fn does rm ${facet}active file, this would be enough
2519 # if we use do_facet <facet> only after the facet added, but
2520 # currently we use do_facet mds in local.sh
2521 for num in `seq $MDSCOUNT`; do
2523 rm -f ${TMP}/mds${num}active
2525 combined_mgs_mds && rm -f $TMP/mgsactive
2527 for num in `seq $OSTCOUNT`; do
2529 rm -f $TMP/ost${num}active
2532 if ! combined_mgs_mds ; then
2539 cleanup_echo_devs () {
2540 local devs=$($LCTL dl | grep echo | awk '{print $4}')
2542 for dev in $devs; do
2543 $LCTL --device $dev cleanup
2544 $LCTL --device $dev detach
2549 nfs_client_mode && return
2558 combined_mgs_mds () {
2559 [[ $MDSDEV1 = $MGSDEV ]] && [[ $mds1_HOST = $mgs_HOST ]]
2563 echo -n "$1" | tr '[:upper:]' '[:lower:]'
2567 echo -n "$1" | tr '[:lower:]' '[:upper:]'
2572 local type=$(facet_type $facet)
2573 local index=$(($(facet_number $facet) - 1))
2574 local fstype=$(facet_fstype $facet)
2579 if [ $type == MGS ] && combined_mgs_mds; then
2583 if [ $type == MGS ] || ( [ $type == MDS ] && combined_mgs_mds ); then
2586 opts="--mgsnode=$MGSNID"
2589 if [ $type != MGS ]; then
2590 opts+=" --fsname=$FSNAME --$(lower ${type/MDS/MDT}) --index=$index"
2593 var=${facet}failover_HOST
2594 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
2595 opts+=" --failnode=$(h2$NETTYPE ${!var})"
2598 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
2599 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
2601 if [ $type == MDS ]; then
2602 opts+=${SECLEVEL:+" --param=mdt.sec_level"}
2603 opts+=${MDSCAPA:+" --param-mdt.capa=$MDSCAPA"}
2604 opts+=${STRIPE_BYTES:+" --param=lov.stripesize=$STRIPE_BYTES"}
2605 opts+=${STRIPES_PER_OBJ:+" --param=lov.stripecount=$STRIPES_PER_OBJ"}
2606 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
2608 if [ $fstype == ldiskfs ]; then
2609 opts+=${IAMDIR:+" --iam-dir"}
2611 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
2612 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
2616 if [ $type == OST ]; then
2617 opts+=${SECLEVEL:+" --param=ost.sec_level"}
2618 opts+=${OSSCAPA:+" --param=ost.capa=$OSSCAPA"}
2620 if [ $fstype == ldiskfs ]; then
2621 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
2625 opts+=" --backfstype=$fstype"
2628 if [ -n "${!var}" ]; then
2629 opts+=" --device-size=${!var}"
2632 var=$(upper $fstype)_MKFS_OPTS
2633 fs_mkfs_opts+=${!var:+" ${!var}"}
2635 var=${type}_FS_MKFS_OPTS
2636 fs_mkfs_opts+=${!var:+" ${!var}"}
2638 if [ -n "${fs_mkfs_opts## }" ]; then
2639 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
2643 opts+=${!var:+" ${!var}"}
2656 # We need ldiskfs here, may as well load them all
2658 [ "$CLIENTONLY" ] && return
2659 echo Formatting mgs, mds, osts
2660 if ! combined_mgs_mds ; then
2661 echo "Format mgs: $(mgsdevname)"
2662 add mgs $(mkfs_opts mgs) --reformat $(mgsdevname) \
2663 $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
2666 for num in `seq $MDSCOUNT`; do
2667 echo "Format mds$num: $(mdsdevname $num)"
2668 add mds$num $(mkfs_opts mds$num) --reformat \
2669 $(mdsdevname $num) $(mdsvdevname $num) \
2670 ${quiet:+>/dev/null} || exit 10
2673 for num in `seq $OSTCOUNT`; do
2674 echo "Format ost$num: $(ostdevname $num)"
2675 add ost$num $(mkfs_opts ost$num) --reformat \
2676 $(ostdevname $num) $(ostvdevname ${num}) \
2677 ${quiet:+>/dev/null} || exit 10
2682 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
2686 grep " $1 " /proc/mounts && zconf_umount `hostname` $*
2690 # 0: success, the old identity set already.
2691 # 1: success, the old identity does not set.
2696 local j=`expr $num - 1`
2697 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
2699 if [ -z "$MDT" ]; then
2703 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
2706 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
2708 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
2711 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
2713 if [ $old = "NONE" ]; then
2722 zconf_umount `hostname` $1 || error "umount failed"
2723 zconf_mount `hostname` $1 || error "mount failed"
2726 writeconf_facet () {
2730 do_facet $facet "$TUNEFS --writeconf $dev"
2734 for num in `seq $MDSCOUNT`; do
2735 DEVNAME=$(mdsdevname $num)
2736 writeconf_facet mds$num $DEVNAME
2739 for num in `seq $OSTCOUNT`; do
2740 DEVNAME=$(ostdevname $num)
2741 writeconf_facet ost$num $DEVNAME
2746 nfs_client_mode && return
2748 sanity_mount_check ||
2749 error "environments are insane!"
2753 if [ -z "$CLIENTONLY" ]; then
2754 echo Setup mgs, mdt, osts
2755 echo $WRITECONF | grep -q "writeconf" && \
2757 if ! combined_mgs_mds ; then
2758 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
2761 for num in `seq $MDSCOUNT`; do
2762 DEVNAME=$(mdsdevname $num)
2763 start mds$num $DEVNAME $MDS_MOUNT_OPTS
2765 # We started mds, now we should set failover variables properly.
2766 # Set mds${num}failover_HOST if it is not set (the default failnode).
2767 local varname=mds${num}failover_HOST
2768 if [ -z "${!varname}" ]; then
2769 eval mds${num}failover_HOST=$(facet_host mds$num)
2772 if [ $IDENTITY_UPCALL != "default" ]; then
2773 switch_identity $num $IDENTITY_UPCALL
2776 for num in `seq $OSTCOUNT`; do
2777 DEVNAME=$(ostdevname $num)
2778 start ost$num $DEVNAME $OST_MOUNT_OPTS
2780 # We started ost$num, now we should set ost${num}failover variable properly.
2781 # Set ost${num}failover_HOST if it is not set (the default failnode).
2782 varname=ost${num}failover_HOST
2783 if [ -z "${!varname}" ]; then
2784 eval ost${num}failover_HOST=$(facet_host ost${num})
2792 # wait a while to allow sptlrpc configuration be propogated to targets,
2793 # only needed when mounting new target devices.
2798 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
2800 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
2803 if [ "$MOUNT_2" ]; then
2804 mount_client $MOUNT2
2805 [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
2810 # by remounting mdt before ost, initial connect from mdt to ost might
2811 # timeout because ost is not ready yet. wait some time to its fully
2812 # recovery. initial obd_connect timeout is 5s; in GSS case it's preceeded
2813 # by a context negotiation rpc with $TIMEOUT.
2814 # FIXME better by monitoring import status.
2817 sleep $((TIMEOUT + 5))
2823 mounted_lustre_filesystems() {
2824 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
2827 init_facet_vars () {
2828 [ "$CLIENTONLY" ] && return 0
2835 eval export ${facet}_dev=${device}
2836 eval export ${facet}_opt=\"$@\"
2838 local dev=${facet}_dev
2839 local label=$(devicelabel ${facet} ${!dev})
2840 [ -z "$label" ] && echo no label for ${!dev} && exit 1
2842 eval export ${facet}_svc=${label}
2844 local varname=${facet}failover_HOST
2845 if [ -z "${!varname}" ]; then
2846 eval $varname=$(facet_host $facet)
2849 # ${facet}failover_dev is set in cfg file
2850 varname=${facet}failover_dev
2851 if [ -n "${!varname}" ] ; then
2852 eval export ${facet}failover_dev=${!varname}
2854 eval export ${facet}failover_dev=$device
2857 # get mount point of already mounted device
2858 # is facet_dev is already mounted then use the real
2859 # mount point of this facet; otherwise use $(facet_mntpt $facet)
2860 # i.e. ${facet}_MOUNT if specified by user or default
2861 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
2862 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
2863 if [ -z $mntpt ]; then
2864 mntpt=$(facet_mntpt $facet)
2866 eval export ${facet}_MOUNT=$mntpt
2869 init_facets_vars () {
2872 if ! remote_mds_nodsh; then
2873 for num in `seq $MDSCOUNT`; do
2874 DEVNAME=`mdsdevname $num`
2875 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
2879 combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
2881 remote_ost_nodsh && return
2883 for num in `seq $OSTCOUNT`; do
2884 DEVNAME=`ostdevname $num`
2885 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
2889 osc_ensure_active () {
2894 while [ $period -lt $timeout ]; do
2895 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
2896 if [ $count -eq 0 ]; then
2900 echo "There are $count OST are inactive, wait $period seconds, and try again"
2902 period=$((period+3))
2905 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
2908 init_param_vars () {
2910 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
2912 log "Using TIMEOUT=$TIMEOUT"
2914 osc_ensure_active $SINGLEMDS $TIMEOUT
2915 osc_ensure_active client $TIMEOUT
2918 if [ $JOBSTATS_AUTO -ne 0 ]; then
2919 echo "enable jobstats, set job scheduler as $JOBID_VAR"
2920 jobid_var=$JOBID_VAR
2922 jobid_var=`$LCTL get_param -n jobid_var`
2923 if [ $jobid_var != "disable" ]; then
2924 echo "disable jobstats as required"
2931 if [ $jobid_var == $JOBID_VAR -o $jobid_var == "disable" ]; then
2932 do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$jobid_var
2933 wait_update $HOSTNAME "$LCTL get_param -n jobid_var" \
2934 $jobid_var || return 1
2937 if [ $QUOTA_AUTO -ne 0 ]; then
2938 if [ "$ENABLE_QUOTA" ]; then
2939 echo "enable quota as required"
2940 setup_quota $MOUNT || return 2
2942 echo "disable quota as required"
2943 $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
2949 nfs_client_mode () {
2950 if [ "$NFSCLIENT" ]; then
2951 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
2952 local clients=$CLIENTS
2953 [ -z $clients ] && clients=$(hostname)
2955 # FIXME: remove hostname when 19215 fixed
2956 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
2957 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
2958 if [[ ${#nfsexport[@]} -eq 0 ]]; then
2959 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
2961 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
2967 check_config_client () {
2970 local mounted=$(mount | grep " $mntpt ")
2971 if [ "$CLIENTONLY" ]; then
2973 # CLIENTONLY should not depend on *_HOST settings
2974 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
2975 # in theory someone could create a new,
2976 # client-only config file that assumed lustre was already
2977 # configured and didn't set the MGSNID. If MGSNID is not set,
2978 # then we should use the mgs nid currently being used
2979 # as the default value. bug 18021
2980 [[ x$MGSNID = x ]] &&
2983 if [[ x$mgc != xMGC$MGSNID ]]; then
2984 if [ "$mgs_HOST" ]; then
2985 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
2986 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
2987 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
2993 local myMGS_host=$mgs_HOST
2994 if [ "$NETTYPE" = "ptl" ]; then
2995 myMGS_host=$(h2ptl $mgs_HOST | sed -e s/@ptl//)
2998 echo Checking config lustre mounted on $mntpt
2999 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
3000 mgshost=$(echo $mgshost | awk -F: '{print $1}')
3002 # if [ "$mgshost" != "$myMGS_host" ]; then
3003 # log "Bad config file: lustre is mounted with mgs $mgshost, but mgs_HOST=$mgs_HOST, NETTYPE=$NETTYPE
3004 # Please use correct config or set mds_HOST correctly!"
3009 check_config_clients () {
3010 local clients=${CLIENTS:-$HOSTNAME}
3013 nfs_client_mode && return
3015 do_rpc_nodes $clients check_config_client $mntpt
3017 sanity_mount_check ||
3018 error "environments are insane!"
3022 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
3023 local cltimeout=$(lctl get_param -n timeout)
3024 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
3025 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
3032 [ -z $mntpt ] && return 1
3033 local mounted=$(mounted_lustre_filesystems)
3035 echo $mounted' ' | grep -w -q $mntpt' '
3039 [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
3043 # empty lustre filesystem may have empty directories lost+found and .lustre
3045 [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
3046 -print | wc -l) = 1 ] || return 1
3047 [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found && return 0
3048 [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre && return 0
3052 check_and_setup_lustre() {
3053 nfs_client_mode && return
3055 local MOUNTED=$(mounted_lustre_filesystems)
3059 # both MOUNT and MOUNT2 are not mounted
3060 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
3061 [ "$REFORMAT" ] && formatall
3062 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
3064 is_mounted $MOUNT || error "NAME=$NAME not mounted"
3065 export I_MOUNTED=yes
3069 elif is_mounted $MOUNT2; then
3071 # MOUNT2 is mounted, while MOUNT_2 is not set
3072 if ! [ "$MOUNT_2" ]; then
3073 cleanup_mount $MOUNT2
3074 export I_UMOUNTED2=yes
3077 # MOUNT2 is mounted, MOUNT_2 is set
3079 # FIXME: what to do if check_config failed?
3081 # 1) remote client has mounted other Lustre fs ?
3082 # 2) it has insane env ?
3083 # let's try umount MOUNT2 on all clients and mount it again:
3084 if ! check_config_clients $MOUNT2; then
3085 cleanup_mount $MOUNT2
3086 restore_mount $MOUNT2
3087 export I_MOUNTED2=yes
3092 # MOUNT is mounted MOUNT2 is not mounted
3093 elif [ "$MOUNT_2" ]; then
3094 restore_mount $MOUNT2
3095 export I_MOUNTED2=yes
3099 # FIXME: what to do if check_config failed?
3101 # 1) remote client has mounted other Lustre fs?
3102 # 2) lustre is mounted on remote_clients atall ?
3103 check_config_clients $MOUNT
3107 set_default_debug_nodes $(comma_list $(nodes_list))
3115 if [ "$ONLY" == "setup" ]; then
3121 local clients=${CLIENTS:-$HOSTNAME}
3124 zconf_mount_clients $clients $mntpt
3128 local clients=${CLIENTS:-$HOSTNAME}
3131 zconf_umount_clients $clients $mntpt
3134 cleanup_and_setup_lustre() {
3135 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
3136 lctl set_param debug=0 || true
3138 if [ "$ONLY" == "cleanup" ]; then
3142 check_and_setup_lustre
3145 # Get all of the server target devices from a given server node and type.
3152 if [ "$type" == ost ]; then
3153 devs=$(get_obdfilter_param $node "" mntdev)
3155 devs=$(do_node $node \
3156 "lctl get_param -n osd-*.$FSNAME-M*.mntdev")
3158 for dev in $devs; do
3160 *loop*) do_node $node "losetup $dev" | \
3161 sed -e "s/.*(//" -e "s/).*//" ;;
3167 # Get all of the server target devices.
3172 MDTDEV=$(get_mnt_devs $(mdts_nodes) mdt)
3176 for node in $(osts_nodes); do
3177 OSTDEVS[i]=$(get_mnt_devs $node ost)
3182 # Run e2fsck on MDT or OST device.
3188 df > /dev/null # update statfs data on disk
3189 local cmd="$E2FSCK -d -v -t -t -f -n $extra_opts $target_dev"
3192 do_node $node $cmd || rc=$?
3193 [ $rc -le $FSCK_MAX_ERR ] || \
3194 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
3198 # verify a directory is shared among nodes.
3199 check_shared_dir() {
3202 [ -z "$dir" ] && return 1
3203 do_rpc_nodes $(comma_list $(nodes_list)) check_logdir $dir
3204 check_write_access $dir || return 1
3208 # Run e2fsck on MDT and OST(s) to generate databases used for lfsck.
3214 check_shared_dir $SHARED_DIRECTORY ||
3215 error "$SHARED_DIRECTORY isn't a shared directory"
3217 export MDSDB=$SHARED_DIRECTORY/mdsdb
3218 export OSTDB=$SHARED_DIRECTORY/ostdb
3220 [ $MDSCOUNT -eq 1 ] || error "CMD is not supported"
3222 run_e2fsck $(mdts_nodes) $MDTDEV "--mdsdb $MDSDB"
3227 for node in $(osts_nodes); do
3228 for dev in ${OSTDEVS[i]}; do
3229 run_e2fsck $node $dev "--mdsdb $MDSDB --ostdb $OSTDB-$ostidx"
3230 OSTDB_LIST="$OSTDB_LIST $OSTDB-$ostidx"
3231 ostidx=$((ostidx + 1))
3238 local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
3242 [ $rc -le $FSCK_MAX_ERR ] || \
3243 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
3244 echo "lfsck finished with rc=$rc"
3246 rm -rvf $MDSDB* $OSTDB* || true
3250 check_and_cleanup_lustre() {
3251 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "lfsck" ]; then
3257 if is_mounted $MOUNT; then
3258 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
3259 error "remove sub-test dirs failed"
3260 [ "$ENABLE_QUOTA" ] && restore_quota_type || true
3263 if [ "$I_UMOUNTED2" = "yes" ]; then
3264 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
3267 if [ "$I_MOUNTED2" = "yes" ]; then
3268 cleanup_mount $MOUNT2
3271 if [ "$I_MOUNTED" = "yes" ]; then
3272 cleanupall -f || error "cleanup failed"
3280 wait_for_function () {
3283 # suppress fn both stderr and stdout
3284 if [ "$1" = "--quiet" ]; then
3286 quiet=" > /dev/null 2>&1"
3298 eval $fn $quiet && return 0
3300 wait=$((wait + sleep))
3301 [ $wait -lt $max ] || return 1
3302 echo waiting $fn, $((max - wait)) secs left ...
3312 echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
3313 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
3314 echo "Network not available!"
3318 echo `date +"%H:%M:%S (%s)"` network interface is UP
3327 # the sed converts spaces to commas, but leaves the last space
3328 # alone, so the line doesn't end with a comma.
3329 echo "$*" | tr -s " " "\n" | sort -b -u | tr "\n" " " | sed 's/ \([^$]\)/,\1/g'
3335 echo $list | grep -qw $item
3338 # list, excluded are the comma separated lists
3339 exclude_items_from_list () {
3345 for item in ${excluded//,/ }; do
3346 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
3348 echo $(comma_list $list)
3351 # list, expand are the comma separated lists
3353 local list=${1//,/ }
3354 local expand=${2//,/ }
3357 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
3358 echo $(comma_list $expanded)
3361 testslist_filter () {
3362 local script=$LUSTRE/tests/${TESTSUITE}.sh
3364 [ -f $script ] || return 0
3366 local start_at=$START_AT
3367 local stop_at=$STOP_AT
3369 local var=${TESTSUITE//-/_}_START_AT
3370 [ x"${!var}" != x ] && start_at=${!var}
3371 var=${TESTSUITE//-/_}_STOP_AT
3372 [ x"${!var}" != x ] && stop_at=${!var}
3374 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
3375 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
3376 /^'${start_at}'$/ {flag = 0}
3377 {if (flag == 1) print $0}
3378 /^'${stop_at}'$/ { flag = 1 }'
3382 (cd `dirname $1`; echo $PWD/`basename $1`)
3386 local types=${1:-"OST MDS MGS"}
3390 for entry in $types; do
3391 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
3392 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
3395 MGS ) list="$list $name";;
3396 MDS|OST ) local count=${type}COUNT
3397 for ((i=1; i<=${!count}; i++)) do
3398 list="$list ${name}$i"
3400 * ) error "Invalid facet type"
3404 echo $(comma_list $list)
3407 ##################################
3408 # Adaptive Timeouts funcs
3411 # only check mds, we assume at_max is the same on all nodes
3412 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
3413 if [ $at_max -eq 0 ]; then
3424 # suppose that all ost-s have the same $at value set
3425 [ $facet != "ost" ] || facet=ost1
3427 do_facet $facet "lctl get_param -n $at"
3445 if [ $facet == "ost" ]; then
3446 facet=$(get_facets OST)
3447 elif [ $facet == "mds" ]; then
3448 facet=$(get_facets MDS)
3450 hosts=$(expand_list $hosts $(facets_hosts $facet))
3453 do_nodes $hosts lctl set_param at_max=$at_max
3456 ##################################
3460 # OBD_FAIL_MDS_ALL_REQUEST_NET
3462 do_facet $SINGLEMDS lctl set_param fail_loc=0x123
3463 do_facet client "$1" || RC=$?
3464 do_facet $SINGLEMDS lctl set_param fail_loc=0
3469 # OBD_FAIL_MDS_ALL_REPLY_NET
3471 do_facet $SINGLEMDS lctl set_param fail_loc=0x122
3472 do_facet client "$@" || RC=$?
3473 do_facet $SINGLEMDS lctl set_param fail_loc=0
3477 drop_reint_reply() {
3478 # OBD_FAIL_MDS_REINT_NET_REP
3480 do_facet $SINGLEMDS lctl set_param fail_loc=0x119
3481 do_facet client "$@" || RC=$?
3482 do_facet $SINGLEMDS lctl set_param fail_loc=0
3487 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
3489 do_facet ost1 lctl set_param fail_loc=0x214
3490 do_facet client "$1" || RC=$?
3491 do_facet client "sync"
3492 do_facet ost1 lctl set_param fail_loc=0
3496 drop_ldlm_cancel() {
3497 #define OBD_FAIL_LDLM_CANCEL 0x304
3499 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
3500 do_nodes $list lctl set_param fail_loc=0x304
3502 do_facet client "$@" || RC=$?
3504 do_nodes $list lctl set_param fail_loc=0
3508 drop_bl_callback() {
3509 #define OBD_FAIL_LDLM_BL_CALLBACK 0x305
3511 do_facet client lctl set_param fail_loc=0x305
3512 do_facet client "$@" || RC=$?
3513 do_facet client lctl set_param fail_loc=0
3518 #define OBD_FAIL_LDLM_REPLY 0x30c
3520 do_facet $SINGLEMDS lctl set_param fail_loc=0x30c
3521 do_facet client "$@" || RC=$?
3522 do_facet $SINGLEMDS lctl set_param fail_loc=0
3530 echo "clearing fail_loc on $facet"
3531 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
3534 set_nodes_failloc () {
3535 do_nodes $(comma_list $1) lctl set_param fail_loc=$2
3538 cancel_lru_locks() {
3539 $LCTL mark "cancel_lru_locks $1 start"
3540 for d in `lctl get_param -N ldlm.namespaces.*.lru_size | egrep -i $1`; do
3541 $LCTL set_param -n $d=clear
3543 $LCTL get_param ldlm.namespaces.*.lock_unused_count | egrep -i $1 | grep -v '=0'
3544 $LCTL mark "cancel_lru_locks $1 stop"
3549 NR_CPU=$(grep -c "processor" /proc/cpuinfo)
3550 DEFAULT_LRU_SIZE=$((100 * NR_CPU))
3551 echo "$DEFAULT_LRU_SIZE"
3556 lctl set_param ldlm.namespaces.*$1*.lru_size=0
3559 lru_resize_disable()
3561 lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
3566 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
3567 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
3568 echo there is still data in page cache $FILE ?
3569 lctl get_param -n $FILE
3577 DEBUGSAVE="$(lctl get_param -n debug)"
3581 [ -n "$DEBUGSAVE" ] && \
3582 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\";"
3587 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
3590 debug_size_restore() {
3591 [ -n "$DEBUG_SIZE_SAVED" ] && \
3592 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
3596 start_full_debug_logging() {
3601 local DEBUG_SIZE=150
3603 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE"
3604 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug=$FULLDEBUG;"
3607 stop_full_debug_logging() {
3612 # prints bash call stack
3615 for (( i=1; i < ${#BASH_LINENO[*]} ; i++ )) ; do
3616 local s=${BASH_SOURCE[$i]}
3617 local l=${BASH_LINENO[$i-1]}
3618 local f=${FUNCNAME[$i]}
3619 echo " = $s:$l:$f()"
3623 ##################################
3625 ##################################
3628 local TYPE=${TYPE:-"FAIL"}
3631 # do not dump logs if $1=false
3632 if [ "x$1" = "xfalse" ]; then
3637 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
3641 # We need to dump the logs on all nodes
3643 gather_logs $(comma_list $(nodes_list))
3647 [ "$TESTSUITELOG" ] && echo "$0: ${TYPE}: $TESTNAME $@" >> $TESTSUITELOG
3648 echo "$@" > $LOGDIR/err
3653 local log=$TESTSUITELOG
3655 [ -f "$log" ] && grep -q FAIL $log && status=1
3668 # use only if we are ignoring failures for this test, bugno required.
3669 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
3670 # e.g. error_ignore 5494 "your message"
3672 local TYPE="IGNORE (bz$1)"
3678 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
3683 log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
3684 [ "$ALWAYS_SKIPPED" ] && \
3685 skip_logged ${TESTNAME} "$@" || true
3686 [ "$TESTSUITELOG" ] && \
3687 echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
3690 build_test_filter() {
3691 EXCEPT="$EXCEPT $(testslist_filter)"
3693 [ "$ONLY" ] && log "only running test `echo $ONLY`"
3697 [ "$EXCEPT$ALWAYS_EXCEPT" ] && \
3698 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
3699 [ "$EXCEPT_SLOW" ] && \
3700 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
3701 for E in $EXCEPT; do
3702 eval EXCEPT_${E}=true
3704 for E in $ALWAYS_EXCEPT; do
3705 eval EXCEPT_ALWAYS_${E}=true
3707 for E in $EXCEPT_SLOW; do
3708 eval EXCEPT_SLOW_${E}=true
3710 for G in $GRANT_CHECK_LIST; do
3711 eval GCHECK_ONLY_${G}=true
3716 if [[ $1 = [a-z]* ]]; then
3723 # print a newline if the last test was skipped
3724 export LAST_SKIPPED=
3725 export ALWAYS_SKIPPED=
3727 # Main entry into test-framework. This is called with the name and
3728 # description of a test. The name is used to find the function to run
3729 # the test using "test_$name".
3731 # This supports a variety of methods of specifying specific test to
3732 # run or not run. These need to be documented...
3737 export base=`basetest $1`
3738 if [ ! -z "$ONLY" ]; then
3740 if [ ${!testname}x != x ]; then
3741 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
3742 run_one_logged $1 "$2"
3746 if [ ${!testname}x != x ]; then
3747 [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
3748 run_one_logged $1 "$2"
3756 if [ ${!testname}x != x ]; then
3758 TESTNAME=test_$1 skip "skipping excluded test $1"
3761 testname=EXCEPT_$base
3762 if [ ${!testname}x != x ]; then
3764 TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
3767 testname=EXCEPT_ALWAYS_$1
3768 if [ ${!testname}x != x ]; then
3771 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
3774 testname=EXCEPT_ALWAYS_$base
3775 if [ ${!testname}x != x ]; then
3778 TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
3781 testname=EXCEPT_SLOW_$1
3782 if [ ${!testname}x != x ]; then
3784 TESTNAME=test_$1 skip "skipping SLOW test $1"
3787 testname=EXCEPT_SLOW_$base
3788 if [ ${!testname}x != x ]; then
3790 TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
3796 run_one_logged $1 "$2"
3807 module_loaded lnet || load_modules
3819 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
3824 strace -o $TMP/$1.strace -ttt $*
3826 log "FINISHED: $*: rc $RC"
3831 equals_msg $1 test complete, duration $2 sec
3832 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
3833 echo duration $2 >>$TESTSUITELOG
3837 # Set TEST_STATUS here; will be used for logging the result
3838 if [ -f $LOGDIR/err ]; then
3843 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
3847 local FFREE=$(do_node $SINGLEMDS \
3848 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
3849 local FTOTAL=$(do_node $SINGLEMDS \
3850 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
3852 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
3856 echo -n "Resetting fail_loc on all nodes..."
3857 do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 2>/dev/null || true"
3863 # Log a message (on all nodes) padded with "=" before and after.
3864 # Also appends a timestamp and prepends the testsuite name.
3867 EQUALS="===================================================================================================="
3869 msg="== ${TESTSUITE} $*"
3871 [[ $last != "=" && $last != " " ]] && msg="$msg "
3872 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
3873 # always include at least == after the message
3874 log "$msg== $(date +"%H:%M:%S (%s)")"
3878 # Run a single test function and cleanup after it.
3880 # This function should be run in a subshell so the test func can
3881 # exit() without stopping the whole script.
3886 tfile=f.${TESTSUITE}.${testnum}
3887 export tdir=d0.${TESTSUITE}/d${base}
3888 export TESTNAME=test_$testnum
3889 local SAVE_UMASK=`umask`
3892 banner "test $testnum: $message"
3893 test_${testnum} || error "test_$testnum failed with $?"
3896 check_grant ${testnum} || error "check_grant $testnum failed with $?"
3897 check_catastrophe || error "LBUG/LASSERT detected"
3898 ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
3906 # Wrapper around run_one to ensure:
3907 # - test runs in subshell
3908 # - output of test is saved to separate log file for error reporting
3909 # - test result is saved to data file
3912 local BEFORE=`date +%s`
3914 local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
3915 local test_log=$LOGDIR/$name
3917 local SAVE_UMASK=`umask`
3921 log_sub_test_begin test_${1}
3922 (run_one $1 "$2") 2>&1 | tee -i $test_log
3923 local RC=${PIPESTATUS[0]}
3925 [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] && \
3926 echo "test_$1 returned $RC" | tee $LOGDIR/err
3928 duration=$((`date +%s` - $BEFORE))
3929 pass "$1" "(${duration}s)"
3930 [ -f $LOGDIR/err ] && TEST_ERROR=$(cat $LOGDIR/err)
3931 log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
3933 if [ -f $LOGDIR/err ]; then
3934 $FAIL_ON_ERROR && exit $RC
3943 # Print information of skipped tests to result.yml
3946 log_sub_test_begin $1
3947 log_sub_test_end "SKIP" "0" "0" "\"$2\""
3951 (cd `dirname $1`; echo $PWD/`basename $1`)
3956 export base=`basetest $1`
3957 [ "$CHECK_GRANT" == "no" ] && return 0
3959 testname=GCHECK_ONLY_${base}
3960 [ ${!testname}x == x ] && return 0
3962 echo -n "checking grant......"
3964 local clients=$CLIENTS
3965 [ -z $clients ] && clients=$(hostname)
3967 # sync all the data and make sure no pending data on server
3968 do_nodes $clients sync
3971 client_grant=`do_nodes $clients \
3972 "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" | \
3973 awk '{total += $1} END{print total}'`
3976 server_grant=`do_nodes $(comma_list $(osts_nodes)) \
3977 "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
3978 awk '{total += $1} END{print total}'`
3980 # check whether client grant == server grant
3981 if [ $client_grant -ne $server_grant ]; then
3982 echo "failed: client:${client_grant} server: ${server_grant}."
3983 do_nodes $(comma_list $(osts_nodes)) \
3984 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
3985 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
3988 echo "pass: client:${client_grant} server: ${server_grant}"
3993 ########################
3999 ost=`echo $1 | awk -F_ '{print $3}'`
4000 if [ -z $ost ]; then
4001 ost=`echo $1 | sed 's/-osc.*//'`
4006 ostuuid_from_index()
4008 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
4011 ostname_from_index() {
4012 local uuid=$(ostuuid_from_index $1)
4016 index_from_ostuuid()
4018 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
4021 mdtuuid_from_index()
4023 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
4028 [ "$node" != "$(hostname)" ]
4034 for node in $(mdts_nodes); do
4035 remote_node $node && return 0
4042 [ "$CLIENTONLY" ] && return 0 || true
4043 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
4048 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" && \
4049 MSKIPPED=1 && return 1
4056 for node in $(osts_nodes) ; do
4057 remote_node $node && return 0
4064 [ "$CLIENTONLY" ] && return 0 || true
4065 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
4070 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
4071 OSKIPPED=1 && return 1
4078 MGS=$(facet_host mgs)
4079 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
4084 remote_mds_nodsh || remote_ost_nodsh || \
4085 $(single_local_node $(comma_list $(nodes_list)))
4091 for num in `seq $MDSCOUNT`; do
4092 MDSNODES="$MDSNODES $(facet_host mds$num)"
4094 NODES_sort=$(for i in $MDSNODES; do echo $i; done | sort -u)
4100 remote_ost && remote_mds
4108 for facet in ${facets//,/ }; do
4109 if [ "$FAILURE_MODE" = HARD ]; then
4110 nodes="$nodes $(facet_active_host $facet)"
4112 nodes="$nodes $(facet_host $facet)"
4115 NODES_sort=$(for i in $nodes; do echo $i; done | sort -u)
4121 local facets=$(get_facets OST)
4122 local nodes=$(facets_nodes $facets)
4128 # FIXME. We need a list of clients
4129 local myNODES=$HOSTNAME
4132 # CLIENTS (if specified) contains the local client
4133 [ -n "$CLIENTS" ] && myNODES=${CLIENTS//,/ }
4135 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
4136 myNODES="$myNODES $(facets_nodes $(get_facets))"
4139 myNODES_sort=$(for i in $myNODES; do echo $i; done | sort -u)
4144 remote_nodes_list () {
4145 local rnodes=$(nodes_list)
4146 rnodes=$(echo " $rnodes " | sed -re "s/\s+$HOSTNAME\s+/ /g")
4150 init_clients_lists () {
4151 # Sanity check: exclude the local client from RCLIENTS
4152 local clients=$(hostlist_expand "$RCLIENTS")
4153 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
4155 # Sanity check: exclude the dup entries
4156 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
4158 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
4160 # Sanity check: exclude the dup entries from CLIENTS
4161 # for those configs which has SINGLCLIENT set to local client
4162 clients=$(for i in $clients; do echo $i; done | sort -u)
4164 CLIENTS=$(comma_list $clients)
4165 local -a remoteclients=($RCLIENTS)
4166 for ((i=0; $i<${#remoteclients[@]}; i++)); do
4167 varname=CLIENT$((i + 2))
4168 eval $varname=${remoteclients[i]}
4171 CLIENTCOUNT=$((${#remoteclients[@]} + 1))
4174 get_random_entry () {
4177 rnodes=${rnodes//,/ }
4179 local -a nodes=($rnodes)
4180 local num=${#nodes[@]}
4181 local i=$((RANDOM * num * 2 / 65536))
4187 [ "$CLIENTONLY" ] || [ "$CLIENTMODSONLY" = yes ]
4192 lctl get_param version | grep -q patchless
4196 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
4197 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
4202 echo $nodes | wc -w || true
4206 local nodes=$(osts_nodes)
4207 local osscount=$(get_node_count "$nodes")
4208 [ ! "$OSTCOUNT" = "$osscount" ]
4212 local nodes=$(mdts_nodes)
4213 local mdtcount=$(get_node_count "$nodes")
4214 [ ! "$MDSCOUNT" = "$mdtcount" ]
4217 generate_machine_file() {
4218 local nodes=${1//,/ }
4219 local machinefile=$2
4221 for node in $nodes; do
4222 echo $node >>$machinefile || \
4223 { echo "can not generate machinefile $machinefile" && return 1; }
4228 local file=$1/stripe
4230 $LFS getstripe -v $file || error
4234 setstripe_nfsserver () {
4237 local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
4238 { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
4240 [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
4242 do_nodev $nfsserver lfs setstripe "$@"
4245 # Check and add a test group.
4251 local gid=$(getent group $group_name | cut -d: -f3)
4252 if [[ -n "$gid" ]]; then
4253 [[ "$gid" -eq "$group_id" ]] || {
4254 error_noexit "inconsistent group ID:" \
4255 "new: $group_id, old: $gid"
4259 groupadd -g $group_id $group_name
4266 # Check and add a test user.
4279 local uid=$(getent passwd $user_name | cut -d: -f3)
4280 if [[ -n "$uid" ]]; then
4281 if [[ "$uid" -eq "$user_id" ]]; then
4282 local dir=$(getent passwd $user_name | cut -d: -f6)
4283 if [[ "$dir" != "$home" ]]; then
4285 usermod -d $home $user_name
4289 error_noexit "inconsistent user ID:" \
4290 "new: $user_id, old: $uid"
4295 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
4302 check_runas_id_ret() {
4304 local myRUNAS_UID=$1
4305 local myRUNAS_GID=$2
4308 if [ -z "$myRUNAS" ]; then
4309 error_exit "myRUNAS command must be specified for check_runas_id"
4312 $myRUNAS krb5_login.sh || \
4313 error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
4315 mkdir $DIR/d0_runas_test
4317 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
4318 $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
4319 rm -rf $DIR/d0_runas_test
4324 local myRUNAS_UID=$1
4325 local myRUNAS_GID=$2
4328 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
4329 error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
4330 Please set RUNAS_ID to some UID which exists on MDS and client or
4331 add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
4334 # obtain the UID/GID for MPI_USER
4338 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
4339 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
4341 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
4342 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
4345 # obtain and cache Kerberos ticket-granting ticket
4346 refresh_krb5_tgt() {
4347 local myRUNAS_UID=$1
4348 local myRUNAS_GID=$2
4351 if [ -z "$myRUNAS" ]; then
4352 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
4355 CLIENTS=${CLIENTS:-$HOSTNAME}
4356 do_nodes $CLIENTS "set -x
4357 if ! $myRUNAS krb5_login.sh; then
4358 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
4363 # Run multiop in the background, but wait for it to print
4364 # "PAUSING" to its stdout before returning from this function.
4365 multiop_bg_pause() {
4366 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
4370 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
4373 echo "$MULTIOP_PROG $FILE v$ARGS"
4374 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
4376 echo "TMPPIPE=${TMPPIPE}"
4377 read -t 60 multiop_output < $TMPPIPE
4378 if [ $? -ne 0 ]; then
4383 if [ "$multiop_output" != "PAUSING" ]; then
4384 echo "Incorrect multiop output: $multiop_output"
4399 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
4405 inodes_available () {
4406 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
4410 mdsrate_inodes_available () {
4411 local min_inodes=$(inodes_available)
4412 echo $((min_inodes * 99 / 100))
4415 # reset llite stat counters
4416 clear_llite_stats(){
4417 lctl set_param -n llite.*.stats 0
4420 # sum llite stat items
4421 calc_llite_stats() {
4422 local res=$(lctl get_param -n llite.*.stats |
4423 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
4427 # reset osc stat counters
4429 lctl set_param -n osc.*.osc_stats 0
4432 # sum osc stat items
4434 local res=$(lctl get_param -n osc.*.osc_stats |
4435 awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
4440 awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
4443 calc_osc_kbytes () {
4444 df $MOUNT > /dev/null
4445 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
4448 # save_lustre_params(node, parameter_mask)
4449 # generate a stream of formatted strings (<node> <param name>=<param value>)
4450 save_lustre_params() {
4452 do_nodesv $1 "lctl get_param $2 | while read s; do echo \\\$s; done"
4455 # restore lustre parameters from input stream, produces by save_lustre_params
4456 restore_lustre_params() {
4460 while IFS=" =" read node name val; do
4461 do_node ${node//:/} "lctl set_param -n $name $val"
4465 check_catastrophe() {
4466 local rnodes=${1:-$(comma_list $(remote_nodes_list))}
4467 local C=$CATASTROPHE
4468 [ -f $C ] && [ $(cat $C) -ne 0 ] && return 1
4470 if [ $rnodes ]; then
4471 do_nodes $rnodes "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
4472 if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
4477 # CMD: determine mds index where directory inode presents
4480 local file=$dir/f0.get_mds_dir_tmpfile
4485 local iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
4486 local -a oldused=($iused)
4488 openfile -f O_CREAT:O_LOV_DELAY_CREATE -m 0644 $file > /dev/null
4490 iused=$(lfs df -i $dir | grep MDT | awk '{print $3}')
4491 local -a newused=($iused)
4494 for ((i=0; i<${#newused[@]}; i++)); do
4495 if [ ${oldused[$i]} -lt ${newused[$i]} ]; then
4501 error "mdt-s : inodes count OLD ${oldused[@]} NEW ${newused[@]}"
4504 mdsrate_cleanup () {
4506 mpi_run -np $1 -machinefile $2 ${MDSRATE} --unlink --nfiles $3 --dir $4 --filefmt $5 $6
4511 delayed_recovery_enabled () {
4512 local var=${SINGLEMDS}_svc
4513 do_facet $SINGLEMDS lctl get_param -n mdd.${!var}.stale_export_age > /dev/null 2>&1
4516 ########################
4518 convert_facet2label() {
4521 if [ x$facet = xost ]; then
4525 local varsvc=${facet}_svc
4527 if [ -n ${!varsvc} ]; then
4530 error "No lablel for $facet!"
4534 get_clientosc_proc_path() {
4535 echo "${1}-osc-[^M]*"
4538 get_lustre_version () {
4539 local facet=${1:-"$SINGLEMDS"}
4540 do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
4543 lustre_version_code() {
4544 local facet=${1:-"$SINGLEMDS"}
4545 version_code $(get_lustre_version $1)
4548 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
4549 # used by MDT would not be changed.
4550 # mdt lov: fsname-mdtlov
4551 # mdt osc: fsname-OSTXXXX-osc
4552 mds_on_old_device() {
4553 local mds=${1:-"$SINGLEMDS"}
4555 if [ $(lustre_version_code $mds) -gt $(version_code 1.9.0) ]; then
4556 do_facet $mds "lctl list_param osc.$FSNAME-OST*-osc \
4557 > /dev/null 2>&1" && return 0
4562 get_mdtosc_proc_path() {
4564 local ost_label=${2:-"*OST*"}
4566 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
4567 local mdt_label=$(convert_facet2label $mds_facet)
4568 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
4570 if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
4571 mds_on_old_device $mds_facet; then
4572 echo "${ost_label}-osc"
4574 echo "${ost_label}-osc-${mdt_index}"
4578 get_osc_import_name() {
4581 local label=$(convert_facet2label $ost)
4583 if [ "${facet:0:3}" = "mds" ]; then
4584 get_mdtosc_proc_path $facet $label
4588 get_clientosc_proc_path $label
4592 _wait_import_state () {
4595 local maxtime=${3:-$(max_recovery_time)}
4599 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
4600 while [ "${CONN_STATE}" != "${expected}" ]; do
4601 if [ "${expected}" == "DISCONN" ]; then
4602 # for disconn we can check after proc entry is removed
4603 [ "x${CONN_STATE}" == "x" ] && return 0
4604 # with AT enabled, we can have connect request timeout near of
4605 # reconnect timeout and test can't see real disconnect
4606 [ "${CONN_STATE}" == "CONNECTING" ] && return 0
4608 [ $i -ge $maxtime ] && \
4609 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
4612 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
4616 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
4620 wait_import_state() {
4623 local maxtime=${3:-$(max_recovery_time)}
4626 for param in ${params//,/ }; do
4627 _wait_import_state $state $param $maxtime || return
4631 # One client request could be timed out because server was not ready
4632 # when request was sent by client.
4633 # The request timeout calculation details :
4635 # /* We give the server rq_timeout secs to process the req, and
4636 # add the network latency for our local timeout. */
4637 # request->rq_deadline = request->rq_sent + request->rq_timeout +
4638 # ptlrpc_at_get_net_latency(request) ;
4640 # ptlrpc_connect_import ()
4641 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
4644 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
4645 # ptlrpc_at_get_net_latency(request) ->
4646 # at_get (max (iat_net_latency=0, at_min)) = at_min
4649 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
4650 # INITIAL_CONNECT_TIMEOUT + at_min
4652 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
4653 # because we can not get this value in runtime,
4654 # the value depends on configure options, and it is not stored in /proc.
4656 # #define CONNECTION_SWITCH_MIN 5U
4657 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
4659 request_timeout () {
4662 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
4663 local init_connect_timeout=$TIMEOUT
4664 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
4666 local at_min=$(at_get $facet at_min)
4668 echo $(( init_connect_timeout + at_min ))
4671 wait_osc_import_state() {
4675 local ost=$(get_osc_import_name $facet $ost_facet)
4677 local param="osc.${ost}.ost_server_uuid"
4679 # 1. wait the deadline of client 1st request (it could be skipped)
4680 # 2. wait the deadline of client 2nd request
4681 local maxtime=$(( 2 * $(request_timeout $facet)))
4683 if ! do_rpc_nodes $(facet_host $facet) \
4684 _wait_import_state $expected $param $maxtime; then
4685 error "import is not in ${expected} state"
4692 get_clientmdc_proc_path() {
4700 # Add paths to lustre tests for 32 and 64 bit systems.
4701 local RPATH="PATH=$RLUSTRE/tests:/usr/lib/lustre/tests:/usr/lib64/lustre/tests:$PATH"
4702 do_nodesv $list "${RPATH} NAME=${NAME} sh rpc.sh $@ "
4705 wait_clients_import_state () {
4712 if [ "$FAILURE_MODE" = HARD ]; then
4713 facets=$(facets_on_host $(facet_active_host $facet))
4716 for facet in ${facets//,/ }; do
4717 local label=$(convert_facet2label $facet)
4720 ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
4721 mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
4722 *) error "unknown facet!" ;;
4724 local params=$(expand_list $params $proc_path)
4727 if ! do_rpc_nodes $list wait_import_state $expected $params; then
4728 error "import is not in ${expected} state"
4738 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
4739 $LCTL get_param obdfilter.*.kbytesavail))
4740 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
4741 $LCTL get_param -n obdfilter.*.tot_granted))
4742 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
4743 $LCTL get_param -n obdfilter.*.kbytestotal))
4744 for ((i=0; i<${#AVAILA[@]}; i++)); do
4745 local -a AVAIL1=(${AVAILA[$i]//=/ })
4746 local -a TOTAL=(${TOTALA[$i]//=/ })
4747 GRANT=$((${GRANTA[$i]}/1024))
4748 # allow 1% of total space in bavail because of delayed
4749 # allocation with ZFS which might release some free space after
4750 # txg commit. For small devices, we set a mininum of 8MB
4751 local LIMIT=$((${TOTAL} / 100 + 8000))
4752 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
4753 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
4754 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
4755 echo " FULL" || echo
4761 do_facet mgs lctl pool_list $1
4765 local fsname=${1%%.*}
4766 local poolname=${1##$fsname.}
4768 do_facet mgs lctl pool_new $1
4770 # get param should return err unless pool is created
4771 [[ $RC -ne 0 ]] && return $RC
4773 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4774 2>/dev/null || echo foo" "" || RC=1
4775 if [[ $RC -eq 0 ]]; then
4778 error "pool_new failed $1"
4783 add_pool_to_list () {
4784 local fsname=${1%%.*}
4785 local poolname=${1##$fsname.}
4787 local listvar=${fsname}_CREATED_POOLS
4788 eval export ${listvar}=$(expand_list ${!listvar} $poolname)
4791 remove_pool_from_list () {
4792 local fsname=${1%%.*}
4793 local poolname=${1##$fsname.}
4795 local listvar=${fsname}_CREATED_POOLS
4796 eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
4799 destroy_pool_int() {
4801 local OSTS=$(do_facet $SINGLEMDS lctl pool_list $1 | \
4802 awk '$1 !~ /^Pool:/ {print $1}')
4803 for ost in $OSTS; do
4804 do_facet mgs lctl pool_remove $1 $ost
4806 do_facet mgs lctl pool_destroy $1
4809 # <fsname>.<poolname> or <poolname>
4811 local fsname=${1%%.*}
4812 local poolname=${1##$fsname.}
4814 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
4818 pool_list $fsname.$poolname || return $?
4820 destroy_pool_int $fsname.$poolname
4822 [[ $RC -ne 0 ]] && return $RC
4824 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
4825 2>/dev/null || echo foo" "foo" || RC=1
4827 if [[ $RC -eq 0 ]]; then
4828 remove_pool_from_list $fsname.$poolname
4830 error "destroy pool failed $1"
4836 local fsname=${1:-$FSNAME}
4838 local listvar=${fsname}_CREATED_POOLS
4842 [ x${!listvar} = x ] && return 0
4844 echo destroy the created pools: ${!listvar}
4845 for poolname in ${!listvar//,/ }; do
4846 destroy_pool $fsname.$poolname
4851 local fsname=${1:-$FSNAME}
4853 destroy_pools $fsname
4859 local ts=$(date +%s)
4862 if [[ ! -f "$YAML_LOG" ]]; then
4863 # init_logging is not performed before gather_logs,
4864 # so the $LOGDIR needs to be checked here
4865 check_shared_dir $LOGDIR && touch $LOGDIR/shared
4868 [ -f $LOGDIR/shared ] && docp=false
4870 # dump lustre logs, dmesg
4872 prefix="$TESTLOG_PREFIX.$TESTNAME"
4874 echo "Dumping lctl log to ${prefix}.*.${suffix}"
4876 if [ "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
4877 echo "Dumping logs only on local client."
4878 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
4879 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
4884 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
4885 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
4886 if [ ! -f $LOGDIR/shared ]; then
4887 do_nodes $list rsync -az "${prefix}.*.${suffix}" $HOSTNAME:$LOGDIR
4900 for i in $(seq 0 $num_mntpts); do
4901 cmd="ls -laf ${mntpt_root}$i/$dir"
4907 for pid in $pids; do
4914 # target_start_and_reset_recovery_timer()
4915 # service_time = at_est2timeout(service_time);
4916 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
4917 # INITIAL_CONNECT_TIMEOUT);
4918 # CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
4919 #define CONNECTION_SWITCH_INC 1
4920 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
4921 #define CONNECTION_SWITCH_MIN 5U
4923 max_recovery_time () {
4924 local init_connect_timeout=$(( TIMEOUT / 20 ))
4925 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
4927 local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1 + init_connect_timeout)) )) ))
4932 get_clients_mount_count () {
4933 local clients=${CLIENTS:-`hostname`}
4935 # we need to take into account the clients mounts and
4936 # exclude mds/ost mounts if any;
4937 do_nodes $clients cat /proc/mounts | grep lustre | grep $MOUNT | wc -l
4941 PROC_CLI="srpc_info"
4949 if [ $M -lt $N ]; then
4953 while [ $N -lt $M ]; do
4963 calc_connection_cnt() {
4966 # MDT->MDT = 2 * C(M, 2)
4970 comb_m2=$(combination $MDSCOUNT 2)
4972 local num_clients=$(get_clients_mount_count)
4974 local cnt_mdt2mdt=$((comb_m2 * 2))
4975 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
4976 local cnt_cli2ost=$((num_clients * OSTCOUNT))
4977 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
4978 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
4979 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
4980 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt + cnt_cli2ost + cnt_cli2mdt))
4994 local cmd="$tgt.srpc.flavor"
4996 if [ $net == "any" ]; then
5001 if [ $dir != "any" ]; then
5006 log "Setting sptlrpc rule: $cmd"
5007 do_facet mgs "$LCTL conf_param $cmd"
5016 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
5017 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
5019 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
5021 if [ "x$bulkspec" != "x" ]; then
5022 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
5024 if [ "x$algs" != "x" ]; then
5025 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
5027 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
5028 if [ $bulk == "bulkn" ]; then
5029 bulk_count=`echo "$output" | grep "bulk flavor" \
5030 | grep "null/null" | wc -l`
5031 elif [ $bulk == "bulki" ]; then
5032 bulk_count=`echo "$output" | grep "bulk flavor" \
5033 | grep "/null" | grep -v "null/" | wc -l`
5035 bulk_count=`echo "$output" | grep "bulk flavor" \
5036 | grep -v "/null" | grep -v "null/" | wc -l`
5040 [ $bulk_count -lt $count ] && count=$bulk_count
5051 local clients=${CLIENTS:-`hostname`}
5053 for c in ${clients//,/ }; do
5054 output=`do_node $c lctl get_param -n mdc.*-MDT*-mdc-*.$PROC_CLI 2>/dev/null`
5055 tmpcnt=`count_flvr "$output" $flavor`
5056 cnt=$((cnt + tmpcnt))
5066 local clients=${CLIENTS:-`hostname`}
5068 for c in ${clients//,/ }; do
5069 output=`do_node $c lctl get_param -n osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null`
5070 tmpcnt=`count_flvr "$output" $flavor`
5071 cnt=$((cnt + tmpcnt))
5081 if [ $MDSCOUNT -le 1 ]; then
5086 for num in `seq $MDSCOUNT`; do
5087 output=`do_facet mds$num lctl get_param -n mdc.*-MDT*-mdc[0-9]*.$PROC_CLI 2>/dev/null`
5088 tmpcnt=`count_flvr "$output" $flavor`
5089 cnt=$((cnt + tmpcnt))
5100 for num in `seq $MDSCOUNT`; do
5101 mdtosc=$(get_mdtosc_proc_path mds$num)
5102 mdtosc=${mdtosc/-MDT*/-MDT\*}
5103 output=$(do_facet mds$num lctl get_param -n \
5104 osc.$mdtosc.$PROC_CLI 2>/dev/null)
5105 tmpcnt=`count_flvr "$output" $flavor`
5106 cnt=$((cnt + tmpcnt))
5115 output=`do_facet client lctl get_param -n mgc.*.$PROC_CLI 2>/dev/null`
5116 count_flvr "$output" $flavor
5121 local dir=$1 # from to
5122 local flavor=$2 # flavor expected
5125 if [ $dir == "cli2mdt" ]; then
5126 res=`flvr_cnt_cli2mdt $flavor`
5127 elif [ $dir == "cli2ost" ]; then
5128 res=`flvr_cnt_cli2ost $flavor`
5129 elif [ $dir == "mdt2mdt" ]; then
5130 res=`flvr_cnt_mdt2mdt $flavor`
5131 elif [ $dir == "mdt2ost" ]; then
5132 res=`flvr_cnt_mdt2ost $flavor`
5133 elif [ $dir == "all2ost" ]; then
5134 res1=`flvr_cnt_mdt2ost $flavor`
5135 res2=`flvr_cnt_cli2ost $flavor`
5136 res=$((res1 + res2))
5137 elif [ $dir == "all2mdt" ]; then
5138 res1=`flvr_cnt_mdt2mdt $flavor`
5139 res2=`flvr_cnt_cli2mdt $flavor`
5140 res=$((res1 + res2))
5141 elif [ $dir == "all2all" ]; then
5142 res1=`flvr_cnt_mdt2ost $flavor`
5143 res2=`flvr_cnt_cli2ost $flavor`
5144 res3=`flvr_cnt_mdt2mdt $flavor`
5145 res4=`flvr_cnt_cli2mdt $flavor`
5146 res=$((res1 + res2 + res3 + res4))
5154 local dir=$1 # from to
5155 local flavor=$2 # flavor expected
5156 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
5160 for ((i=0;i<20;i++)); do
5161 echo -n "checking $dir..."
5162 res=$(do_check_flavor $dir $flavor)
5163 echo "found $res/$expect $flavor connections"
5164 [ $res -ge $expect ] && return 0
5168 echo "Error checking $flavor of $dir: expect $expect, actual $res"
5172 restore_to_default_flavor()
5174 local proc="mgs.MGS.live.$FSNAME"
5176 echo "restoring to default flavor..."
5178 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
5180 # remove all existing rules if any
5181 if [ $nrule -ne 0 ]; then
5182 echo "$nrule existing rules"
5183 for rule in `do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor."`; do
5184 echo "remove rule: $rule"
5185 spec=`echo $rule | awk -F = '{print $1}'`
5186 do_facet mgs "$LCTL conf_param -d $spec"
5190 # verify no rules left
5191 nrule=`do_facet mgs lctl get_param -n $proc 2>/dev/null | grep ".srpc.flavor." | wc -l`
5192 [ $nrule -ne 0 ] && error "still $nrule rules left"
5194 # wait for default flavor to be applied
5195 # currently default flavor for all connections are 'null'
5196 wait_flavor all2all null
5197 echo "now at default flavor settings"
5202 local flavor=${1:-null}
5204 echo "setting all flavor to $flavor"
5206 # FIXME need parameter to this fn
5207 # and remove global vars
5208 local cnt_all2all=$(calc_connection_cnt all2all)
5210 local res=$(do_check_flavor all2all $flavor)
5211 if [ $res -eq $cnt_all2all ]; then
5212 echo "already have total $res $flavor connections"
5216 echo "found $res $flavor out of total $cnt_all2all connections"
5217 restore_to_default_flavor
5219 [[ $flavor = null ]] && return 0
5221 set_rule $FSNAME any any $flavor
5222 wait_flavor all2all $flavor
5228 # Checking for shared logdir
5229 if [ ! -d $dir ]; then
5230 # Not found. Create local logdir
5233 touch $dir/check_file.$(hostname -s)
5238 check_write_access() {
5243 for node in $(nodes_list); do
5244 file=$dir/check_file.$(short_hostname $node)
5245 if [[ ! -f "$file" ]]; then
5246 # Logdir not accessible/writable from this node.
5249 rm -f $file || return 1
5255 if [[ -n $YAML_LOG ]]; then
5258 local SAVE_UMASK=`umask`
5261 export YAML_LOG=${LOGDIR}/results.yml
5265 if [ ! -f $YAML_LOG ]; then # If the yaml log already exists then we will just append to it
5266 if check_shared_dir $LOGDIR; then
5267 touch $LOGDIR/shared
5268 echo "Logging to shared log directory: $LOGDIR"
5270 echo "Logging to local directory: $LOGDIR"
5273 yml_nodes_file $LOGDIR >> $YAML_LOG
5274 yml_results_file >> $YAML_LOG
5281 yml_log_test $1 >> $YAML_LOG
5285 yml_log_test_status $@ >> $YAML_LOG
5288 log_sub_test_begin() {
5289 yml_log_sub_test_begin "$@" >> $YAML_LOG
5292 log_sub_test_end() {
5293 yml_log_sub_test_end "$@" >> $YAML_LOG
5299 local llverdev_opts=$2
5300 local devname=$(basename $1)
5301 local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
5302 # loop devices aren't in /proc/partitions
5303 [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
5305 size=$(($size / 1024 / 1024)) # Gb
5307 local partial_arg=""
5308 # Run in partial (fast) mode if the size
5309 # of a partition > 1 GB
5310 [ $size -gt 1 ] && partial_arg="-p"
5312 llverdev --force $partial_arg $llverdev_opts $dev
5318 local llverfs_opts=$2
5319 local partial_arg=""
5320 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
5322 # Run in partial (fast) mode if the size
5323 # of a partition > 1 GB
5324 [ $size -gt 1 ] && partial_arg="-p"
5326 llverfs $partial_arg $llverfs_opts $dir
5329 remove_mdt_files() {
5334 local mntpt=$(facet_mntpt $facet)
5335 local opts=$MDS_MOUNT_OPTS
5337 echo "removing files from $mdtdev on $facet: $files"
5338 if [ $(facet_fstype $facet) == ldiskfs ] &&
5339 ! do_facet $facet test -b ${!dev}; then
5340 opts=$(csa_add "$opts" -o loop)
5342 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
5346 rm $mntpt/ROOT/$f || { rc=$?; break; }
5348 umount -f $mntpt || return $?
5352 duplicate_mdt_files() {
5357 local mntpt=$(facet_mntpt $facet)
5358 local opts=$MDS_MOUNT_OPTS
5360 echo "duplicating files on $mdtdev on $facet: $files"
5361 mkdir -p $mntpt || return $?
5362 if [ $(facet_fstype $facet) == ldiskfs ] &&
5363 ! do_facet $facet test -b ${!dev}; then
5364 opts=$(csa_add "$opts" -o loop)
5366 mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
5377 tmp=$(mktemp $TMP/setfattr.XXXXXXXXXX)
5378 pushd $mntpt/ROOT > /dev/null || return $?
5381 touch $f.bad || return $?
5382 getfattr -n trusted.lov $f | sed "s#$f#&.bad#" > $tmp
5384 [ $rc -eq 0 ] || return $rc
5385 setfattr --restore $tmp || return $?
5391 local devs=${1//,/ }
5394 local rslt=$TMP/sgpdd_survey
5396 # sgpdd-survey cleanups ${rslt}.* files
5398 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
5404 # returns the canonical name for an ldiskfs device
5409 do_facet $facet "dv=\\\$(lctl get_param -n $dev);
5410 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
5411 echo dm-\\\${foo##*:};
5413 echo \\\$(basename \\\$dv);
5417 is_sanity_benchmark() {
5418 local benchmarks="dbench bonnie iozone fsx"
5420 for b in $benchmarks; do
5421 if [ "$b" == "$suite" ]; then
5429 $LCTL get_param -n osc.*.kbytesavail | sort -n | head -n1
5432 # Get the block size of the filesystem.
5438 size=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
5439 awk '/^Block size:/ {print $3}')
5443 # Check whether the "large_xattr" feature is enabled or not.
5444 large_xattr_enabled() {
5445 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
5447 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 | grep -q large_xattr"
5448 return ${PIPESTATUS[0]}
5451 # Get the maximum xattr size supported by the filesystem.
5455 if large_xattr_enabled; then
5456 # include/linux/limits.h: #define XATTR_SIZE_MAX 65536
5459 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
5460 local block_size=$(get_block_size $SINGLEMDS $mds_dev)
5462 # maximum xattr size = size of block - size of header -
5463 # size of 1 entry - 4 null bytes
5464 size=$((block_size - 32 - 32 - 4))
5470 # Dump the value of the named xattr from a file.
5475 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
5478 # Generate a string with size of $size bytes.
5480 local size=${1:-1024} # in bytes
5482 echo "$(head -c $size < /dev/zero | tr '\0' y)"
5485 reformat_external_journal() {
5486 if [ ! -z ${EJOURNAL} ]; then
5487 local rcmd="do_facet ${SINGLEMDS}"
5489 echo "reformat external journal on ${SINGLEMDS}:${EJOURNAL}"
5490 ${rcmd} mke2fs -O journal_dev ${EJOURNAL} || return 1
5494 # MDT file-level backup/restore
5495 mds_backup_restore() {
5496 local devname=$(mdsdevname ${SINGLEMDS//mds/})
5497 local mntpt=$(facet_mntpt brpt)
5498 local rcmd="do_facet ${SINGLEMDS}"
5499 local metaea=${TMP}/backup_restore.ea
5500 local metadata=${TMP}/backup_restore.tgz
5501 local opts=${MDS_MOUNT_OPTS}
5503 if ! ${rcmd} test -b ${devname}; then
5504 opts=$(csa_add "$opts" -o loop)
5507 echo "file-level backup/restore on ${SINGLEMDS}:${devname}"
5509 # step 1: build mount point
5510 ${rcmd} mkdir -p $mntpt
5511 # step 2: cleanup old backup
5512 ${rcmd} rm -f $metaea $metadata
5514 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
5515 # step 4: backup metaea
5517 ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
5519 # step 5: backup metadata
5521 ${rcmd} tar zcf $metadata -C $mntpt/ . > /dev/null 2>&1 || return 3
5523 ${rcmd} umount -d $mntpt || return 4
5524 # step 7: reformat external journal if needed
5525 reformat_external_journal || return 5
5526 # step 8: reformat dev
5527 echo "reformat new device"
5528 add ${SINGLEMDS} $(mkfs_opts ${SINGLEMDS}) --backfstype ldiskfs \
5529 --reformat $devname > /dev/null || return 6
5531 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
5532 # step 10: restore metadata
5534 ${rcmd} tar zxfp $metadata -C $mntpt > /dev/null 2>&1 || return 8
5535 # step 11: restore metaea
5537 ${rcmd} "cd $mntpt && setfattr --restore=$metaea && cd - " || return 9
5538 # step 12: remove recovery logs
5539 echo "remove recovery logs"
5540 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
5541 # step 13: umount dev
5542 ${rcmd} umount -d $mntpt || return 10
5543 # step 14: cleanup tmp backup
5544 ${rcmd} rm -f $metaea $metadata
5549 local devname=$(mdsdevname ${SINGLEMDS//mds/})
5550 local mntpt=$(facet_mntpt brpt)
5551 local rcmd="do_facet ${SINGLEMDS}"
5553 local opts=${MDS_MOUNT_OPTS}
5555 if ! ${rcmd} test -b ${devname}; then
5556 opts=$(csa_add "$opts" -o loop)
5559 echo "remove OI files: idx=${idx}"
5561 # step 1: build mount point
5562 ${rcmd} mkdir -p $mntpt
5564 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
5565 if [ -z $idx ]; then
5566 # step 3: remove all OI files
5567 ${rcmd} rm -fv $mntpt/oi.16*
5568 elif [ $idx -lt 2 ]; then
5569 ${rcmd} rm -fv $mntpt/oi.16.${idx}
5573 # others, rm oi.16.[idx, idx * idx, idx ** ...]
5574 for ((i=${idx}; i<64; i=$((i * idx)))); do
5575 ${rcmd} rm -fv $mntpt/oi.16.${i}
5579 ${rcmd} umount -d $mntpt || return 2
5580 # OI files will be recreated when mounted as lustre next time.