3 trap 'print_summary && print_stack_trace | tee $TF_FAIL && \
4 echo "$TESTSUITE: FAIL: test-framework exiting on error"' ERR
8 export REFORMAT=${REFORMAT:-""}
9 export WRITECONF=${WRITECONF:-""}
10 export VERBOSE=${VERBOSE:-false}
11 export GSS=${GSS:-false}
12 export GSS_SK=${GSS_SK:-false}
14 export SHARED_KEY=${SHARED_KEY:-false}
15 export SK_PATH=${SK_PATH:-/tmp/test-framework-keys}
16 export SK_OM_PATH=$SK_PATH'/tmp-request-mount'
17 export SK_MOUNTED=${SK_MOUNTED:-false}
18 export SK_FLAVOR=${SK_FLAVOR:-ski}
19 export SK_NO_KEY=${SK_NO_KEY:-true}
20 export SK_UNIQUE_NM=${SK_UNIQUE_NM:-false}
21 export SK_S2S=${SK_S2S:-false}
22 export SK_S2SNM=${SK_S2SNM:-TestFrameNM}
23 export SK_S2SNMCLI=${SK_S2SNMCLI:-TestFrameNMCli}
24 export SK_SKIPFIRST=${SK_SKIPFIRST:-true}
25 export IDENTITY_UPCALL=default
27 export FLAKEY=${FLAKEY:-true}
28 # specify environment variable containing batch job name for server statistics
29 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
31 #export PDSH="pdsh -S -Rssh -w"
32 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
33 export UMOUNT=${UMOUNT:-"umount -d"}
35 export LSNAPSHOT_CONF="/etc/ldev.conf"
36 export LSNAPSHOT_LOG="/var/log/lsnapshot.log"
38 export DATA_SEQ_MAX_WIDTH=0x1ffffff
40 # sles12 umount has a issue with -d option
41 [ -e /etc/SuSE-release ] && grep -w VERSION /etc/SuSE-release | grep -wq 12 && {
42 export UMOUNT="umount"
45 # function used by scripts run on remote nodes
46 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
47 . $LUSTRE/tests/functions.sh
48 . $LUSTRE/tests/yaml.sh
50 export LD_LIBRARY_PATH=${LUSTRE}/utils/.libs:${LUSTRE}/utils:${LD_LIBRARY_PATH}
52 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
54 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
56 if [ -f "$EXCEPT_LIST_FILE" ]; then
57 echo "Reading test skip list from $EXCEPT_LIST_FILE"
62 # check config files for options in decreasing order of preference
63 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
64 MODPROBECONF=/etc/modprobe.d/lustre.conf
65 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
66 MODPROBECONF=/etc/modprobe.d/Lustre
67 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
68 MODPROBECONF=/etc/modprobe.conf
70 sanitize_parameters() {
71 for i in DIR DIR1 DIR2 MOUNT MOUNT1 MOUNT2
75 if [ -d "$path" ]; then
76 eval export $i=$(echo $path | sed -r 's/\/+$//g')
82 [[ $DIR/ = $MOUNT/* ]] ||
83 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
84 [[ $DIR1/ = $MOUNT1/* ]] ||
85 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
86 [[ $DIR2/ = $MOUNT2/* ]] ||
87 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
89 [ -n "$failed" ] && exit 99 || true
93 echo "usage: $0 [-r] [-f cfgfile]"
101 [ -z "$DEFAULT_SUITES" ] && return 0
102 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
104 local form="%-13s %-17s %-9s %s %s\n"
106 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
107 echo "---------------------------------------------------------------"
108 for O in $DEFAULT_SUITES; do
109 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
110 [ "${!O}" = "no" ] && continue || true
111 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
112 local log=${TMP}/${o}.log
114 if is_sanity_benchmark $o; then
115 log=${TMP}/sanity-benchmark.log
120 local status=Unfinished
123 skipped=$(grep excluded $log |
124 awk '{ printf " %s", $3 }' | sed 's/test_//g')
125 slow=$(egrep "^PASS|^FAIL" $log |
126 tr -d "("| sed s/s\)$//g | sort -nr -k 3 |
127 head -n5 | awk '{ print $2":"$3"s" }')
128 total=$(grep duration $log | awk '{ print $2 }')
129 if [ "${!O}" = "done" ]; then
133 local durations=$(egrep "^PASS|^FAIL" $log |
134 tr -d "("| sed s/s\)$//g |
135 awk '{ print $2":"$3"|" }')
136 details=$(printf "%s\n%s %s %s\n" "$details" \
137 "DDETAILS" "$O" "$(echo $durations)")
140 printf "$form" $status "$O" "${total}" "E=$skipped"
141 printf "$form" "-" "-" "-" "S=$(echo $slow)"
144 for O in $DEFAULT_SUITES; do
145 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
146 if [ "${!O}" = "no" ]; then
147 printf "$form" "Skipped" "$O" ""
151 # print the detailed tests durations if DDETAILS=true
157 # Get information about the Lustre environment. The information collected
158 # will be used in Lustre tests.
159 # usage: get_lustre_env
160 # input: No required or optional arguments
161 # output: No return values, environment variables are exported
165 export mds1_FSTYPE=${mds1_FSTYPE:-$(facet_fstype mds1)}
166 export ost1_FSTYPE=${ost1_FSTYPE:-$(facet_fstype ost1)}
168 export MGS_VERSION=$(lustre_version_code mgs)
169 export MDS1_VERSION=$(lustre_version_code mds1)
170 export OST1_VERSION=$(lustre_version_code ost1)
171 export CLIENT_VERSION=$(lustre_version_code client)
174 # Prefer using "mds1" directly instead of SINGLEMDS.
175 # Keep this for compat until it is removed from scripts.
176 export SINGLEMDS=${SINGLEMDS:-mds1}
180 export LUSTRE=$(absolute_path $LUSTRE)
181 export TESTSUITE=$(basename $0 .sh)
182 export TEST_FAILED=false
183 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
184 export RPC_MODE=${RPC_MODE:-false}
185 export DO_CLEANUP=${DO_CLEANUP:-true}
186 export KEEP_ZPOOL=${KEEP_ZPOOL:-false}
187 export CLEANUP_DM_DEV=false
188 export PAGE_SIZE=$(get_page_size client)
189 export NAME=${NAME:-local}
191 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
193 export MKE2FS=$MKE2FS
194 if [ -z "$MKE2FS" ]; then
195 if which mkfs.ldiskfs >/dev/null 2>&1; then
196 export MKE2FS=mkfs.ldiskfs
202 export DEBUGFS=$DEBUGFS
203 if [ -z "$DEBUGFS" ]; then
204 if which debugfs.ldiskfs >/dev/null 2>&1; then
205 export DEBUGFS=debugfs.ldiskfs
207 export DEBUGFS=debugfs
211 export TUNE2FS=$TUNE2FS
212 if [ -z "$TUNE2FS" ]; then
213 if which tunefs.ldiskfs >/dev/null 2>&1; then
214 export TUNE2FS=tunefs.ldiskfs
216 export TUNE2FS=tune2fs
220 export E2LABEL=$E2LABEL
221 if [ -z "$E2LABEL" ]; then
222 if which label.ldiskfs >/dev/null 2>&1; then
223 export E2LABEL=label.ldiskfs
225 export E2LABEL=e2label
229 export DUMPE2FS=$DUMPE2FS
230 if [ -z "$DUMPE2FS" ]; then
231 if which dumpfs.ldiskfs >/dev/null 2>&1; then
232 export DUMPE2FS=dumpfs.ldiskfs
234 export DUMPE2FS=dumpe2fs
238 export E2FSCK=$E2FSCK
239 if [ -z "$E2FSCK" ]; then
240 if which fsck.ldiskfs >/dev/null 2>&1; then
241 export E2FSCK=fsck.ldiskfs
247 export RESIZE2FS=$RESIZE2FS
248 if [ -z "$RESIZE2FS" ]; then
249 if which resizefs.ldiskfs >/dev/null 2>&1; then
250 export RESIZE2FS=resizefs.ldiskfs
252 export RESIZE2FS=resize2fs
256 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
257 export FSCK_MAX_ERR=4 # File system errors left uncorrected
259 export ZFS=${ZFS:-zfs}
260 export ZPOOL=${ZPOOL:-zpool}
261 export ZDB=${ZDB:-zdb}
262 export PARTPROBE=${PARTPROBE:-partprobe}
264 #[ -d /r ] && export ROOT=${ROOT:-/r}
265 export TMP=${TMP:-$ROOT/tmp}
266 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
267 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
268 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
270 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
271 if ! echo $PATH | grep -q $LUSTRE/utils; then
272 export PATH=$LUSTRE/utils:$PATH
274 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
275 export PATH=$LUSTRE/utils/gss:$PATH
277 if ! echo $PATH | grep -q $LUSTRE/tests; then
278 export PATH=$LUSTRE/tests:$PATH
280 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
281 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
283 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
284 [ ! -f "$LST" ] && export LST=$(which lst)
285 export LSTSH=${LSTSH:-"$LUSTRE/../lustre-iokit/lst-survey/lst.sh"}
286 [ ! -f "$LSTSH" ] && export LSTSH=$(which lst.sh)
287 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
288 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
289 export MCREATE=${MCREATE:-mcreate}
290 export MULTIOP=${MULTIOP:-multiop}
291 export MMAP_CAT=${MMAP_CAT:-mmap_cat}
292 export STATX=${STATX:-statx}
293 # Ubuntu, at least, has a truncate command in /usr/bin
294 # so fully path our truncate command.
295 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
296 export FSX=${FSX:-$LUSTRE/tests/fsx}
297 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
298 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
299 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
300 export PATH=$LUSTRE/tests/racer:$PATH:
302 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
303 export PATH=$LUSTRE/tests/mpi:$PATH
306 export LNETCTL=${LNETCTL:-"$LUSTRE/../lnet/utils/lnetctl"}
307 [ ! -f "$LNETCTL" ] && export LNETCTL=$(which lnetctl 2> /dev/null)
308 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
309 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
310 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
311 [ ! -f "$LFS" ] && export LFS=$(which lfs)
312 export KSOCKLND_CONFIG=${KSOCKLND_CONFIG:-"$LUSTRE/scripts/ksocklnd-config"}
313 [ ! -f "$KSOCKLND_CONFIG" ] &&
314 export KSOCKLND_CONFIG=$(which ksocklnd-config 2> /dev/null)
316 export PERM_CMD=$(echo ${PERM_CMD:-"$LCTL conf_param"})
318 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
319 if [ ! -f "$L_GETIDENTITY" ]; then
320 if `which l_getidentity > /dev/null 2>&1`; then
321 export L_GETIDENTITY=$(which l_getidentity)
323 export L_GETIDENTITY=NONE
326 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
327 [ ! -f "$LL_DECODE_FILTER_FID" ] &&
328 export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
329 export LL_DECODE_LINKEA=${LL_DECODE_LINKEA:-"$LUSTRE/utils/ll_decode_linkea"}
330 [ ! -f "$LL_DECODE_LINKEA" ] &&
331 export LL_DECODE_LINKEA="ll_decode_linkea"
332 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
333 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
334 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
335 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
336 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
337 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
338 [ ! -f "$LUSTRE_RMMOD" ] &&
339 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
340 export LUSTRE_ROUTES_CONVERSION=${LUSTRE_ROUTES_CONVERSION:-$LUSTRE/scripts/lustre_routes_conversion}
341 [ ! -f "$LUSTRE_ROUTES_CONVERSION" ] &&
342 export LUSTRE_ROUTES_CONVERSION=$(which lustre_routes_conversion 2> /dev/null)
343 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
344 [ ! -f "$LFS_MIGRATE" ] &&
345 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
346 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
347 [ ! -f "$LR_READER" ] &&
348 export LR_READER=$(which lr_reader 2> /dev/null)
349 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
350 export LSOM_SYNC=${LSOM_SYNC:-"$LUSTRE/utils/llsom_sync"}
351 [ ! -f "$LSOM_SYNC" ] &&
352 export LSOM_SYNC=$(which llsom_sync 2> /dev/null)
353 [ -z "$LSOM_SYNC" ] && export LSOM_SYNC="/usr/sbin/llsom_sync"
354 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
355 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
356 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
358 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
360 export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
361 [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
363 export DMSETUP=${DMSETUP:-dmsetup}
364 export DM_DEV_PATH=${DM_DEV_PATH:-/dev/mapper}
365 export LOSETUP=${LOSETUP:-losetup}
367 if [ "$ACCEPTOR_PORT" ]; then
368 export PORT_OPT="--port $ACCEPTOR_PORT"
372 $RPC_MODE || echo "Using GSS shared-key feature"
374 export LGSS_SK=$(which lgss_sk 2> /dev/null)
376 export LGSS_SK="$LUSTRE/utils/gss/lgss_sk"
378 error_exit "built with lgss_sk disabled! SEC=$SEC"
386 $RPC_MODE || echo "Using GSS/krb5 ptlrpc security flavor"
387 which lgss_keyring > /dev/null 2>&1 ||
388 error_exit "built with gss disabled! SEC=$SEC"
399 IDENTITY_UPCALL=false
403 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
405 # Paths on remote nodes, if different
406 export RLUSTRE=${RLUSTRE:-$LUSTRE}
407 export RPWD=${RPWD:-$PWD}
408 export I_MOUNTED=${I_MOUNTED:-"no"}
409 export AUSTER_CLEANUP=${AUSTER_CLEANUP:-false}
410 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
411 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
412 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
413 ! -f $LUSTRE/mdt/mdt.ko ]; then
414 export CLIENTMODSONLY=yes
417 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
418 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
422 while getopts "rvwf:" opt $*; do
427 w) WRITECONF=writeconf;;
432 shift $((OPTIND - 1))
435 # print the durations of each test if "true"
436 DDETAILS=${DDETAILS:-false}
437 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
442 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
444 # Constants used in more than one test script
445 export LOV_MAX_STRIPE_COUNT=2000
446 export DELETE_OLD_POOLS=${DELETE_OLD_POOLS:-false}
447 export KEEP_POOLS=${KEEP_POOLS:-false}
448 export PARALLEL=${PARALLEL:-"no"}
450 export BLCKSIZE=${BLCKSIZE:-4096}
451 export MACHINEFILE=${MACHINEFILE:-$TMP/$(basename $0 .sh).machines}
454 # use localrecov to enable recovery for local clients, LU-12722
455 [[ $MDS1_VERSION -lt $(version_code 2.13.52) ]] || {
456 export MDS_MOUNT_OPTS=${MDS_MOUNT_OPTS:-"-o localrecov"}
457 export MGS_MOUNT_OPTS=${MGS_MOUNT_OPTS:-"-o localrecov"}
460 [[ $OST1_VERSION -lt $(version_code 2.13.52) ]] ||
461 export OST_MOUNT_OPTS=${OST_MOUNT_OPTS:-"-o localrecov"}
468 ncpts=$(do_facet $facet "lctl get_param -n " \
469 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
471 if [ $ncpts -eq 0 ]; then
478 # Return a numeric version code based on a version string. The version
479 # code is useful for comparison two version strings to see which is newer.
481 # split arguments like "1.8.6-wc3" into "1", "8", "6", "3"
482 eval set -- $(tr "[:punct:][a-zA-Z]" " " <<< $*)
484 echo -n $(((${1:-0}<<24) | (${2:-0}<<16) | (${3:-0}<<8) | (${4:-0})))
487 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
488 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
490 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
492 # usage: lustre_build_version
494 # All Lustre versions support "lctl get_param" to report the version of the
495 # code running in the kernel (what our tests are interested in), but it
496 # doesn't work without modules loaded. After 2.9.53 and in upstream kernels
497 # the "version" parameter doesn't include "lustre: " at the beginning.
498 # If that fails, call "lctl lustre_build_version" which prints either (or both)
499 # the userspace and kernel build versions, but until 2.8.55 required root
500 # access to get the Lustre kernel version. If that also fails, fall back to
501 # using "lctl --version", which is easy to parse and works without the kernel
502 # modules, but was only added in 2.6.50 and only prints the lctl tool version,
503 # not the module version, though they are usually the same.
505 # Various commands and their output format for different Lustre versions:
506 # lctl get_param version: 2.9.55
507 # lctl get_param version: lustre: 2.8.53
508 # lctl get_param version: lustre: 2.6.52
509 # kernel: patchless_client
510 # build: v2_6_92_0-2.6.32-431.el6_lustre.x86_64
511 # lctl lustre_build_version: Lustre version: 2.8.53_27_gae67fc01
512 # lctl lustre_build_version: error: lustre_build_version: Permission denied
513 # (as non-root user) lctl version: v2_6_92_0-2.6.32-431.el6.x86_64
514 # lctl lustre_build_version: Lustre version: 2.5.3-2.6.32.26-175.fc12.x86_64
515 # lctl version: 2.5.3-2.6.32..26-175fc12.x86_64
516 # lctl --version: lctl 2.6.50
518 # output: prints version string to stdout in (up to 4) dotted-decimal values
519 lustre_build_version() {
520 local facet=${1:-client}
521 local facet_version=${facet}_VERSION
523 # if the global variable is already set, then use that
524 [ -n "${!facet_version}" ] && echo ${!facet_version} && return
526 # this is the currently-running version of the kernel modules
527 local ver=$(do_facet $facet "$LCTL get_param -n version 2>/dev/null")
528 # we mostly test 2.10+ systems, only try others if the above fails
529 if [ -z "$ver" ]; then
530 ver=$(do_facet $facet "$LCTL lustre_build_version 2>/dev/null")
532 if [ -z "$ver" ]; then
533 ver=$(do_facet $facet "$LCTL --version 2>/dev/null" |
536 local lver=$(egrep -i "lustre: |version: " <<<"$ver" | head -n 1)
537 [ -n "$lver" ] && ver="$lver"
539 lver=$(sed -e 's/[^:]*: //' -e 's/^v//' -e 's/[ -].*//' <<<$ver |
540 tr _ . | cut -d. -f1-4)
542 # save in global variable for the future
543 export $facet_version=$lver
548 # Report the Lustre numeric build version code for the supplied facet.
549 lustre_version_code() {
550 version_code $(lustre_build_version $1)
554 /sbin/lsmod | grep -q "^\<$1\>"
557 check_lfs_df_ret_val() {
558 # Ignore only EOPNOTSUPP (which is 95; Operation not supported) error
559 # returned by 'lfs df' for valid dentry but not a lustrefs.
561 # 'lfs df' historically always returned success(0) instead of
562 # EOPNOTSUPP. This function for compatibility reason, ignores and
563 # masquerades EOPNOTSUPP as success.
564 [[ $1 -eq 95 ]] && return 0
577 msg="$(insmod $module $args 2>&1)" && return 0 || rc=$?
580 # parallels can't load modules directly from prlfs, use /tmp instead
581 if $PRLFS || [[ "$(stat -f -c%t $module)" == "7c7c6673" ]]; then
582 local target="$(mktemp)"
584 cp "$module" "$target"
587 [[ $rc == 0 ]] && PRLFS=true
595 # Load a module on the system where this is running.
597 # usage: load_module module_name [module arguments for insmod/modprobe]
599 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
600 # will be used as the arguments. Otherwise arguments will be obtained from
601 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
604 local module=$1 # '../libcfs/libcfs/libcfs', 'obdclass/obdclass', ...
607 local base=$(basename $module $ext)
609 local -A module_is_loaded_aa
613 for mod in $(lsmod | awk '{ print $1; }'); do
614 module_is_loaded_aa[${mod//-/_}]=true
618 ${module_is_loaded_aa[${1//-/_}]:-false}
621 if module_is_loaded $base; then
625 if [[ -f $LUSTRE/$module$ext ]]; then
626 path=$LUSTRE/$module$ext
627 elif [[ "$base" == lnet_selftest ]] &&
628 [[ -f $LUSTRE/../lnet/selftest/$base$ext ]]; then
629 path=$LUSTRE/../lnet/selftest/$base$ext
634 if [[ -n "$path" ]]; then
635 # Try to load any non-Lustre modules that $module depends on.
636 for mod in $(modinfo --field=depends $path | tr ',' ' '); do
637 if ! module_is_loaded $mod; then
643 # If no module arguments were passed then get them from
644 # $MODOPTS_<MODULE>, otherwise from modprobe.conf.
645 if [ $# -eq 0 ]; then
646 # $MODOPTS_<MODULE>; we could use associative arrays, but that's
647 # not in Bash until 4.x, so we resort to eval.
648 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
649 eval set -- \$$optvar
650 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
651 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
653 opt=$(awk -v var="^options $base" '$0 ~ var \
654 {gsub("'"options $base"'",""); print}' \
656 set -- $(echo -n $opt)
658 # Ensure we have accept=all for lnet
659 if [[ "$base" == lnet ]]; then
660 # OK, this is a bit wordy...
661 local arg accept_all_present=false
664 [[ "$arg" == accept=all ]] &&
665 accept_all_present=true
668 $accept_all_present || set -- "$@" accept=all
675 [ $# -gt 0 ] && echo "${module} options: '$*'"
677 # Note that insmod will ignore anything in modprobe.conf, which is why
678 # we're passing options on the command-line. If $path does not exist
679 # then we must be testing a "make install" or"rpm" installation. Also
680 # note that failing to load ptlrpc_gss is not considered fatal.
681 if [[ -n "$path" ]]; then
682 lustre_insmod $path "$@"
683 elif [[ "$base" == ptlrpc_gss ]]; then
684 if ! modprobe $base "$@" 2>/dev/null; then
685 echo "gss/krb5 is not supported"
693 $LCTL mark "$LNETCTL $*"
699 # For kmemleak-enabled kernels we need clear all past state
700 # that obviously has nothing to do with this Lustre run
701 # Disable automatic memory scanning to avoid perf hit.
702 if [ -f /sys/kernel/debug/kmemleak ] ; then
703 echo scan=off > /sys/kernel/debug/kmemleak || true
704 echo scan > /sys/kernel/debug/kmemleak || true
705 echo clear > /sys/kernel/debug/kmemleak || true
708 echo Loading modules from $LUSTRE
712 if [ -f /sys/devices/system/cpu/online ]; then
713 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
714 echo "detected $ncpus online CPUs by sysfs"
716 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
719 if [ $rc -eq 0 ]; then
720 echo "detected $ncpus online CPUs by getconf"
722 echo "Can't detect number of CPUs"
727 # if there is only one CPU core, libcfs can only create one partition
728 # if there is more than 4 CPU cores, libcfs should create multiple CPU
729 # partitions. So we just force libcfs to create 2 partitions for
730 # system with 2 or 4 cores
731 local saved_opts="$MODOPTS_LIBCFS"
733 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
734 # force to enable multiple CPU partitions
735 echo "Force libcfs to create 2 CPU partitions"
736 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
738 echo "libcfs will create CPU partition based on online CPUs"
741 load_module ../libcfs/libcfs/libcfs
742 # Prevent local MODOPTS_LIBCFS being passed as part of environment
743 # variable to remote nodes
746 set_default_debug "neterror net nettrace malloc"
747 if [ "$1" = "config_on_load=1" ]; then
748 load_module ../lnet/lnet/lnet
750 load_module ../lnet/lnet/lnet "$@"
753 LNDPATH=${LNDPATH:-"../lnet/klnds"}
754 if [ -z "$LNETLND" ]; then
756 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
757 tcp*) LNETLND="socklnd/ksocklnd" ;;
758 kfi*) LNETLND="kfilnd/kkfilnd" ;;
759 gni*) LNETLND="gnilnd/kgnilnd" ;;
760 *) local lnd="${NETTYPE%%[0-9]}lnd"
761 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
762 LNETLND="$lnd/k$lnd" ||
763 LNETLND="socklnd/ksocklnd"
766 load_module ../lnet/klnds/$LNETLND
768 if [ "$1" = "config_on_load=1" ]; then
769 do_lnetctl lnet configure --all ||
774 load_modules_local() {
775 if [ -n "$MODPROBE" ]; then
777 echo "Using modprobe to load modules"
781 # Create special udev test rules on every node
782 if [ -f $LUSTRE/lustre/conf/99-lustre.rules ]; then {
783 sed -e 's|/usr/sbin/lctl|$LCTL|g' $LUSTRE/lustre/conf/99-lustre.rules > /etc/udev/rules.d/99-lustre-test.rules
785 echo "SUBSYSTEM==\"lustre\", ACTION==\"change\", ENV{PARAM}==\"?*\", RUN+=\"$LCTL set_param '\$env{PARAM}=\$env{SETTING}'\"" > /etc/udev/rules.d/99-lustre-test.rules
787 udevadm control --reload-rules
792 load_module obdclass/obdclass
793 if ! client_only; then
794 MODOPTS_PTLRPC=${MODOPTS_PTLRPC:-"lbug_on_grant_miscount=1"}
796 load_module ptlrpc/ptlrpc
797 load_module ptlrpc/gss/ptlrpc_gss
805 load_module obdecho/obdecho
806 if ! client_only; then
807 load_module lfsck/lfsck
808 [ "$LQUOTA" != "no" ] &&
809 load_module quota/lquota $LQUOTAOPTS
810 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
811 load_module osd-zfs/osd_zfs
812 elif [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
813 load_module ../ldiskfs/ldiskfs
814 load_module osd-ldiskfs/osd_ldiskfs
826 load_module llite/lustre
827 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
829 rm -f $OGDB/ogdb-$HOSTNAME
830 $LCTL modules > $OGDB/ogdb-$HOSTNAME
832 # 'mount' doesn't look in $PATH, just sbin
833 local mount_lustre=$LUSTRE/utils/mount.lustre
834 if [ -f $mount_lustre ]; then
835 local sbin_mount=$(readlink -f /sbin)/mount.lustre
836 if grep -qw "$sbin_mount" /proc/mounts; then
837 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
839 if ! grep -qw "$sbin_mount" /proc/mounts; then
840 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
841 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
842 cat <<- EOF > "$sbin_mount"
845 echo "This $sbin_mount just a mountpoint." 1>&2
846 echo "It is never supposed to be run." 1>&2
847 logger -p emerg -- "using stub $sbin_mount $@"
850 chmod a+x $sbin_mount
852 mount --bind $mount_lustre $sbin_mount ||
853 error "can't bind $mount_lustre to $sbin_mount"
864 # load modules on remote nodes optionally
865 # lustre-tests have to be installed on these nodes
866 if $LOAD_MODULES_REMOTE; then
867 local list=$(comma_list $(remote_nodes_list))
869 # include failover nodes in case they are not in the list yet
871 for facet in ${facets//,/ }; do
872 failover=$(facet_failover_host $facet)
873 [ -n "$list" ] && [[ ! "$list" =~ "$failover" ]] &&
874 list="$list,$failover"
877 if [ -n "$list" ]; then
878 echo "loading modules on: '$list'"
879 do_rpc_nodes "$list" load_modules_local
885 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
886 LEAK_PORTALS=$(dmesg | tail -n 20 | egrep -i "libcfs.*memory leaked" ||
888 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
889 echo "$LEAK_LUSTRE" 1>&2
890 echo "$LEAK_PORTALS" 1>&2
891 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
892 echo "Memory leaks detected"
893 [ -n "$IGNORE_LEAK" ] &&
894 { echo "ignoring leaks" && return 0; } || true
899 unload_modules_local() {
900 $LUSTRE_RMMOD ldiskfs || return 2
902 [ -f /etc/udev/rules.d/99-lustre-test.rules ] &&
903 rm /etc/udev/rules.d/99-lustre-test.rules
904 udevadm control --reload-rules
907 check_mem_leak || return 254
915 wait_exit_ST client # bug 12845
917 unload_modules_local || rc=$?
919 if $LOAD_MODULES_REMOTE; then
920 local list=$(comma_list $(remote_nodes_list))
921 if [ -n "$list" ]; then
922 echo "unloading modules on: '$list'"
923 do_rpc_nodes "$list" unload_modules_local
927 local sbin_mount=$(readlink -f /sbin)/mount.lustre
928 if grep -qe "$sbin_mount " /proc/mounts; then
929 umount $sbin_mount || true
930 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
934 [[ $rc -eq 0 ]] && echo "modules unloaded."
940 local facet=${1:-ost1}
944 case $(facet_fstype $facet) in
945 ldiskfs) size=32;; # largest seen is 64 with multiple OSTs
946 # grant_block_size is in bytes, allow at least 2x max blocksize
947 zfs) size=$(lctl get_param osc.$FSNAME*.import |
948 awk '/grant_block_size:/ {print $2/512; exit;}')
952 [[ $facet =~ mds ]] && mult=$MDTCOUNT
953 echo -n $((size * mult))
957 local facet=${1:-$SINGLEMDS}
958 local fstype=$(facet_fstype $facet)
961 ldiskfs) size=4;; # ~4KB per inode
962 zfs) size=11;; # 10 to 11KB per inode
968 check_gss_daemon_nodes() {
972 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
973 if [ \\\"\\\$num\\\" -ne 1 ]; then
974 echo \\\$num instance of $dname;
979 check_gss_daemon_facet() {
983 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
984 if [ $num -ne 1 ]; then
985 echo "$num instance of $dname on $facet"
995 echo "Stopping "$@" on $list"
996 do_nodes $list "killall -2 $* 2>/dev/null || true"
999 # start gss daemons on all nodes, or "daemon" on "nodes" if set
1000 start_gss_daemons() {
1004 if [ "$nodes" ] && [ "$daemon" ] ; then
1005 echo "Starting gss daemon on nodes: $nodes"
1006 do_nodes $nodes "$daemon" || return 8
1010 nodes=$(comma_list $(mdts_nodes))
1011 echo "Starting gss daemon on mds: $nodes"
1013 # Start all versions, in case of switching
1014 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 1
1016 do_nodes $nodes "$LSVCGSSD -vvv" || return 1
1019 nodes=$(comma_list $(osts_nodes))
1020 echo "Starting gss daemon on ost: $nodes"
1022 # Start all versions, in case of switching
1023 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 3
1025 do_nodes $nodes "$LSVCGSSD -vvv" || return 3
1027 # starting on clients
1029 local clients=${CLIENTS:-$HOSTNAME}
1031 # wait daemons entering "stable" status
1035 # check daemons are running
1037 nodes=$(comma_list $(mdts_nodes) $(osts_nodes))
1038 check_gss_daemon_nodes $nodes lsvcgssd || return 5
1041 stop_gss_daemons() {
1042 local nodes=$(comma_list $(mdts_nodes))
1044 send_sigint $nodes lsvcgssd lgssd
1046 nodes=$(comma_list $(osts_nodes))
1047 send_sigint $nodes lsvcgssd
1049 nodes=${CLIENTS:-$HOSTNAME}
1050 send_sigint $nodes lgssd
1054 # Add mount flags for shared key
1057 if grep -q skpath <<< "$mt_opts" ; then
1058 mt_opts=$(echo $mt_opts |
1059 sed -e "s#skpath=[^ ,]*#skpath=$SK_PATH#")
1061 if [ -z "$mt_opts" ]; then
1062 mt_opts="-o skpath=$SK_PATH"
1064 mt_opts="$mt_opts,skpath=$SK_PATH"
1074 /usr/lib/lustre/* | /usr/lib64/lustre/* | /usr/lib/lustre | \
1083 [ $from_tree = true ]
1087 if $SHARED_KEY; then
1096 if ! module_loaded ptlrpc_gss; then
1097 load_module ptlrpc/gss/ptlrpc_gss
1098 module_loaded ptlrpc_gss ||
1099 error_exit "init_gss: GSS=$GSS, but gss/krb5 missing"
1102 if $GSS_KRB5 || $GSS_SK; then
1103 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
1106 if $GSS_SK && ! $SK_NO_KEY; then
1107 echo "Loading basic SSK keys on all servers"
1108 do_nodes $(comma_list $(all_server_nodes)) \
1109 "$LGSS_SK -t server -l $SK_PATH/$FSNAME.key || true"
1110 do_nodes $(comma_list $(all_server_nodes)) \
1111 "keyctl show | grep lustre | cut -c1-11 |
1113 xargs -IX keyctl setperm X 0x3f3f3f3f"
1116 if $GSS_SK && $SK_NO_KEY; then
1117 local numclients=${1:-$CLIENTCOUNT}
1118 local clients=${CLIENTS:-$HOSTNAME}
1120 # security ctx config for keyring
1122 local lgssc_conf_file="/etc/request-key.d/lgssc.conf"
1124 if from_build_tree; then
1125 mkdir -p $SK_OM_PATH
1126 if grep -q request-key /proc/mounts > /dev/null; then
1127 echo "SSK: Request key already mounted."
1129 mount -o bind $SK_OM_PATH /etc/request-key.d/
1131 local lgssc_conf_line='create lgssc * * '
1132 lgssc_conf_line+=$(which lgss_keyring)
1133 lgssc_conf_line+=' %o %k %t %d %c %u %g %T %P %S'
1134 echo "$lgssc_conf_line" > $lgssc_conf_file
1137 [ -e $lgssc_conf_file ] ||
1138 error_exit "Could not find key options in $lgssc_conf_file"
1139 echo "$lgssc_conf_file content is:"
1140 cat $lgssc_conf_file
1142 if ! local_mode; then
1143 if from_build_tree; then
1144 do_nodes $(comma_list $(all_nodes)) "mkdir -p \
1146 do_nodes $(comma_list $(all_nodes)) "mount \
1147 -o bind $SK_OM_PATH \
1148 /etc/request-key.d/"
1149 do_nodes $(comma_list $(all_nodes)) "rsync \
1150 -aqv $HOSTNAME:$lgssc_conf_file \
1151 $lgssc_conf_file >/dev/null 2>&1"
1153 do_nodes $(comma_list $(all_nodes)) \
1154 "echo $lgssc_conf_file: ; \
1155 cat $lgssc_conf_file"
1159 # create shared key on all nodes
1160 mkdir -p $SK_PATH/nodemap
1161 rm -f $SK_PATH/$FSNAME.key $SK_PATH/nodemap/c*.key \
1162 $SK_PATH/$FSNAME-*.key
1163 # for nodemap testing each client may need own key,
1164 # and S2S now requires keys as well, both for "client"
1167 $LGSS_SK -t server -f$FSNAME -n $SK_S2SNMCLI \
1168 -w $SK_PATH/$FSNAME-nmclient.key \
1169 -d /dev/urandom >/dev/null 2>&1
1170 $LGSS_SK -t mgs,server -f$FSNAME -n $SK_S2SNM \
1171 -w $SK_PATH/$FSNAME-s2s-server.key \
1172 -d /dev/urandom >/dev/null 2>&1
1175 $LGSS_SK -t server -f$FSNAME -w $SK_PATH/$FSNAME.key \
1176 -d /dev/urandom >/dev/null 2>&1
1178 for i in $(seq 0 $((numclients - 1))); do
1179 $LGSS_SK -t server -f$FSNAME -n c$i \
1180 -w $SK_PATH/nodemap/c$i.key -d /dev/urandom \
1184 if ! local_mode; then
1185 for lnode in $(all_nodes); do
1186 scp -r $SK_PATH ${lnode}:$(dirname $SK_PATH)/
1189 # Set client keys to client type to generate prime P
1191 do_nodes $(all_nodes) "$LGSS_SK -t client,server -m \
1192 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1194 do_nodes $clients "$LGSS_SK -t client -m \
1195 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1196 do_nodes $clients "find $SK_PATH/nodemap \
1197 -name \*.key | xargs -IX $LGSS_SK -t client \
1198 -m X >/dev/null 2>&1"
1199 # also have a client key available on server side,
1200 # for local client mount
1201 do_nodes $(comma_list $(all_server_nodes)) \
1202 "cp $SK_PATH/$FSNAME.key $SK_PATH/${FSNAME}_cli.key && \
1203 $LGSS_SK -t client -m \
1204 $SK_PATH/${FSNAME}_cli.key >/dev/null 2>&1"
1206 # This is required for servers as well, if S2S in use
1208 do_nodes $(comma_list $(mdts_nodes)) \
1209 "cp $SK_PATH/$FSNAME-s2s-server.key \
1210 $SK_PATH/$FSNAME-s2s-client.key; $LGSS_SK \
1211 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1213 do_nodes $(comma_list $(osts_nodes)) \
1214 "cp $SK_PATH/$FSNAME-s2s-server.key \
1215 $SK_PATH/$FSNAME-s2s-client.key; $LGSS_SK \
1216 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1218 do_nodes $clients "$LGSS_SK -t client \
1219 -m $SK_PATH/$FSNAME-nmclient.key \
1224 # mount options for servers and clients
1225 MGS_MOUNT_OPTS=$(add_sk_mntflag $MGS_MOUNT_OPTS)
1226 MDS_MOUNT_OPTS=$(add_sk_mntflag $MDS_MOUNT_OPTS)
1227 OST_MOUNT_OPTS=$(add_sk_mntflag $OST_MOUNT_OPTS)
1228 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
1230 if [ -z "$LGSS_KEYRING_DEBUG" ]; then
1231 LGSS_KEYRING_DEBUG=4
1235 if [ -n "$LGSS_KEYRING_DEBUG" ] && \
1236 ( local_mode || from_build_tree ); then
1238 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
1239 elif [ -n "$LGSS_KEYRING_DEBUG" ]; then
1240 do_nodes $(comma_list $(all_nodes)) "modprobe ptlrpc_gss && \
1242 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG"
1249 # maybe cleanup credential cache?
1256 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNM"
1257 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNMCLI"
1258 $RPC_MODE || echo "Sleeping for 10 sec for Nodemap.."
1262 $RPC_MODE || echo "Cleaning up Shared Key.."
1263 do_nodes $(comma_list $(all_nodes)) "rm -f \
1264 $SK_PATH/$FSNAME*.key $SK_PATH/nodemap/$FSNAME*.key"
1265 do_nodes $(comma_list $(all_nodes)) "keyctl show | \
1266 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
1267 if from_build_tree; then
1268 # Remove the mount and clean up the files we added to
1270 do_nodes $(comma_list $(all_nodes)) "while grep -q \
1271 request-key.d /proc/mounts; do umount \
1272 /etc/request-key.d/; done"
1273 do_nodes $(comma_list $(all_nodes)) "rm -f \
1274 $SK_OM_PATH/lgssc.conf"
1275 do_nodes $(comma_list $(all_nodes)) "rmdir $SK_OM_PATH"
1283 local var=${facet}_svc
1291 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
1292 tr '[:lower:]' '[:upper:]'
1298 if [ $facet == mgs ] || [ $facet == client ]; then
1302 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
1310 if [ -n "${!var}" ]; then
1315 var=$(facet_type $facet)FSTYPE
1316 if [ -n "${!var}" ]; then
1321 if [ -n "$FSTYPE" ]; then
1326 if [[ $facet == mgs ]] && combined_mgs_mds; then
1338 local facets=$(get_facets)
1341 for facet in ${facets//,/ }; do
1342 if [[ $node == $(facet_host $facet) ]] ||
1343 [[ $node == "$(facet_failover_host $facet)" ]]; then
1344 fstype=$(facet_fstype $facet)
1345 if [[ $fstypes != *$fstype* ]]; then
1346 fstypes+="${fstypes:+,}$fstype"
1355 local num=$(facet_number $facet)
1358 if [[ $(facet_type $facet) = OST ]]; then
1359 index=OSTINDEX${num}
1360 if [[ -n "${!index}" ]]; then
1365 index=${OST_INDICES[num - 1]}
1368 [[ -n "$index" ]] || index=$((num - 1))
1376 local fstype=$(facet_fstype $facet)
1380 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
1382 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
1383 ${dev} 2>/dev/null");;
1385 error "unknown fstype!";;
1392 # Get the device of a facet.
1399 mgs) device=$(mgsdevname) ;;
1400 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
1401 ost*) device=$(ostdevname $(facet_number $facet)) ;;
1402 fs2mds) device=$(mdsdevname 1_2) ;;
1403 fs2ost) device=$(ostdevname 1_2) ;;
1404 fs3ost) device=$(ostdevname 2_2) ;;
1412 # Get the virtual device of a facet.
1419 mgs) device=$(mgsvdevname) ;;
1420 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
1421 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
1422 fs2mds) device=$(mdsvdevname 1_2) ;;
1423 fs2ost) device=$(ostvdevname 1_2) ;;
1424 fs3ost) device=$(ostvdevname 2_2) ;;
1432 local virt=$(virt-what 2> /dev/null)
1434 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1436 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1439 VMware|KVM|VirtualBox|Parallels|Bochs)
1440 echo $virt | tr '[A-Z]' '[a-z]' ;;
1446 # Re-read the partition table on failover partner host.
1447 # After a ZFS storage pool is created on a shared device, the partition table
1448 # on the device may change. However, the operating system on the failover
1449 # host may not notice the change automatically. Without the up-to-date partition
1450 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1451 # relative to partition rather than disk beginnings.
1453 # This function performs partprobe on the failover host to make it re-read the
1456 refresh_partition_table() {
1461 host=$(facet_passive_host $facet)
1462 if [[ -n "$host" ]]; then
1463 do_node $host "$PARTPROBE $device"
1468 # Get ZFS storage pool name.
1475 device=$(facet_device $facet)
1476 # poolname is string before "/"
1477 poolname="${device%%/*}"
1484 # Get ZFS local fsname.
1486 zfs_local_fsname() {
1488 local lfsname=$(basename $(facet_device $facet))
1494 # Create ZFS storage pool.
1501 local opts=${@:-"-o cachefile=none"}
1503 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1504 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1505 $ZPOOL create -f $opts $poolname $vdev"
1509 # Create ZFS file system.
1515 local opts=${@:-"-o mountpoint=legacy"}
1517 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1518 $ZFS create $opts $dataset"
1522 # Export ZFS storage pool.
1523 # Before exporting the pool, all datasets within the pool should be unmounted.
1531 poolname=$(zpool_name $facet)
1533 if [[ -n "$poolname" ]]; then
1534 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1535 grep -q ^$poolname/ /proc/mounts ||
1536 $ZPOOL export $opts $poolname"
1541 # Destroy ZFS storage pool.
1542 # Destroy the given pool and free up any devices for other use. This command
1543 # tries to unmount any active datasets before destroying the pool.
1544 # -f Force any active datasets contained within the pool to be unmounted.
1548 local poolname=${2:-$(zpool_name $facet)}
1550 if [[ -n "$poolname" ]]; then
1551 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1552 $ZPOOL destroy -f $poolname"
1557 # Import ZFS storage pool.
1558 # Force importing, even if the pool appears to be potentially active.
1563 local opts=${@:-"-o cachefile=none -o failmode=panic"}
1566 poolname=$(zpool_name $facet)
1568 if [[ -n "$poolname" ]]; then
1569 opts+=" -d $(dirname $(facet_vdevice $facet))"
1570 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1571 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1572 $ZPOOL import -f $opts $poolname"
1577 # Reimport ZFS storage pool with new name
1582 local opts="-o cachefile=none"
1583 local poolname=$(zpool_name $facet)
1585 opts+=" -d $(dirname $(facet_vdevice $facet))"
1586 do_facet $facet "$ZPOOL export $poolname;
1587 $ZPOOL import $opts $poolname $newpool"
1591 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1592 # is not automatically imported on system startup.
1594 # In a failover environment, this will provide resource level fencing which
1595 # will ensure that the same ZFS storage pool will not be imported concurrently
1596 # on different nodes.
1598 disable_zpool_cache() {
1602 poolname=$(zpool_name $facet)
1604 if [[ -n "$poolname" ]]; then
1605 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1610 # This and set_osd_param() shall be used to access OSD parameters
1611 # once existed under "obdfilter":
1616 # writethrough_cache_enable
1620 local device=${2:-$FSNAME-OST*}
1623 do_nodes $nodes "$LCTL get_param -n osd-*.$device.$name"
1628 local device=${2:-$FSNAME-OST*}
1632 do_nodes $nodes "$LCTL set_param -n osd-*.$device.$name=$value"
1636 local dz=${1:-$DEBUG_SIZE}
1638 if [ -f /sys/devices/system/cpu/possible ]; then
1639 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1641 local cpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1644 # bug 19944, adjust size to be -gt num_possible_cpus()
1645 # promise 2MB for every cpu at least
1646 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1649 lctl set_param debug_mb=$dz
1652 set_default_debug () {
1653 local debug=${1:-"$PTLDEBUG"}
1654 local subsys=${2:-"$SUBSYSTEM"}
1655 local debug_size=${3:-$DEBUG_SIZE}
1657 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1659 lctl set_param subsystem_debug="${subsys# }" >/dev/null
1661 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1664 set_default_debug_nodes () {
1666 local debug="${2:-"$PTLDEBUG"}"
1667 local subsys="${3:-"$SUBSYSTEM"}"
1668 local debug_size="${4:-$DEBUG_SIZE}"
1670 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1671 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1675 [[ -z "$nodes" ]] ||
1676 do_rpc_nodes "$nodes" set_default_debug \
1677 \\\"$debug\\\" \\\"$subsys\\\" $debug_size || true
1680 set_default_debug_facet () {
1682 local debug="${2:-"$PTLDEBUG"}"
1683 local subsys="${3:-"$SUBSYSTEM"}"
1684 local debug_size="${4:-$DEBUG_SIZE}"
1685 local node=$(facet_active_host $facet)
1687 [ -n "$node" ] || error "No host defined for facet $facet"
1689 set_default_debug_nodes $node "$debug" "$subsys" $debug_size
1692 set_params_nodes () {
1693 [[ $# -ge 2 ]] || return 0
1697 do_nodes $nodes $LCTL set_param "$@"
1700 set_params_clients () {
1701 local clients=${1:-$CLIENTS}
1702 local params=${2:-$CLIENT_LCTL_SETPARAM_PARAM}
1704 [[ -n $params ]] || return 0
1705 set_params_nodes $clients $params
1709 local hostid=${1:-$(hostid)}
1711 if [ ! -s /etc/hostid ]; then
1712 printf $(echo -n $hostid |
1713 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1719 local facets=${1:-$(get_facets)}
1725 for facet in ${facets//,/ }; do
1726 mount_facet $facet &
1730 for ((index=0; index<$total; index++)); do
1731 wait ${mountpids[index]}
1733 [ $RC -eq 0 ] && continue
1735 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1736 skip_noexit "Restart of $facet failed!." &&
1739 error "Restart of $facet failed!"
1747 # Add argument "arg" (e.g., "loop") to the comma-separated list
1748 # of arguments for option "opt" (e.g., "-o") on command
1749 # line "opts" (e.g., "-o flock").
1755 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1757 if echo "$opts" | grep -q $opt_pattern; then
1758 opts=$(echo "$opts" | sed -e \
1759 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1761 opts+="${opts:+ }$opt $arg"
1767 # Associate loop device with a given regular file.
1768 # Return the loop device.
1770 setup_loop_device() {
1774 do_facet $facet "loop_dev=\\\$($LOSETUP -j $file | cut -d : -f 1);
1775 if [[ -z \\\$loop_dev ]]; then
1776 loop_dev=\\\$($LOSETUP -f);
1777 $LOSETUP \\\$loop_dev $file || loop_dev=;
1779 echo -n \\\$loop_dev"
1783 # Detach a loop device.
1785 cleanup_loop_device() {
1789 do_facet $facet "! $LOSETUP $loop_dev >/dev/null 2>&1 ||
1790 $LOSETUP -d $loop_dev"
1794 # Check if a given device is a block device.
1801 [[ -n "$dev" ]] || return 1
1802 do_facet $facet "test -b $dev" || return 1
1803 if [[ -n "$size" ]]; then
1804 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k \
1805 count=1 skip=$size 2>&1" |
1806 awk '($3 == "in") { print $1 }')
1807 [[ "$in" = "1+0" ]] || return 1
1812 # Check if a given device is a device-mapper device.
1818 [[ -n "$dev" ]] || return 1
1819 do_facet $facet "$DMSETUP status $dev >/dev/null 2>&1"
1823 # Check if a given device is a device-mapper flakey device.
1825 is_dm_flakey_dev() {
1830 [[ -n "$dev" ]] || return 1
1832 type=$(do_facet $facet "$DMSETUP status $dev 2>&1" |
1834 [[ $type = flakey ]] && return 0 || return 1
1838 # Check if device-mapper flakey device is supported by the kernel
1839 # of $facet node or not.
1841 dm_flakey_supported() {
1845 do_facet $facet "modprobe dm-flakey;
1846 $DMSETUP targets | grep -q flakey" &> /dev/null
1850 # Get the device-mapper flakey device name of a given facet.
1852 dm_facet_devname() {
1854 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
1856 echo -n ${facet}_flakey
1860 # Get the device-mapper flakey device of a given facet.
1861 # A device created by dmsetup will appear as /dev/mapper/<device-name>.
1863 dm_facet_devpath() {
1866 echo -n $DM_DEV_PATH/$(dm_facet_devname $facet)
1870 # Set a device-mapper device with a new table.
1872 # The table has the following format:
1873 # <logical_start_sector> <num_sectors> <target_type> <target_args>
1875 # flakey <target_args> includes:
1876 # <destination_device> <offset> <up_interval> <down_interval> \
1877 # [<num_features> [<feature_arguments>]]
1879 # linear <target_args> includes:
1880 # <destination_device> <start_sector>
1882 dm_set_dev_table() {
1885 local target_type=$3
1891 read tmp num_sectors tmp real_dev tmp \
1892 <<< $(do_facet $facet "$DMSETUP table $dm_dev")
1894 case $target_type in
1896 table="0 $num_sectors flakey $real_dev 0 0 1800 1 drop_writes"
1899 table="0 $num_sectors linear $real_dev 0"
1901 *) error "invalid target type $target_type" ;;
1904 do_facet $facet "$DMSETUP suspend --nolockfs --noflush $dm_dev" ||
1905 error "failed to suspend $dm_dev"
1906 do_facet $facet "$DMSETUP load $dm_dev --table \\\"$table\\\"" ||
1907 error "failed to load $target_type table into $dm_dev"
1908 do_facet $facet "$DMSETUP resume $dm_dev" ||
1909 error "failed to resume $dm_dev"
1913 # Set a device-mapper flakey device as "read-only" by using the "drop_writes"
1914 # feature parameter.
1917 # All write I/O is silently ignored.
1918 # Read I/O is handled correctly.
1920 dm_set_dev_readonly() {
1922 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1924 dm_set_dev_table $facet $dm_dev flakey
1928 # Set a device-mapper device to traditional linear mapping mode.
1930 dm_clear_dev_readonly() {
1932 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1934 dm_set_dev_table $facet $dm_dev linear
1938 # Set the device of a given facet as "read-only".
1940 set_dev_readonly() {
1942 local svc=${facet}_svc
1944 if [[ $(facet_fstype $facet) = zfs ]] ||
1945 ! dm_flakey_supported $facet; then
1946 do_facet $facet $LCTL --device ${!svc} readonly
1948 dm_set_dev_readonly $facet
1953 # Get size in 512-byte sectors (BLKGETSIZE64 / 512) of a given device.
1960 num_sectors=$(do_facet $facet "blockdev --getsz $dev 2>/dev/null")
1961 [[ ${PIPESTATUS[0]} = 0 && -n "$num_sectors" ]] || num_sectors=0
1962 echo -n $num_sectors
1966 # Create a device-mapper device with a given block device or regular file (will
1967 # be associated with loop device).
1968 # Return the full path of the device-mapper device.
1972 local real_dev=$2 # destination device
1973 local dm_dev_name=${3:-$(dm_facet_devname $facet)} # device name
1974 local dm_dev=$DM_DEV_PATH/$dm_dev_name # device-mapper device
1976 # check if the device-mapper device to be created already exists
1977 if is_dm_dev $facet $dm_dev; then
1978 # if the existing device was set to "read-only", then clear it
1979 ! is_dm_flakey_dev $facet $dm_dev ||
1980 dm_clear_dev_readonly $facet $dm_dev
1986 # check if the destination device is a block device, and if not,
1987 # associate it with a loop device
1988 is_blkdev $facet $real_dev ||
1989 real_dev=$(setup_loop_device $facet $real_dev)
1990 [[ -n "$real_dev" ]] || { echo -n $real_dev; return 2; }
1992 # now create the device-mapper device
1993 local num_sectors=$(get_num_sectors $facet $real_dev)
1994 local table="0 $num_sectors linear $real_dev 0"
1997 do_facet $facet "$DMSETUP create $dm_dev_name --table \\\"$table\\\"" ||
1998 { rc=${PIPESTATUS[0]}; dm_dev=; }
1999 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
2006 # Map the facet name to its device variable name.
2008 facet_device_alias() {
2010 local dev_alias=$facet
2013 fs2mds) dev_alias=mds1_2 ;;
2014 fs2ost) dev_alias=ost1_2 ;;
2015 fs3ost) dev_alias=ost2_2 ;;
2023 # Save the original value of the facet device and export the new value.
2029 local active_facet=$(facet_active $facet)
2030 local dev_alias=$(facet_device_alias $active_facet)
2031 local dev_name=${dev_alias}_dev
2032 local dev=${!dev_name}
2034 if [[ $active_facet = $facet ]]; then
2035 local failover_dev=${dev_alias}failover_dev
2036 if [[ ${!failover_dev} = $dev ]]; then
2037 eval export ${failover_dev}_saved=$dev
2038 eval export ${failover_dev}=$dm_dev
2041 dev_alias=$(facet_device_alias $facet)
2042 local facet_dev=${dev_alias}_dev
2043 if [[ ${!facet_dev} = $dev ]]; then
2044 eval export ${facet_dev}_saved=$dev
2045 eval export ${facet_dev}=$dm_dev
2049 eval export ${dev_name}_saved=$dev
2050 eval export ${dev_name}=$dm_dev
2054 # Restore the saved value of the facet device.
2059 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
2060 local dev_alias=$(facet_device_alias $facet)
2062 local saved_dev=${dev_alias}_dev_saved
2063 [[ -z ${!saved_dev} ]] ||
2064 eval export ${dev_alias}_dev=${!saved_dev}
2066 saved_dev=${dev_alias}failover_dev_saved
2067 [[ -z ${!saved_dev} ]] ||
2068 eval export ${dev_alias}failover_dev=${!saved_dev}
2072 # Remove a device-mapper device.
2073 # If the destination device is a loop device, then also detach it.
2077 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2081 is_dm_dev $facet $dm_dev || return 0
2083 read major minor <<< $(do_facet $facet "$DMSETUP table $dm_dev" |
2084 awk '{ print $4 }' | awk -F: '{ print $1" "$2 }')
2086 do_facet $facet "$DMSETUP remove $dm_dev"
2087 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
2089 unexport_dm_dev $facet
2091 # detach a loop device
2092 [[ $major -ne 7 ]] || cleanup_loop_device $facet /dev/loop$minor
2094 # unload dm-flakey module
2095 do_facet $facet "modprobe -r dm-flakey" || true
2101 local active_facet=$(facet_active $facet)
2102 local dev_alias=$(facet_device_alias $active_facet)
2103 local dev=${dev_alias}_dev
2104 local opt=${facet}_opt
2105 local mntpt=$(facet_mntpt $facet)
2106 local opts="${!opt} $@"
2107 local fstype=$(facet_fstype $facet)
2109 local dm_dev=${!dev}
2111 [[ $dev == "mgsfailover_dev" ]] && combined_mgs_mds &&
2112 dev=mds1failover_dev
2114 module_loaded lustre || load_modules
2118 if dm_flakey_supported $facet; then
2119 dm_dev=$(dm_create_dev $facet ${!dev})
2120 [[ -n "$dm_dev" ]] || dm_dev=${!dev}
2123 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
2125 devicelabel=$(do_facet ${facet} "$E2LABEL $dm_dev");;
2127 # import ZFS storage pool
2128 import_zpool $facet || return ${PIPESTATUS[0]}
2130 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
2131 lustre:svname $dm_dev");;
2133 error "unknown fstype!";;
2136 echo "Starting ${facet}: $opts $dm_dev $mntpt"
2137 # for testing LU-482 error handling in mount_facets() and test_0a()
2138 if [ -f $TMP/test-lu482-trigger ]; then
2141 local seq_width=$(($OSTSEQWIDTH / $OSTCOUNT))
2142 (( $seq_width >= 16384 )) || seq_width=16384
2144 "mkdir -p $mntpt; $MOUNT_CMD $opts $dm_dev $mntpt"
2146 if [[ ${facet} =~ ost ]]; then
2147 do_facet ${facet} "$LCTL set_param \
2148 seq.cli-$(devicelabel $facet $dm_dev)-super.width=$seq_width"
2152 if [ $RC -ne 0 ]; then
2153 echo "Start of $dm_dev on ${facet} failed ${RC}"
2157 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
2158 if [[ "$health" != "healthy" ]]; then
2159 error "$facet is in a unhealthy state"
2162 set_default_debug_facet $facet
2164 if [[ $opts =~ .*nosvc.* ]]; then
2165 echo "Start $dm_dev without service"
2170 wait_update_facet ${facet} "$E2LABEL $dm_dev \
2171 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
2172 "" || error "$dm_dev failed to initialize!";;
2174 wait_update_facet ${facet} "$ZFS get -H -o value \
2175 lustre:svname $dm_dev 2>/dev/null | \
2176 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
2177 error "$dm_dev failed to initialize!";;
2180 error "unknown fstype!";;
2184 # commit the device label change to disk
2185 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
2186 echo "Commit the device label on ${!dev}"
2187 do_facet $facet "sync; sleep 1; sync"
2191 label=$(devicelabel ${facet} $dm_dev)
2192 [ -z "$label" ] && echo no label for $dm_dev && exit 1
2193 eval export ${facet}_svc=${label}
2194 echo Started ${label}
2196 export_dm_dev $facet $dm_dev
2201 # start facet device options
2207 local dev_alias=$(facet_device_alias $facet)
2209 eval export ${dev_alias}_dev=${device}
2210 eval export ${facet}_opt=\"$*\"
2212 combined_mgs_mds && [[ ${dev_alias} == mds1 ]] &&
2213 eval export mgs_dev=${device}
2215 local varname=${dev_alias}failover_dev
2216 if [ -n "${!varname}" ] ; then
2217 eval export ${dev_alias}failover_dev=${!varname}
2219 eval export ${dev_alias}failover_dev=$device
2220 combined_mgs_mds && [[ ${dev_alias} == mds1 ]] &&
2221 eval export mgsfailover_dev=${device}
2225 local mntpt=$(facet_mntpt $facet)
2226 do_facet ${facet} mkdir -p $mntpt
2227 eval export ${facet}_MOUNT=$mntpt
2228 mount_facet ${facet}
2238 local HOST=$(facet_active_host $facet)
2239 [[ -z $HOST ]] && echo stop: no host for $facet && return 0
2241 local mntpt=$(facet_mntpt $facet)
2242 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts || true")
2243 if [ ${running} -ne 0 ]; then
2244 echo "Stopping $mntpt (opts:$*) on $HOST"
2245 do_facet ${facet} $UMOUNT "$@" $mntpt
2248 # umount should block, but we should wait for unrelated obd's
2249 # like the MGS or MGC to also stop.
2250 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
2252 if [[ $(facet_fstype $facet) == zfs ]]; then
2253 # export ZFS storage pool
2254 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
2255 elif dm_flakey_supported $facet; then
2256 local host=${facet}_HOST
2257 local failover_host=${facet}failover_HOST
2258 if [[ -n ${!failover_host} && ${!failover_host} != ${!host} ]]||
2259 $CLEANUP_DM_DEV || [[ $facet = fs* ]]; then
2260 dm_cleanup_dev $facet
2265 # get mdt quota type
2267 local varsvc=${SINGLEMDS}_svc
2268 do_facet $SINGLEMDS $LCTL get_param -n \
2269 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
2272 # get ost quota type
2274 # All OSTs should have same quota type
2275 local varsvc=ost1_svc
2276 do_facet ost1 $LCTL get_param -n \
2277 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
2280 # restore old quota type settings
2282 for usr in $QUOTA_USERS; do
2283 echo "Setting up quota on $HOSTNAME:$MOUNT for $usr..."
2285 cmd="$LFS setquota -$type $usr -b 0"
2286 cmd="$cmd -B 0 -i 0 -I 0 $MOUNT"
2288 eval $cmd || error "$cmd FAILED!"
2290 # display the quota status
2291 echo "Quota settings for $usr : "
2292 $LFS quota -v -u $usr $MOUNT || true
2294 if [ "$old_MDT_QUOTA_TYPE" ]; then
2295 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2296 do_facet mgs $PERM_CMD \
2297 osd-*.$FSNAME-MDT*.quota_slave.enabled = \
2300 do_facet mgs $PERM_CMD \
2301 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
2304 if [ "$old_OST_QUOTA_TYPE" ]; then
2305 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2306 do_facet mgs $PERM_CMD \
2307 osd-*.$FSNAME-OST*.quota_slave.enabled = \
2310 do_facet mgs $LCTL conf_param \
2311 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
2316 # Handle the case when there is a space in the lfs df
2317 # "filesystem summary" line the same as when there is no space.
2318 # This will allow fixing the "lfs df" summary line in the future.
2320 $LFS df $* | sed -e 's/filesystem /filesystem_/'
2321 check_lfs_df_ret_val $?
2324 # Get free inodes on the MDT specified by mdt index, free indoes on
2325 # the whole filesystem will be returned when index == -1.
2331 if [ $index -eq -1 ]; then
2334 mdt_uuid=$(mdtuuid_from_index $index)
2337 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
2342 # Get the OST device status from 'lfs df' with a given OST index.
2346 local mnt_pnt=${2:-$MOUNT}
2350 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
2351 lfs_df $opts $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
2357 # save old quota type & set new quota type
2358 local mdt_qtype=$(mdt_quota_type)
2359 local ost_qtype=$(ost_quota_type)
2361 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
2362 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
2364 export old_MDT_QUOTA_TYPE=$mdt_qtype
2365 export old_OST_QUOTA_TYPE=$ost_qtype
2367 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2368 do_facet mgs $PERM_CMD \
2369 osd-*.$FSNAME-MDT*.quota_slave.enabled=$QUOTA_TYPE
2370 do_facet mgs $PERM_CMD \
2371 osd-*.$FSNAME-OST*.quota_slave.enabled=$QUOTA_TYPE
2373 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$QUOTA_TYPE ||
2374 error "set mdt quota type failed"
2375 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$QUOTA_TYPE ||
2376 error "set ost quota type failed"
2379 local quota_usrs=$QUOTA_USERS
2381 # get_filesystem_size
2382 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
2383 local blk_soft=$((disksz + 1024))
2384 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
2386 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
2387 local i_soft=$inodes
2388 local i_hard=$((i_soft + i_soft / 20))
2390 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
2391 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
2392 "inode-hardlimit: $i_hard"
2395 for usr in $quota_usrs; do
2396 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
2398 cmd="$LFS setquota -$type $usr -b $blk_soft"
2399 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
2401 eval $cmd || error "$cmd FAILED!"
2403 # display the quota status
2404 echo "Quota settings for $usr : "
2405 $LFS quota -v -u $usr $mntpt || true
2412 local opts=${3:-$MOUNT_OPTS}
2413 opts=${opts:+-o $opts}
2414 local flags=${4:-$MOUNT_FLAGS}
2416 local device=$MGSNID:/$FSNAME$FILESET
2417 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2418 echo "Bad mount command: opt=$flags $opts dev=$device " \
2424 # update mount option with skpath
2425 opts=$(add_sk_mntflag $opts)
2428 echo "Starting client: $client: $flags $opts $device $mnt"
2429 do_node $client mkdir -p $mnt
2430 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
2431 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
2433 #disable FILESET if not supported
2434 do_nodes $client lctl get_param -n \
2435 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2436 device=$MGSNID:/$FSNAME
2437 do_node $client mkdir -p $mnt/$FILESET
2438 do_node $client "! grep -q $mnt' ' /proc/mounts ||
2441 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2442 # Mount using nodemap key
2443 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2444 if $SK_UNIQUE_NM; then
2445 mountkey=$SK_PATH/nodemap/c0.key
2447 local prunedopts=$(echo $opts |
2448 sed -e "s#skpath=[^,^ ]*#skpath=$mountkey#g")
2449 do_node $client $MOUNT_CMD $flags $prunedopts $device $mnt ||
2452 do_node $client $MOUNT_CMD $flags $opts $device $mnt ||
2456 set_default_debug_nodes $client
2457 set_params_clients $client
2468 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
2470 [ "$3" ] && force=-f
2471 [ $running -eq 0 ] && return 0
2473 echo "Stopping client $client $mnt (opts:$force)"
2474 do_node $client lsof -t $mnt || need_kill=no
2475 if [ "x$force" != "x" ] && [ "x$need_kill" != "xno" ]; then
2476 pids=$(do_node $client lsof -t $mnt | sort -u);
2477 if [ -n "$pids" ]; then
2478 do_node $client kill -9 $pids || true
2482 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") ||
2484 if [ $busy -ne 0 ] ; then
2485 echo "$mnt is still busy, wait one second" && sleep 1
2486 do_node $client umount $force $mnt
2490 # Mount the file system on the MDS
2491 mount_mds_client() {
2492 local host=$(facet_active_host $SINGLEMDS)
2494 zconf_mount $host $MOUNT2 $MOUNT_OPTS ||
2495 error "unable to mount $MOUNT2 on $host"
2498 # Unmount the file system on the MDS
2499 umount_mds_client() {
2500 local host=$(facet_active_host $SINGLEMDS)
2501 zconf_umount $host $MOUNT2
2502 do_facet $SINGLEMDS "rmdir $MOUNT2"
2505 # nodes is comma list
2506 sanity_mount_check_nodes () {
2512 # FIXME: assume that all cluster nodes run the same os
2513 [ "$(uname)" = Linux ] || return 0
2516 for mnt in $mnts ; do
2517 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
2518 mpts=\\\$(mount | grep -c $mnt' ');
2519 if [ \\\$running -ne \\\$mpts ]; then
2520 echo \\\$(hostname) env are INSANE!;
2523 [ $? -eq 0 ] || rc=1
2528 sanity_mount_check_servers () {
2529 [ -n "$CLIENTONLY" ] &&
2530 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
2531 echo Checking servers environments
2533 # FIXME: modify get_facets to display all facets wo params
2534 local facets="$(get_facets OST),$(get_facets MDS),mgs"
2538 for facet in ${facets//,/ }; do
2539 node=$(facet_host ${facet})
2540 mntpt=$(facet_mntpt $facet)
2541 sanity_mount_check_nodes $node $mntpt ||
2542 { error "server $node environments are insane!"; return 1; }
2546 sanity_mount_check_clients () {
2547 local clients=${1:-$CLIENTS}
2548 local mntpt=${2:-$MOUNT}
2549 local mntpt2=${3:-$MOUNT2}
2551 [ -z $clients ] && clients=$(hostname)
2552 echo Checking clients $clients environments
2554 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
2555 error "clients environments are insane!"
2558 sanity_mount_check () {
2559 sanity_mount_check_servers || return 1
2560 sanity_mount_check_clients || return 2
2563 # mount clients if not mouted
2564 zconf_mount_clients() {
2567 local opts=${3:-$MOUNT_OPTS}
2568 opts=${opts:+-o $opts}
2569 local flags=${4:-$MOUNT_FLAGS}
2570 local device=$MGSNID:/$FSNAME$FILESET
2571 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2572 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
2577 echo "Starting client $clients: $flags $opts $device $mnt"
2578 do_nodes $clients mkdir -p $mnt
2579 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ]; then
2580 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2581 # Mount with own nodemap key
2583 # Mount all server nodes first with per-NM keys
2584 for nmclient in ${clients//,/ }; do
2585 do_nodes $(comma_list $(all_server_nodes)) \
2586 "$LGSS_SK -t server -l $SK_PATH/nodemap/c$i.key"
2589 # set perms for per-nodemap keys else permission denied
2590 do_nodes $(comma_list $(all_nodes)) \
2591 "keyctl show | grep lustre | cut -c1-11 |
2593 xargs -IX keyctl setperm X 0x3f3f3f3f"
2594 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2596 for nmclient in ${clients//,/ }; do
2597 if $SK_UNIQUE_NM; then
2598 mountkey=$SK_PATH/nodemap/c$i.key
2600 do_node $nmclient "! grep -q $mnt' ' \
2601 /proc/mounts || umount $mnt"
2602 local prunedopts=$(add_sk_mntflag $opts);
2603 prunedopts=$(echo $prunedopts | sed -e \
2604 "s#skpath=[^ ^,]*#skpath=$mountkey#g")
2606 do_nodes $(comma_list $(all_server_nodes)) \
2609 do_node $nmclient $MOUNT_CMD $flags \
2610 $prunedopts $MGSNID:/$FSNAME $mnt ||
2615 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2617 do_nodes $clients $MOUNT_CMD $flags $opts \
2618 $MGSNID:/$FSNAME $mnt || return 1
2620 #disable FILESET if not supported
2621 do_nodes $clients lctl get_param -n \
2622 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2623 device=$MGSNID:/$FSNAME
2624 do_nodes $clients mkdir -p $mnt/$FILESET
2625 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2629 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2630 # Mount with nodemap key
2632 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2633 for nmclient in ${clients//,/ }; do
2634 if $SK_UNIQUE_NM; then
2635 mountkey=$SK_PATH/nodemap/c$i.key
2637 local prunedopts=$(echo $opts | sed -e \
2638 "s#skpath=[^ ^,]*#skpath=$mountkey#g");
2639 do_node $nmclient "! grep -q $mnt' ' /proc/mounts ||
2642 running=\\\$(mount | grep -c $mnt' ');
2644 if [ \\\$running -eq 0 ] ; then
2646 $MOUNT_CMD $flags $prunedopts $device $mnt;
2649 lustre_mnt_count=\\\$(mount | grep $mnt' ' | \
2650 grep 'type lustre' | wc -l);
2651 if [ \\\$running -ne \\\$lustre_mnt_count ] ; then
2652 echo zconf_mount_clients FAILED: \
2653 mount count \\\$running, not matching \
2654 with mount count of 'type lustre' \
2655 \\\$lustre_mnt_count;
2659 exit \\\$rc" || return ${PIPESTATUS[0]}
2666 if $SHARED_KEY; then
2667 tmpopts=$(add_sk_mntflag $opts)
2670 running=\\\$(mount | grep -c $mnt' ');
2672 if [ \\\$running -eq 0 ] ; then
2674 $MOUNT_CMD $flags $tmpopts $device $mnt;
2677 exit \\\$rc" || return ${PIPESTATUS[0]}
2680 echo "Started clients $clients: "
2681 do_nodes $clients "mount | grep $mnt' '"
2683 set_default_debug_nodes $clients
2684 set_params_clients $clients
2689 zconf_umount_clients() {
2694 [ "$3" ] && force=-f
2696 echo "Stopping clients: $clients $mnt (opts:$force)"
2697 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
2698 if [ \\\$running -ne 0 ] ; then
2699 echo Stopping client \\\$(hostname) $mnt opts:$force;
2700 lsof $mnt || need_kill=no;
2701 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
2702 pids=\\\$(lsof -t $mnt | sort -u);
2703 if [ -n \\\"\\\$pids\\\" ]; then
2707 while umount $force $mnt 2>&1 | grep -q "busy"; do
2708 echo "$mnt is still busy, wait one second" && sleep 1;
2716 echo + $POWER_DOWN $node
2720 shutdown_node_hard () {
2722 local attempts=$SHUTDOWN_ATTEMPTS
2724 for i in $(seq $attempts) ; do
2727 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 &&
2729 echo "waiting for $host to fail attempts=$attempts"
2730 [ $i -lt $attempts ] ||
2731 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
2737 local mnt=${2:-$MOUNT}
2740 if [ "$FAILURE_MODE" = HARD ]; then
2741 shutdown_node_hard $client
2743 zconf_umount_clients $client $mnt -f
2750 local facets="$(get_facets OST),$(get_facets MDS)"
2752 combined_mgs_mds || facets="$facets,mgs"
2754 for facet in ${facets//,/ }; do
2755 if [ $(facet_active_host $facet) == $host ]; then
2756 affected="$affected $facet"
2760 echo $(comma_list $affected)
2765 local host=${2:-$(facet_host $facet)}
2767 local label=$(convert_facet2label $facet)
2768 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
2771 facets_up_on_host () {
2774 local facets=$(facets_on_host $host)
2776 for facet in ${facets//,/ }; do
2777 if $(facet_up $facet $host); then
2778 affected_up="$affected_up $facet"
2782 echo $(comma_list $affected_up)
2787 local affected_facet
2788 local affected_facets
2790 if [[ "$FAILURE_MODE" = HARD ]]; then
2791 if [[ $(facet_fstype $facet) = ldiskfs ]] &&
2792 dm_flakey_supported $facet; then
2793 affected_facets=$(affected_facets $facet)
2794 for affected_facet in ${affected_facets//,/ }; do
2795 unexport_dm_dev $affected_facet
2799 shutdown_node_hard $(facet_active_host $facet)
2808 echo + $POWER_UP $node
2821 local node=$(facet_active_host $facet)
2822 local sleep_time=${2:-10}
2824 if [ "$FAILURE_MODE" = HARD ]; then
2834 if [ "$FAILURE_MODE" = HARD ]; then
2837 if $LOAD_MODULES_REMOTE; then
2838 echo "loading modules on $node: $facet"
2839 do_rpc_nodes $node load_modules_local
2848 for facet in ${facets//,/ }; do
2849 hosts=$(expand_list $hosts $(facet_host $facet) )
2855 _check_progs_installed () {
2859 for prog in $progs; do
2860 if ! [ "$(which $prog)" -o "${!prog}" ]; then
2861 echo $prog missing on $(hostname)
2868 check_progs_installed () {
2872 do_rpc_nodes "$nodes" _check_progs_installed "$@"
2875 # recovery-scale functions
2877 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
2880 start_client_load() {
2883 local var=$(node_var_name $client)_load
2884 eval export ${var}=$load
2886 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
2887 BREAK_ON_ERROR=$BREAK_ON_ERROR \
2888 END_RUN_FILE=$END_RUN_FILE \
2889 LOAD_PID_FILE=$LOAD_PID_FILE \
2890 TESTLOG_PREFIX=$TESTLOG_PREFIX \
2891 TESTNAME=$TESTNAME \
2892 DBENCH_LIB=$DBENCH_LIB \
2893 DBENCH_SRC=$DBENCH_SRC \
2894 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
2899 MPIRUN_OPTIONS=\\\"$MPIRUN_OPTIONS\\\" \
2900 MACHINEFILE_OPTION=\\\"$MACHINEFILE_OPTION\\\" \
2901 num_clients=$(get_node_count ${CLIENTS//,/ }) \
2902 ior_THREADS=$ior_THREADS ior_iteration=$ior_iteration \
2903 ior_blockSize=$ior_blockSize \
2904 ior_blockUnit=$ior_blockUnit \
2905 ior_xferSize=$ior_xferSize ior_type=$ior_type \
2906 ior_DURATION=$ior_DURATION \
2907 ior_stripe_params=\\\"$ior_stripe_params\\\" \
2908 ior_custom_params=\\\"$ior_custom_param\\\" \
2909 mpi_ior_custom_threads=$mpi_ior_custom_threads \
2912 log "Started client load: ${load} on $client"
2914 # get the children process IDs
2915 local pids=$(ps --ppid $ppid -o pid= | xargs)
2916 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
2920 start_client_loads () {
2921 local -a clients=(${1//,/ })
2922 local numloads=${#CLIENT_LOADS[@]}
2924 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
2925 local load=$((nodenum % numloads))
2926 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[load]}
2928 # bug 22169: wait the background threads to start
2932 # only for remote client
2933 check_client_load () {
2935 local var=$(node_var_name $client)_load
2936 local testload=run_${!var}.sh
2938 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
2940 # bug 18914: try to connect several times not only when
2941 # check ps, but while check_node_health also
2945 while [ $RC = 254 -a $tries -gt 0 ]; do
2949 if ! check_node_health $client; then
2951 if [ $RC -eq 254 ]; then
2952 # FIXME: not sure how long we shuold sleep here
2956 echo "check node health failed: RC=$RC "
2960 # We can continue try to connect if RC=254
2961 # Just print the warning about this
2962 if [ $RC = 254 ]; then
2963 echo "got a return status of $RC from do_node while checking " \
2964 "node health on $client"
2967 # see if the load is still on the client
2970 while [ $RC = 254 -a $tries -gt 0 ]; do
2974 if ! do_node $client \
2975 "ps auxwww | grep -v grep | grep -q $testload"; then
2980 if [ $RC = 254 ]; then
2981 echo "got a return status of $RC from do_node while checking " \
2982 "(node health and 'ps') the client load on $client"
2983 # see if we can diagnose a bit why this is
2988 check_client_loads () {
2989 local clients=${1//,/ }
2993 for client in $clients; do
2994 check_client_load $client
2996 if [ "$rc" != 0 ]; then
2997 log "Client load failed on node $client, rc=$rc"
3003 restart_client_loads () {
3004 local clients=${1//,/ }
3005 local expectedfail=${2:-""}
3009 for client in $clients; do
3010 check_client_load $client
3012 if [ "$rc" != 0 -a "$expectedfail" ]; then
3013 local var=$(node_var_name $client)_load
3015 start_client_load $client ${!var}
3016 echo "Restarted client load ${!var}: on $client. Checking ..."
3017 check_client_load $client
3019 if [ "$rc" != 0 ]; then
3020 log "Client load failed to restart on node $client, rc=$rc"
3021 # failure one client load means test fail
3022 # we do not need to check other
3031 # Start vmstat and save its process ID in a file.
3036 [ -z "$nodes" -o -z "$pid_file" ] && return 0
3039 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
3040 2>/dev/null </dev/null & echo \\\$! > $pid_file"
3043 # Display the nodes on which client loads failed.
3044 print_end_run_file() {
3048 [ -s $file ] || return 0
3050 echo "Found the END_RUN_FILE file: $file"
3053 # A client load will stop if it finds the END_RUN_FILE file.
3054 # That does not mean the client load actually failed though.
3055 # The first node in END_RUN_FILE is the one we are interested in.
3058 if [ -n "$node" ]; then
3059 local var=$(node_var_name $node)_load
3061 local prefix=$TESTLOG_PREFIX
3062 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
3063 local stdout_log=$prefix.run_${!var}_stdout.$node.log
3064 local debug_log=$(echo $stdout_log |
3065 sed 's/\(.*\)stdout/\1debug/')
3067 echo "Client load ${!var} failed on node $node:"
3073 # Stop the process which had its PID saved in a file.
3078 [ -z "$nodes" -o -z "$pid_file" ] && return 0
3080 do_nodes $nodes "test -f $pid_file &&
3081 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
3084 # Stop all client loads.
3085 stop_client_loads() {
3086 local nodes=${1:-$CLIENTS}
3089 # stop the client loads
3090 stop_process $nodes $pid_file
3092 # clean up the processes that started them
3093 [ -n "$CLIENT_LOAD_PIDS" ] &&
3094 kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
3096 # End recovery-scale functions
3099 # wait for a command to return the expected result
3101 # This will run @check on @node repeatedly until the output matches @expect
3102 # based on the supplied condition, or until @max_wait seconds have elapsed,
3103 # whichever comes first. @cond may be one of the normal bash operators,
3104 # "-gt", "-ge", "-eq", "-le", "-lt", "==", "!=", or "=~", and must be quoted
3105 # in the caller to avoid unintentional evaluation by the shell in the caller.
3107 # If @max_wait is not specified, the condition will be checked for up to 90s.
3109 # If --verbose is passed as the first argument, the result is printed on each
3110 # value change, otherwise it is only printed after every 10s interval.
3112 # If --quiet is passed as the first/second argument, the do_node() command
3113 # will not print the remote command before executing it each time.
3115 # Using wait_update_cond() or related helper function is preferable to adding
3116 # a "long enough" wait for some state to change in the background, since
3117 # "long enough" may be too short due to tunables, system config, or running in
3118 # a VM, and must by necessity wait too long for most cases or risk failure.
3120 # usage: wait_update_cond [--verbose] [--quiet] node check cond expect [max_wait]
3121 wait_update_cond() {
3125 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3126 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3132 local max_wait=${5:-90}
3136 local begin=$SECONDS
3140 while (( $waited <= $max_wait )); do
3141 result=$(do_node $quiet $node "$check")
3143 eval [[ "'$result'" $cond "'$expect'" ]]
3144 if [[ $? == 0 ]]; then
3145 [[ -n "$quiet" ]] && return 0
3146 [[ -z "$result" || $waited -le $sleep ]] ||
3147 echo "Updated after ${waited}s: want '$expect' got '$result'"
3150 if [[ -n "$verbose" && "$result" != "$prev_result" ]]; then
3151 [[ -z "$quiet" && -n "$prev_result" ]] &&
3152 echo "Changed after ${waited}s: from '$prev_result' to '$result'"
3153 prev_result="$result"
3155 (( $waited % $print == 0 )) && {
3156 [[ -z "$quiet" ]] &&
3157 echo "Waiting $((max_wait - waited))s for '$expect'"
3161 waited=$((SECONDS - begin))
3164 [[ -z "$quiet" ]] &&
3165 echo "Update not seen after ${max_wait}s: want '$expect' got '$result'"
3170 # usage: wait_update [--verbose] [--quiet] node check expect [max_wait]
3175 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3176 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3183 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3186 # usage: wait_update_facet_cond [--verbose] facet check cond expect [max_wait]
3187 wait_update_facet_cond() {
3191 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3192 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3194 local node=$(facet_active_host $1)
3200 wait_update_cond $verbose $quiet $node "$check" "$cond" "$expect" $max_wait
3203 # usage: wait_update_facet [--verbose] facet check expect [max_wait]
3204 wait_update_facet() {
3208 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3209 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3211 local node=$(facet_active_host $1)
3216 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3220 do_nodes $(comma_list $(mdts_nodes)) \
3221 "lctl set_param -n os[cd]*.*MDT*.force_sync=1"
3222 do_nodes $(comma_list $(osts_nodes)) \
3223 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
3224 grep -v 'Found no match'
3228 local zfs_wait=${2:-5}
3230 # the occupied disk space will be released
3231 # only after TXGs are committed
3232 if [[ $(facet_fstype $1) == zfs ]]; then
3233 echo "sleep $zfs_wait for ZFS $(facet_fstype $1)"
3241 local lwm=$3 #low watermark
3242 local size_mb #how many MB should we write to pass watermark
3243 local ost_name=$(ostname_from_index $ost_idx)
3245 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3247 if (( $free_kb / 1024 > lwm )); then
3248 size_mb=$((free_kb / 1024 - lwm))
3250 #If 10% of free space cross low watermark use it
3251 if (( $free_kb / 10240 > size_mb )); then
3252 size_mb=$((free_kb / 10240))
3254 #At least we need to store 1.1 of difference between
3255 #free space and low watermark
3256 size_mb=$((size_mb + size_mb / 10))
3258 if (( lwm <= $free_kb / 1024 )) ||
3259 [ ! -f $DIR/${filename}.fill_ost$ost_idx ]; then
3260 $LFS setstripe -i $ost_idx -c1 $DIR/${filename}.fill_ost$ost_idx
3261 dd if=/dev/zero of=$DIR/${filename}.fill_ost$ost_idx bs=1M \
3262 count=$size_mb oflag=append conv=notrunc
3267 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3268 echo "OST still has $((free_kb / 1024)) MB free"
3271 # This checks only the primary MDS
3272 ost_watermarks_get() {
3274 local ost_name=$(ostname_from_index $ost_idx)
3275 local mdtosc_proc=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
3277 local hwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3278 osp.$mdtosc_proc.reserved_mb_high)
3279 local lwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3280 osp.$mdtosc_proc.reserved_mb_low)
3285 # Note that we set watermarks on all MDSes (necessary for striped dirs)
3286 ost_watermarks_set() {
3290 local ost_name=$(ostname_from_index $ost_idx)
3291 local facets=$(get_facets MDS)
3293 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param -n \
3294 osp.*$ost_name*.reserved_mb_low=$lwm \
3295 osp.*$ost_name*.reserved_mb_high=$hwm > /dev/null
3297 # sleep to ensure we see the change
3301 ost_watermarks_set_low_space() {
3303 local wms=$(ost_watermarks_get $ost_idx)
3304 local ost_name=$(ostname_from_index $ost_idx)
3306 local old_lwm=$(echo $wms | awk '{ print $1 }')
3307 local old_hwm=$(echo $wms | awk '{ print $2 }')
3309 local blocks=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3310 # minimal extension size is 64M
3312 if (( $blocks / 1024 > 50 )); then
3313 new_lwm=$((blocks / 1024 - 50))
3315 local new_hwm=$((new_lwm + 5))
3317 ost_watermarks_set $ost_idx $new_lwm $new_hwm
3318 echo "watermarks: $old_lwm $old_hwm $new_lwm $new_hwm"
3321 # Set watermarks to ~current available space & then write data to fill it
3322 # Note OST is not *actually* full after this, it just reports ENOSPC in the
3323 # internal statfs used by the stripe allocator
3325 # first parameter is the filename-prefix, which must get under t-f cleanup
3326 # requirements (rm -rf $DIR/[Rdfs][0-9]*), i.e. $tfile work fine
3327 ost_watermarks_set_enospc() {
3331 local ost_name=$(ostname_from_index $ost_idx)
3332 local facets=$(get_facets MDS)
3336 for MDS in ${facets//,/ }; do
3337 local mdtosc_proc=$(get_mdtosc_proc_path $MDS $ost_name)
3339 do_facet $MDS $LCTL get_param -n \
3340 osp.$mdtosc_proc.reserved_mb_high ||
3341 skip "remote MDS does not support reserved_mb_high"
3344 wms=$(ost_watermarks_set_low_space $ost_idx)
3345 local new_lwm=$(echo $wms | awk '{ print $4 }')
3346 fill_ost $filename $ost_idx $new_lwm
3347 #First enospc could execute orphan deletion so repeat
3348 fill_ost $filename $ost_idx $new_lwm
3352 ost_watermarks_enospc_delete_files() {
3356 rm -f $DIR/${filename}.fill_ost$ost_idx
3358 wait_delete_completed
3362 # clean up from "ost_watermarks_set_enospc"
3363 ost_watermarks_clear_enospc() {
3369 ost_watermarks_enospc_delete_files $filename $ost_idx
3370 ost_watermarks_set $ost_idx $old_lwm $old_hwm
3371 echo "set OST$ost_idx lwm back to $old_lwm, hwm back to $old_hwm"
3374 wait_delete_completed_mds() {
3375 local max_wait=${1:-20}
3377 local stime=$(date +%s)
3382 # find MDS with pending deletions
3383 for node in $(mdts_nodes); do
3384 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
3385 2>/dev/null | calc_sum)
3386 if [[ $changes -eq 0 ]]; then
3389 mds2sync="$mds2sync $node"
3391 if [ -z "$mds2sync" ]; then
3392 wait_zfs_commit $SINGLEMDS
3395 mds2sync=$(comma_list $mds2sync)
3397 # sync MDS transactions
3398 do_nodes $mds2sync "$LCTL set_param -n os[cd]*.*MD*.force_sync 1"
3400 # wait till all changes are sent and commmitted by OSTs
3401 # for ldiskfs space is released upon execution, but DMU
3402 # do this upon commit
3405 while [[ $WAIT -ne $max_wait ]]; do
3406 changes=$(do_nodes $mds2sync \
3407 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
3408 #echo "$node: $changes changes on all"
3409 if [[ $changes -eq 0 ]]; then
3410 wait_zfs_commit $SINGLEMDS
3412 # the occupied disk space will be released
3413 # only after TXGs are committed
3414 wait_zfs_commit ost1
3422 echo "Delete is not completed in $((etime - stime)) seconds"
3423 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
3430 # we can use "for" here because we are waiting the slowest
3431 for host in ${hostlist//,/ }; do
3432 check_network "$host" 900
3434 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
3441 for facet in ${facetlist//,/ }; do
3442 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
3444 wait_for_host $hostlist
3447 _wait_recovery_complete () {
3450 # Use default policy if $2 is not passed by caller.
3451 local MAX=${2:-$(max_recovery_time)}
3456 while [ $WAIT -lt $MAX ]; do
3457 STATUS=$(lctl get_param -n $param | grep status)
3459 [[ $STATUS == "status: COMPLETE" ||
3460 $STATUS == "status: INACTIVE" ]] && return 0
3463 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
3465 echo "$param recovery not done in $MAX sec. $STATUS"
3469 wait_recovery_complete () {
3472 # with an assumption that at_max is the same on all nodes
3473 local MAX=${2:-$(max_recovery_time)}
3476 if [ "$FAILURE_MODE" = HARD ]; then
3477 facets=$(facets_on_host $(facet_active_host $facet))
3479 echo affected facets: $facets
3481 facets=${facets//,/ }
3482 # We can use "for" here because we are waiting the slowest.
3483 # The mgs not having the recovery_status proc entry, exclude it
3484 # from the facet list.
3485 for facet in ${facets//mgs/ }; do
3486 local var_svc=${facet}_svc
3487 local param="*.${!var_svc}.recovery_status"
3489 local host=$(facet_active_host $facet)
3490 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
3494 wait_mds_ost_sync () {
3495 # just because recovery is done doesn't mean we've finished
3496 # orphan cleanup. Wait for llogs to get synchronized.
3497 echo "Waiting for orphan cleanup..."
3498 # MAX value includes time needed for MDS-OST reconnection
3499 local MAX=$(( TIMEOUT * 2 ))
3500 local WAIT_TIMEOUT=${1:-$MAX}
3503 local list=$(comma_list $(mdts_nodes))
3504 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
3505 if ! do_facet $SINGLEMDS \
3506 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
3508 # old way, use mds_sync
3510 list=$(comma_list $(osts_nodes))
3511 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
3514 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
3515 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
3516 local -a sync=($(do_nodes $list "$cmd"))
3519 for ((i=0; i<${#sync[@]}; i++)); do
3521 [ ${sync[$i]} -eq 1 ] && continue
3523 [ ${sync[$i]} -eq 0 ] && continue
3525 # there is a not finished MDS-OST synchronization
3529 sleep 2 # increase waiting time and cover statfs cache
3530 [ ${con} -eq 1 ] && return 0
3531 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
3535 # show which nodes are not finished.
3536 cmd=$(echo $cmd | sed 's/-n//')
3537 do_nodes $list "$cmd"
3538 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
3542 # Wait OSTs to be active on both client and MDT side.
3544 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
3545 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
3546 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
3547 error "wait_update OSTs up on client failed"
3549 cmd="$LCTL get_param osp.$FSNAME-OST*-MDT0000.prealloc_last_id |
3550 awk '/=[1-9][0-9]/ { c += 1 } END { printf \\\"%d\\\", c }'"
3551 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
3552 error "wait_update OSTs up on MDT0000 failed"
3555 wait_destroy_complete () {
3556 echo "Waiting for MDT destroys to complete"
3557 # MAX value shouldn't be big as this mean server responsiveness
3558 # never increase this just to make test pass but investigate
3559 # why it takes so long time
3562 local list=$(comma_list $(mdts_nodes))
3563 while [ $WAIT -lt $MAX ]; do
3564 local -a RPCs=($(do_nodes $list $LCTL get_param -n osp.*.destroys_in_flight))
3568 for ((i=0; i<${#RPCs[@]}; i++)); do
3569 [ ${RPCs[$i]} -eq 0 ] && continue
3570 # there are still some destroy RPCs in flight
3574 [ ${con} -eq 1 ] && return 0 # done waiting
3576 echo "Waiting ${WAIT}s for local destroys to complete"
3579 echo "MDT destroys weren't done in $MAX sec."
3583 wait_delete_completed() {
3584 wait_delete_completed_mds $1 || return $?
3585 wait_destroy_complete || return $?
3594 # conf-sanity 31 takes a long time cleanup
3595 while [ $WAIT -lt 300 ]; do
3596 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null &&
3597 lctl dl | grep ' ST ' || true")
3598 [ -z "${running}" ] && return 0
3599 echo "waited $WAIT for${running}"
3600 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
3602 WAIT=$((WAIT + INTERVAL))
3604 echo "service didn't stop after $WAIT seconds. Still running:"
3609 wait_remote_prog () {
3615 [ "$PDSH" = "no_dsh" ] && return 0
3617 while [ $WAIT -lt $2 ]; do
3618 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" |
3619 grep -v grep) || true
3620 [ -z "${running}" ] && return 0 || true
3621 echo "waited $WAIT for: "
3623 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
3625 WAIT=$((WAIT + INTERVAL))
3627 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" |
3628 grep -v grep | awk '{print $2}')
3629 [ -z "$pids" ] && return 0
3630 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
3631 # FIXME: not portable
3632 for pid in $pids; do
3633 cat /proc/${pid}/status || true
3634 cat /proc/${pid}/wchan || true
3636 kill -9 $pid || true
3645 local clients=${1:-$CLIENTS}
3648 if [[ -z "$clients" ]]; then
3649 $LFS df $MOUNT > /dev/null || rc=$?
3651 $PDSH $clients "$LFS df $MOUNT" > /dev/null || rc=$?
3658 local clients=${1:-$CLIENTS}
3661 _lfs_df_check "$clients" || rc=$?
3663 check_lfs_df_ret_val $rc
3667 # not every config has many clients
3673 (( MDSCOUNT == 1 )) && return
3675 # wait so that statfs data on MDT expire
3676 local delay=$(do_facet mds1 $LCTL \
3677 get_param -n osp.*MDT*MDT0000.maxage | sort -n | tail -1)
3679 [ -n "$delay" ] || error "fail to get maxage"
3681 local nodes=$(comma_list $(mdts_nodes))
3682 # initiate statfs RPC, all to all MDTs
3683 do_nodes $nodes $LCTL get_param -N osp.*MDT*MDT*.filesfree >&/dev/null
3684 do_nodes $nodes $LCTL get_param -N osp.*MDT*MDT*.filesfree >&/dev/null
3688 # usually checked on particular client or locally
3698 client_reconnect_try() {
3699 local f=$MOUNT/recon
3702 if [ -z "$CLIENTS" ]; then
3703 $LFS df $MOUNT; uname -n >> $f
3705 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
3707 echo "Connected clients: $(cat $f)"
3708 ls -l $f > /dev/null
3712 client_reconnect() {
3713 # one client_reconnect_try call does not always do the job...
3715 client_reconnect_try && break
3720 affected_facets () {
3723 local host=$(facet_active_host $facet)
3724 local affected=$facet
3726 if [ "$FAILURE_MODE" = HARD ]; then
3727 affected=$(facets_up_on_host $host)
3733 local E2FSCK_ON_MDT0=false
3734 if [ "$1" == "--fsck" ]; then
3736 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
3748 #Because it will only get up facets, we need get affected
3749 #facets before shutdown
3750 #For HARD Failure mode, it needs make sure facets on the same
3751 #HOST will only be shutdown and reboot once
3752 for facet in ${facets//,/ }; do
3753 local affected_facet
3755 #check whether facet has been included in other affected facets
3756 for ((index=0; index<$total; index++)); do
3757 [[ ,${affecteds[index]}, == *,$facet,* ]] && skip=1
3760 if [ $skip -eq 0 ]; then
3761 affecteds[$total]=$(affected_facets $facet)
3766 for ((index=0; index<$total; index++)); do
3767 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
3768 local host=$(facet_active_host $facet)
3769 echo "Failing ${affecteds[index]} on $host"
3770 shutdown_facet $facet
3773 echo "$(date +'%H:%M:%S (%s)') shut down"
3778 for facet in ${facets//,/ }; do
3779 local host=$(facet_active_host $facet)
3781 hostlist=$(expand_list $hostlist $host)
3782 if [ $(facet_host $facet) = \
3783 $(facet_failover_host $facet) ]; then
3784 waithostlist=$(expand_list $waithostlist $host)
3788 if [ "$FAILURE_MODE" = HARD ]; then
3789 for host in ${hostlist//,/ }; do
3792 echo "$(date +'%H:%M:%S (%s)') $hostlist rebooted"
3793 # We need to wait the rebooted hosts in case if
3794 # facet_HOST == facetfailover_HOST
3795 if ! [ -z "$waithostlist" ]; then
3796 wait_for_host $waithostlist
3797 if $LOAD_MODULES_REMOTE; then
3798 echo "loading modules on $waithostlist"
3799 do_rpc_nodes $waithostlist load_modules_local
3806 if [[ " ${affecteds[@]} " =~ " $SINGLEMDS " ]]; then
3807 change_active $SINGLEMDS
3810 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
3811 $(facet_device $SINGLEMDS) "-n" || error "Running e2fsck")
3815 for ((index=0; index<$total; index++)); do
3816 if [[ ${affecteds[index]} != $SINGLEMDS ]]; then
3817 change_active ${affecteds[index]}
3821 init_facets_vars_simple
3823 # start mgs first if it is affected
3824 if ! combined_mgs_mds &&
3825 list_member ${affecteds[index]} mgs; then
3826 mount_facet mgs || error "Restart of mgs failed"
3827 affecteds[index]=$(exclude_items_from_list \
3828 ${affecteds[index]} mgs)
3830 if [ -n "${affecteds[index]}" ]; then
3831 echo mount facets: ${affecteds[index]}
3832 mount_facets ${affecteds[index]} &
3836 for ((index=0; index<$total; index++)); do
3837 if [ -n "${affecteds[index]}" ]; then
3838 wait ${mountpids[index]}
3842 do_nodes $(comma_list $(all_nodes)) \
3843 "keyctl show | grep lustre | cut -c1-11 |
3845 xargs -IX keyctl setperm X 0x3f3f3f3f"
3848 echo "$(date +'%H:%M:%S (%s)') targets are mounted"
3850 if [ "$FAILURE_MODE" = HARD ]; then
3851 hostlist=$(exclude_items_from_list $hostlist $waithostlist)
3852 if ! [ -z "$hostlist" ]; then
3853 wait_for_host $hostlist
3854 if $LOAD_MODULES_REMOTE; then
3855 echo "loading modules on $hostlist"
3856 do_rpc_nodes $hostlist load_modules_local
3861 echo "$(date +'%H:%M:%S (%s)') facet_failover done"
3866 do_facet $facet "sync; sync; sync"
3869 # make sure there will be no seq change
3870 local clients=${CLIENTS:-$HOSTNAME}
3871 local f=fsa-\\\$\(hostname\)
3872 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
3873 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
3875 local svc=${facet}_svc
3876 do_facet $facet $LCTL --device ${!svc} notransno
3878 # If a ZFS OSD is made read-only here, its pool is "freezed". This
3879 # in-memory state has to be cleared by either rebooting the host or
3880 # exporting and reimporting the pool.
3882 # Although the uberblocks are not updated when a pool is freezed,
3883 # transactions are still written to the disks. Modified blocks may be
3884 # cached in memory when tests try reading them back. The
3885 # export-and-reimport process also evicts any cached pool data from
3886 # memory to provide the correct "data loss" semantics.
3888 # In the test framework, the exporting and importing operations are
3889 # handled by stop() and mount_facet() separately, which are used
3890 # inside fail() and fail_abort().
3892 set_dev_readonly $facet
3893 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
3894 $LCTL mark "local REPLAY BARRIER on ${!svc}"
3897 replay_barrier_nodf() {
3898 local facet=$1 echo running=${running}
3899 do_facet $facet "sync; sync; sync"
3900 local svc=${facet}_svc
3901 echo Replay barrier on ${!svc}
3902 do_facet $facet $LCTL --device ${!svc} notransno
3903 set_dev_readonly $facet
3904 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
3905 $LCTL mark "local REPLAY BARRIER on ${!svc}"
3908 replay_barrier_nosync() {
3909 local facet=$1 echo running=${running}
3910 local svc=${facet}_svc
3911 echo Replay barrier on ${!svc}
3912 do_facet $facet $LCTL --device ${!svc} notransno
3913 set_dev_readonly $facet
3914 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
3915 $LCTL mark "local REPLAY BARRIER on ${!svc}"
3919 # Get Lustre client uuid for a given Lustre mount point.
3922 local mntpnt=${1:-$MOUNT}
3924 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
3925 local uuid=$($LCTL get_param -n llite.$name.uuid)
3930 mds_evict_client() {
3931 local mntpnt=${1:-$MOUNT}
3932 local uuid=$(get_client_uuid $mntpnt)
3934 do_facet $SINGLEMDS \
3935 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
3938 ost_evict_client() {
3939 local mntpnt=${1:-$MOUNT}
3940 local uuid=$(get_client_uuid $mntpnt)
3943 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
3948 local clients=${CLIENTS:-$HOSTNAME}
3950 SK_NO_KEY_save=$SK_NO_KEY
3952 export SK_NO_KEY=false
3954 facet_failover $* || error "failover: $?"
3955 export SK_NO_KEY=$SK_NO_KEY_save
3956 # to initiate all OSC idling connections
3958 wait_clients_import_ready "$clients" "$facets"
3959 clients_up || error "post-failover stat: $?"
3965 facet_failover $facet
3970 local abort_type=${2:-"abort_recovery"}
3973 change_active $facet
3974 wait_for_facet $facet
3975 mount_facet $facet -o $abort_type
3976 clients_up || echo "first stat failed: $?"
3977 clients_up || error "post-failover stat: $?"
3981 # LU-16159: abort recovery will cancel update logs, which may leave broken
3982 # directories in the system, remove name entry if necessary
3983 fail_abort_cleanup() {
3985 find $DIR/$tdir -depth | while read D; do
3986 rmdir "$D" || $LFS rm_entry "$D" || error "rm $D failed"
3990 host_nids_address() {
3994 do_nodes $nodes "$LCTL list_nids | grep -w $net | cut -f 1 -d @"
3998 if [ "$1" = "'*'" ]; then echo \'*\'; else
4004 if [[ -n "$NETTYPE" ]]; then
4005 h2name_or_ip "$1" "$NETTYPE"
4007 h2name_or_ip "$1" "$2"
4010 declare -fx h2nettype
4012 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
4013 # expressions format. As a bonus we can then just pass in those variables
4014 # to pdsh. What this function does is take a HOSTLIST type string and
4015 # expand it into a space deliminated list for us.
4023 [ -z "$hostlist" ] && return
4025 # Translate the case of [..],..,[..] to [..] .. [..]
4026 list="${hostlist/],/] }"
4028 [[ "$front" == *,* ]] && {
4031 list=${list/${old}/${new}}
4034 for item in $list; do
4035 # Test if we have any []'s at all
4036 if [ "$item" != "${item/\[/}" ]; then {
4037 # Expand the [*] into list
4041 if [ "$name" != "$item" ]; then
4042 group=${item#$name[*}
4045 for range in ${group//,/ }; do
4051 # Number of leading zeros
4054 end=$(echo $end | sed 's/0*//')
4055 [[ -z "$end" ]] && end=0
4056 [[ $padlen2 -gt $padlen ]] && {
4057 [[ $padlen2 -eq ${#end} ]] &&
4061 begin=$(echo $begin | sed 's/0*//')
4062 [ -z $begin ] && begin=0
4064 if [ ! -z "${begin##[!0-9]*}" ]; then
4065 order=$(seq -f "%0${padlen}g" $begin $end)
4067 order=$(eval echo {$begin..$end});
4070 for num in $order; do
4071 value="${name#*,}${num}${back}"
4073 [ "$value" != "${value/\[/}" ] && {
4074 value=$(hostlist_expand "$value")
4076 myList="$myList $value"
4081 myList="$myList $item"
4084 myList=${myList//,/ }
4085 myList=${myList:1} # Remove first character which is a space
4087 # Filter any duplicates without sorting
4089 myList="${list%% *}"
4091 while [[ "$list" != ${myList##* } ]]; do
4092 local tlist=" $list"
4094 list=${tlist// ${list%% *} / }
4096 myList="$myList ${list%% *}"
4098 myList="${myList%* }";
4100 # We can select an object at an offset in the list
4103 for item in $myList; do
4105 [ $cnt -eq $offset ] && {
4109 [ $(get_node_count $myList) -ne 1 ] && myList=""
4118 [ "$facet" == client ] && echo -n $HOSTNAME && return
4119 varname=${facet}_HOST
4120 if [ -z "${!varname}" ]; then
4121 if [ "${facet:0:3}" == "ost" ]; then
4122 local fh=${facet%failover}_HOST
4123 eval export ${facet}_HOST=${!fh}
4124 if [ -z "${!varname}" ]; then
4125 eval export ${facet}_HOST=${ost_HOST}
4127 elif [ "${facet:0:3}" == "mdt" -o \
4128 "${facet:0:3}" == "mds" -o \
4129 "${facet:0:3}" == "mgs" ]; then
4131 if [ "${facet}" == "mgsfailover" ] &&
4132 [ -n "$mds1failover_HOST" ]; then
4133 temp=$mds1failover_HOST
4137 eval export ${facet}_HOST=$temp
4143 facet_failover_host() {
4147 var=${facet}failover_HOST
4148 if [ -n "${!var}" ]; then
4153 if combined_mgs_mds && [ $facet == "mgs" ] &&
4154 [ -n "$mds1failover_HOST" ]; then
4155 echo $mds1failover_HOST
4159 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
4160 "${facet:0:3}" == "mgs" ]; then
4162 eval export ${facet}failover_host=${mds_HOST}
4167 if [[ $facet == ost* ]]; then
4168 eval export ${facet}failover_host=${ost_HOST}
4176 local activevar=${facet}active
4178 if [ -f $TMP/${facet}active ] ; then
4179 source $TMP/${facet}active
4182 active=${!activevar}
4183 if [ -z "$active" ] ; then
4190 facet_active_host() {
4191 facet_host $(facet_active $1)
4194 # Get the passive failover partner host of facet.
4195 facet_passive_host() {
4197 [[ $facet = client ]] && return
4199 local host=${facet}_HOST
4200 local failover_host=${facet}failover_HOST
4201 local active_host=$(facet_active_host $facet)
4203 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
4205 if [[ $active_host = ${!host} ]]; then
4206 echo -n ${!failover_host}
4216 for facet in ${facetlist//,/ }; do
4217 local failover=${facet}failover
4218 local host=`facet_host $failover`
4220 [ -z "$host" ] && return
4222 local curactive=`facet_active $facet`
4224 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
4225 eval export ${facet}active=$facet
4227 eval export ${facet}active=$failover
4229 # save the active host for this facet
4230 local activevar=${facet}active
4232 echo "$activevar=${!activevar}" > $TMP/$activevar
4233 [[ $facet = mds1 ]] && combined_mgs_mds && \
4234 echo "mgsactive=${!activevar}" > $TMP/mgsactive
4235 local TO=`facet_active_host $facet`
4236 echo "Failover $facet to $TO"
4244 # do not strip off hostname if verbose, b=19215
4245 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4246 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4252 if [ "$HOST" = "$HOSTNAME" ]; then
4254 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
4255 echo "cannot run remote command on $HOST with $myPDSH"
4258 if $VERBOSE && [[ -z "$quiet" ]]; then
4259 echo "CMD: $HOST $*" >&2
4260 $myPDSH $HOST "$LCTL mark \"$*\"" > /dev/null 2>&1 || :
4263 if [[ "$myPDSH" == "rsh" ]] ||
4264 [[ "$myPDSH" == *pdsh* && "$myPDSH" != *-S* ]]; then
4265 # we need this because rsh and pdsh do not return
4266 # exit code of an executed command
4267 local command_status="$TMP/cs"
4268 eval $myPDSH $HOST ":> $command_status"
4269 eval $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests;
4270 PATH=\$PATH:/sbin:/usr/sbin;
4272 LUSTRE=\"$RLUSTRE\" bash -c \"$*\") ||
4273 echo command failed >$command_status"
4274 [[ -n "$($myPDSH $HOST cat $command_status)" ]] && return 1 ||
4278 if [[ -n "$verbose" ]]; then
4279 # print HOSTNAME for myPDSH="no_dsh"
4280 if [[ $myPDSH = no_dsh ]]; then
4282 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4283 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")" |
4284 sed -e "s/^/${HOSTNAME}: /"
4287 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4288 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")"
4292 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4293 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")" |
4294 sed "s/^${HOST}: //"
4296 return ${PIPESTATUS[0]}
4300 # Execute exact command line on host
4302 # The \a host may be on a local or remote node, which is determined at
4303 # the time the command is run. Does careful argument quotation to
4304 # ensure that the exact command line is executed without any globbing,
4305 # substitution, or shell interpretation on the remote side. Does not
4306 # support --verbose or --quiet. Does not include "$host: " prefixes on
4307 # output. See also do_facet_vp().
4309 # usage: do_node_vp "$host" "$command" "$arg"...
4314 if [[ "$host" == "$HOSTNAME" ]]; then
4315 bash -c "$(printf -- ' %q' "$@")"
4319 if [[ "${PDSH}" != *pdsh* || "${PDSH}" != *-S* ]]; then
4320 echo "cannot run '$*' on host '${host}' with PDSH='${PDSH}'" >&2
4324 # -N Disable hostname: prefix on lines of output.
4326 $PDSH "${host}" -N "cd $RPWD; PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; export LUSTRE=$RLUSTRE; $(printf -- ' %q' "$@")"
4329 single_local_node () {
4330 [ "$1" = "$HOSTNAME" ]
4333 # Outputs environment variable assignments that should be passed to remote nodes
4337 local facets=$(get_facets)
4340 for var in ${!MODOPTS_*}; do
4341 value=${!var//\"/\\\"}
4342 echo -n " ${var}=\"$value\""
4345 for facet in ${facets//,/ }; do
4347 if [ -n "${!var}" ]; then
4348 echo -n " $var=${!var}"
4352 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
4353 if [ -n "${!var}" ]; then
4354 echo -n " $var=${!var}"
4358 for var in VERBOSE; do
4359 if [ -n "${!var}" ]; then
4360 echo -n " $var=${!var}"
4364 if [ -n "$FSTYPE" ]; then
4365 echo -n " FSTYPE=$FSTYPE"
4368 for var in LNETLND NETTYPE; do
4369 if [ -n "${!var}" ]; then
4370 echo -n " $var=${!var}"
4379 # do not strip off hostname if verbose, b=19215
4380 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4381 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4386 if single_local_node $rnodes; then
4387 do_node $verbose $quiet $rnodes "$@"
4391 # This is part from do_node
4394 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] &&
4395 echo "cannot run remote command on $rnodes with $myPDSH" &&
4398 export FANOUT=$(get_node_count "${rnodes//,/ }")
4399 if $VERBOSE && [[ -z "$quiet" ]]; then
4400 echo "CMD: $rnodes $*" >&2
4401 $myPDSH $rnodes "$LCTL mark \"$*\"" > /dev/null 2>&1 || :
4404 # do not replace anything from pdsh output if -N is used
4405 # -N Disable hostname: prefix on lines of output.
4406 if [[ -n "$verbose" || $myPDSH = *-N* ]]; then
4407 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) bash -c \"$*\")"
4409 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) bash -c \"$*\")" | sed -re "s/^[^:]*: //g"
4411 return ${PIPESTATUS[0]}
4415 # Execute commands on a single service's host
4417 # The \a facet (service) may be on a local or remote node, which is
4418 # determined at the time the command is run.
4420 # usage: do_facet $facet command [arg ...]
4425 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4426 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4430 local host=$(facet_active_host $facet)
4432 [ -z "$host" ] && echo "No host defined for facet ${facet}" && exit 1
4433 do_node $verbose $quiet $host "$@"
4437 # Execute exact command line on the host of a facet
4439 # The \a facet (service) may be on a local or remote node, which is
4440 # determined at the time the command is run. Does careful argument
4441 # quotation to ensure that the exact command line is executed without
4442 # any globbing, substitution, or shell interpretation on the remote
4443 # side. Does not support --verbose or --quiet. Does not include
4444 # "$host: " prefixes on output.
4446 # usage: do_facet_vp "$facet" "$command" "$arg"...
4449 local host=$(facet_active_host "$facet")
4452 if [[ -z "$host" ]]; then
4453 echo "no host defined for facet ${facet}" >&2
4457 do_node_vp "$host" "$@"
4460 # Function: do_facet_random_file $FACET $FILE $SIZE
4461 # Creates FILE with random content on the given FACET of given SIZE
4463 do_facet_random_file() {
4467 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
4468 do_facet $facet "$cmd 2>/dev/null"
4471 do_facet_create_file() {
4475 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
4476 do_facet $facet "$cmd 2>/dev/null"
4480 do_nodes --verbose "$@"
4486 # make sure its not already running
4488 rm -f $TMP/${facet}active
4489 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
4491 # make sure in-tree ldiskfs is loaded before mkfs
4492 if local_mode && [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
4493 load_module ../ldiskfs/ldiskfs
4496 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
4498 if [[ $(facet_fstype $facet) == zfs ]]; then
4500 # After formatting a ZFS target, "cachefile=none" property will
4501 # be set on the ZFS storage pool so that the pool is not
4502 # automatically imported on system startup. And then the pool
4503 # will be exported so as to leave the importing and exporting
4504 # operations handled by mount_facet() and stop() separately.
4506 refresh_partition_table $facet $(facet_vdevice $facet)
4507 disable_zpool_cache $facet
4512 # Device formatted as ost
4515 local DEVNAME=OSTDEV$num
4517 local fstype=$(facet_fstype ost$num)
4521 local dev=ost${num}_dev
4522 [[ -n ${!dev} ]] && eval DEVPTR=${!dev} ||
4523 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
4524 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
4526 #try $OSTZFSDEVn - independent of vdev
4527 DEVNAME=OSTZFSDEV$num
4528 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
4530 error "unknown fstype!";;
4536 # Physical device location of data
4542 local fstype=$(facet_fstype ost$num)
4546 # vdevs are not supported by ldiskfs
4549 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
4550 # Device formatted by zfs
4552 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
4554 error "unknown fstype!";;
4560 # Logical device formatted for lustre
4563 local DEVNAME=MDSDEV$num
4565 local fstype=$(facet_fstype mds$num)
4569 local dev=mds${num}_dev
4570 [[ -n ${!dev} ]] && eval DEVPTR=${!dev} ||
4571 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
4572 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
4574 # try $MDSZFSDEVn - independent of vdev
4575 DEVNAME=MDSZFSDEV$num
4576 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
4578 error "unknown fstype!";;
4584 # Physical location of data
4588 local fstype=$(facet_fstype mds$num)
4592 # vdevs are not supported by ldiskfs
4595 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
4596 # Device formatted by ZFS
4597 local DEVNAME=MDSDEV$num
4598 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
4600 error "unknown fstype!";;
4608 local fstype=$(facet_fstype mgs)
4612 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4613 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $MDSDEV1 ] ); then
4614 DEVPTR=$(mdsdevname 1)
4616 [[ -n $mgs_dev ]] && DEVPTR=$mgs_dev ||
4620 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4621 ( [ -z "$MGSZFSDEV" ] &&
4622 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
4623 DEVPTR=$(mdsdevname 1)
4625 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
4628 error "unknown fstype!";;
4637 local fstype=$(facet_fstype mgs)
4641 # vdevs are not supported by ldiskfs
4644 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4645 ( [ -z "$MGSDEV" ] &&
4646 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
4647 VDEVPTR=$(mdsvdevname 1)
4648 elif [ -n "$MGSDEV" ]; then
4652 error "unknown fstype!";;
4660 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
4662 local var=${facet}_MOUNT
4663 eval mntpt=${!var:-${MOUNT}-$facet}
4670 local dev=$(facet_device $facet)
4671 local mnt=${2:-$(facet_mntpt $facet)}
4675 if dm_flakey_supported $facet; then
4676 dm_dev=$(dm_create_dev $facet $dev)
4677 [[ -n "$dm_dev" ]] || dm_dev=$dev
4679 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
4680 export_dm_dev $facet $dm_dev
4682 do_facet $facet mount -t ldiskfs $opts $dm_dev $mnt
4687 local dev=$(facet_device $facet)
4688 local mnt=${2:-$(facet_mntpt $facet)}
4690 do_facet $facet $UMOUNT $mnt
4694 echo -n "$1" | tr -c '[:alnum:]\n' '_'
4699 local ds=$(facet_device $facet)
4700 local mnt=${2:-$(facet_mntpt $facet)}
4705 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
4706 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
4707 do_facet $facet $ZFS set canmount=noauto $ds
4709 # The "legacy" mount method is used here because "zfs unmount $mnt"
4710 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
4711 # targets are not available at the time, the stat(2) on $MOUNT will
4714 do_facet $facet $ZFS set mountpoint=legacy $ds
4715 do_facet $facet mount -t zfs $ds $mnt
4716 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
4717 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
4722 local ds=$(facet_device $facet)
4723 local mnt=${2:-$(facet_mntpt $facet)}
4724 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
4725 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
4726 local mntpt=${!var_mntpt}
4727 local canmnt=${!var_canmnt}
4731 do_facet $facet umount $mnt
4732 do_facet $facet $ZFS set mountpoint=$mntpt $ds
4733 do_facet $facet $ZFS set canmount=$canmnt $ds
4740 local fstype=$(facet_fstype $facet)
4742 mount_$fstype $facet $mnt
4748 local fstype=$(facet_fstype $facet)
4750 unmount_$fstype $facet $mnt
4757 # make sure we are using the primary server, so test-framework will
4758 # be able to clean up properly.
4759 activemds=`facet_active mds1`
4760 if [ $activemds != "mds1" ]; then
4764 local clients=$CLIENTS
4765 [ -z $clients ] && clients=$(hostname)
4767 zconf_umount_clients $clients $MOUNT "$*" || true
4768 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
4770 [ -n "$CLIENTONLY" ] && return
4772 # The add fn does rm ${facet}active file, this would be enough
4773 # if we use do_facet <facet> only after the facet added, but
4774 # currently we use do_facet mds in local.sh
4776 for num in `seq $MDSCOUNT`; do
4778 rm -f ${TMP}/mds${num}active
4780 combined_mgs_mds && rm -f $TMP/mgsactive
4782 for num in `seq $OSTCOUNT`; do
4784 rm -f $TMP/ost${num}active
4787 if ! combined_mgs_mds ; then
4791 if $SHARED_KEY; then
4792 export SK_MOUNTED=false
4798 cleanup_echo_devs () {
4801 local devs=$($LCTL dl | grep echo | awk '{print $4}')
4803 for dev in $devs; do
4804 $LCTL --device $dev cleanup
4805 $LCTL --device $dev detach
4810 nfs_client_mode && return
4811 cifs_client_mode && return
4814 CLEANUP_DM_DEV=true stopall $*
4821 combined_mgs_mds () {
4822 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
4823 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
4827 echo -n "$1" | tr '[:upper:]' '[:lower:]'
4831 echo -n "$1" | tr '[:lower:]' '[:upper:]'
4843 var=$(echo "$var" | sed -e 's/,\( \)*/,/g')
4844 for i in $(echo "$var"); do
4845 if [ "$i" == "-O" ]; then
4847 first_o=$(($first_o + 1))
4850 if [ "$i" == "-E" ]; then
4852 first_e=$(($first_e + 1 ))
4857 [ $first_o -gt 1 ] && opt_o+=",";
4861 [ $first_e -gt 1 ] && opt_e+=",";
4872 [ -n "$opt_o" ] && echo " -O $opt_o"
4873 [ -n "$opt_e" ] && echo " -E $opt_e"
4879 local fsname=${3:-"$FSNAME"}
4880 local type=$(facet_type $facet)
4881 local index=$(facet_index $facet)
4882 local fstype=$(facet_fstype $facet)
4883 local host=$(facet_host $facet)
4887 local varbs=${facet}_BLOCKSIZE
4889 if [ $type == MGS ] || ( [ $type == MDS ] &&
4890 [ "$dev" == $(mgsdevname) ] &&
4891 [ "$host" == "$(facet_host mgs)" ] ); then
4894 opts="--mgsnode=$MGSNID"
4897 if [ $type != MGS ]; then
4898 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
4902 var=${facet}failover_HOST
4903 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
4904 opts+=" --failnode=$(h2nettype ${!var})"
4907 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
4908 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
4910 if [ $type == MDS ]; then
4911 opts+=${DEF_STRIPE_SIZE:+" --param=lov.stripesize=$DEF_STRIPE_SIZE"}
4912 opts+=${DEF_STRIPE_COUNT:+" --param=lov.stripecount=$DEF_STRIPE_COUNT"}
4913 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
4915 if [ $fstype == ldiskfs ]; then
4917 if [ -n "${!var}" ]; then
4918 fs_mkfs_opts+=" -J device=${!var}"
4920 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
4922 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
4926 if [ $type == OST ]; then
4927 if [ $fstype == ldiskfs ]; then
4929 if [ -n "${!var}" ]; then
4930 fs_mkfs_opts+=" -J device=${!var}"
4932 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
4937 opts+=" --backfstype=$fstype"
4940 if [ -n "${!var}" ]; then
4941 opts+=" --device-size=${!var}"
4944 var=$(upper $fstype)_MKFS_OPTS
4945 fs_mkfs_opts+=${!var:+" ${!var}"}
4947 var=${type}_FS_MKFS_OPTS
4948 fs_mkfs_opts+=${!var:+" ${!var}"}
4950 [[ "$QUOTA_TYPE" =~ "p" ]] && fs_mkfs_opts+=" -O project"
4952 [ $fstype == ldiskfs ] && fs_mkfs_opts+=" -b ${!varbs:-$BLCKSIZE}"
4953 [ $fstype == ldiskfs ] && fs_mkfs_opts=$(squash_opt $fs_mkfs_opts)
4955 if [ -n "${fs_mkfs_opts## }" ]; then
4956 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
4960 opts+=${!var:+" ${!var}"}
4967 local type=$(facet_type $facet)
4968 local var=${type}_MOUNT_FS_OPTS
4970 if [ -n "${!var}" ]; then
4971 opts+=" --mountfsoptions=${!var}"
4976 check_ost_indices() {
4977 local index_count=${#OST_INDICES[@]}
4978 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
4980 # OST count is greater than the index count in $OST_INDEX_LIST.
4981 # We need check whether there are duplicate indices.
4985 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
4986 index=$(facet_index ost$i)
4987 for j in $(seq 0 $((index_count - 1))); do
4988 [[ $index -ne ${OST_INDICES[j]} ]] ||
4989 error "ost$i has the same index $index as ost$((j+1))"
4996 local facet_type=$1 # mgs || mds || ost
4998 local facet=${1}${2}
5001 case "$(facet_fstype $facet)" in
5003 device=$(${facet_type}devname $facet_num)
5006 device=$(${facet_type}vdevname $facet_num)
5009 error "Unhandled filesystem type"
5013 do_facet $facet "[ -e \"$device\" ]" && return
5015 # Note: the following check only works with absolute paths
5016 [[ ! "$device" =~ ^/dev/ ]] || [[ "$device" =~ ^/dev/shm/ ]] ||
5017 error "$facet: device '$device' does not exist"
5019 # zpool create doesn't like empty files
5020 [[ $(facet_fstype $facet) == zfs ]] && return 0
5022 do_facet $facet "touch \"${device}\""
5031 echo "Format mgs: $(mgsdevname)"
5032 reformat_external_journal mgs
5034 # touch "device" in case it is a loopback file for testing and needs to
5035 # be created. mkfs.lustre doesn't do this to avoid accidentally writing
5036 # to non-existent files in /dev if the admin made a typo during setup
5039 add mgs $(mkfs_opts mgs $(mgsdevname)) $(mountfs_opts mgs) --reformat \
5040 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
5050 echo "Format mds$num: $(mdsdevname $num)"
5051 reformat_external_journal mds$num
5053 __touch_device mds $num
5055 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
5056 $(mountfs_opts mds$num) --reformat $(mdsdevname $num) \
5057 $(mdsvdevname $num) ${quiet:+>/dev/null} || exit 10
5066 echo "Format ost$num: $(ostdevname $num)"
5067 reformat_external_journal ost$num
5069 __touch_device ost $num
5071 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
5072 $(mountfs_opts ost$num) --reformat $(ostdevname $num) \
5073 $(ostvdevname ${num}) ${quiet:+>/dev/null} || exit 10
5078 # Set hostid for ZFS/SPL zpool import protection
5079 # (Assumes MDS version is also OSS version)
5080 if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ];
5082 do_rpc_nodes "$(comma_list $(all_server_nodes))" set_hostid
5085 # We need ldiskfs here, may as well load them all
5087 [ -n "$CLIENTONLY" ] && return
5088 echo Formatting mgs, mds, osts
5089 if ! combined_mgs_mds ; then
5093 for num in $(seq $MDSCOUNT); do
5097 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
5099 for num in $(seq $OSTCOUNT); do
5105 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
5109 grep " $1 " /proc/mounts && zconf_umount $HOSTNAME $*
5113 # 0: success, the old identity set already.
5114 # 1: success, the old identity does not set.
5119 local j=`expr $num - 1`
5120 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
5122 if [ -z "$MDT" ]; then
5126 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
5129 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
5131 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
5134 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
5136 if [ $old = "NONE" ]; then
5145 zconf_umount $HOSTNAME $1 || error "umount failed"
5146 zconf_mount $HOSTNAME $1 || error "mount failed"
5154 rm -f $TMP/${facet}active
5155 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
5160 local mdt_count=${1:-$MDSCOUNT}
5161 local ost_count=${2:-$OSTCOUNT}
5164 for num in $(seq $mdt_count); do
5165 DEVNAME=$(mdsdevname $num)
5166 writeconf_facet mds$num $DEVNAME || rc=$?
5169 for num in $(seq $ost_count); do
5170 DEVNAME=$(ostdevname $num)
5171 writeconf_facet ost$num $DEVNAME || rc=$?
5177 if ! combined_mgs_mds ; then
5178 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
5187 for num in $(seq $MDSCOUNT); do
5188 devname=$(mdsdevname $num)
5189 start mds$num $devname $MDS_MOUNT_OPTS
5191 # We started mds$num, now we should set mds${num}_HOST
5192 # and mds${num}failover_HOST variables properly if they
5194 host=$(facet_host mds$num)
5195 for varname in mds${num}_HOST mds${num}failover_HOST; do
5196 if [[ -z "${!varname}" ]]; then
5200 if [ $IDENTITY_UPCALL != "default" ]; then
5201 switch_identity $num $IDENTITY_UPCALL
5209 for num in $(seq $OSTCOUNT); do
5211 rm -f $TMP/ost${num}active
5220 for num in $(seq $OSTCOUNT); do
5221 devname=$(ostdevname $num)
5222 start ost$num $devname $OST_MOUNT_OPTS
5224 # We started ost$num, now we should set ost${num}_HOST
5225 # and ost${num}failover_HOST variables properly if they
5227 host=$(facet_host ost$num)
5228 for varname in ost${num}_HOST ost${num}failover_HOST; do
5229 if [[ -z "${!varname}" ]]; then
5237 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
5238 if [ ! -z $arg1 ]; then
5239 [ "$arg1" = "server_only" ] && return
5242 if [ -n "$CLIENTS" ]; then
5243 zconf_mount_clients $CLIENTS $MOUNT
5247 if [ "$MOUNT_2" ]; then
5248 mount_client $MOUNT2
5249 if [ -n "$CLIENTS" ]; then
5250 zconf_mount_clients $CLIENTS $MOUNT2
5255 sk_nodemap_setup() {
5256 local sk_map_name=${1:-$SK_S2SNM}
5257 local sk_map_nodes=${2:-$HOSTNAME}
5258 do_node $(mgs_node) "$LCTL nodemap_add $sk_map_name"
5259 for servernode in $sk_map_nodes; do
5260 local nids=$(do_nodes $servernode "$LCTL list_nids")
5261 for nid in $nids; do
5262 do_node $(mgs_node) "$LCTL nodemap_add_range --name \
5263 $sk_map_name --range $nid"
5271 nfs_client_mode && return
5272 cifs_client_mode && return
5274 sanity_mount_check || error "environments are insane!"
5280 if [ -z "$CLIENTONLY" ]; then
5281 echo Setup mgs, mdt, osts
5282 echo $WRITECONF | grep -q "writeconf" && writeconf_all
5284 if $SK_MOUNTED; then
5285 echo "Shared Key file system already mounted"
5290 if $SHARED_KEY; then
5291 export SK_MOUNTED=true
5295 echo "GSS_SK: setting kernel keyring perms"
5296 do_nodes $(comma_list $(all_nodes)) \
5297 "keyctl show | grep lustre | cut -c1-11 |
5299 xargs -IX keyctl setperm X 0x3f3f3f3f"
5302 # Need to start one nodemap for servers,
5303 # and one for clients.
5304 sk_nodemap_setup $SK_S2SNM \
5305 $(comma_list $(all_server_nodes))
5307 sk_nodemap_setup $SK_S2SNMCLI \
5308 ${CLIENTS:-$HOSTNAME}
5309 echo "Nodemap set up for SK S2S, remounting."
5318 # wait a while to allow sptlrpc configuration be propogated to targets,
5319 # only needed when mounting new target devices.
5327 # by remounting mdt before ost, initial connect from mdt to ost might
5328 # timeout because ost is not ready yet. wait some time to its fully
5329 # recovery. initial obd_connect timeout is 5s; in GSS case it's
5330 # preceeded by a context negotiation rpc with $TIMEOUT.
5331 # FIXME better by monitoring import status.
5334 set_rule $FSNAME any cli2mdt $SK_FLAVOR
5335 set_rule $FSNAME any cli2ost $SK_FLAVOR
5336 if $SK_SKIPFIRST; then
5337 export SK_SKIPFIRST=false
5341 "lctl set_param osc.*.idle_connect=1"
5344 wait_flavor cli2mdt $SK_FLAVOR
5345 wait_flavor cli2ost $SK_FLAVOR
5350 sleep $((TIMEOUT + 5))
5356 mounted_lustre_filesystems() {
5357 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
5360 init_facet_vars () {
5361 [ -n "$CLIENTONLY" ] && return 0
5368 eval export ${facet}_dev=${device}
5369 eval export ${facet}_opt=\"$*\"
5371 local dev=${facet}_dev
5373 # We need to loop for the label
5374 # in case its not initialized yet.
5375 for wait_time in {0,1,3,5,10}; do
5377 if [ $wait_time -gt 0 ]; then
5378 echo "${!dev} not yet initialized,"\
5379 "waiting ${wait_time} seconds."
5383 local label=$(devicelabel ${facet} ${!dev})
5385 # Check to make sure the label does
5386 # not include ffff at the end of the label.
5387 # This indicates it has not been initialized yet.
5389 if [[ $label =~ [f|F]{4}$ ]]; then
5390 # label is not initialized, unset the result
5391 # and either try again or fail
5398 [ -z "$label" ] && echo no label for ${!dev} && exit 1
5400 eval export ${facet}_svc=${label}
5402 local varname=${facet}failover_HOST
5403 if [ -z "${!varname}" ]; then
5405 if combined_mgs_mds && [ $facet == "mgs" ] &&
5406 [ -n "$mds1failover_HOST" ]; then
5407 temp=$mds1failover_HOST
5409 temp=$(facet_host $facet)
5411 eval export $varname=$temp
5414 varname=${facet}_HOST
5415 if [ -z "${!varname}" ]; then
5416 eval export $varname=$(facet_host $facet)
5419 # ${facet}failover_dev is set in cfg file
5420 varname=${facet}failover_dev
5421 if [ -n "${!varname}" ] ; then
5422 eval export ${facet}failover_dev=${!varname}
5424 eval export ${facet}failover_dev=$device
5427 # get mount point of already mounted device
5428 # is facet_dev is already mounted then use the real
5429 # mount point of this facet; otherwise use $(facet_mntpt $facet)
5430 # i.e. ${facet}_MOUNT if specified by user or default
5431 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
5432 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
5433 if [ -z $mntpt ]; then
5434 mntpt=$(facet_mntpt $facet)
5436 eval export ${facet}_MOUNT=$mntpt
5439 init_facets_vars () {
5442 if ! remote_mds_nodsh; then
5443 for num in $(seq $MDSCOUNT); do
5444 DEVNAME=$(mdsdevname $num)
5445 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
5449 init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
5451 if ! remote_ost_nodsh; then
5452 for num in $(seq $OSTCOUNT); do
5453 DEVNAME=$(ostdevname $num)
5454 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
5459 init_facets_vars_simple () {
5462 if ! remote_mds_nodsh; then
5463 for num in $(seq $MDSCOUNT); do
5464 devname=$(mdsdevname $num)
5465 eval export mds${num}_dev=${devname}
5466 eval export mds${num}_opt=\"${MDS_MOUNT_OPTS}\"
5470 if ! combined_mgs_mds ; then
5471 eval export mgs_dev=$(mgsdevname)
5472 eval export mgs_opt=\"${MGS_MOUNT_OPTS}\"
5475 if ! remote_ost_nodsh; then
5476 for num in $(seq $OSTCOUNT); do
5477 devname=$(ostdevname $num)
5478 eval export ost${num}_dev=${devname}
5479 eval export ost${num}_opt=\"${OST_MOUNT_OPTS}\"
5484 osc_ensure_active () {
5489 while [ $period -lt $timeout ]; do
5490 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
5491 if [ $count -eq 0 ]; then
5495 echo "$count OST inactive, wait $period seconds, and try again"
5497 period=$((period+3))
5500 [ $period -lt $timeout ] ||
5501 log "$count OST are inactive after $timeout seconds, give up"
5504 set_conf_param_and_check() {
5508 local ORIG=$(do_facet $myfacet "$TEST")
5509 if [ $# -gt 3 ]; then
5515 echo "Setting $PARAM from $ORIG to $FINAL"
5516 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
5517 error "conf_param $PARAM failed"
5519 wait_update_facet $myfacet "$TEST" "$FINAL" ||
5520 error "check $PARAM failed!"
5523 set_persistent_param() {
5527 local orig=$(do_facet $myfacet "$LCTL get_param -n $test_param")
5529 if [ $# -gt 3 ]; then
5536 if [[ $PERM_CMD == *"set_param -P"* ]]; then
5537 echo "Setting $test_param from $orig to $final"
5538 do_facet mgs "$PERM_CMD $test_param='$final'" ||
5539 error "$PERM_CMD $test_param failed"
5541 echo "Setting $param from $orig to $final"
5542 do_facet mgs "$PERM_CMD $param='$final'" ||
5543 error "$PERM_CMD $param failed"
5547 set_persistent_param_and_check() {
5551 local orig=$(do_facet $myfacet "$LCTL get_param -n $test_param")
5553 if [ $# -gt 3 ]; then
5560 set_persistent_param $myfacet $test_param $param "$final"
5562 wait_update_facet $myfacet "$LCTL get_param -n $test_param" "$final" ||
5563 error "check $param failed!"
5566 init_param_vars () {
5567 TIMEOUT=$(lctl get_param -n timeout)
5568 TIMEOUT=${TIMEOUT:-20}
5570 if [ -n "$arg1" ]; then
5571 [ "$arg1" = "server_only" ] && return
5574 remote_mds_nodsh && log "Using TIMEOUT=$TIMEOUT" && return 0
5576 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
5577 log "Using TIMEOUT=$TIMEOUT"
5579 # tune down to speed up testing on (usually) small setups
5580 local mgc_timeout=/sys/module/mgc/parameters/mgc_requeue_timeout_min
5581 do_nodes $(comma_list $(nodes_list)) \
5582 "[ -f $mgc_timeout ] && echo 1 > $mgc_timeout; exit 0"
5584 osc_ensure_active $SINGLEMDS $TIMEOUT
5585 osc_ensure_active client $TIMEOUT
5586 $LCTL set_param osc.*.idle_timeout=debug
5588 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
5589 local current_jobid_var=$($LCTL get_param -n jobid_var)
5591 if [ $JOBID_VAR = "existing" ]; then
5592 echo "keeping jobstats as $current_jobid_var"
5593 elif [ $current_jobid_var != $JOBID_VAR ]; then
5594 echo "setting jobstats to $JOBID_VAR"
5596 set_persistent_param_and_check client \
5597 "jobid_var" "$FSNAME.sys.jobid_var" $JOBID_VAR
5600 echo "jobstats not supported by server"
5603 if [ $QUOTA_AUTO -ne 0 ]; then
5604 if [ "$ENABLE_QUOTA" ]; then
5605 echo "enable quota as required"
5606 setup_quota $MOUNT || return 2
5608 echo "disable quota as required"
5609 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
5613 (( MDS1_VERSION <= $(version_code 2.13.52) )) ||
5614 do_facet mgs "$LCTL set_param -P lod.*.mdt_hash=crush"
5618 nfs_client_mode () {
5619 if [ "$NFSCLIENT" ]; then
5620 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
5621 local clients=$CLIENTS
5623 [ -z $clients ] && clients=$(hostname)
5625 # FIXME: remove hostname when 19215 fixed
5626 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
5627 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts |
5628 awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
5629 if [[ ${#nfsexport[@]} -eq 0 ]]; then
5630 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
5632 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
5638 cifs_client_mode () {
5639 [ x$CIFSCLIENT = xyes ] &&
5640 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
5643 check_config_client () {
5645 local mounted=$(mount | grep " $mntpt ")
5647 if [ -n "$CLIENTONLY" ]; then
5649 # CLIENTONLY should not depend on *_HOST settings
5650 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
5651 # in theory someone could create a new,
5652 # client-only config file that assumed lustre was already
5653 # configured and didn't set the MGSNID. If MGSNID is not set,
5654 # then we should use the mgs nid currently being used
5655 # as the default value. bug 18021
5656 [[ x$MGSNID = x ]] &&
5659 if [[ x$mgc != xMGC$MGSNID ]]; then
5660 if [ "$mgs_HOST" ]; then
5661 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST |
5662 grep PING | awk '{print $3}' |
5663 sed -e "s/(//g" -e "s/)//g")
5665 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
5666 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
5672 echo Checking config lustre mounted on $mntpt
5673 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
5674 mgshost=$(echo $mgshost | awk -F: '{print $1}')
5678 check_config_clients () {
5679 local clients=${CLIENTS:-$HOSTNAME}
5682 nfs_client_mode && return
5683 cifs_client_mode && return
5685 do_rpc_nodes "$clients" check_config_client $mntpt
5687 sanity_mount_check || error "environments are insane!"
5691 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
5692 local cltimeout=$(lctl get_param -n timeout)
5693 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
5694 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
5701 [ -z $mntpt ] && return 1
5702 local mounted=$(mounted_lustre_filesystems)
5704 echo $mounted' ' | grep -w -q $mntpt' '
5709 local ostsn=${2:-$OSTCOUNT}
5710 local npools=${FS_NPOOLS:-$((OSTCOUNT / ostsn))}
5713 echo ostsn=$ostsn npools=$npools
5714 if [[ $ostsn -gt $OSTCOUNT ]]; then
5715 echo "request to use $ostsn OSTs in the pool, \
5716 using max available OSTCOUNT=$OSTCOUNT"
5719 for (( n=0; n < $npools; n++ )); do
5721 if ! $DELETE_OLD_POOLS; then
5722 log "request to not delete old pools: $FSNAME.$p exist?"
5723 if ! check_pool_not_exist $FSNAME.$p; then
5724 echo "Using existing $FSNAME.$p"
5725 $LCTL pool_list $FSNAME.$p
5729 create_pool $FSNAME.$p $KEEP_POOLS ||
5730 error "create_pool $FSNAME.$p failed"
5732 local first=$(( (n * ostsn) % OSTCOUNT ))
5733 local last=$(( (first + ostsn - 1) % OSTCOUNT ))
5734 if [[ $first -le $last ]]; then
5735 pool_add_targets $p $first $last ||
5736 error "pool_add_targets $p $first $last failed"
5738 pool_add_targets $p $first $(( OSTCOUNT - 1 )) ||
5739 error "pool_add_targets $p $first \
5740 $(( OSTCOUNT - 1 )) failed"
5741 pool_add_targets $p 0 $last ||
5742 error "pool_add_targets $p 0 $last failed"
5747 set_pools_quota () {
5754 [[ $ENABLE_QUOTA ]] || error "Required Pool Quotas: \
5755 $POOLS_QUOTA_USERS_SET, but ENABLE_QUOTA not set!"
5757 # POOLS_QUOTA_USERS_SET=
5758 # "quota15_1:20M -- for all of the found pools
5759 # quota15_2:1G:gpool0
5760 # quota15_3 -- for global limit only
5761 # quota15_4:200M:gpool0
5762 # quota15_4:200M:gpool1"
5764 declare -a pq_userset=(${POOLS_QUOTA_USERS_SET="mpiuser"})
5766 declare -A pq_limits
5768 for ((i=0; i<${#pq_userset[@]}; i++)); do
5769 u=${pq_userset[i]%%:*}
5771 # user gets no pool limits if
5772 # POOLS_QUOTA_USERS_SET does not specify it
5773 [[ ${pq_userset[i]} =~ : ]] && o=${pq_userset[i]##$u:}
5774 pq_limits[$u]+=" $o"
5776 pq_users=(${!pq_limits[@]})
5781 for ((i=0; i<${#pq_users[@]}; i++)); do
5783 # set to max limit (_u64)
5784 $LFS setquota -u $u -B $((2**24 - 1))T $DIR
5785 opts=(${pq_limits[$u]})
5786 for ((j=0; j<${#opts[@]}; j++)); do
5789 # Set limit for all existing pools if
5791 if [ $p == $o ]; then
5792 p=$(list_pool $FSNAME | sed "s/$FSNAME.//")
5793 echo "No pool specified for $u,
5794 set limit $o for all existing pools"
5797 $LFS setquota -u $u -B $o --pool $pool $DIR ||
5798 error "setquota -u $u -B $o \
5799 --pool $pool failed"
5802 $LFS quota -uv $u --pool $DIR
5806 do_check_and_setup_lustre() {
5807 # If auster does not want us to setup, then don't.
5808 ! ${do_setup} && return
5810 echo "=== $TESTSUITE: start setup $(date +'%H:%M:%S (%s)') ==="
5813 nfs_client_mode && return
5814 cifs_client_mode && return
5816 local MOUNTED=$(mounted_lustre_filesystems)
5820 # both MOUNT and MOUNT2 are not mounted
5821 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
5822 [ "$REFORMAT" = "yes" ] && CLEANUP_DM_DEV=true formatall
5823 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
5825 is_mounted $MOUNT || error "NAME=$NAME not mounted"
5826 export I_MOUNTED=yes
5830 elif is_mounted $MOUNT2; then
5832 # MOUNT2 is mounted, while MOUNT_2 is not set
5833 if ! [ "$MOUNT_2" ]; then
5834 cleanup_mount $MOUNT2
5835 export I_UMOUNTED2=yes
5838 # MOUNT2 is mounted, MOUNT_2 is set
5840 # FIXME: what to do if check_config failed?
5842 # 1) remote client has mounted other Lustre fs ?
5843 # 2) it has insane env ?
5844 # let's try umount MOUNT2 on all clients and mount it
5846 if ! check_config_clients $MOUNT2; then
5847 cleanup_mount $MOUNT2
5848 restore_mount $MOUNT2
5849 export I_MOUNTED2=yes
5853 # MOUNT is mounted MOUNT2 is not mounted
5854 elif [ "$MOUNT_2" ]; then
5855 restore_mount $MOUNT2
5856 export I_MOUNTED2=yes
5860 # FIXME: what to do if check_config failed?
5862 # 1) remote client has mounted other Lustre fs?
5863 # 2) lustre is mounted on remote_clients atall ?
5864 check_config_clients $MOUNT
5868 set_default_debug_nodes $(comma_list $(nodes_list))
5872 if [ -z "$CLIENTONLY" -a $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ]; then
5874 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
5875 facets="$(get_facets OST)"
5876 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
5877 facets="$facets,$(get_facets MDS)"
5878 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
5879 facets="$facets,mgs"
5880 local nodes="$(facets_hosts ${facets})"
5881 if [ -n "$nodes" ] ; then
5882 do_nodes $nodes "$LCTL set_param \
5883 osd-ldiskfs.track_declares_assert=1 || true"
5887 if [ -n "$fs_STRIPEPARAMS" ]; then
5888 setstripe_getstripe $MOUNT $fs_STRIPEPARAMS
5897 if $DELETE_OLD_POOLS; then
5901 if [[ -n "$FS_POOL" ]]; then
5902 create_pools $FS_POOL $FS_POOL_NOSTS
5905 if [[ -n "$POOLS_QUOTA_USERS_SET" ]]; then
5909 echo "=== $TESTSUITE: finish setup $(date +'%H:%M:%S (%s)') ==="
5911 if [[ "$ONLY" == "setup" ]]; then
5916 check_and_setup_lustre() {
5917 local start_stamp=$(date +%s)
5918 local saved_umask=$(umask)
5919 local log=$TESTLOG_PREFIX.test_setup.test_log.$(hostname -s).log
5928 log_sub_test_begin test_setup
5930 if ! do_check_and_setup_lustre 2>&1 > >(tee -i $log); then
5931 error=$(tail -1 $log)
5936 stop_stamp=$(date +%s)
5937 duration=$((stop_stamp - start_stamp))
5939 log_sub_test_end "$status" "$duration" "$rc" "$error"
5947 local clients=${CLIENTS:-$HOSTNAME}
5950 zconf_mount_clients $clients $mntpt
5954 local clients=${CLIENTS:-$HOSTNAME}
5957 zconf_umount_clients $clients $mntpt
5960 cleanup_and_setup_lustre() {
5961 if [[ "$ONLY" == "cleanup" ]] || grep -q "$MOUNT" /proc/mounts; then
5962 lctl set_param debug=0 || true
5965 if [[ "$ONLY" == "cleanup" ]]; then
5970 do_check_and_setup_lustre
5973 # Run e2fsck on MDT or OST device.
5978 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
5979 local log=$TMP/e2fsck.log
5982 # turn on pfsck if it is supported
5983 do_node $node $E2FSCK -h 2>&1 | grep -qw -- -m && cmd+=" -m8"
5985 do_node $node $cmd 2>&1 | tee $log
5987 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
5989 if [ $MDSCOUNT -gt 1 ]; then
5990 skip_noexit "DNE mode isn't supported!"
5994 error "It's not DNE mode."
5999 [ $rc -le $FSCK_MAX_ERR ] ||
6000 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
6006 # Run resize2fs on MDT or OST device.
6015 do_facet $facet "$RESIZE2FS $opts $device $size"
6018 # verify a directory is shared among nodes.
6019 check_shared_dir() {
6021 local list=${2:-$(comma_list $(nodes_list))}
6023 [ -z "$dir" ] && return 1
6024 do_rpc_nodes "$list" check_logdir $dir
6025 check_write_access $dir "$list" || return 1
6030 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
6031 $LCTL set_param printk=+lfsck
6032 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
6034 for k in $(seq $MDSCOUNT); do
6035 # wait up to 10+1 minutes for LFSCK to complete
6036 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
6037 mdd.$(facet_svc mds${k}).lfsck_layout |
6038 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
6039 error "MDS${k} layout isn't the expected 'completed'"
6040 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
6041 mdd.$(facet_svc mds${k}).lfsck_namespace |
6042 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
6043 error "MDS${k} namespace isn't the expected 'completed'"
6045 local rep_mdt=$(do_nodes $(comma_list $(mdts_nodes)) \
6046 $LCTL get_param -n mdd.$FSNAME-*.lfsck_* |
6047 awk '/repaired/ { print $2 }' | calc_sum)
6048 local rep_ost=$(do_nodes $(comma_list $(osts_nodes)) \
6049 $LCTL get_param -n obdfilter.$FSNAME-*.lfsck_* |
6050 awk '/repaired/ { print $2 }' | calc_sum)
6051 local repaired=$((rep_mdt + rep_ost))
6052 [ $repaired -eq 0 ] ||
6053 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
6056 dump_file_contents() {
6062 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
6063 error_noexit false \
6064 "Invalid parameters for dump_file_contents()"
6067 for node in ${nodes}; do
6068 do_node $node "for i in \\\$(find $dir -type f); do
6069 echo ====\\\${i}=======================;
6071 done" >> ${logname}.${node}.log
6075 dump_command_output() {
6081 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
6082 error_noexit false \
6083 "Invalid parameters for dump_command_output()"
6087 for node in ${nodes}; do
6088 do_node $node "echo ====${cmd}=======================;
6089 $cmd" >> ${logname}.${node}.log
6096 # dump file contents from /proc/spl in case of zfs test
6097 if [ "$(facet_fstype ost1)" = "zfs" ]; then
6098 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
6099 dump_command_output \
6100 "$(osts_nodes)" "zpool events -v" "${logname}"
6103 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
6104 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
6105 dump_command_output \
6106 "$(mdts_nodes)" "zpool events -v" "${logname}"
6110 do_check_and_cleanup_lustre() {
6111 echo "=== $TESTSUITE: start cleanup $(date +'%H:%M:%S (%s)') ==="
6113 if [[ "$LFSCK_ALWAYS" == "yes" && "$TESTSUITE" != "sanity-lfsck" && \
6114 "$TESTSUITE" != "sanity-scrub" ]]; then
6118 if is_mounted $MOUNT; then
6119 if $DO_CLEANUP; then
6120 [[ -n "$DIR" ]] && rm -rf $DIR/[Rdfs][0-9]* ||
6121 error "remove sub-test dirs failed"
6125 [[ -n "$ENABLE_QUOTA" ]] && restore_quota || true
6128 if [[ "$I_UMOUNTED2" == "yes" ]]; then
6129 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
6132 if [[ "$I_MOUNTED2" == "yes" ]]; then
6133 cleanup_mount $MOUNT2
6136 if [[ "$I_MOUNTED" == "yes" ]] && ! $AUSTER_CLEANUP; then
6137 cleanupall -f || error "cleanup failed"
6141 echo "=== $TESTSUITE: finish cleanup $(date +'%H:%M:%S (%s)') ==="
6144 check_and_cleanup_lustre() {
6145 local start_stamp=$(date +%s)
6146 local saved_umask=$(umask)
6147 local log=$TESTLOG_PREFIX.test_cleanup.test_log.$(hostname -s).log
6156 log_sub_test_begin test_cleanup
6158 if ! do_check_and_cleanup_lustre 2>&1 > >(tee -i $log); then
6159 error=$(tail -1 $log)
6164 stop_stamp=$(date +%s)
6165 duration=$((stop_stamp - start_stamp))
6167 log_sub_test_end "$status" "$duration" "$rc" "$error"
6177 wait_for_function () {
6180 # suppress fn both stderr and stdout
6181 if [ "$1" = "--quiet" ]; then
6183 quiet=" > /dev/null 2>&1"
6194 eval $fn $quiet && return 0
6196 [ $wait -lt $max ] || return 1
6197 echo waiting $fn, $((max - wait)) secs left ...
6198 wait=$((wait + sleep))
6199 [ $wait -gt $max ] && ((sleep -= wait - max))
6209 [ "$host" = "$HOSTNAME" ] && return 0
6211 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep; then
6212 echo "$(date +'%H:%M:%S (%s)') waited for $host network ${max}s"
6222 # Convert a space-delimited list to a comma-delimited list. If the input is
6223 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
6225 # echo is used to convert newlines to spaces, since it doesn't
6226 # introduce a trailing space as using "tr '\n' ' '" does
6227 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
6233 echo $list | grep -qw $item
6236 # list, excluded are the comma separated lists
6237 exclude_items_from_list () {
6243 for item in ${excluded//,/ }; do
6244 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
6246 echo $(comma_list $list)
6249 # list, expand are the comma separated lists
6251 local list=${1//,/ }
6252 local expand=${2//,/ }
6255 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
6256 echo $(comma_list $expanded)
6259 testslist_filter () {
6260 local script=$LUSTRE/tests/${TESTSUITE}.sh
6262 [ -f $script ] || return 0
6264 local start_at=$START_AT
6265 local stop_at=$STOP_AT
6267 local var=${TESTSUITE//-/_}_START_AT
6268 [ x"${!var}" != x ] && start_at=${!var}
6269 var=${TESTSUITE//-/_}_STOP_AT
6270 [ x"${!var}" != x ] && stop_at=${!var}
6272 sed -n 's/^test_\([^ (]*\).*/\1/p' $script |
6273 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
6274 /^'${start_at}'$/ {flag = 0}
6275 {if (flag == 1) print $0}
6276 /^'${stop_at}'$/ { flag = 1 }'
6280 (cd `dirname $1`; echo $PWD/`basename $1`)
6284 local types=${1:-"OST MDS MGS"}
6288 for entry in $types; do
6289 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
6290 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
6293 MGS ) list="$list $name";;
6294 MDS|OST|AGT ) local count=${type}COUNT
6295 for ((i=1; i<=${!count}; i++)) do
6296 list="$list ${name}$i"
6298 * ) error "Invalid facet type"
6302 echo $(comma_list $list)
6305 ##################################
6306 # Adaptive Timeouts funcs
6309 # only check mds, we assume at_max is the same on all nodes
6310 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
6312 if [ $at_max -eq 0 ]; then
6323 # suppose that all ost-s have the same $at value set
6324 [ $facet != "ost" ] || facet=ost1
6326 do_facet $facet "lctl get_param -n $at"
6340 for facet in "$@"; do
6341 if [ $facet == "ost" ]; then
6342 facet=$(get_facets OST)
6343 elif [ $facet == "mds" ]; then
6344 facet=$(get_facets MDS)
6346 hosts=$(expand_list $hosts $(facets_hosts $facet))
6349 do_nodes $hosts lctl set_param at_max=$at_max
6352 ##################################
6356 # OBD_FAIL_MDS_ALL_REQUEST_NET
6358 do_facet $SINGLEMDS lctl set_param fail_val=0 fail_loc=0x123
6359 do_facet client "$1" || RC=$?
6360 do_facet $SINGLEMDS lctl set_param fail_loc=0
6365 # OBD_FAIL_MDS_ALL_REPLY_NET
6367 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
6369 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
6373 drop_reint_reply() {
6374 # OBD_FAIL_MDS_REINT_NET_REP
6376 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
6378 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
6382 drop_update_reply() {
6383 # OBD_FAIL_OUT_UPDATE_NET_REP
6387 do_facet mds${index} lctl set_param fail_loc=0x1701
6388 do_facet client "$@" || RC=$?
6389 do_facet mds${index} lctl set_param fail_loc=0
6394 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
6397 local timeout=${2:-0}
6398 # default is (obd_timeout / 4) if unspecified
6399 echo "timeout is $timeout/$2"
6400 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
6401 do_facet client "$1" || RC=$?
6402 do_facet client "sync"
6403 do_facet ost1 lctl set_param fail_loc=0
6407 drop_ldlm_cancel() {
6408 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
6410 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
6411 do_nodes $list lctl set_param fail_loc=0x304
6413 do_facet client "$@" || RC=$?
6415 do_nodes $list lctl set_param fail_loc=0
6419 drop_bl_callback_once() {
6421 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
6422 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
6423 do_facet client lctl set_param fail_loc=0x80000305
6424 do_facet client "$@" || rc=$?
6425 do_facet client lctl set_param fail_loc=0
6426 do_facet client lctl set_param fail_val=0
6427 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
6431 drop_bl_callback() {
6433 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
6434 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
6435 do_facet client lctl set_param fail_loc=0x305
6436 do_facet client "$@" || rc=$?
6437 do_facet client lctl set_param fail_loc=0
6438 do_facet client lctl set_param fail_val=0
6439 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
6443 drop_mdt_ldlm_reply() {
6444 #define OBD_FAIL_MDS_LDLM_REPLY_NET 0x157
6446 local list=$(comma_list $(mdts_nodes))
6448 do_nodes $list lctl set_param fail_loc=0x157
6450 do_facet client "$@" || RC=$?
6452 do_nodes $list lctl set_param fail_loc=0
6456 drop_mdt_ldlm_reply_once() {
6457 #define OBD_FAIL_MDS_LDLM_REPLY_NET 0x157
6459 local list=$(comma_list $(mdts_nodes))
6461 do_nodes $list lctl set_param fail_loc=0x80000157
6463 do_facet client "$@" || RC=$?
6465 do_nodes $list lctl set_param fail_loc=0
6473 echo "clearing fail_loc on $facet"
6474 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
6477 set_nodes_failloc () {
6479 do_nodes $(comma_list $1) lctl set_param fail_val=$fv fail_loc=$2
6482 cancel_lru_locks() {
6483 #$LCTL mark "cancel_lru_locks $1 start"
6484 $LCTL set_param -n ldlm.namespaces.*$1*.lru_size=clear
6485 $LCTL get_param ldlm.namespaces.*$1*.lock_unused_count | grep -v '=0'
6486 #$LCTL mark "cancel_lru_locks $1 stop"
6491 local nr_cpu=$(grep -c "processor" /proc/cpuinfo)
6493 echo $((100 * nr_cpu))
6498 lctl set_param ldlm.namespaces.*$1*.lru_size=0
6501 lru_resize_disable()
6504 local lru_size=${2:-$(default_lru_size)}
6506 $LCTL set_param ldlm.namespaces.*$dev*.lru_size=$lru_size
6511 local mountpath=${1:-$MOUNT}
6514 [ -z "$(mount | grep "$mountpath .*flock" | grep -v noflock)" ] && RC=1
6521 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
6522 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
6523 echo there is still data in page cache $FILE ?
6524 lctl get_param -n $FILE
6532 DEBUGSAVE="$(lctl get_param -n debug)"
6533 DEBUGSAVE_SERVER=$(do_facet $SINGLEMDS "$LCTL get_param -n debug")
6537 [ -n "$DEBUGSAVE" ] &&
6538 do_nodes $CLIENTS "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\""||
6542 [ -n "$DEBUGSAVE_SERVER" ] &&
6543 do_nodes $(comma_list $(all_server_nodes)) \
6544 "$LCTL set_param debug=\\\"${DEBUGSAVE_SERVER}\\\"" ||
6550 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
6553 debug_size_restore() {
6554 [ -n "$DEBUG_SIZE_SAVED" ] &&
6555 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
6559 start_full_debug_logging() {
6564 local debug_size=150
6565 local nodes=$(comma_list $(nodes_list))
6567 do_nodes $nodes "$LCTL set_param debug=$fulldebug debug_mb=$debug_size"
6570 stop_full_debug_logging() {
6575 # prints bash call stack
6576 print_stack_trace() {
6579 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
6580 local src=${BASH_SOURCE[$i]}
6581 local lineno=${BASH_LINENO[$i-1]}
6582 local funcname=${FUNCNAME[$i]}
6583 echo " = $src:$lineno:$funcname()"
6588 local TYPE=${TYPE:-"FAIL"}
6591 # do not dump logs if $1=false
6592 if [ "x$1" = "xfalse" ]; then
6597 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $* "
6598 (print_stack_trace 2) >&2
6600 # We need to dump the logs on all nodes
6602 gather_logs $(comma_list $(nodes_list))
6606 [ "$TESTSUITELOG" ] &&
6607 echo "$TESTSUITE: $TYPE: $TESTNAME $*" >> $TESTSUITELOG
6608 if [ -z "$*" ]; then
6609 echo "error() without useful message, please fix" > $LOGDIR/err
6611 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
6612 echo "$@" > $LOGDIR/ignore
6614 echo "$@" > $LOGDIR/err
6618 # cleanup the env for failed tests
6622 ##################################
6624 ##################################
6626 # usage: stack_trap arg sigspec
6628 # stack_trap() behaves like bash's built-in trap, except that it "stacks" the
6629 # command "arg" on top of previously defined commands for "sigspec" instead
6630 # of overwriting them.
6631 # stacked traps are executed in reverse order of their registration
6633 # arg and sigspec have the same meaning as in man (1) trap
6637 local sigspec="${2:-EXIT}"
6639 # Use "trap -p" to get the quoting right
6640 local old_trap="$(trap -p "$sigspec")"
6641 # Append ";" and remove the leading "trap -- '" added by "trap -p"
6642 old_trap="${old_trap:+"; ${old_trap#trap -- \'}"}"
6644 # Once again, use "trap -p" to get the quoting right
6645 local new_trap="$(trap -- "$arg" "$sigspec"
6647 trap -- '' "$sigspec")"
6649 # Remove the trailing "' $sigspec" part added by "trap -p" and merge
6651 # The resulting string should be safe to "eval" as it is (supposedly
6652 # correctly) quoted by "trap -p"
6653 eval "${new_trap%\' $sigspec}${old_trap:-"' $sigspec"}"
6662 local logs="$TESTSUITELOG $1"
6664 for log in $logs; do
6665 if [ -f "$log" ]; then
6666 grep -qw FAIL $log && status=1
6683 # use only if we are ignoring failures for this test, bugno required.
6684 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
6685 # e.g. error_ignore bz5494 "your message" or
6686 # error_ignore LU-5494 "your message"
6688 local TYPE="IGNORE ($1)"
6693 error_and_remount() {
6695 remount_client $MOUNT
6699 # Throw an error if it's not running in vm - usually for performance
6702 local virt=$(running_in_vm)
6703 if [[ -n "$virt" ]]; then
6704 echo "running in VM '$virt', ignore error"
6705 error_ignore env=$virt "$@"
6712 # Function: skip_env()
6713 # Purpose: to skip a test during developer testing because some tool
6714 # is missing, but fail the test in release testing because the test
6715 # environment is not configured properly".
6718 $FAIL_ON_SKIP_ENV && error false "$@" || skip "$@"
6723 log " SKIP: $TESTSUITE $TESTNAME $*"
6725 if [[ -n "$ALWAYS_SKIPPED" ]]; then
6726 skip_logged $TESTNAME "$@"
6729 echo "$@" > $LOGDIR/skip
6732 [[ -n "$TESTSUITELOG" ]] &&
6733 echo "$TESTSUITE: SKIP: $TESTNAME $*" >> $TESTSUITELOG || true
6743 # For interop testing treate EOPNOTSUPP as success
6749 echo $retstr | awk -F'|' '{print $1}' |
6750 grep -E unsupported\|"(Operation not supported)"
6751 (( $? == 0 )) || error "$retstr"
6755 # Add a list of tests to ALWAYS_EXCEPT due to an issue.
6756 # Usage: always_except LU-4815 23 42q ...
6758 function always_except() {
6759 local issue="${1:-}" # single jira style issue ("LU-4815")
6764 if ! [[ "$issue" =~ ^[[:upper:]]+-[[:digit:]]+$ ]]; then
6765 error "always_except: invalid issue '$issue' for tests '$*'"
6768 for test_num in "$@"; do
6769 ALWAYS_EXCEPT+=" $test_num"
6773 build_test_filter() {
6774 EXCEPT="$EXCEPT $(testslist_filter)"
6776 # allow test numbers separated by '+', or ',', in addition to ' '
6777 # to avoid issues with multiple arguments handling by shell/autotest
6778 for O in ${ONLY//[+,]/ }; do
6779 if [[ $O =~ [0-9]*-[0-9]* ]]; then
6780 for ((num=${O%-[0-9]*}; num <= ${O#[0-9]*-}; num++)); do
6788 [[ -z "$EXCEPT$ALWAYS_EXCEPT" ]] ||
6789 log "excepting tests: $(echo $EXCEPT $ALWAYS_EXCEPT)"
6790 [[ -z "$EXCEPT_SLOW" ]] ||
6791 log "skipping tests SLOW=no: $(echo $EXCEPT_SLOW)"
6792 for E in ${EXCEPT//[+,]/ }; do
6793 eval EXCEPT_${E}=true
6795 for E in ${ALWAYS_EXCEPT//[+,]/ }; do
6796 eval EXCEPT_ALWAYS_${E}=true
6798 for E in ${EXCEPT_SLOW//[+,]/ }; do
6799 eval EXCEPT_SLOW_${E}=true
6801 for G in ${GRANT_CHECK_LIST//[+,]/ }; do
6802 eval GCHECK_ONLY_${G}=true
6807 if [[ $1 = [a-z]* ]]; then
6810 echo ${1%%[a-zA-Z]*}
6814 # print a newline if the last test was skipped
6815 export LAST_SKIPPED=
6816 export ALWAYS_SKIPPED=
6818 # Main entry into test-framework. This is called with the number and
6819 # description of a test. The number is used to find the function to run
6820 # the test using "test_$name".
6822 # This supports a variety of methods of specifying specific test to
6824 # - ONLY= env variable with space-separated list of test numbers to run
6825 # - EXCEPT= env variable with space-separated list of test numbers to exclude
6831 export base=$(basetest $testnum)
6832 export TESTNAME=test_$testnum
6836 # Check the EXCEPT, ALWAYS_EXCEPT and SLOW lists to see if we
6837 # need to skip the current test. If so, set the ALWAYS_SKIPPED flag.
6838 local isexcept=EXCEPT_$testnum
6839 local isexcept_base=EXCEPT_$base
6840 if [ ${!isexcept}x != x ]; then
6842 skip_message="skipping excluded test $testnum"
6843 elif [ ${!isexcept_base}x != x ]; then
6845 skip_message="skipping excluded test $testnum (base $base)"
6848 isexcept=EXCEPT_ALWAYS_$testnum
6849 isexcept_base=EXCEPT_ALWAYS_$base
6850 if [ ${!isexcept}x != x ]; then
6852 skip_message="skipping ALWAYS excluded test $testnum"
6853 elif [ ${!isexcept_base}x != x ]; then
6855 skip_message="skipping ALWAYS excluded test $testnum (base $base)"
6858 isexcept=EXCEPT_SLOW_$testnum
6859 isexcept_base=EXCEPT_SLOW_$base
6860 if [ ${!isexcept}x != x ]; then
6862 skip_message="skipping SLOW test $testnum"
6863 elif [ ${!isexcept_base}x != x ]; then
6865 skip_message="skipping SLOW test $testnum (base $base)"
6868 # If there are tests on the ONLY list, check if the current test
6869 # is on that list and, if so, check if the test is to be skipped
6870 # and if we are supposed to honor the skip lists.
6871 if [ -n "$ONLY" ]; then
6872 local isonly=ONLY_$testnum
6873 local isonly_base=ONLY_$base
6874 if [[ ${!isonly}x != x || ${!isonly_base}x != x ]]; then
6876 if [[ -n "$ALWAYS_SKIPPED" &&
6877 -n "$HONOR_EXCEPT" ]]; then
6879 skip_noexit "$skip_message"
6882 [ -n "$LAST_SKIPPED" ] &&
6883 echo "" && LAST_SKIPPED=
6885 run_one_logged $testnum "$testmsg"
6895 if [ -n "$ALWAYS_SKIPPED" ]; then
6897 skip_noexit "$skip_message"
6900 run_one_logged $testnum "$testmsg"
6907 load_module ../libcfs/libcfs/libcfs
6920 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
6925 strace -o $TMP/$1.strace -ttt $*
6927 log "FINISHED: $*: rc $RC"
6934 banner "test complete, duration $duration sec"
6935 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
6936 echo "duration $duration" >>$TESTSUITELOG
6940 # Set TEST_STATUS here. It will be used for logging the result.
6943 if [[ -f $LOGDIR/err ]]; then
6945 elif [[ -f $LOGDIR/skip ]]; then
6948 echo "$TEST_STATUS $*" 2>&1 | tee -a $TESTSUITELOG
6952 local FFREE=$(do_node $SINGLEMDS \
6953 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
6954 local FTOTAL=$(do_node $SINGLEMDS \
6955 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
6957 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" ||
6962 #echo -n "Resetting fail_loc on all nodes..."
6963 do_nodes --quiet $(comma_list $(nodes_list)) \
6964 "lctl set_param -n fail_loc=0 fail_val=0 2>/dev/null" || true
6970 # Log a message (on all nodes) padded with "=" before and after.
6971 # Also appends a timestamp and prepends the testsuite name.
6974 # ======================================================== 15:06:12 (1624050372)
6975 EQUALS="========================================================"
6977 msg="== ${TESTSUITE} $*"
6979 [[ $last != "=" && $last != " " ]] && msg="$msg "
6980 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
6981 # always include at least == after the message
6982 log "$msg== $(date +"%H:%M:%S (%s)")"
6985 check_dmesg_for_errors() {
6987 local errors="VFS: Busy inodes after unmount of\|\
6988 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
6989 group descriptors corrupted"
6991 res=$(do_nodes -q $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
6992 [ -z "$res" ] && return 0
6993 echo "Kernel error detected: $res"
6998 # Run a single test function and cleanup after it.
7000 # This function should be run in a subshell so the test func can
7001 # exit() without stopping the whole script.
7006 local SAVE_UMASK=`umask`
7009 if ! grep -q $DIR /proc/mounts; then
7013 banner "test $testnum: $testmsg"
7014 test_${testnum} || error "test_$testnum failed with $?"
7017 check_grant ${testnum} || error "check_grant $testnum failed with $?"
7019 check_dmesg_for_errors || error "Error in dmesg detected"
7020 if [ "$PARALLEL" != "yes" ]; then
7021 ps auxww | grep -v grep | grep -q "multiop " &&
7022 error "multiop still running"
7030 # Wrapper around run_one to ensure:
7031 # - test runs in subshell
7032 # - output of test is saved to separate log file for error reporting
7033 # - test result is saved to data file
7036 local before=$SECONDS
7039 export tfile=f${testnum}.${TESTSUITE}
7040 export tdir=d${testnum}.${TESTSUITE}
7041 local test_log=$TESTLOG_PREFIX.$TESTNAME.test_log.$(hostname -s).log
7042 local zfs_debug_log=$TESTLOG_PREFIX.$TESTNAME.zfs_log
7043 local SAVE_UMASK=$(umask)
7047 rm -f $LOGDIR/err $LOGDIR/ignore $LOGDIR/skip
7049 # if $ONLY is set, repeat subtest $ONLY_REPEAT times, otherwise once
7050 local repeat=${ONLY:+$ONLY_REPEAT}
7052 for ((testiter=0; testiter < ${repeat:-1}; testiter++)); do
7053 local before_sub=$SECONDS
7055 log_sub_test_begin $TESTNAME
7056 # remove temp files between repetitions to avoid test failures
7057 if [[ -n "$append" ]]; then
7058 [[ -n "$tdir" ]] && rm -rvf $DIR/$tdir*
7059 [[ -n "$tfile" ]] && rm -vf $DIR/$tfile*
7060 echo "subtest iteration $testiter/$repeat"
7062 # loop around subshell so stack_trap EXIT triggers each time
7063 (run_one $testnum "$testmsg") 2>&1 | tee -i $append $test_log
7066 local duration_sub=$((SECONDS - before_sub))
7069 [[ $rc != 0 && ! -f $LOGDIR/err ]] &&
7070 echo "$TESTNAME returned $rc" | tee $LOGDIR/err
7072 if [[ -f $LOGDIR/err ]]; then
7073 test_error=$(cat $LOGDIR/err)
7075 elif [[ -f $LOGDIR/ignore ]]; then
7076 test_error=$(cat $LOGDIR/ignore)
7077 elif [[ -f $LOGDIR/skip ]]; then
7078 test_error=$(cat $LOGDIR/skip)
7084 pass "$testnum" "(${duration_sub}s)"
7085 if [ -n "${DUMP_OK}" ]; then
7086 gather_logs $(comma_list $(nodes_list))
7089 log_sub_test_end $TEST_STATUS $duration_sub "$rc" "$test_error"
7090 [[ $rc != 0 || "$TEST_STATUS" != "PASS" ]] && break
7093 if [[ "$TEST_STATUS" != "SKIP" && -f $TF_SKIP ]]; then
7097 if [ -f $LOGDIR/err ]; then
7098 log_zfs_info "$zfs_debug_log"
7099 $FAIL_ON_ERROR && exit $rc
7112 # Print information of skipped tests to result.yml
7115 log_sub_test_begin $1
7117 log_sub_test_end "SKIP" "0" "0" "$@"
7120 grant_from_clients() {
7124 do_nodes $nodes "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
7128 grant_from_servers() {
7132 # which is tot_granted less grant_precreate
7133 do_nodes $nodes "$LCTL get_param obdfilter.${FSNAME}-OST*.tot_granted" \
7134 " obdfilter.${FSNAME}-OST*.tot_pending" \
7135 " obdfilter.${FSNAME}-OST*.grant_precreate" |
7136 tr '=' ' ' | awk '/tot_granted/{ total += $2 };
7137 /tot_pending/{ total -= $2 };
7138 /grant_precreate/{ total -= $2 };
7139 END { printf("%0.0f", total) }'
7143 export base=$(basetest $1)
7144 [ "$CHECK_GRANT" == "no" ] && return 0
7146 local isonly_base=GCHECK_ONLY_${base}
7147 local isonly=GCHECK_ONLY_$1
7148 [ ${!isonly_base}x == x -a ${!isonly}x == x ] && return 0
7150 echo -n "checking grant......"
7152 local osts=$(comma_list $(osts_nodes))
7153 local clients=$CLIENTS
7154 [ -z "$clients" ] && clients=$(hostname)
7156 # sync all the data and make sure no pending data on server
7157 do_nodes $clients sync
7158 do_nodes $clients $LFS df # initiate all idling connections
7161 cli_grant=$(grant_from_clients $clients)
7164 # which is tot_granted less grant_precreate
7165 srv_grant=$(grant_from_servers $osts)
7168 # check whether client grant == server grant
7169 while [[ $cli_grant != $srv_grant && count++ -lt 30 ]]; do
7170 echo "wait for client:$cli_grant == server:$srv_grant"
7172 cli_grant=$(grant_from_clients $clients)
7173 srv_grant=$(grant_from_servers $osts)
7175 if [[ $cli_grant -ne $srv_grant ]]; then
7176 do_nodes $(comma_list $(osts_nodes)) \
7177 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*" \
7178 "obdfilter.${FSNAME}-OST*.grant_*"
7179 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
7180 error "failed grant check: client:$cli_grant server:$srv_grant"
7182 echo "pass grant check: client:$cli_grant server:$srv_grant"
7186 ########################
7192 ost=`echo $1 | awk -F_ '{print $3}'`
7193 if [ -z $ost ]; then
7194 ost=`echo $1 | sed 's/-osc.*//'`
7199 ostuuid_from_index()
7201 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
7204 ostname_from_index() {
7205 local uuid=$(ostuuid_from_index $1 $2)
7210 mdtname_from_index() {
7211 local uuid=$(mdtuuid_from_index $1 $2)
7215 mdssize_from_index () {
7216 local mdt=$(mdtname_from_index $2)
7217 $LFS df $1 | grep $mdt | awk '{ print $2 }'
7220 index_from_ostuuid()
7222 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
7225 mdtuuid_from_index()
7227 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
7231 # Return unique identifier for given hostname
7234 echo $host_name | md5sum | cut -d' ' -f1
7238 # Returns list of ip addresses for each interface
7240 ip addr | awk '/inet / {print $2}' | awk -F/ '{print $1}'
7244 # Returns list of interfaces configured for LNet
7246 local nids=( $($LCTL list_nids | xargs echo) )
7248 [[ -z ${nids[@]} ]] &&
7251 if [[ ${NETTYPE} =~ kfi* ]]; then
7252 $LNETCTL net show 2>/dev/null | awk '/ cxi[0-9]+$/{print $NF}' |
7253 sort -u | xargs echo
7257 declare -a INTERFACES
7259 for ((i = 0; i < ${#nids[@]}; i++)); do
7260 ip=$(sed 's/^\(.*\)@.*$/\1/'<<<${nids[i]})
7261 INTERFACES[i]=$(ip -o a s |
7262 awk '$4 ~ /^'$ip'\//{print $2}')
7263 INTERFACES=($(echo "${INTERFACES[@]}" | tr ' ' '\n' | uniq | tr '\n' ' '))
7264 if [[ -z ${INTERFACES[i]} ]]; then
7265 error "Can't determine interface name for NID ${nids[i]}"
7266 elif [[ 1 -ne $(wc -w <<<${INTERFACES[i]}) ]]; then
7267 error "Found $(wc -w <<<${INTERFACES[i]}) interfaces for NID ${nids[i]}. Expect 1"
7271 echo "${INTERFACES[@]}"
7276 # return 1 if addr is remote
7277 # return 0 if addr is local
7280 # Cache address list to avoid mutiple execution of local_addr_list
7281 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
7283 for i in $LOCAL_ADDR_LIST ; do
7284 [[ "$i" == "$addr" ]] && return 0
7289 # return true(0) if host_name is local
7290 # return false(1) if host_name is remote
7293 local is_local="IS_LOCAL_$(host_id $host_name)"
7295 if [ -z "${!is_local-}" ] ; then
7296 eval $is_local=false
7297 local host_ip=$(getent ahostsv4 $host_name |
7298 awk 'NR == 1 { print $1 }')
7299 is_local_addr "$host_ip" && eval $is_local=true
7313 for node in $(mdts_nodes); do
7314 remote_node $node && return 0
7321 [ -n "$CLIENTONLY" ] && return 0 || true
7322 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
7327 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" &&
7328 MSKIPPED=1 && return 1
7335 for node in $(osts_nodes) ; do
7336 remote_node $node && return 0
7343 [ -n "$CLIENTONLY" ] && return 0 || true
7344 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
7349 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" &&
7350 OSKIPPED=1 && return 1
7356 [ -n "$CLIENTONLY" ] && return 0 || true
7358 MGS=$(facet_host mgs)
7359 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
7364 remote_mds_nodsh || remote_ost_nodsh ||
7365 $(single_local_node $(comma_list $(nodes_list)))
7369 remote_ost && remote_mds
7372 # Get the active nodes for facets.
7380 for facet in ${facets//,/ }; do
7381 nodes="$nodes $(facet_active_host $facet)"
7384 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7388 # Get name of the active MGS node.
7390 echo -n $(facets_nodes $(get_facets MGS))
7393 # Get all of the active MDS nodes.
7395 echo -n $(facets_nodes $(get_facets MDS))
7398 # Get all of the active OSS nodes.
7400 echo -n $(facets_nodes $(get_facets OST))
7403 # Get all of the client nodes and active server nodes.
7405 local nodes=$HOSTNAME
7409 # CLIENTS (if specified) contains the local client
7410 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
7412 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
7413 nodes="$nodes $(facets_nodes $(get_facets))"
7416 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7420 # Get all of the remote client nodes and remote active server nodes.
7421 remote_nodes_list () {
7422 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
7425 # Get all of the MDS nodes, including active and passive nodes.
7433 for i in $(seq $MDSCOUNT); do
7435 failover_host=mds${i}failover_HOST
7436 nodes="$nodes ${!host} ${!failover_host}"
7439 [ -n "$nodes" ] || nodes="${mds_HOST} ${mdsfailover_HOST}"
7440 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7444 # Get all of the OSS nodes, including active and passive nodes.
7452 for i in $(seq $OSTCOUNT); do
7454 failover_host=ost${i}failover_HOST
7455 nodes="$nodes ${!host} ${!failover_host}"
7458 [ -n "$nodes" ] || nodes="${ost_HOST} ${ostfailover_HOST}"
7459 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7463 # Get all of the server nodes, including active and passive nodes.
7464 all_server_nodes () {
7469 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
7471 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7475 # Get all of the client and server nodes, including active and passive nodes.
7477 local nodes=$HOSTNAME
7481 # CLIENTS (if specified) contains the local client
7482 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
7484 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
7485 nodes="$nodes $(all_server_nodes)"
7488 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7492 init_clients_lists () {
7493 # Sanity check: exclude the local client from RCLIENTS
7494 local clients=$(hostlist_expand "$RCLIENTS")
7495 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
7497 # Sanity check: exclude the dup entries
7498 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
7500 export CLIENT1=${CLIENT1:-$HOSTNAME}
7501 export SINGLECLIENT=$CLIENT1
7503 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
7505 # Sanity check: exclude the dup entries from CLIENTS
7506 # for those configs which has SINGLCLIENT set to local client
7507 clients=$(for i in $clients; do echo $i; done | sort -u)
7509 export CLIENTS=$(comma_list $clients)
7510 local -a remoteclients=($RCLIENTS)
7511 for ((i=0; $i<${#remoteclients[@]}; i++)); do
7512 varname=CLIENT$((i + 2))
7514 eval export $varname=${remoteclients[i]}
7517 export CLIENTCOUNT=$((${#remoteclients[@]} + 1))
7520 get_random_entry () {
7523 rnodes=${rnodes//,/ }
7525 local -a nodes=($rnodes)
7526 local num=${#nodes[@]}
7527 local i=$((RANDOM * num * 2 / 65536))
7533 [ -n "$CLIENTONLY" ] || [ "x$CLIENTMODSONLY" = "xyes" ]
7537 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
7538 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
7544 echo $nodes | wc -w || true
7548 local nodes=$(mdts_nodes)
7549 local mdtcount=$(get_node_count "$nodes")
7551 [ ! "$MDSCOUNT" = "$mdtcount" ]
7554 generate_machine_file() {
7555 local nodes=${1//,/ }
7556 local machinefile=$2
7559 for node in $nodes; do
7560 echo $node >>$machinefile ||
7561 { echo "can not generate machinefile $machinefile" &&
7567 local file=$1/stripe
7570 $LFS getstripe -v $file || error "getstripe $file failed"
7574 # Check and add a test group.
7580 local gid=$(getent group $group_name | cut -d: -f3)
7581 if [[ -n "$gid" ]]; then
7582 [[ "$gid" -eq "$group_id" ]] || {
7583 error_noexit "inconsistent group ID:" \
7584 "new: $group_id, old: $gid"
7588 echo "adding group $group_name:$group_id"
7589 getent group $group_name || true
7590 getent group $group_id || true
7591 groupadd -g $group_id $group_name
7598 # Check and add a test user.
7611 local uid=$(getent passwd $user_name | cut -d: -f3)
7612 if [[ -n "$uid" ]]; then
7613 if [[ "$uid" -eq "$user_id" ]]; then
7614 local dir=$(getent passwd $user_name | cut -d: -f6)
7615 if [[ "$dir" != "$home" ]]; then
7617 usermod -d $home $user_name
7621 error_noexit "inconsistent user ID:" \
7622 "new: $user_id, old: $uid"
7627 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
7634 check_runas_id_ret() {
7636 local myRUNAS_UID=$1
7637 local myRUNAS_GID=$2
7641 if [ -z "$myRUNAS" ]; then
7642 error_exit "check_runas_id_ret requires myRUNAS argument"
7646 error "Unable to execute $myRUNAS"
7648 id $myRUNAS_UID > /dev/null ||
7649 error "Invalid RUNAS_ID $myRUNAS_UID. Please set RUNAS_ID to " \
7650 "some UID which exists on MDS and client or add user " \
7651 "$myRUNAS_UID:$myRUNAS_GID on these nodes."
7654 $myRUNAS krb5_login.sh ||
7655 error "Failed to refresh krb5 TGT for UID $myRUNAS_ID."
7657 mkdir $DIR/d0_runas_test
7659 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
7660 $myRUNAS -u $myRUNAS_UID -g $myRUNAS_GID touch $DIR/d0_runas_test/f$$ ||
7662 rm -rf $DIR/d0_runas_test
7667 local myRUNAS_UID=$1
7668 local myRUNAS_GID=$2
7672 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
7673 error "unable to write to $DIR/d0_runas_test as " \
7677 # obtain the UID/GID for MPI_USER
7681 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
7682 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
7684 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
7685 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
7688 # obtain and cache Kerberos ticket-granting ticket
7689 refresh_krb5_tgt() {
7690 local myRUNAS_UID=$1
7691 local myRUNAS_GID=$2
7694 if [ -z "$myRUNAS" ]; then
7695 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
7698 CLIENTS=${CLIENTS:-$HOSTNAME}
7699 do_nodes $CLIENTS "set -x
7700 if ! $myRUNAS krb5_login.sh; then
7701 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
7706 # Run multiop in the background, but wait for it to print
7707 # "PAUSING" to its stdout before returning from this function.
7708 multiop_bg_pause() {
7709 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
7713 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
7716 echo "$MULTIOP_PROG $FILE v$ARGS"
7717 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
7720 echo "TMPPIPE=${TMPPIPE}"
7721 read -t 60 multiop_output < $TMPPIPE
7722 if [ $? -ne 0 ]; then
7727 if [ "$multiop_output" != "PAUSING" ]; then
7728 echo "Incorrect multiop output: $multiop_output"
7743 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
7745 echo $((SECONDS - start))
7749 inodes_available () {
7750 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
7751 sort -un | head -n1) || return 1
7756 mdsrate_inodes_available () {
7757 local min_inodes=$(inodes_available)
7759 echo $((min_inodes * 99 / 100))
7762 bytes_available () {
7763 echo $(df -P -B 1 "$MOUNT" | awk 'END {print $4}')
7766 mdsrate_bytes_available () {
7767 local bytes=$(bytes_available)
7769 echo $((bytes * 99 / 100))
7772 # reset stat counters
7774 local paramfile="$1"
7776 lctl set_param -n $paramfile=0
7781 local paramfile="$1"
7784 lctl get_param -n $paramfile |
7785 awk '/^'$stat'/ { sum += $2 } END { printf("%0.0f", sum) }'
7789 awk '{sum += $1} END { printf("%0.0f", sum) }'
7792 calc_osc_kbytes () {
7793 $LFS df $MOUNT > /dev/null
7794 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
7798 wait_delete_completed
7799 AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7800 echo "OST kbytes available: ${AVAIL[*]}"
7805 for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7806 #echo OST $i: ${AVAIL[i]}kb
7807 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7811 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7816 echo "Min free space: OST $MINI: $MINV"
7817 echo "Max free space: OST $MAXI: $MAXV"
7820 # save_lustre_params(comma separated facet list, parameter_mask)
7821 # generate a stream of formatted strings (<facet> <param name>=<param value>)
7822 save_lustre_params() {
7827 for facet in ${facets//,/ }; do
7828 facet_svc=$(facet_svc $facet)
7830 "params=\\\$($LCTL get_param $2);
7831 [[ -z \\\"$facet_svc\\\" ]] && param= ||
7832 param=\\\$(grep $facet_svc <<< \\\"\\\$params\\\");
7833 [[ -z \\\$param ]] && param=\\\"\\\$params\\\";
7834 while read s; do echo $facet \\\$s;
7835 done <<< \\\"\\\$param\\\""
7839 # restore lustre parameters from input stream, produces by save_lustre_params
7840 restore_lustre_params() {
7845 while IFS=" =" read facet name val; do
7846 do_facet $facet "$LCTL set_param -n $name=$val"
7850 check_node_health() {
7851 local nodes=${1:-$(comma_list $(nodes_list))}
7852 local health=$TMP/node_health.$$
7854 do_nodes -q $nodes "$LCTL get_param catastrophe 2>&1" | tee $health |
7855 grep "catastrophe=1" && error "LBUG/LASSERT detected"
7856 # Only check/report network health if get_param isn't reported, since
7857 # *clearly* the network is working if get_param returned something.
7858 if (( $(grep -c catastro $health) != $(wc -w <<< ${nodes//,/ }) )); then
7859 for node in ${nodes//,/ }; do
7860 check_network $node 5
7866 mdsrate_cleanup () {
7868 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
7869 --nfiles $3 --dir $4 --filefmt $5 $6
7875 local test_type="$1"
7888 local mdtest_basedir
7889 local mdtest_actions
7890 local mdtest_options
7891 local stripe_options
7894 case "$test_type" in
7896 stripe_options=(-c 1 -i 0)
7897 mdtest_actions=(-F -R)
7902 stripe_options=(-c -1)
7903 mdtest_actions=(-F -R)
7904 file_size=$((1024 * 1024 * 1024))
7908 stripe_options=(-c 1)
7909 mdtest_actions=(-C -D -E -k -r)
7914 stripe_options=(-c 1)
7915 mdtest_actions=(-C -D -E -k -r)
7920 stripe_options=(-c -1)
7926 if [[ -n "$MDTEST_DEBUG" ]]; then
7927 mdtest_options+=(-v -v -v)
7930 num_dirs=${NUM_DIRS:-$num_dirs}
7931 num_files=${NUM_FILES:-$num_files}
7932 file_size=${FILE_SIZE:-$file_size}
7933 free_space=$(mdsrate_bytes_available)
7935 if (( file_size * num_files > free_space )); then
7936 file_size=$((free_space / num_files))
7937 log "change file size to $file_size due to" \
7938 "number of files $num_files and" \
7939 "free space limit in $free_space"
7942 if (( file_size > 0 )); then
7943 log "set file size to $file_size"
7944 mdtest_options+=(-w=$file_size)
7947 params_file=$TMP/$TESTSUITE-$TESTNAME.parameters
7948 mdtest_basedir=$MOUNT/mdtest
7949 mdtest_options+=(-d=$mdtest_basedir)
7952 num_hosts=$(get_node_count ${CLIENTS//,/ })
7953 num_procs=$((num_cores * num_hosts))
7954 num_inodes=$(mdsrate_inodes_available)
7956 if (( num_inodes < num_files )); then
7957 log "change the number of files $num_files to the" \
7958 "number of available inodes $num_inodes"
7959 num_files=$num_inodes
7962 if (( num_dirs > 1 )); then
7963 num_entries=$((num_files / num_dirs))
7964 log "split $num_files files to $num_dirs" \
7965 "with $num_entries files each"
7966 mdtest_options+=(-I=$num_entries)
7969 generate_machine_file $CLIENTS $MACHINEFILE ||
7970 error "can not generate machinefile"
7972 install -v -d -m 0777 $mdtest_basedir
7974 setstripe_getstripe $mdtest_basedir ${stripe_options[@]}
7976 save_lustre_params $(get_facets MDS) \
7977 mdt.*.enable_remote_dir_gid > $params_file
7979 do_nodes $(comma_list $(mdts_nodes)) \
7980 $LCTL set_param mdt.*.enable_remote_dir_gid=-1
7982 stack_trap "restore_lustre_params < $params_file" EXIT
7984 for np in 1 $num_procs; do
7985 num_entries=$((num_files / np ))
7987 mpi_run $MACHINEFILE_OPTION $MACHINEFILE \
7988 -np $np -npernode $num_cores $MDTEST \
7989 ${mdtest_options[@]} -n=$num_entries \
7990 ${mdtest_actions[@]} 2>&1 | tee -a "$LOG"
7994 if (( rc != 0 )); then
7995 mpi_run $MACHINEFILE_OPTION $MACHINEFILE \
7996 -np $np -npernode $num_cores $MDTEST \
7997 ${mdtest_options[@]} -n=$num_entries \
7998 -r 2>&1 | tee -a "$LOG"
8003 rmdir -v $mdtest_basedir
8004 rm -v $state $MACHINEFILE
8009 ########################
8011 convert_facet2label() {
8014 if [ x$facet = xost ]; then
8016 elif [ x$facet = xmgs ] && combined_mgs_mds ; then
8020 local varsvc=${facet}_svc
8022 if [ -n "${!varsvc}" ]; then
8025 error "No label for $facet!"
8029 get_clientosc_proc_path() {
8030 echo "${1}-osc-[-0-9a-f]*"
8033 get_mdtosc_proc_path() {
8035 local ost_label=${2:-"*OST*"}
8037 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
8038 local mdt_label=$(convert_facet2label $mds_facet)
8039 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
8041 if [[ $ost_label = *OST* ]]; then
8042 echo "${ost_label}-osc-${mdt_index}"
8044 echo "${ost_label}-osp-${mdt_index}"
8048 get_osc_import_name() {
8051 local label=$(convert_facet2label $ost)
8053 if [ "${facet:0:3}" = "mds" ]; then
8054 get_mdtosc_proc_path $facet $label
8058 get_clientosc_proc_path $label
8062 _wait_import_state () {
8064 local CONN_PROC="$2"
8065 local maxtime=${3:-$(max_recovery_time)}
8066 local err_on_fail=${4:-1}
8070 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
8071 while ! echo "${CONN_STATE}" | egrep -q "^${expected}\$" ; do
8072 if [[ "${expected}" == "DISCONN" ]]; then
8073 # for disconn we can check after proc entry is removed
8074 [[ -z "${CONN_STATE}" ]] && return 0
8075 # with AT, we can have connect request timeout near
8076 # reconnect timeout and test can't see real disconnect
8077 [[ "${CONN_STATE}" == "CONNECTING" ]] && return 0
8079 if (( $i >= $maxtime )); then
8080 (( $err_on_fail != 0 )) &&
8081 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}"
8085 # Add uniq for multi-mount case
8086 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null |
8091 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
8095 wait_import_state() {
8098 local maxtime=${3:-$(max_recovery_time)}
8099 local err_on_fail=${4:-1}
8102 for param in ${params//,/ }; do
8103 _wait_import_state "$expected" "$param" $maxtime $err_on_fail ||
8108 wait_import_state_mount() {
8109 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
8113 wait_import_state "$@"
8116 # One client request could be timed out because server was not ready
8117 # when request was sent by client.
8118 # The request timeout calculation details :
8120 # /* We give the server rq_timeout secs to process the req, and
8121 # add the network latency for our local timeout. */
8122 # request->rq_deadline = request->rq_sent + request->rq_timeout +
8123 # ptlrpc_at_get_net_latency(request) ;
8125 # ptlrpc_connect_import ()
8126 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
8129 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
8130 # ptlrpc_at_get_net_latency(request) ->
8131 # at_get (max (iat_net_latency=0, at_min)) = at_min
8134 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
8135 # INITIAL_CONNECT_TIMEOUT + at_min
8137 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
8138 # because we can not get this value in runtime,
8139 # the value depends on configure options, and it is not stored in /proc.
8141 # #define CONNECTION_SWITCH_MIN 5U
8142 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
8144 request_timeout () {
8147 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
8148 local init_connect_timeout=$TIMEOUT
8149 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
8151 local at_min=$(at_get $facet at_min)
8153 echo $(( init_connect_timeout + at_min ))
8156 _wait_osc_import_state() {
8160 local target=$(get_osc_import_name $facet $ost_facet)
8161 local param="os[cp].${target}.ost_server_uuid"
8165 # 1. wait the deadline of client 1st request (it could be skipped)
8166 # 2. wait the deadline of client 2nd request
8167 local maxtime=$(( 2 * $(request_timeout $facet)))
8169 if [[ $facet == client* ]]; then
8170 # During setup time, the osc might not be setup, it need wait
8171 # until list_param can return valid value.
8172 params=$($LCTL list_param $param 2>/dev/null || true)
8173 while [ -z "$params" ]; do
8174 if [ $i -ge $maxtime ]; then
8175 echo "can't get $param in $maxtime secs"
8180 params=$($LCTL list_param $param 2>/dev/null || true)
8184 if [[ $ost_facet = mds* ]]; then
8185 # no OSP connection to itself
8186 if [[ $facet = $ost_facet ]]; then
8189 param="osp.${target}.mdt_server_uuid"
8193 local plist=$(comma_list $params)
8194 if ! do_rpc_nodes "$(facet_active_host $facet)" \
8195 wait_import_state $expected $plist $maxtime; then
8196 error "$facet: import is not in $expected state after $maxtime"
8203 wait_osc_import_state() {
8209 if [[ $facet = mds ]]; then
8210 for num in $(seq $MDSCOUNT); do
8211 _wait_osc_import_state mds$num "$ost_facet" "$expected"
8214 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
8218 wait_osc_import_ready() {
8219 wait_osc_import_state $1 $2 "\(FULL\|IDLE\)"
8222 _wait_mgc_import_state() {
8225 local error_on_failure=${3:-1}
8226 local param="mgc.*.mgs_server_uuid"
8230 # 1. wait the deadline of client 1st request (it could be skipped)
8231 # 2. wait the deadline of client 2nd request
8232 local maxtime=$(( 2 * $(request_timeout $facet)))
8234 if [[ $facet == client* ]]; then
8235 # During setup time, the osc might not be setup, it need wait
8236 # until list_param can return valid value. And also if there
8237 # are mulitple osc entries we should list all of them before
8239 params=$($LCTL list_param $param 2>/dev/null || true)
8240 while [ -z "$params" ]; do
8241 if [ $i -ge $maxtime ]; then
8242 echo "can't get $param in $maxtime secs"
8247 params=$($LCTL list_param $param 2>/dev/null || true)
8250 local plist=$(comma_list $params)
8251 if ! do_rpc_nodes "$(facet_active_host $facet)" \
8252 wait_import_state $expected $plist $maxtime \
8253 $error_on_failure; then
8254 if [ $error_on_failure -ne 0 ]; then
8255 error "import is not in ${expected} state"
8263 wait_mgc_import_state() {
8266 local error_on_failure=${3:-1}
8269 if [[ $facet = mds ]]; then
8270 for num in $(seq $MDSCOUNT); do
8271 _wait_mgc_import_state mds$num "$expected" \
8272 $error_on_failure || return
8275 _wait_mgc_import_state "$facet" "$expected" \
8276 $error_on_failure || return
8280 wait_dne_interconnect() {
8283 if [ $MDSCOUNT -gt 1 ]; then
8284 for num in $(seq $MDSCOUNT); do
8285 wait_osc_import_ready mds mds$num
8290 get_clientmdc_proc_path() {
8294 get_clientmgc_proc_path() {
8301 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
8306 [ -z "$list" ] && return 0
8308 # Add paths to lustre tests for 32 and 64 bit systems.
8309 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
8310 local TESTPATH="$RLUSTRE/tests:"
8311 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
8312 do_nodes ${quiet:-"--verbose"} $list "${RPATH} NAME=${NAME} \
8313 TESTLOG_PREFIX=$TESTLOG_PREFIX TESTNAME=$TESTNAME \
8317 wait_clients_import_state () {
8321 local facets="$facet"
8323 if [ "$FAILURE_MODE" = HARD ]; then
8324 facets=$(for f in ${facet//,/ }; do
8325 facets_on_host $(facet_active_host $f) | tr "," "\n"
8326 done | sort -u | paste -sd , )
8329 for facet in ${facets//,/ }; do
8330 local label=$(convert_facet2label $facet)
8333 ost* ) proc_path="osc.$(get_clientosc_proc_path \
8334 $label).ost_server_uuid" ;;
8335 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
8336 $label).mds_server_uuid" ;;
8337 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
8338 $label).mgs_server_uuid" ;;
8339 *) error "unknown facet!" ;;
8342 local params=$(expand_list $params $proc_path)
8345 if ! do_rpc_nodes "$list" wait_import_state_mount "$expected" $params;
8347 error "import is not in ${expected} state"
8352 wait_clients_import_ready() {
8353 wait_clients_import_state "$1" "$2" "\(FULL\|IDLE\)"
8363 # wait until all MDTs are in the expected state
8364 for ((num = 1; num <= $MDSCOUNT; num++)); do
8365 local mdtosp=$(get_mdtosc_proc_path mds${num} ${tgt_name})
8369 if [ $facet = "mds" ]; then
8370 mproc="osp.$mdtosp.active"
8371 [ $num -eq $((tgt_idx + 1)) ] && continue
8373 mproc="osc.$mdtosp.active"
8379 local result=$(do_facet mds${num} "$LCTL get_param -n $mproc")
8382 [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $mproc"
8383 if [ $result -eq $expected ]; then
8384 echo -n "target updated after "
8385 echo "$wait sec (got $result)"
8389 if [ $wait -eq $max ]; then
8390 error "$tgt_name: wanted $expected got $result"
8392 echo "Waiting $((max - wait)) secs for $tgt_name"
8402 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
8403 $LCTL get_param obdfilter.*.kbytesavail))
8404 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
8405 $LCTL get_param -n obdfilter.*.tot_granted))
8406 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
8407 $LCTL get_param -n obdfilter.*.kbytestotal))
8408 for ((i=0; i<${#AVAILA[@]}; i++)); do
8409 local -a AVAIL1=(${AVAILA[$i]//=/ })
8410 local -a TOTAL=(${TOTALA[$i]//=/ })
8411 GRANT=$((${GRANTA[$i]}/1024))
8412 # allow 1% of total space in bavail because of delayed
8413 # allocation with ZFS which might release some free space after
8414 # txg commit. For small devices, we set a mininum of 8MB
8415 local LIMIT=$((${TOTAL} / 100 + 8000))
8416 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
8417 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
8418 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
8419 echo " FULL" || echo
8425 echo -e "$(do_facet $SINGLEMDS $LCTL pool_list $1 | sed '1d')"
8428 check_pool_not_exist() {
8429 local fsname=${1%%.*}
8430 local poolname=${1##$fsname.}
8431 [[ $# -ne 1 ]] && return 0
8432 [[ x$poolname = x ]] && return 0
8433 list_pool $fsname | grep -w $1 && return 1
8438 local fsname=${1%%.*}
8439 local poolname=${1##$fsname.}
8440 local keep_pools=${2:-false}
8442 stack_trap "destroy_test_pools $fsname" EXIT
8443 do_facet mgs lctl pool_new $1
8445 # get param should return err unless pool is created
8446 [[ $RC -ne 0 ]] && return $RC
8448 for mds_id in $(seq $MDSCOUNT); do
8449 local mdt_id=$((mds_id-1))
8450 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
8451 wait_update_facet mds$mds_id \
8452 "lctl get_param -n lod.$lodname.pools.$poolname \
8453 2>/dev/null || echo foo" "" ||
8454 error "mds$mds_id: pool_new failed $1"
8456 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
8457 2>/dev/null || echo foo" "" || error "pool_new failed $1"
8459 $keep_pools || add_pool_to_list $1
8463 add_pool_to_list () {
8464 local fsname=${1%%.*}
8465 local poolname=${1##$fsname.}
8467 local listvar=${fsname}_CREATED_POOLS
8468 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
8472 remove_pool_from_list () {
8473 local fsname=${1%%.*}
8474 local poolname=${1##$fsname.}
8476 local listvar=${fsname}_CREATED_POOLS
8477 local temp=${listvar}=$(exclude_items_from_list "${!listvar}" $poolname)
8481 # cleanup all pools exist on $FSNAME
8482 destroy_all_pools () {
8484 for i in $(list_pool $FSNAME); do
8489 destroy_pool_int() {
8491 local OSTS=$(list_pool $1)
8492 for ost in $OSTS; do
8493 do_facet mgs lctl pool_remove $1 $ost
8495 wait_update_facet $SINGLEMDS "lctl pool_list $1 | wc -l" "1" ||
8496 error "MDS: pool_list $1 failed"
8497 do_facet mgs lctl pool_destroy $1
8500 # <fsname>.<poolname> or <poolname>
8502 local fsname=${1%%.*}
8503 local poolname=${1##$fsname.}
8505 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
8509 check_pool_not_exist $fsname.$poolname && return 0 || true
8511 destroy_pool_int $fsname.$poolname
8513 [[ $RC -ne 0 ]] && return $RC
8514 for mds_id in $(seq $MDSCOUNT); do
8515 local mdt_id=$((mds_id-1))
8516 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
8517 wait_update_facet mds$mds_id \
8518 "lctl get_param -n lod.$lodname.pools.$poolname \
8519 2>/dev/null || echo foo" "foo" ||
8520 error "mds$mds_id: destroy pool failed $1"
8522 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
8523 2>/dev/null || echo foo" "foo" || error "destroy pool failed $1"
8525 remove_pool_from_list $fsname.$poolname
8531 local fsname=${1:-$FSNAME}
8533 local listvar=${fsname}_CREATED_POOLS
8535 [ x${!listvar} = x ] && return 0
8537 echo "Destroy the created pools: ${!listvar}"
8538 for poolname in ${!listvar//,/ }; do
8539 destroy_pool $fsname.$poolname
8543 destroy_test_pools () {
8545 local fsname=${1:-$FSNAME}
8546 destroy_pools $fsname || true
8552 local ts=$(date +%s)
8555 if [[ ! -f "$YAML_LOG" ]]; then
8556 # init_logging is not performed before gather_logs,
8557 # so the $LOGDIR needs to be checked here
8558 check_shared_dir $LOGDIR && touch $LOGDIR/shared
8561 [ -f $LOGDIR/shared ] && docp=false
8563 # dump lustre logs, dmesg, and journal if GSS_SK=true
8565 prefix="$TESTLOG_PREFIX.$TESTNAME"
8567 echo "Dumping lctl log to ${prefix}.*.${suffix}"
8569 if [ -n "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
8570 echo "Dumping logs only on local client."
8571 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
8572 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
8573 [ "$SHARED_KEY" = true ] && find $SK_PATH -name '*.key' -exec \
8574 $LGSS_SK -r {} \; &> \
8575 ${prefix}.ssk_keys.$(hostname -s).${suffix}
8576 [ "$SHARED_KEY" = true ] && lctl get_param 'nodemap.*.*' > \
8577 ${prefix}.nodemaps.$(hostname -s).${suffix}
8578 [ "$GSS" = true ] && keyctl show > \
8579 ${prefix}.keyring.$(hostname -s).${suffix}
8580 [ "$GSS" = true ] && journalctl -a > \
8581 ${prefix}.journal.$(hostname -s).${suffix}
8586 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
8587 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
8588 if [ "$SHARED_KEY" = true ]; then
8589 do_nodesv $list "find $SK_PATH -name '*.key' -exec \
8590 $LGSS_SK -r {} \; &> \
8591 ${prefix}.ssk_keys.\\\$(hostname -s).${suffix}"
8592 do_facet mds1 "lctl get_param 'nodemap.*.*' > \
8593 ${prefix}.nodemaps.\\\$(hostname -s).${suffix}"
8595 if [ "$GSS" = true ]; then
8596 do_nodesv $list "keyctl show > \
8597 ${prefix}.keyring.\\\$(hostname -s).${suffix}"
8598 do_nodesv $list "journalctl -a > \
8599 ${prefix}.journal.\\\$(hostname -s).${suffix}"
8602 if [ ! -f $LOGDIR/shared ]; then
8603 local remote_nodes=$(exclude_items_from_list $list $HOSTNAME)
8605 for node in ${remote_nodes//,/ }; do
8606 rsync -az -e ssh $node:${prefix}.'*'.${suffix} $LOGDIR &
8620 for i in $(seq 0 $num_mntpts); do
8621 cmd="ls -laf ${mntpt_root}$i/$dir"
8627 for pid in $pids; do
8634 # check_and_start_recovery_timer()
8635 # service_time = at_est2timeout(service_time);
8636 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
8637 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
8639 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
8640 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
8641 #define CONNECTION_SWITCH_MIN 5
8642 #define CONNECTION_SWITCH_INC 5
8643 max_recovery_time() {
8644 local init_connect_timeout=$((TIMEOUT / 20))
8645 ((init_connect_timeout >= 5)) || init_connect_timeout=5
8647 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
8648 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
8650 echo -n $service_time
8653 recovery_time_min() {
8654 local connection_switch_min=5
8655 local connection_switch_inc=5
8656 local connection_switch_max
8657 local reconnect_delay_max
8658 local initial_connect_timeout
8662 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
8663 (($connection_switch_min > $TIMEOUT)) &&
8664 max=$connection_switch_min || max=$TIMEOUT
8665 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
8667 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
8668 timeout_20=$((TIMEOUT/20))
8669 (($connection_switch_min > $timeout_20)) &&
8670 initial_connect_timeout=$connection_switch_min ||
8671 initial_connect_timeout=$timeout_20
8673 reconnect_delay_max=$((connection_switch_max + connection_switch_inc +
8674 initial_connect_timeout))
8675 echo $((2 * reconnect_delay_max))
8678 get_clients_mount_count () {
8679 local clients=${CLIENTS:-$HOSTNAME}
8681 # we need to take into account the clients mounts and
8682 # exclude mds/ost mounts if any;
8683 do_nodes $clients cat /proc/mounts | grep lustre |
8684 grep -w $MOUNT | wc -l
8688 PROC_CLI="srpc_info"
8689 PROC_CON="srpc_contexts"
8697 if [ $M -lt $N ]; then
8701 while [ $N -lt $M ]; do
8711 calc_connection_cnt() {
8714 # MDT->MDT = 2 * C(M, 2)
8718 comb_m2=$(combination $MDSCOUNT 2)
8720 local num_clients=$(get_clients_mount_count)
8722 local cnt_mdt2mdt=$((comb_m2 * 2))
8723 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
8724 local cnt_cli2ost=$((num_clients * OSTCOUNT))
8725 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
8726 if is_mounted $MOUNT2; then
8727 cnt_cli2mdt=$((cnt_cli2mdt * 2))
8728 cnt_cli2ost=$((cnt_cli2ost * 2))
8736 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
8737 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
8738 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt \
8739 + cnt_cli2ost + cnt_cli2mdt))
8753 local cmd="$tgt.srpc.flavor"
8755 if [ $net == "any" ]; then
8760 if [ $dir != "any" ]; then
8765 log "Setting sptlrpc rule: $cmd"
8766 do_facet mgs "$LCTL conf_param $cmd"
8772 local total_ctx=$(echo "$output" | grep -c "expire.*key.*hdl")
8782 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
8783 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
8785 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
8787 if [ "x$bulkspec" != "x" ]; then
8788 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
8790 if [ "x$algs" != "x" ]; then
8791 bulk_count=`echo "$output" | grep "bulk flavor" |
8794 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
8796 if [ $bulk == "bulkn" ]; then
8797 bulk_count=`echo "$output" |
8798 grep "bulk flavor" | grep "null/null" |
8800 elif [ $bulk == "bulki" ]; then
8801 bulk_count=`echo "$output" |
8802 grep "bulk flavor" | grep "/null" |
8803 grep -v "null/" | wc -l`
8805 bulk_count=`echo "$output" |
8806 grep "bulk flavor" | grep -v "/null" |
8807 grep -v "null/" | wc -l`
8810 [ $bulk_count -lt $count ] && count=$bulk_count
8821 local clients=${CLIENTS:-$HOSTNAME}
8823 for c in ${clients//,/ }; do
8824 local output=$(do_node $c lctl get_param -n \
8825 mdc.*-*-mdc-*.$PROC_CLI 2>/dev/null)
8826 local tmpcnt=$(count_flvr "$output" $flavor)
8828 if $GSS_SK && [ $flavor != "null" ]; then
8829 # tmpcnt=min(contexts,flavors) to ensure SK context is
8831 output=$(do_node $c lctl get_param -n \
8832 mdc.*-MDT*-mdc-*.$PROC_CON 2>/dev/null)
8833 local outcon=$(count_contexts "$output")
8835 if [ "$outcon" -lt "$tmpcnt" ]; then
8839 cnt=$((cnt + tmpcnt))
8849 local clients=${CLIENTS:-$HOSTNAME}
8851 for c in ${clients//,/ }; do
8853 do_node $c lctl set_param osc.*.idle_connect=1 >/dev/null 2>&1
8854 local output=$(do_node $c lctl get_param -n \
8855 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null)
8856 local tmpcnt=$(count_flvr "$output" $flavor)
8858 if $GSS_SK && [ $flavor != "null" ]; then
8859 # tmpcnt=min(contexts,flavors) to ensure SK context is on
8860 output=$(do_node $c lctl get_param -n \
8861 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CON 2>/dev/null)
8862 local outcon=$(count_contexts "$output")
8864 if [ "$outcon" -lt "$tmpcnt" ]; then
8868 cnt=$((cnt + tmpcnt))
8878 if [ $MDSCOUNT -le 1 ]; then
8883 for num in `seq $MDSCOUNT`; do
8884 local output=$(do_facet mds$num lctl get_param -n \
8885 osp.*-MDT*osp-MDT*.$PROC_CLI 2>/dev/null)
8886 local tmpcnt=$(count_flvr "$output" $flavor)
8888 if $GSS_SK && [ $flavor != "null" ]; then
8889 # tmpcnt=min(contexts,flavors) to ensure SK context is on
8890 output=$(do_facet mds$num lctl get_param -n \
8891 osp.*-MDT*osp-MDT*.$PROC_CON 2>/dev/null)
8892 local outcon=$(count_contexts "$output")
8894 if [ "$outcon" -lt "$tmpcnt" ]; then
8898 cnt=$((cnt + tmpcnt))
8909 for num in `seq $MDSCOUNT`; do
8910 mdtosc=$(get_mdtosc_proc_path mds$num)
8911 mdtosc=${mdtosc/-MDT*/-MDT\*}
8912 local output=$(do_facet mds$num lctl get_param -n \
8913 os[cp].$mdtosc.$PROC_CLI 2>/dev/null)
8914 # Ensure SK context is on
8915 local tmpcnt=$(count_flvr "$output" $flavor)
8917 if $GSS_SK && [ $flavor != "null" ]; then
8918 output=$(do_facet mds$num lctl get_param -n \
8919 os[cp].$mdtosc.$PROC_CON 2>/dev/null)
8920 local outcon=$(count_contexts "$output")
8922 if [ "$outcon" -lt "$tmpcnt" ]; then
8926 cnt=$((cnt + tmpcnt))
8935 local output=$(do_facet client lctl get_param -n mgc.*.$PROC_CLI \
8937 count_flvr "$output" $flavor
8942 local dir=$1 # from to
8943 local flavor=$2 # flavor expected
8946 if [ $dir == "cli2mdt" ]; then
8947 res=`flvr_cnt_cli2mdt $flavor`
8948 elif [ $dir == "cli2ost" ]; then
8949 res=`flvr_cnt_cli2ost $flavor`
8950 elif [ $dir == "mdt2mdt" ]; then
8951 res=`flvr_cnt_mdt2mdt $flavor`
8952 elif [ $dir == "mdt2ost" ]; then
8953 res=`flvr_cnt_mdt2ost $flavor`
8954 elif [ $dir == "all2ost" ]; then
8955 res1=`flvr_cnt_mdt2ost $flavor`
8956 res2=`flvr_cnt_cli2ost $flavor`
8957 res=$((res1 + res2))
8958 elif [ $dir == "all2mdt" ]; then
8959 res1=`flvr_cnt_mdt2mdt $flavor`
8960 res2=`flvr_cnt_cli2mdt $flavor`
8961 res=$((res1 + res2))
8962 elif [ $dir == "all2all" ]; then
8963 res1=`flvr_cnt_mdt2ost $flavor`
8964 res2=`flvr_cnt_cli2ost $flavor`
8965 res3=`flvr_cnt_mdt2mdt $flavor`
8966 res4=`flvr_cnt_cli2mdt $flavor`
8967 res=$((res1 + res2 + res3 + res4))
8975 local dir=$1 # from to
8976 local flavor=$2 # flavor expected
8977 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
8978 local WAITFLAVOR_MAX=20 # how many retries before abort?
8981 for ((i = 0; i < $WAITFLAVOR_MAX; i++)); do
8982 echo -n "checking $dir..."
8983 res=$(do_check_flavor $dir $flavor)
8984 echo "found $res/$expect $flavor connections"
8985 [ $res -ge $expect ] && return 0
8989 echo "Error checking $flavor of $dir: expect $expect, actual $res"
8990 # echo "Dumping additional logs for SK debug.."
8991 do_nodes $(comma_list $(all_server_nodes)) "keyctl show"
8993 gather_logs $(comma_list $(nodes_list))
8998 restore_to_default_flavor()
9000 local proc="mgs.MGS.live.$FSNAME"
9002 echo "restoring to default flavor..."
9004 local nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
9005 grep ".srpc.flavor" | wc -l)
9007 # remove all existing rules if any
9008 if [ $nrule -ne 0 ]; then
9009 echo "$nrule existing rules"
9010 for rule in $(do_facet mgs lctl get_param -n $proc 2>/dev/null |
9011 grep ".srpc.flavor."); do
9012 echo "remove rule: $rule"
9013 spec=`echo $rule | awk -F = '{print $1}'`
9014 do_facet mgs "$LCTL conf_param -d $spec"
9018 # verify no rules left
9019 nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
9020 grep ".srpc.flavor." | wc -l)
9021 [ $nrule -ne 0 ] && error "still $nrule rules left"
9023 # wait for default flavor to be applied
9026 set_rule $FSNAME any any $SK_FLAVOR
9027 wait_flavor all2all $SK_FLAVOR
9029 set_rule $FSNAME any cli2mdt $SK_FLAVOR
9030 set_rule $FSNAME any cli2ost $SK_FLAVOR
9031 wait_flavor cli2mdt $SK_FLAVOR
9032 wait_flavor cli2ost $SK_FLAVOR
9034 echo "GSS_SK now at default flavor: $SK_FLAVOR"
9036 wait_flavor all2all null
9042 local flavor=${1:-null}
9044 echo "setting all flavor to $flavor"
9046 # FIXME need parameter to this fn
9047 # and remove global vars
9048 local cnt_all2all=$(calc_connection_cnt all2all)
9050 local res=$(do_check_flavor all2all $flavor)
9051 if [ $res -eq $cnt_all2all ]; then
9052 echo "already have total $res $flavor connections"
9056 echo "found $res $flavor out of total $cnt_all2all connections"
9057 restore_to_default_flavor
9059 [[ $flavor = null ]] && return 0
9061 if $GSS_SK && [ $flavor != "null" ]; then
9063 set_rule $FSNAME any any $flavor
9064 wait_flavor all2all $flavor
9066 set_rule $FSNAME any cli2mdt $flavor
9067 set_rule $FSNAME any cli2ost $flavor
9068 set_rule $FSNAME any mdt2ost null
9069 set_rule $FSNAME any mdt2mdt null
9070 wait_flavor cli2mdt $flavor
9071 wait_flavor cli2ost $flavor
9073 echo "GSS_SK now at flavor: $flavor"
9075 set_rule $FSNAME any cli2mdt $flavor
9076 set_rule $FSNAME any cli2ost $flavor
9077 set_rule $FSNAME any mdt2ost null
9078 set_rule $FSNAME any mdt2mdt null
9079 wait_flavor cli2mdt $flavor
9080 wait_flavor cli2ost $flavor
9087 # Checking for shared logdir
9088 if [ ! -d $dir ]; then
9089 # Not found. Create local logdir
9092 touch $dir/check_file.$(hostname -s)
9097 check_write_access() {
9099 local list=${2:-$(comma_list $(nodes_list))}
9103 for node in ${list//,/ }; do
9104 file=$dir/check_file.$(short_nodename $node)
9105 if [[ ! -f "$file" ]]; then
9106 # Logdir not accessible/writable from this node.
9109 rm -f $file || return 1
9115 [[ -n $YAML_LOG ]] && return
9116 local save_umask=$(umask)
9119 export YAML_LOG=${LOGDIR}/results.yml
9123 # If the yaml log already exists then we will just append to it
9124 if [ ! -f $YAML_LOG ]; then
9125 if check_shared_dir $LOGDIR; then
9126 touch $LOGDIR/shared
9127 echo "Logging to shared log directory: $LOGDIR"
9129 echo "Logging to local directory: $LOGDIR"
9132 yml_nodes_file $LOGDIR >> $YAML_LOG
9133 yml_results_file >> $YAML_LOG
9138 # log actual client and server versions if needed for debugging
9139 log "Client: $(lustre_build_version client)"
9140 log "MDS: $(lustre_build_version mds1)"
9141 log "OSS: $(lustre_build_version ost1)"
9145 yml_log_test $1 >> $YAML_LOG
9149 yml_log_test_status "$@" >> $YAML_LOG
9152 log_sub_test_begin() {
9153 yml_log_sub_test_begin "$@" >> $YAML_LOG
9156 log_sub_test_end() {
9157 yml_log_sub_test_end "$@" >> $YAML_LOG
9163 local llverdev_opts="$*"
9164 local devname=$(basename $dev)
9165 local size=$(awk "/$devname$/ {print \$3}" /proc/partitions)
9166 # loop devices aren't in /proc/partitions
9167 [[ -z "$size" ]] && size=$(stat -c %s $dev)
9169 local size_gb=$((size / 1024 / 1024)) # Gb
9171 local partial_arg=""
9172 # Run in partial (fast) mode if the size of a partition > 1 GB
9173 (( $size == 0 || $size_gb > 1 )) && partial_arg="-p"
9175 llverdev --force $partial_arg $llverdev_opts $dev
9181 local llverfs_opts=$2
9182 local use_partial_arg=$3
9183 local partial_arg=""
9184 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
9186 # Run in partial (fast) mode if the size of a partition > 1 GB
9187 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
9189 llverfs $partial_arg $llverfs_opts $dir
9193 local devs=${1//,/ }
9196 local rslt=$TMP/sgpdd_survey
9198 # sgpdd-survey cleanups ${rslt}.* files
9200 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
9206 # returns the canonical name for an ldiskfs device
9211 do_facet $facet "dv=\\\$($LCTL get_param -n $dev);
9212 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
9213 echo dm-\\\${foo##*:};
9215 name=\\\$(basename \\\$dv);
9216 if [[ \\\$name = *flakey* ]]; then
9217 name=\\\$(lsblk -o NAME,KNAME |
9218 awk /\\\$name/'{print \\\$NF}');
9224 is_sanity_benchmark() {
9225 local benchmarks="dbench bonnie iozone fsx"
9228 for b in $benchmarks; do
9229 if [ "$b" == "$suite" ]; then
9237 $LFS df | grep OST | awk '{print $4}' | sort -un | head -1
9241 # Get the available size (KB) of a given obd target.
9248 [[ $facet != client ]] || return 0
9250 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
9255 # Get the page size (bytes) on a given facet node.
9256 # The local client page_size is directly available in PAGE_SIZE.
9260 local page_size=$(getconf PAGE_SIZE 2>/dev/null)
9262 [ -z "$CLIENTONLY" -a "$facet" != "client" ] &&
9263 page_size=$(do_facet $facet getconf PAGE_SIZE)
9264 echo -n ${page_size:-4096}
9268 # Get the block count of the filesystem.
9275 [ -z "$CLIENTONLY" ] &&
9276 count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
9277 awk '/^Block count:/ {print $3}')
9281 # Check whether the "ea_inode" feature is enabled or not, to allow
9282 # ldiskfs xattrs over one block in size. Allow both the historical
9283 # Lustre feature name (large_xattr) and the upstream name (ea_inode).
9284 large_xattr_enabled() {
9285 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
9287 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
9289 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
9290 grep -E -q '(ea_inode|large_xattr)'"
9291 return ${PIPESTATUS[0]}
9294 # Get the maximum xattr size supported by the filesystem.
9296 $LCTL get_param -n llite.*.max_easize
9299 # Dump the value of the named xattr from a file.
9304 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
9307 # Generate a string with size of $size bytes.
9309 local size=${1:-1024} # in bytes
9311 echo "$(head -c $size < /dev/zero | tr '\0' y)"
9314 reformat_external_journal() {
9319 local varbs=${facet}_BLOCKSIZE
9320 if [ -n "${!var}" ]; then
9321 local rcmd="do_facet $facet"
9322 local bs=${!varbs:-$BLCKSIZE}
9325 echo "reformat external journal on $facet:${!var}"
9326 ${rcmd} mke2fs -O journal_dev $bs ${!var} || return 1
9330 # MDT file-level backup/restore
9331 mds_backup_restore() {
9334 local devname=$(mdsdevname $(facet_number $facet))
9335 local mntpt=$(facet_mntpt brpt)
9336 local rcmd="do_facet $facet"
9337 local metadata=${TMP}/backup_restore.tgz
9338 local opts=${MDS_MOUNT_FS_OPTS}
9339 local svc=${facet}_svc
9341 if ! ${rcmd} test -b ${devname}; then
9342 opts=$(csa_add "$opts" -o loop)
9345 echo "file-level backup/restore on $facet:${devname}"
9347 # step 1: build mount point
9348 ${rcmd} mkdir -p $mntpt
9349 # step 2: cleanup old backup
9350 ${rcmd} rm -f $metadata
9352 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 3
9353 if [ ! -z $igif ]; then
9354 # step 3.5: rm .lustre
9355 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 3
9357 # step 4: backup metadata
9359 ${rcmd} tar zcf $metadata --xattrs --xattrs-include="trusted.*" \
9360 --sparse -C $mntpt/ . > /dev/null 2>&1 || return 4
9362 ${rcmd} $UMOUNT $mntpt || return 5
9363 # step 6: reformat dev
9364 echo "reformat new device"
9365 format_mdt $(facet_number $facet)
9367 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
9368 # step 8: restore metadata
9370 ${rcmd} tar zxfp $metadata --xattrs --xattrs-include="trusted.*" \
9371 --sparse -C $mntpt > /dev/null 2>&1 || return 8
9372 # step 9: remove recovery logs
9373 echo "remove recovery logs"
9374 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
9375 # step 10: umount dev
9376 ${rcmd} $UMOUNT $mntpt || return 10
9377 # step 11: cleanup tmp backup
9378 ${rcmd} rm -f $metaea $metadata
9379 # step 12: reset device label - it's not virgin on
9380 ${rcmd} e2label $devname ${!svc}
9387 local devname=$(mdsdevname $(facet_number $facet))
9388 local mntpt=$(facet_mntpt brpt)
9389 local rcmd="do_facet $facet"
9390 local opts=${MDS_MOUNT_FS_OPTS}
9392 if ! ${rcmd} test -b ${devname}; then
9393 opts=$(csa_add "$opts" -o loop)
9396 echo "removing OI files on $facet: idx=${idx}"
9398 # step 1: build mount point
9399 ${rcmd} mkdir -p $mntpt
9401 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
9402 if [ -z $idx ]; then
9403 # step 3: remove all OI files
9404 ${rcmd} rm -fv $mntpt/oi.16*
9405 elif [ $idx -lt 2 ]; then
9406 ${rcmd} rm -fv $mntpt/oi.16.${idx}
9410 # others, rm oi.16.[idx, idx * idx, idx ** ...]
9411 for ((i=${idx}; i<64; i=$((i * idx)))); do
9412 ${rcmd} rm -fv $mntpt/oi.16.${i}
9416 ${rcmd} $UMOUNT $mntpt || return 2
9417 # OI files will be recreated when mounted as lustre next time.
9420 # generate maloo upload-able log file name
9421 # \param logname specify unique part of file name
9422 generate_logname() {
9423 local logname=${1:-"default_logname"}
9425 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
9428 # make directory on different MDTs
9433 local hash_name=("all_char" "fnv_1a_64" "crush")
9434 local dirstripe_count=${DIRSTRIPE_COUNT:-"2"}
9435 local dirstripe_index=${DIRSTRIPE_INDEX:-$((base % $MDSCOUNT))}
9438 (( $MDS1_VERSION > $(version_code 2.15.0) )) &&
9439 hash_name+=("crush2")
9441 while getopts "c:H:i:p" opt; do
9443 c) dirstripe_count=$OPTARG;;
9444 H) hash_type=$OPTARG;;
9445 i) dirstripe_index=$OPTARG;;
9447 \?) error "only support -c -H -i -p";;
9451 shift $((OPTIND - 1))
9452 [ $# -eq 1 ] || error "Only creating single directory is supported"
9455 local parent=$(dirname $path)
9456 if [ "$p_option" == "-p" ]; then
9457 [ -d $path ] && return 0
9458 if [ ! -d ${parent} ]; then
9459 mkdir -p ${parent} ||
9460 error "mkdir parent '$parent' failed"
9464 if [ $MDSCOUNT -le 1 ] || ! is_lustre ${parent}; then
9465 mkdir $path || error "mkdir '$path' failed"
9469 if [ $dirstripe_index -eq -1 ]; then
9470 mdt_index=$((base % MDSCOUNT))
9472 mdt_index=$dirstripe_index
9475 # randomly choose hash type
9476 [ -z "$hash_type" ] &&
9477 hash_type=${hash_name[$((RANDOM % ${#hash_name[@]}))]}
9479 if (($MDS1_VERSION >= $(version_code 2.8.0))); then
9480 if [ $dirstripe_count -eq -1 ]; then
9481 dirstripe_count=$((RANDOM % MDSCOUNT + 1))
9487 echo "striped dir -i$mdt_index -c$dirstripe_count -H $hash_type $path"
9488 $LFS mkdir -i$mdt_index -c$dirstripe_count -H $hash_type $path ||
9489 error "mkdir -i $mdt_index -c$dirstripe_count -H $hash_type $path failed"
9493 # free_fd: find the smallest and not in use file descriptor [above @last_fd]
9495 # If called many times, passing @last_fd will avoid repeated searching
9496 # already-open FDs repeatedly if we know they are still in use.
9498 # usage: free_fd [last_fd]
9501 local max_fd=$(ulimit -n)
9502 local fd=$((${1:-2} + 1))
9504 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
9507 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
9511 check_mount_and_prep()
9513 is_mounted $MOUNT || setupall
9515 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
9516 mkdir_on_mdt0 $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
9517 for idx in $(seq $MDSCOUNT); do
9518 local name="MDT$(printf '%04x' $((idx - 1)))"
9519 rm -rf $MOUNT/.lustre/lost+found/$name/*
9523 # calcule how many ost-objects to be created.
9524 precreated_ost_obj_count()
9528 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
9529 local ost_name="OST$(printf '%04x' $ost_idx)"
9530 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
9531 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
9532 osp.$proc_path.prealloc_last_id)
9533 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
9534 osp.$proc_path.prealloc_next_id)
9535 echo $((last_id - next_id + 1))
9538 check_file_in_pool()
9543 local res=$($LFS getstripe $file | grep 0x | cut -f2)
9546 for t in $tlist ; do
9547 [ "$i" -eq "$t" ] && continue 2
9550 echo "pool list: $tlist"
9551 echo "striping: $res"
9552 error_noexit "$file not allocated in $pool"
9559 echo "Creating new pool"
9562 create_pool $FSNAME.$pool ||
9563 { error_noexit "No pool created, result code $?"; return 1; }
9564 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
9565 { error_noexit "$pool not in lfs pool_list"; return 2; }
9568 pool_add_targets() {
9569 echo "Adding targets to pool"
9575 if [ -z $last ]; then
9578 local list=$(seq $first $step $last)
9581 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
9582 local tg=$(for i in $list;
9583 do printf -- "-e $FSNAME-OST%04x_UUID " $i; done)
9584 local firstx=$(printf "%04x" $first)
9585 local lastx=$(printf "%04x" $last)
9587 do_facet mgs $LCTL pool_add \
9588 $FSNAME.$pool $FSNAME-OST[$firstx-$lastx/$step]
9590 if (( $? != 0 && $? != 17 )); then
9591 error_noexit "pool_add $FSNAME-OST[$firstx-$lastx/$step] failed"
9595 # wait for OSTs to be added to the pool
9596 for mds_id in $(seq $MDSCOUNT); do
9597 local mdt_id=$((mds_id-1))
9598 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
9599 wait_update_facet mds$mds_id \
9600 "lctl get_param -n lod.$lodname.pools.$pool |
9601 grep $tg | sort -u | tr '\n' ' '" "$t" || {
9602 error_noexit "mds$mds_id: Add to pool failed"
9606 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool |
9607 grep $tg | sort -u | tr '\n' ' ' " "$t" || {
9608 error_noexit "Add to pool failed"
9616 echo "Setting pool on directory $tdir"
9618 $LFS setstripe -c 2 -p $pool $tdir && return 0
9620 error_noexit "Cannot set pool $pool to $tdir"
9627 echo "Checking pool on directory $tdir"
9629 local res=$($LFS getstripe --pool $tdir | sed "s/\s*$//")
9630 [ "$res" = "$pool" ] && return 0
9632 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
9636 pool_dir_rel_path() {
9637 echo "Testing relative path works well"
9642 mkdir -p $root/$tdir/$tdir
9644 pool_set_dir $pool $tdir || return 1
9645 pool_set_dir $pool ./$tdir || return 2
9646 pool_set_dir $pool ../$tdir || return 3
9647 pool_set_dir $pool ../$tdir/$tdir || return 4
9648 rm -rf $tdir; cd - > /dev/null
9651 pool_alloc_files() {
9652 echo "Checking files allocation from directory pool"
9659 for i in $(seq -w 1 $count)
9661 local file=$tdir/file-$i
9663 check_file_in_pool $file $pool "$tlist" || \
9664 failed=$((failed + 1))
9666 [ "$failed" = 0 ] && return 0
9668 error_noexit "$failed files not allocated in $pool"
9672 pool_create_files() {
9673 echo "Creating files in pool"
9681 for i in $(seq -w 1 $count)
9683 local file=$tdir/spoo-$i
9684 $LFS setstripe -p $pool $file
9685 check_file_in_pool $file $pool "$tlist" || \
9686 failed=$((failed + 1))
9688 [ "$failed" = 0 ] && return 0
9690 error_noexit "$failed files not allocated in $pool"
9695 echo "Checking 'lfs df' output"
9698 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
9700 local res=$($LFS df --pool $FSNAME.$pool |
9702 grep "$FSNAME-OST" |
9704 [ "$res" = "$t" ] && return 0
9706 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
9710 pool_file_rel_path() {
9711 echo "Creating files in a pool with relative pathname"
9716 { error_noexit "unable to create $tdir"; return 1 ; }
9717 local file="/..$tdir/$tfile-1"
9718 $LFS setstripe -p $pool $file ||
9719 { error_noexit "unable to create $file" ; return 2 ; }
9722 $LFS setstripe -p $pool $tfile-2 || {
9723 error_noexit "unable to create $tfile-2 in $tdir"
9728 pool_remove_first_target() {
9729 echo "Removing first target from a pool"
9730 pool_remove_target $1 -1
9733 pool_remove_target() {
9737 local pname="lov.$FSNAME-*.pools.$pool"
9738 if [ $index -eq -1 ]; then
9739 local t=$($LCTL get_param -n $pname | head -1)
9741 local t=$(printf "$FSNAME-OST%04x_UUID" $index)
9744 echo "Removing $t from $pool"
9745 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
9746 for mds_id in $(seq $MDSCOUNT); do
9747 local mdt_id=$((mds_id-1))
9748 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
9749 wait_update_facet mds$mds_id \
9750 "lctl get_param -n lod.$lodname.pools.$pool |
9752 error_noexit "mds$mds_id: $t not removed from" \
9757 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
9758 error_noexit "$t not removed from $FSNAME.$pool"
9763 pool_remove_all_targets() {
9764 echo "Removing all targets from pool"
9767 local pname="lov.$FSNAME-*.pools.$pool"
9768 for t in $($LCTL get_param -n $pname | sort -u)
9770 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
9772 for mds_id in $(seq $MDSCOUNT); do
9773 local mdt_id=$((mds_id-1))
9774 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
9775 wait_update_facet mds$mds_id "lctl get_param -n \
9776 lod.$lodname.pools.$pool" "" || {
9777 error_noexit "mds$mds_id: Pool $pool not drained"
9781 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
9782 error_noexit "Pool $FSNAME.$pool cannot be drained"
9785 # striping on an empty/nonexistant pool should fall back
9786 # to "pool of everything"
9788 error_noexit "failed to use fallback striping for empty pool"
9791 # setstripe on an empty pool should fail
9792 $LFS setstripe -p $pool $file 2>/dev/null && {
9793 error_noexit "expected failure when creating file" \
9801 echo "Destroying pool"
9805 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
9808 # striping on an empty/nonexistant pool should fall back
9809 # to "pool of everything"
9811 error_noexit "failed to use fallback striping for missing pool"
9814 # setstripe on an empty pool should fail
9815 $LFS setstripe -p $pool $file 2>/dev/null && {
9816 error_noexit "expected failure when creating file" \
9821 # get param should return err once pool is gone
9822 if wait_update $HOSTNAME "lctl get_param -n \
9823 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
9825 remove_pool_from_list $FSNAME.$pool
9828 error_noexit "Pool $FSNAME.$pool is not destroyed"
9832 # Get and check the actual stripe count of one file.
9833 # Usage: check_stripe_count <file> <expected_stripe_count>
9834 check_stripe_count() {
9839 [[ -z "$file" || -z "$expected" ]] &&
9840 error "check_stripe_count: invalid argument"
9842 local cmd="$LFS getstripe -c $file"
9843 actual=$($cmd) || error "$cmd failed"
9844 actual=${actual%% *}
9846 if [[ $actual -ne $expected ]]; then
9847 [[ $expected -eq -1 ]] || { $LFS getstripe $file;
9848 error "$cmd not expected ($expected): found $actual"; }
9849 [[ $actual -eq $OSTCOUNT ]] || { $LFS getstripe $file;
9850 error "$cmd not OST count ($OSTCOUNT): found $actual"; }
9854 # Get and check the actual list of OST indices on one file.
9855 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
9861 [[ -z "$file" || -z "$expected" ]] &&
9862 error "check_obdidx: invalid argument!"
9864 obdidx=$(comma_list $($LFS getstripe $file | grep -A $OSTCOUNT obdidx |
9865 grep -v obdidx | awk '{print $1}' | xargs))
9867 [[ $obdidx = $expected ]] ||
9868 error "list of OST indices on $file is $obdidx," \
9869 "should be $expected"
9872 # Get and check the actual OST index of the first stripe on one file.
9873 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
9874 check_start_ost_idx() {
9879 [[ -z "$file" || -z "$expected" ]] &&
9880 error "check_start_ost_idx: invalid argument!"
9882 start_ost_idx=$($LFS getstripe $file | grep -A 1 obdidx |
9883 grep -v obdidx | awk '{print $1}')
9885 [[ $start_ost_idx = $expected ]] ||
9886 error "OST index of the first stripe on $file is" \
9887 "$start_ost_idx, should be $expected"
9890 killall_process () {
9891 local clients=${1:-$(hostname)}
9896 do_nodes $clients "killall $signal $name"
9901 do_facet mgs "$LCTL snapshot_create -F $FSNAME $*"
9906 do_facet mgs "$LCTL snapshot_destroy -F $FSNAME $*"
9911 do_facet mgs "$LCTL snapshot_modify -F $FSNAME $*"
9916 do_facet mgs "$LCTL snapshot_list -F $FSNAME $*"
9921 do_facet mgs "$LCTL snapshot_mount -F $FSNAME $*"
9926 do_facet mgs "$LCTL snapshot_umount -F $FSNAME $*"
9933 do_facet mgs "cat $LSNAPSHOT_LOG"
9939 echo "Cleaning test environment ..."
9941 # Every lsnapshot command takes exclusive lock with others,
9942 # so can NOT destroy the snapshot during list with 'xargs'.
9944 local ssname=$(lsnapshot_list | grep snapshot_name |
9945 grep lss_ | awk '{ print $2 }' | head -n 1)
9946 [ -z "$ssname" ] && break
9948 lsnapshot_destroy -n $ssname -f ||
9949 lss_err "Fail to destroy $ssname by force"
9959 local host=$(facet_active_host $facet)
9960 local dir=$(dirname $(facet_vdevice $facet))
9961 local pool=$(zpool_name $facet)
9962 local lfsname=$(zfs_local_fsname $facet)
9963 local label=${FSNAME}-${role}$(printf '%04x' $idx)
9966 "echo '$host - $label zfs:${dir}/${pool}/${lfsname} - -' >> \
9972 do_facet mgs "rm -f $LSNAPSHOT_CONF"
9973 echo "Generating $LSNAPSHOT_CONF on MGS ..."
9975 if ! combined_mgs_mds ; then
9976 [ $(facet_fstype mgs) != zfs ] &&
9977 skip "Lustre snapshot 1 only works for ZFS backend"
9979 local host=$(facet_active_host mgs)
9980 local dir=$(dirname $(facet_vdevice mgs))
9981 local pool=$(zpool_name mgs)
9982 local lfsname=$(zfs_local_fsname mgs)
9985 "echo '$host - MGS zfs:${dir}/${pool}/${lfsname} - -' \
9986 >> $LSNAPSHOT_CONF" || lss_err "generate lss conf (mgs)"
9989 for num in `seq $MDSCOUNT`; do
9990 [ $(facet_fstype mds$num) != zfs ] &&
9991 skip "Lustre snapshot 1 only works for ZFS backend"
9993 lss_gen_conf_one mds$num MDT $((num - 1)) ||
9994 lss_err "generate lss conf (mds$num)"
9997 for num in `seq $OSTCOUNT`; do
9998 [ $(facet_fstype ost$num) != zfs ] &&
9999 skip "Lustre snapshot 1 only works for ZFS backend"
10001 lss_gen_conf_one ost$num OST $((num - 1)) ||
10002 lss_err "generate lss conf (ost$num)"
10005 do_facet mgs "cat $LSNAPSHOT_CONF"
10008 # Parse 'lfs getstripe -d <path_with_dir_name>' for non-composite dir
10009 parse_plain_dir_param()
10011 local invalues=($1)
10014 if [[ ${invalues[0]} =~ "stripe_count:" ]]; then
10015 param="-c ${invalues[1]}"
10017 if [[ ${invalues[2]} =~ "stripe_size:" ]]; then
10018 param="$param -S ${invalues[3]}"
10020 if [[ ${invalues[4]} =~ "pattern:" ]]; then
10021 if [[ ${invalues[5]} =~ "stripe_offset:" ]]; then
10022 param="$param -i ${invalues[6]}"
10024 param="$param -L ${invalues[5]} -i ${invalues[7]}"
10026 elif [[ ${invalues[4]} =~ "stripe_offset:" ]]; then
10027 param="$param -i ${invalues[5]}"
10032 parse_plain_param()
10035 local val=$(awk '{print $2}' <<< $line)
10037 if [[ $line =~ ^"lmm_stripe_count:" ]]; then
10039 elif [[ $line =~ ^"lmm_stripe_size:" ]]; then
10041 elif [[ $line =~ ^"lmm_stripe_offset:" && $SKIP_INDEX != yes ]]; then
10043 elif [[ $line =~ ^"lmm_pattern:" ]]; then
10048 parse_layout_param()
10054 while read line; do
10055 if [[ ! -z $line ]]; then
10056 if [[ -z $mode ]]; then
10057 if [[ $line =~ ^"stripe_count:" ]]; then
10059 elif [[ $line =~ ^"lmm_stripe_count:" ]]; then
10061 elif [[ $line =~ ^"lcm_layout_gen:" ]]; then
10066 if [[ $mode = "plain_dir" ]]; then
10067 param=$(parse_plain_dir_param "$line")
10068 elif [[ $mode = "plain_file" ]]; then
10069 val=$(parse_plain_param "$line")
10070 [[ ! -z $val ]] && param="$param $val"
10071 elif [[ $mode = "pfl" ]]; then
10072 val=$(echo $line | awk '{print $2}')
10073 if [[ $line =~ ^"lcme_extent.e_end:" ]]; then
10074 if [[ $val = "EOF" ]]; then
10075 param="$param -E -1"
10077 param="$param -E $val"
10079 elif [[ $line =~ ^"stripe_count:" ]]; then
10081 val=$(parse_plain_dir_param "$line")
10082 param="$param $val"
10085 val=$(parse_plain_param "$line")
10086 [[ ! -z $val ]] && param="$param $val"
10096 local param=$($LFS getstripe -d $1 | parse_layout_param)
10100 lfsck_verify_pfid()
10105 # Cancel locks before setting lfsck_verify_pfid so that errors are more
10107 cancel_lru_locks mdc
10108 cancel_lru_locks osc
10110 # make sure PFID is set correctly for files
10111 do_nodes $(comma_list $(osts_nodes)) \
10112 "$LCTL set_param -n obdfilter.${FSNAME}-OST*.lfsck_verify_pfid=1"
10115 cat $f &> /dev/nullA ||
10116 { rc=$?; echo "verify $f failed"; break; }
10119 do_nodes $(comma_list $(osts_nodes)) \
10120 "$LCTL set_param -n obdfilter.${FSNAME}-OST*.lfsck_verify_pfid=0"
10124 # check that clients "oscs" was evicted after "before"
10125 check_clients_evicted() {
10132 for osc in $oscs; do
10133 echo "Check state for $osc"
10134 local evicted=$(do_facet client $LCTL get_param osc.$osc.state |
10135 tail -n 5 | awk -F"[ ,]" \
10136 '/EVICTED/ { if (mx<$4) { mx=$4; } } END { print mx }')
10137 if (($? == 0)) && (($evicted > $before)); then
10138 echo "$osc is evicted at $evicted"
10141 echo "$osc was not evicted after $before:"
10142 do_facet client $LCTL get_param osc.$osc.state |
10147 [ $rc -eq 0 ] || error "client not evicted from OST"
10150 # check that clients OSCS current_state is FULL
10151 check_clients_full() {
10156 for osc in $oscs; do
10157 wait_update_facet client \
10158 "lctl get_param -n osc.$osc.state |
10159 grep 'current_state: FULL'" \
10160 "current_state: FULL" $timeout
10161 [ $? -eq 0 ] || error "$osc state is not FULL"
10166 __changelog_deregister() {
10168 local mdt="$(facet_svc $facet)"
10172 # skip cleanup if no user registered for this MDT
10173 [ -z "$cl_user" ] && echo "$mdt: no changelog user" && return 0
10174 # user is no longer registered, skip cleanup
10175 changelog_users "$facet" | grep -q "$cl_user" ||
10176 { echo "$mdt: changelog user '$cl_user' not found"; return 0; }
10178 # From this point, if any operation fails, it is an error
10179 __changelog_clear $facet $cl_user 0 ||
10180 error_noexit "$mdt: changelog_clear $cl_user 0 fail: $rc"
10181 do_facet $facet $LCTL --device $mdt changelog_deregister $cl_user ||
10182 error_noexit "$mdt: changelog_deregister '$cl_user' fail: $rc"
10185 declare -Ax CL_USERS
10186 changelog_register() {
10187 for M in $(seq $MDSCOUNT); do
10189 local mdt="$(facet_svc $facet)"
10192 cl_mask=$(do_facet $facet $LCTL get_param \
10193 mdd.${mdt}.changelog_mask -n)
10194 stack_trap "do_facet $facet $LCTL \
10195 set_param mdd.$mdt.changelog_mask=\'$cl_mask\' -n" EXIT
10196 do_facet $facet $LCTL set_param mdd.$mdt.changelog_mask=+hsm ||
10197 error "$mdt: changelog_mask=+hsm failed: $?"
10200 cl_user=$(do_facet $facet $LCTL --device $mdt \
10201 changelog_register -n "$@") ||
10202 error "$mdt: register changelog user failed: $?"
10203 stack_trap "__changelog_deregister $facet $cl_user" EXIT
10205 stack_trap "CL_USERS[$facet]='${CL_USERS[$facet]}'" EXIT
10206 # Bash does not support nested arrays, but the format of a
10207 # cl_user is constrained enough to use whitespaces as separators
10208 CL_USERS[$facet]+="$cl_user "
10210 echo "Registered $MDSCOUNT changelog users: '${CL_USERS[*]% }'"
10213 changelog_deregister() {
10215 # bash assoc arrays do not guarantee to list keys in created order
10216 # so reorder to get same order than in changelog_register()
10217 local cl_facets=$(echo "${!CL_USERS[@]}" | tr " " "\n" | sort |
10220 for facet in $cl_facets; do
10221 for cl_user in ${CL_USERS[$facet]}; do
10222 __changelog_deregister $facet $cl_user || return $?
10224 unset CL_USERS[$facet]
10228 changelog_users() {
10230 local service=$(facet_svc $facet)
10232 do_facet $facet $LCTL get_param -n mdd.$service.changelog_users
10235 changelog_user_rec() {
10238 local service=$(facet_svc $facet)
10240 changelog_users $facet | awk '$1 == "'$cl_user'" { print $2 }'
10243 changelog_chmask() {
10246 do_nodes $(comma_list $(mdts_nodes)) \
10247 $LCTL set_param mdd.*.changelog_mask="$mask"
10250 # usage: __changelog_clear FACET CL_USER [+]INDEX
10251 __changelog_clear()
10254 local mdt="$(facet_svc $facet)"
10260 # Remove the leading '+'
10262 rec+=$(changelog_user_rec $facet $cl_user)
10269 if [ $rec -eq 0 ]; then
10270 echo "$mdt: clear the changelog for $cl_user of all records"
10272 echo "$mdt: clear the changelog for $cl_user to record #$rec"
10274 $LFS changelog_clear $mdt $cl_user $rec
10277 # usage: changelog_clear [+]INDEX [facet]...
10279 # If INDEX is prefixed with '+', increment every changelog user's record index
10280 # by INDEX. Otherwise, clear the changelog up to INDEX for every changelog
10282 changelog_clear() {
10286 local cl_facets="$@"
10287 # bash assoc arrays do not guarantee to list keys in created order
10288 # so reorder to get same order than in changelog_register()
10289 [[ -n "$cl_facets" ]] ||
10290 cl_facets=$(echo "${!CL_USERS[@]}" | tr " " "\n" | sort |
10294 for facet in $cl_facets; do
10295 for cl_user in ${CL_USERS[$facet]}; do
10296 __changelog_clear $facet $cl_user $idx || rc=${rc:-$?}
10306 for M in $(seq $MDSCOUNT); do
10308 local mdt="$(facet_svc $facet)"
10312 output=$($LFS changelog $mdt)
10314 if [ $ret -ne 0 ]; then
10316 elif [ -n "$output" ]; then
10317 echo "$output" | sed -e 's/^/'$mdt'./'
10324 changelog_extract_field() {
10327 local identifier=$3
10329 changelog_dump | gawk "/$cltype.*$file$/ {
10330 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
10334 # Prints a changelog record produced by "lfs changelog" as an associative array
10337 # $> changelog2array 16 01CREAT 10:28:46.968438800 2018.03.09 0x0 \
10338 # t=[0x200000401:0x10:0x0] j=touch.501 ef=0xf u=501:501 \
10339 # nid=0@lo p=[0x200000007:0x1:0x0] blob
10340 # ([index]='16' [type]='CREAT' [time]='10:28:46.968438800'
10341 # [date]='2018.03.09' [flags]=0x0 ['target-fid']='[0x200000401:0x10:0x0]'
10342 # ['jobid']='touch.501' ['extra-flags']='0x0f' [uid]='0' ['gid']='0'
10343 # ['nid']='0@lo' ['parent-fid']='[0x200000007:0x1:0x0]')
10345 # Note that the changelog record is not quoted
10346 # Also note that the line breaks in the output were only added for readability
10348 # Typically, you want to eval the output of the command to fill an actual
10349 # associative array, like this:
10350 # $> eval declare -A changelog=$(changelog2array $entry)
10352 # It can then be accessed like any bash associative array:
10353 # $> echo "${changelog[index]}" "${changelog[type]}" "${changelog[flags]}"
10355 # $> echo "${changelog[uid]}":"${changelog[gid]}"
10363 # A changelog, as printed by "lfs changelog" typically looks like this:
10364 # <index> <type> <time> <date> <flags> <key1=value1> <key2=value2> ...
10366 # Parse the positional part of the changelog
10368 # changelog_dump() prefixes records with their mdt's name
10369 local index="${1##*.}"
10371 printf "[index]='%s' [type]='%s' [time]='%s' [date]='%s' [flags]='%s'" \
10372 "$index" "${2:2}" "$3" "$4" "$5"
10374 # Parse the key/value part of the changelog
10375 for arg in "${@:5}"; do
10376 # Check it matches a key=value syntax
10377 [[ "$arg" =~ ^[[:alpha:]]+= ]] || continue
10379 local key="${arg%%=*}"
10380 local value="${arg#*=}"
10384 # u is actually for uid AND gid: u=UID:GID
10385 printf " [uid]='%s'" "${value%:*}"
10387 value="${value#*:}"
10415 printf " ['%s']='%s'" "$key" "$value"
10422 # Format and print a changelog record
10424 # Interpreted sequences are:
10426 # %f the "flags" attribute of a changelog record
10427 __changelog_printf()
10432 for ((i = 0; i < ${#format}; i++)); do
10433 local char="${format:$i:1}"
10434 if [ "$char" != % ]; then
10435 printf '%c' "$char"
10440 char="${format:$i:1}"
10443 printf '%s' "${changelog[flags]}"
10453 # Filter changelog records
10457 local action='print'
10460 while [ $# -gt 0 ]; do
10471 filter[${1#-}]="$2"
10480 changelog_dump | { while read -r record; do
10481 eval local -A changelog=$(changelog2array $record)
10482 for key in "${!filter[@]}"; do
10485 [ "${changelog[$key]}" == "${filter[$key]}" ]
10492 case "${action:-print}" in
10494 printf '%s\n' "$record"
10497 __changelog_printf "$format"
10507 [ ! -d "$dir" ] && return
10509 [ -z "$layout" ] && {
10510 $LFS setstripe -d $dir || error "error deleting stripe '$dir'"
10514 setfattr -n trusted.lov -v $layout $dir ||
10515 error "error restoring layout '$layout' to '$dir'"
10518 # save the layout of a directory, the returned string will be used by
10519 # restore_layout() to restore the layout
10522 local str=$(getfattr -n trusted.lov --absolute-names -e hex $dir \
10523 2> /dev/null | awk -F'=' '/trusted.lov/{ print $2 }')
10527 # save layout of a directory and restore it at exit
10528 save_layout_restore_at_exit() {
10530 local layout=$(save_layout $dir)
10532 stack_trap "restore_layout $dir $layout" EXIT
10535 verify_yaml_layout() {
10539 local msg_prefix=$4
10541 echo "getstripe --yaml $src"
10542 $LFS getstripe --yaml $src > $temp || error "getstripe $src failed"
10543 echo "setstripe --yaml=$temp $dst"
10544 $LFS setstripe --yaml=$temp $dst|| error "setstripe $dst failed"
10547 local layout1=$(get_layout_param $src)
10548 local layout2=$(get_layout_param $dst)
10549 # compare their layout info
10550 [ "$layout1" == "$layout2" ] ||
10551 error "$msg_prefix $src/$dst layouts are not equal"
10554 is_project_quota_supported() {
10555 $ENABLE_PROJECT_QUOTAS || return 1
10556 [[ -z "$SAVE_PROJECT_SUPPORTED" ]] || return $SAVE_PROJECT_SUPPORTED
10557 local save_project_supported=1
10559 [[ "$(facet_fstype $SINGLEMDS)" == "ldiskfs" &&
10560 $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.9.55) ]] &&
10561 do_facet mds1 lfs --list-commands |& grep -q project &&
10562 save_project_supported=0
10564 [[ "$(facet_fstype $SINGLEMDS)" == "zfs" &&
10565 $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.10.53) ]] &&
10566 do_facet mds1 $ZPOOL get all | grep -q project_quota &&
10567 save_project_supported=0
10569 # cache state of project quotas once instead of re-checking each time
10570 export SAVE_PROJECT_SUPPORTED=$save_project_supported
10571 echo "using SAVE_PROJECT_SUPPORTED=$SAVE_PROJECT_SUPPORTED"
10573 return $save_project_supported
10576 # ZFS project quota enable/disable:
10577 # This feature will become active as soon as it is enabled and will never
10578 # return to being disabled. Each filesystem will be upgraded automatically
10579 # when remounted or when [a] new file is created under that filesystem. The
10580 # upgrade can also be triggered on filesystems via `zfs set version=current
10581 # <pool/fs>`. The upgrade process runs in the background and may take a
10582 # while to complete for the filesystems containing a large number of files.
10583 enable_project_quota() {
10584 is_project_quota_supported || return 0
10585 local zkeeper=${KEEP_ZPOOL}
10586 stack_trap "KEEP_ZPOOL=$zkeeper" EXIT
10588 stopall || error "failed to stopall (1)"
10590 local zfeat_en="feature@project_quota=enabled"
10591 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
10592 local facet_fstype=${facet:0:3}1_FSTYPE
10595 if [ "${!facet_fstype}" = "zfs" ]; then
10596 devname=$(zpool_name ${facet})
10597 do_facet ${facet} $ZPOOL set "$zfeat_en" $devname ||
10598 error "$ZPOOL set $zfeat_en $devname"
10600 [ ${facet:0:3} == "mds" ] &&
10601 devname=$(mdsdevname ${facet:3}) ||
10602 devname=$(ostdevname ${facet:3})
10603 do_facet ${facet} $TUNE2FS -O project $devname ||
10604 error "tune2fs $devname failed"
10608 KEEP_ZPOOL="${zkeeper}"
10613 disable_project_quota() {
10614 is_project_quota_supported || return 0
10615 [ "$mds1_FSTYPE" != "ldiskfs" ] && return 0
10616 stopall || error "failed to stopall (1)"
10618 for num in $(seq $MDSCOUNT); do
10619 do_facet mds$num $TUNE2FS -Q ^prj $(mdsdevname $num) ||
10620 error "tune2fs $(mdsdevname $num) failed"
10623 for num in $(seq $OSTCOUNT); do
10624 do_facet ost$num $TUNE2FS -Q ^prj $(ostdevname $num) ||
10625 error "tune2fs $(ostdevname $num) failed"
10633 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
10634 # the following associated variables are added:
10636 # AGTCOUNT: number of agents
10637 # AGTDEV{N}: target HSM mount point (root path of the backend)
10638 # agt{N}_HOST: hostname of the agent agt{N}
10639 # SINGLEAGT: facet of the single agent
10641 # The number of agents is initialized as the number of remote client nodes.
10642 # By default, only single copytool is started on a remote client/agent. If there
10643 # was no remote client, then the copytool will be started on the local client.
10649 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
10650 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
10652 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
10653 if [[ $CLIENTCOUNT -gt 1 ]] &&
10654 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
10655 skip_env "SHARED_DIRECTORY should be accessible"\
10656 "on all client nodes"
10660 # We used to put the HSM archive in $SHARED_DIRECTORY but that
10661 # meant NFS issues could hose sanity-hsm sessions. So now we
10662 # use $TMP instead.
10663 for n in $(seq $AGTCOUNT); do
10664 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
10665 agent=CLIENT$((n + 1))
10666 if [[ -z "${!agent}" ]]; then
10667 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
10670 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
10671 local var=agt${n}_HOST
10672 [[ ! -z "${!var}" ]] || error "agt${n}_HOST is empty!"
10675 export SINGLEAGT=${SINGLEAGT:-agt1}
10677 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
10678 export HSMTOOL_PID_FILE=${HSMTOOL_PID_FILE:-"/var/run/lhsmtool_posix.pid"}
10679 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
10680 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
10681 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
10682 export HSMTOOL_TESTDIR
10683 export HSMTOOL_ARCHIVE_FORMAT=${HSMTOOL_ARCHIVE_FORMAT:-v2}
10685 if ! [[ $HSMTOOL =~ hsmtool ]]; then
10686 echo "HSMTOOL = '$HSMTOOL' does not contain 'hsmtool', GLWT" >&2
10689 HSM_ARCHIVE_NUMBER=2
10691 # The test only support up to 10 MDTs
10692 MDT_PREFIX="mdt.$FSNAME-MDT000"
10693 HSM_PARAM="${MDT_PREFIX}0.hsm"
10695 # archive is purged at copytool setup
10696 HSM_ARCHIVE_PURGE=true
10698 # Don't allow copytool error upon start/setup
10699 HSMTOOL_NOERROR=false
10702 # Get the backend root path for the given agent facet.
10703 copytool_device() {
10705 local dev=AGTDEV$(facet_number $facet)
10710 get_mdt_devices() {
10712 # get MDT device for each mdc
10713 for mdtno in $(seq 1 $MDSCOUNT); do
10714 local idx=$(($mdtno - 1))
10715 MDT[$idx]=$($LCTL get_param -n \
10716 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
10717 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
10721 pkill_copytools() {
10725 do_nodes "$hosts" \
10726 "pkill --pidfile=$HSMTOOL_PID_FILE --signal=$signal hsmtool"
10729 copytool_continue() {
10730 local agents=${1:-$(facet_active_host $SINGLEAGT)}
10732 pkill_copytools "$agents" CONT || return 0
10733 echo "Copytool is continued on $agents"
10737 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
10739 echo "Killing existing copytools on $hosts"
10740 pkill_copytools "$hosts" TERM || return 0
10741 copytool_continue "$hosts"
10744 copytool_monitor_cleanup() {
10745 local facet=${1:-$SINGLEAGT}
10746 local agent=$(facet_active_host $facet)
10748 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
10749 # Should die when the copytool dies, but just in case.
10750 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
10751 cmd+=" 2>/dev/null || true"
10752 do_node $agent "$cmd"
10753 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
10754 export HSMTOOL_MONITOR_DIR=
10757 # The pdsh should die on its own when the monitor dies. Just
10758 # in case, though, try to clean up to avoid any cruft.
10759 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
10760 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null || true
10761 export HSMTOOL_MONITOR_PDSH=
10767 local host="$(facet_host "$1")"
10768 local prefix=$TESTLOG_PREFIX
10769 [ -n "$TESTNAME" ] && prefix+=.$TESTNAME
10771 printf "${prefix}.copytool${archive_id}_log.${host}.log"
10774 __lhsmtool_rebind()
10776 do_facet $facet $HSMTOOL \
10777 "${hsmtool_options[@]}" --rebind "$@" "$mountpoint"
10780 __lhsmtool_import()
10782 mkdir -p "$(dirname "$2")" ||
10783 error "cannot create directory '$(dirname "$2")'"
10784 do_facet $facet $HSMTOOL \
10785 "${hsmtool_options[@]}" --import "$@" "$mountpoint"
10790 local host="$(facet_host "$facet")"
10791 local cmd="$HSMTOOL ${hsmtool_options[@]} --daemon --pid-file=$HSMTOOL_PID_FILE"
10793 [ -n "$bandwidth" ] && cmd+=" --bandwidth $bandwidth"
10794 [ -n "$archive_id" ] && cmd+=" --archive $archive_id"
10795 # [ ${#misc_options[@]} -gt 0 ] &&
10796 # cmd+=" $(IFS=" " echo "$@")"
10797 cmd+=" $@ \"$mountpoint\""
10799 echo "Starting copytool '$facet' on '$host' with cmdline '$cmd'"
10800 stack_trap "pkill_copytools $host TERM || true" EXIT
10801 do_node "$host" "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
10805 local facet="${1:-$SINGLEAGT}"
10807 printf "$(copytool_device "$facet")/${TESTSUITE}.${TESTNAME}/"
10810 # Main entry point to perform copytool related operations
10814 # setup setup a copytool to run in the background, that copytool will be
10816 # import import a file from an HSM backend
10817 # rebind rebind an archived file to a new fid
10819 # Although the semantics might suggest otherwise, one does not need to 'setup'
10820 # a copytool before a call to 'copytool import' or 'copytool rebind'.
10827 # Use default values
10828 local facet=$SINGLEAGT
10829 local mountpoint="${MOUNT2:-$MOUNT}"
10832 local fail_on_error=true
10833 local -a hsmtool_options=()
10834 local -a action_options=()
10836 if [[ -n "$HSMTOOL_ARCHIVE_FORMAT" ]]; then
10837 hsmtool_options+=("--archive-format=$HSMTOOL_ARCHIVE_FORMAT")
10840 if [[ -n "$HSMTOOL_VERBOSE" ]]; then
10841 hsmtool_options+=("$HSMTOOL_VERBOSE")
10844 while [ $# -gt 0 ]; do
10856 local archive_id="$1"
10860 local hsm_root="$1"
10864 local bandwidth="$1" # in MB/s
10867 local fail_on_error=false
10870 # Uncommon(/copytool dependent) option
10871 action_options+=("$1")
10877 local hsm_root="${hsm_root:-$(hsm_root "$facet")}"
10878 hsmtool_options+=("--hsm-root=$hsm_root")
10880 stack_trap "do_facet $facet rm -rf '$hsm_root'" EXIT
10881 do_facet $facet mkdir -p "$hsm_root" ||
10882 error "mkdir '$hsm_root' failed"
10886 local copytool=lhsmtool
10890 __${copytool}_${action} "${action_options[@]}"
10891 if [ $? -ne 0 ]; then
10896 local host="$(facet_host $facet)"
10897 error_msg="Failed to start copytool $facet on '$host'"
10900 local src="${action_options[0]}"
10901 local dest="${action_options[1]}"
10902 error_msg="Failed to import '$src' to '$dest'"
10905 error_msg="could not rebind file"
10909 $fail_on_error && error "$error_msg" || echo "$error_msg"
10914 local client_count=$1
10915 if [[ $CLIENTCOUNT -lt $client_count ]]; then
10916 skip "Need $client_count or more clients, have $CLIENTCOUNT"
10923 $LFS path2fid $1 | tr -d '[]'
10924 return ${PIPESTATUS[0]}
10932 if [[ $u == "user" ]]; then
10933 st=$($RUNAS $LFS hsm_state $f)
10936 st=$($LFS hsm_state $f)
10939 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
10941 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
10945 check_hsm_flags() {
10949 local st=$(get_hsm_flags $f)
10950 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
10959 if [[ "$value" != "" ]]; then
10962 for mdtno in $(seq 1 $MDSCOUNT); do
10963 local idx=$(($mdtno - 1))
10964 local facet=mds${mdtno}
10965 # if $arg include -P option, run 1 set_param per MDT on the MGS
10966 # else, run set_param on each MDT
10967 [[ $arg = *"-P"* ]] && facet=mgs
10968 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
10969 [[ $? != 0 ]] && rc=1
10974 mdts_check_param() {
10980 for mdtno in $(seq 1 $MDSCOUNT); do
10981 local idx=$(($mdtno - 1))
10982 wait_update_facet --verbose mds${mdtno} \
10983 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
10985 error "$key state is not '$target' on mds${mdtno}"
10989 cdt_set_mount_state() {
10990 mdts_set_param "-P" hsm_control "$1"
10991 # set_param -P is asynchronous operation and could race with set_param.
10992 # In such case configs could be retrieved and applied at mgc after
10993 # set_param -P completion. Sleep here to avoid race with set_param.
10994 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
10995 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
10996 # and 10 seconds to retrieve config from server.
11000 cdt_check_state() {
11001 mdts_check_param hsm_control "$1" 20
11004 cdt_set_sanity_policy() {
11005 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
11008 mdts_set_param "" hsm.policy "+NRA"
11009 mdts_set_param "" hsm.policy "-NBR"
11010 CDT_POLICY_HAD_CHANGED=
11018 mdts_set_param "$opt -n" "hsm.$param" "$value"
11022 wait_request_state() {
11026 # 4th arg (mdt index) is optional
11027 local mdtidx=${4:-0}
11028 local mds=mds$(($mdtidx + 1))
11030 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
11031 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
11033 wait_update_facet --verbose $mds "$cmd" "$state" 200 ||
11034 error "request on $fid is not $state on $mds"
11042 local WAIT_MAX=${4:-60}
11045 # We need to run do_node in bg, because pdsh does not exit
11046 # if child process of run script exists.
11047 # I.e. pdsh does not exit when runmultiop_bg_pause exited,
11048 # because of multiop_bg_pause -> $MULTIOP_PROG &
11049 # By the same reason we need sleep a bit after do_nodes starts
11050 # to let runmultiop_bg_pause start muliop and
11051 # update /tmp/multiop_bg.pid ;
11052 # The rm /tmp/multiop_bg.pid guarantees here that
11053 # we have the updated by runmultiop_bg_pause
11054 # /tmp/multiop_bg.pid file
11056 local pid_file=$TMP/multiop_bg.pid.$$
11058 do_node $client "MULTIOP_PID_FILE=$pid_file LUSTRE= \
11059 runmultiop_bg_pause $file $cmds" &
11063 while [[ $wait_time -lt $WAIT_MAX ]]; do
11065 wait_time=$((wait_time + 3))
11066 multiop_pid=$(do_node $client cat $pid_file)
11067 if [ -n "$multiop_pid" ]; then
11072 [ -n "$multiop_pid" ] ||
11073 error "$client : Can not get multiop_pid from $pid_file "
11075 eval export $(node_var_name $client)_multiop_pid=$multiop_pid
11076 eval export $(node_var_name $client)_do_node_pid=$pid
11077 local var=$(node_var_name $client)_multiop_pid
11078 echo client $client multiop_bg started multiop_pid=${!var}
11084 local multiop_pid=$(node_var_name $client)_multiop_pid
11085 local do_node_pid=$(node_var_name $client)_do_node_pid
11087 echo "Stopping multiop_pid=${!multiop_pid} (kill ${!multiop_pid} on $client)"
11088 do_node $client kill -USR1 ${!multiop_pid}
11090 wait ${!do_node_pid}
11094 local delay=$(do_facet $SINGLEMDS lctl get_param -n lo[vd].*.qos_maxage |
11095 awk '{ print $1 * 2; exit; }')
11099 check_component_count() {
11100 local comp_cnt=$($LFS getstripe --component-count $1)
11101 [ $comp_cnt -eq $2 ] || error "$1, component count $comp_cnt != $2"
11104 # Verify there are no init components with "extension" flag
11105 verify_no_init_extension() {
11106 local flg_opts="--component-flags init,extension"
11107 local found=$($LFS find $flg_opts $1 | wc -l)
11108 [ $found -eq 0 ] || error "$1 has component with initialized extension"
11111 # Verify there is at least one component starting at 0
11112 verify_comp_at_zero() {
11113 flg_opts="--component-flags init"
11114 found=$($LFS find --component-start 0M $flg_opts $1 | wc -l)
11115 [ $found -eq 1 ] ||
11116 error "No component starting at zero(!)"
11119 # version after which Self-Extending Layouts are available
11122 sel_layout_sanity() {
11126 verify_no_init_extension $file
11127 verify_comp_at_zero $file
11128 check_component_count $file $comp_cnt
11131 statx_supported() {
11132 $STATX --quiet --version
11136 # lfs rm_entry is disabled on native client
11137 is_rmentry_supported() {
11138 $LFS rm_entry $DIR/dir/not/exists > /dev/null
11139 # is return code ENOENT?
11144 # wrappers for createmany and unlinkmany
11145 # to set debug=0 if number of creates is high enough
11146 # this is to speedup testing
11148 function createmany() {
11152 if (( count > 100 )); then
11154 do_nodes $(comma_list $(all_nodes)) $LCTL set_param -n debug=0
11156 $LUSTRE/tests/createmany $*
11158 debugrestore > /dev/null
11163 function unlinkmany() {
11167 if (( count > 100 )); then
11169 do_nodes $(comma_list $(all_nodes)) $LCTL set_param -n debug=0
11171 $LUSTRE/tests/unlinkmany $*
11173 debugrestore > /dev/null
11178 # Check if fallocate on facet is working. Returns fallocate mode if enabled.
11179 # Takes optional facet name as argument, to allow separate MDS/OSS checks.
11180 function check_fallocate_supported()
11182 local facet=${1:-ost1}
11183 local supported="FALLOCATE_SUPPORTED_$facet"
11184 local fstype="${facet}_FSTYPE"
11186 if [[ -n "${!supported}" ]]; then
11187 echo "${!supported}"
11190 if [[ -z "${!fstype}" ]]; then
11191 eval export $fstype=$(facet_fstype $facet)
11193 if [[ "${!fstype}" != "ldiskfs" ]]; then
11194 echo "fallocate on ${!fstype} doesn't consume space" 1>&2
11198 local fa_mode="osd-ldiskfs.$(facet_svc $facet).fallocate_zero_blocks"
11199 local mode=$(do_facet $facet $LCTL get_param -n $fa_mode 2>/dev/null |
11202 if [[ -z "$mode" ]]; then
11203 echo "fallocate not supported on $facet" 1>&2
11206 eval export $supported="$mode"
11212 # Check if fallocate supported on OSTs, enable if unset, skip if unavailable.
11213 # Takes optional facet name as argument.
11214 function check_fallocate_or_skip()
11218 check_fallocate_supported $1 || skip "fallocate not supported"
11221 # Check if fallocate supported on OSTs, enable if unset, default mode=0
11222 # Optionally pass the OST fallocate mode (0=unwritten extents, 1=zero extents)
11223 function check_set_fallocate()
11225 local new_mode="$1"
11226 local fa_mode="osd-ldiskfs.*.fallocate_zero_blocks"
11227 local old_mode="$(check_fallocate_supported)"
11229 [[ -n "$old_mode" ]] || { echo "fallocate not supported"; return 1; }
11230 [[ -z "$new_mode" && "$old_mode" != "-1" ]] &&
11231 { echo "keep default fallocate mode: $old_mode"; return 0; }
11232 [[ "$new_mode" && "$old_mode" == "$new_mode" ]] &&
11233 { echo "keep current fallocate mode: $old_mode"; return 0; }
11234 local osts=$(comma_list $(osts_nodes))
11236 stack_trap "do_nodes $osts $LCTL set_param $fa_mode=$old_mode"
11237 do_nodes $osts $LCTL set_param $fa_mode=${new_mode:-0} ||
11238 error "set $fa_mode=$new_mode"
11241 # Check if fallocate supported on OSTs, enable if unset, skip if unavailable
11242 function check_set_fallocate_or_skip()
11244 check_set_fallocate || skip "need >= 2.13.57 and ldiskfs for fallocate"
11247 function disable_opencache()
11249 local state=$($LCTL get_param -n "llite.*.opencache_threshold_count" |
11252 test -z "${saved_OPENCACHE_value}" &&
11253 export saved_OPENCACHE_value="$state"
11255 [[ "$state" = "off" ]] && return
11257 $LCTL set_param -n "llite.*.opencache_threshold_count"=off
11260 function set_opencache()
11262 local newvalue="$1"
11263 local state=$($LCTL get_param -n "llite.*.opencache_threshold_count")
11265 [[ -n "$newvalue" ]] || return
11267 [[ -n "${saved_OPENCACHE_value}" ]] ||
11268 export saved_OPENCACHE_value="$state"
11270 $LCTL set_param -n "llite.*.opencache_threshold_count"=$newvalue
11275 function restore_opencache()
11277 [[ -z "${saved_OPENCACHE_value}" ]] ||
11278 $LCTL set_param -n "llite.*.opencache_threshold_count"=${saved_OPENCACHE_value}
11281 # LU-13417: XXX lots of tests assume the directory to be created under MDT0,
11282 # created on MDT0, use this function to create directory on specific MDT
11283 # explicitly, and set default LMV to create subdirs on the same MDT too.
11288 while getopts "i:" opt $*; do
11294 shift $((OPTIND - 1))
11296 $LFS mkdir -i $mdt -c 1 $*
11300 mkdir_on_mdt -i0 $*
11303 # Wait for nodemap synchronization
11305 local nodemap_name=$1
11310 local is_active=$(do_facet mgs $LCTL get_param -n nodemap.active)
11311 local max_retries=20
11315 local mgs_ip=$(host_nids_address $mgs_HOST $NETTYPE | cut -d' ' -f1)
11318 if [ "$nodemap_name" == "active" ]; then
11319 proc_param="active"
11320 elif [ -z "$key" ]; then
11321 proc_param=${nodemap_name}
11323 proc_param="${nodemap_name}.${key}"
11325 if [ "$opt" == "inactive" ]; then
11326 # check nm sync even if nodemap is not activated
11330 (( is_active == 0 )) && [ "$proc_param" != "active" ] && return
11332 if [ -z "$value" ]; then
11333 out1=$(do_facet mgs $LCTL get_param $opt \
11334 nodemap.${proc_param} 2>/dev/null)
11335 echo "On MGS ${mgs_ip}, ${proc_param} = $out1"
11340 # if servers run on the same node, it is impossible to tell if they get
11341 # synced with the mgs, so just wait an arbitrary 10 seconds
11342 if [ $(facet_active_host mgs) == $(facet_active_host mds) ] &&
11343 [ $(facet_active_host mgs) == $(facet_active_host ost1) ]; then
11344 echo "waiting 10 secs for sync"
11349 # wait up to 10 seconds for other servers to sync with mgs
11350 for i in $(seq 1 10); do
11351 for node in $(all_server_nodes); do
11352 local node_ip=$(host_nids_address $node $NETTYPE |
11356 if [ -z "$value" ]; then
11357 [ $node_ip == $mgs_ip ] && continue
11360 out2=$(do_node $node_ip $LCTL get_param $opt \
11361 nodemap.$proc_param 2>/dev/null)
11362 echo "On $node ${node_ip}, ${proc_param} = $out2"
11363 [ "$out1" != "$out2" ] && is_sync=false && break
11368 if ! $is_sync; then
11371 echo OTHER - IP: $node_ip
11373 error "mgs and $nodemap_name ${key} mismatch, $i attempts"
11375 echo "waited $((i - 1)) seconds for sync"
11378 consume_precreations() {
11382 local extra=${4:-2}
11383 local OST=$(ostname_from_index $OSTIDX $dir)
11385 mkdir_on_mdt -i $(facet_index $mfacet) $dir/${OST}
11386 $LFS setstripe -i $OSTIDX -c 1 ${dir}/${OST}
11389 local mdtosc_proc=$(get_mdtosc_proc_path $mfacet $OST)
11390 local last_id=$(do_facet $mfacet $LCTL get_param -n \
11391 osp.$mdtosc_proc.prealloc_last_id)
11392 local next_id=$(do_facet $mfacet $LCTL get_param -n \
11393 osp.$mdtosc_proc.prealloc_next_id)
11394 echo "Creating to objid $last_id on ost $OST..."
11395 createmany -o $dir/${OST}/f $next_id $((last_id - next_id + extra))
11398 __exhaust_precreations() {
11401 local FAILIDX=${3:-$OSTIDX}
11402 local ofacet=ost$((OSTIDX + 1))
11404 mkdir_on_mdt0 $DIR/$tdir
11405 local mdtidx=$($LFS getstripe -m $DIR/$tdir)
11406 local mfacet=mds$((mdtidx + 1))
11407 echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
11409 local mdtosc_proc=$(get_mdtosc_proc_path $mfacet)
11410 do_facet $mfacet $LCTL get_param osp.$mdtosc_proc.prealloc*
11412 #define OBD_FAIL_OST_ENOSPC 0x215
11413 do_facet $ofacet $LCTL set_param fail_val=$FAILIDX fail_loc=0x215
11415 consume_precreations $DIR/$tdir $mfacet $OSTIDX
11417 do_facet $mfacet $LCTL get_param osp.$mdtosc_proc.prealloc*
11418 do_facet $ofacet $LCTL set_param fail_loc=$FAILLOC
11421 exhaust_precreations() {
11422 __exhaust_precreations $1 $2 $3
11426 exhaust_all_precreations() {
11428 for (( i=0; i < OSTCOUNT; i++ )) ; do
11429 __exhaust_precreations $i $1 -1
11436 local MDTIDX=$(facet_index $mfacet)
11437 local MDT=$(mdtname_from_index $MDTIDX $DIR)
11440 #define OBD_FAIL_OSP_FORCE_NEW_SEQ 0x210a
11441 do_facet $mfacet $LCTL set_param fail_loc=0x210a
11442 mkdir_on_mdt -i $MDTIDX $DIR/${MDT}
11443 for (( i=0; i < OSTCOUNT; i++ )) ; do
11444 # consume preallocated objects, to wake up precreate thread
11445 consume_precreations $DIR/${MDT} $mfacet $i
11447 do_facet $mfacet $LCTL set_param fail_loc=0
11451 force_new_seq_all() {
11454 for (( i=0; i < MDSCOUNT; i++ )) ; do
11455 force_new_seq mds$((i + 1)) &
11461 ost_set_temp_seq_width_all() {
11462 local osts=$(comma_list $(osts_nodes))
11463 local width=$(do_facet ost1 $LCTL get_param -n seq.*OST0000-super.width)
11465 do_nodes $osts $LCTL set_param seq.*OST*-super.width=$1
11466 stack_trap "do_nodes $osts $LCTL set_param seq.*OST*-super.width=$width"
11469 verify_yaml_available() {
11470 python3 -c "import yaml; yaml.safe_load('''a: b''')"
11474 python3 -c "import sys, yaml; obj = yaml.safe_load(sys.stdin)"
11477 verify_compare_yaml() {
11478 python3 -c "import sys, yaml; f=open(\"$1\", \"r\"); obj1 = yaml.safe_load(f); f=open(\"$2\", \"r\"); obj2 = yaml.safe_load(f); sys.exit(obj1 != obj2)"
11481 zfs_or_rotational() {
11483 local ost_name=$(ostname_from_index $ost_idx)
11484 local nonrotat=$(do_facet ost1 $LCTL get_param -n osd-*.$ost_name.nonrotational)
11486 if [ "$ost1_FSTYPE" == "zfs" ] || [ "$nonrotat" -eq 0 ]; then