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 GSS_PIPEFS=false
15 export SHARED_KEY=${SHARED_KEY:-false}
16 export SK_PATH=${SK_PATH:-/tmp/test-framework-keys}
17 export SK_OM_PATH=$SK_PATH'/tmp-request-mount'
18 export SK_MOUNTED=${SK_MOUNTED:-false}
19 export SK_FLAVOR=${SK_FLAVOR:-ski}
20 export SK_NO_KEY=${SK_NO_KEY:-true}
21 export SK_UNIQUE_NM=${SK_UNIQUE_NM:-false}
22 export SK_S2S=${SK_S2S:-false}
23 export SK_S2SNM=${SK_S2SNM:-TestFrameNM}
24 export SK_S2SNMCLI=${SK_S2SNMCLI:-TestFrameNMCli}
25 export SK_SKIPFIRST=${SK_SKIPFIRST:-true}
26 export IDENTITY_UPCALL=default
28 export FLAKEY=${FLAKEY:-true}
29 # specify environment variable containing batch job name for server statistics
30 export JOBID_VAR=${JOBID_VAR:-"procname_uid"} # or "existing" or "disable"
32 #export PDSH="pdsh -S -Rssh -w"
33 export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
34 export UMOUNT=${UMOUNT:-"umount -d"}
36 export LSNAPSHOT_CONF="/etc/ldev.conf"
37 export LSNAPSHOT_LOG="/var/log/lsnapshot.log"
39 # sles12 umount has a issue with -d option
40 [ -e /etc/SuSE-release ] && grep -w VERSION /etc/SuSE-release | grep -wq 12 && {
41 export UMOUNT="umount"
44 # function used by scripts run on remote nodes
45 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
46 . $LUSTRE/tests/functions.sh
47 . $LUSTRE/tests/yaml.sh
49 export LD_LIBRARY_PATH=${LUSTRE}/utils/.libs:${LUSTRE}/utils:${LD_LIBRARY_PATH}
51 LUSTRE_TESTS_CFG_DIR=${LUSTRE_TESTS_CFG_DIR:-${LUSTRE}/tests/cfg}
53 EXCEPT_LIST_FILE=${EXCEPT_LIST_FILE:-${LUSTRE_TESTS_CFG_DIR}/tests-to-skip.sh}
55 if [ -f "$EXCEPT_LIST_FILE" ]; then
56 echo "Reading test skip list from $EXCEPT_LIST_FILE"
61 # check config files for options in decreasing order of preference
62 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/lustre.conf ] &&
63 MODPROBECONF=/etc/modprobe.d/lustre.conf
64 [ -z "$MODPROBECONF" -a -f /etc/modprobe.d/Lustre ] &&
65 MODPROBECONF=/etc/modprobe.d/Lustre
66 [ -z "$MODPROBECONF" -a -f /etc/modprobe.conf ] &&
67 MODPROBECONF=/etc/modprobe.conf
69 sanitize_parameters() {
70 for i in DIR DIR1 DIR2 MOUNT MOUNT1 MOUNT2
73 if [ -d "$path" ]; then
74 eval export $i=$(echo $path | sed -r 's/\/+$//g')
80 [[ $DIR/ = $MOUNT/* ]] ||
81 { failed=1 && echo "DIR=$DIR not in $MOUNT. Aborting."; }
82 [[ $DIR1/ = $MOUNT1/* ]] ||
83 { failed=1 && echo "DIR1=$DIR1 not in $MOUNT1. Aborting."; }
84 [[ $DIR2/ = $MOUNT2/* ]] ||
85 { failed=1 && echo "DIR2=$DIR2 not in $MOUNT2. Aborting"; }
87 [ -n "$failed" ] && exit 99 || true
91 echo "usage: $0 [-r] [-f cfgfile]"
99 [ -z "$DEFAULT_SUITES" ] && return 0
100 [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
102 local form="%-13s %-17s %-9s %s %s\n"
104 printf "$form" "status" "script" "Total(sec)" "E(xcluded) S(low)"
105 echo "---------------------------------------------------------------"
106 for O in $DEFAULT_SUITES; do
107 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
108 [ "${!O}" = "no" ] && continue || true
109 local o=$(echo $O | tr "[:upper:]_" "[:lower:]-")
110 local log=${TMP}/${o}.log
111 if is_sanity_benchmark $o; then
112 log=${TMP}/sanity-benchmark.log
117 local status=Unfinished
119 skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
121 slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
122 sort -nr -k 3 | head -n5 | awk '{ print $2":"$3"s" }')
123 total=$(grep duration $log | awk '{ print $2 }')
124 if [ "${!O}" = "done" ]; then
128 local durations=$(egrep "^PASS|^FAIL" $log |
129 tr -d "("| sed s/s\)$//g |
130 awk '{ print $2":"$3"|" }')
131 details=$(printf "%s\n%s %s %s\n" "$details" \
132 "DDETAILS" "$O" "$(echo $durations)")
135 printf "$form" $status "$O" "${total}" "E=$skipped"
136 printf "$form" "-" "-" "-" "S=$(echo $slow)"
139 for O in $DEFAULT_SUITES; do
140 O=$(echo $O | tr "-" "_" | tr "[:lower:]" "[:upper:]")
141 if [ "${!O}" = "no" ]; then
142 printf "$form" "Skipped" "$O" ""
146 # print the detailed tests durations if DDETAILS=true
152 # Get information about the Lustre environment. The information collected
153 # will be used in Lustre tests.
154 # usage: get_lustre_env
155 # input: No required or optional arguments
156 # output: No return values, environment variables are exported
160 export mds1_FSTYPE=${mds1_FSTYPE:-$(facet_fstype mds1)}
161 export ost1_FSTYPE=${ost1_FSTYPE:-$(facet_fstype ost1)}
163 export MGS_VERSION=$(lustre_version_code mgs)
164 export MDS1_VERSION=$(lustre_version_code mds1)
165 export OST1_VERSION=$(lustre_version_code ost1)
166 export CLIENT_VERSION=$(lustre_version_code client)
169 # Prefer using "mds1" directly instead of SINGLEMDS.
170 # Keep this for compat until it is removed from scripts.
171 export SINGLEMDS=${SINGLEMDS:-mds1}
175 export LUSTRE=$(absolute_path $LUSTRE)
176 export TESTSUITE=$(basename $0 .sh)
177 export TEST_FAILED=false
178 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
179 export RPC_MODE=${RPC_MODE:-false}
180 export DO_CLEANUP=${DO_CLEANUP:-true}
181 export KEEP_ZPOOL=${KEEP_ZPOOL:-false}
182 export CLEANUP_DM_DEV=false
183 export PAGE_SIZE=$(get_page_size client)
185 export MKE2FS=$MKE2FS
186 if [ -z "$MKE2FS" ]; then
187 if which mkfs.ldiskfs >/dev/null 2>&1; then
188 export MKE2FS=mkfs.ldiskfs
194 export DEBUGFS=$DEBUGFS
195 if [ -z "$DEBUGFS" ]; then
196 if which debugfs.ldiskfs >/dev/null 2>&1; then
197 export DEBUGFS=debugfs.ldiskfs
199 export DEBUGFS=debugfs
203 export TUNE2FS=$TUNE2FS
204 if [ -z "$TUNE2FS" ]; then
205 if which tunefs.ldiskfs >/dev/null 2>&1; then
206 export TUNE2FS=tunefs.ldiskfs
208 export TUNE2FS=tune2fs
212 export E2LABEL=$E2LABEL
213 if [ -z "$E2LABEL" ]; then
214 if which label.ldiskfs >/dev/null 2>&1; then
215 export E2LABEL=label.ldiskfs
217 export E2LABEL=e2label
221 export DUMPE2FS=$DUMPE2FS
222 if [ -z "$DUMPE2FS" ]; then
223 if which dumpfs.ldiskfs >/dev/null 2>&1; then
224 export DUMPE2FS=dumpfs.ldiskfs
226 export DUMPE2FS=dumpe2fs
230 export E2FSCK=$E2FSCK
231 if [ -z "$E2FSCK" ]; then
232 if which fsck.ldiskfs >/dev/null 2>&1; then
233 export E2FSCK=fsck.ldiskfs
239 export RESIZE2FS=$RESIZE2FS
240 if [ -z "$RESIZE2FS" ]; then
241 if which resizefs.ldiskfs >/dev/null 2>&1; then
242 export RESIZE2FS=resizefs.ldiskfs
244 export RESIZE2FS=resize2fs
248 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
249 export FSCK_MAX_ERR=4 # File system errors left uncorrected
251 export ZFS=${ZFS:-zfs}
252 export ZPOOL=${ZPOOL:-zpool}
253 export ZDB=${ZDB:-zdb}
254 export PARTPROBE=${PARTPROBE:-partprobe}
256 #[ -d /r ] && export ROOT=${ROOT:-/r}
257 export TMP=${TMP:-$ROOT/tmp}
258 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
259 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
260 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
262 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
263 if ! echo $PATH | grep -q $LUSTRE/utils; then
264 export PATH=$LUSTRE/utils:$PATH
266 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
267 export PATH=$LUSTRE/utils/gss:$PATH
269 if ! echo $PATH | grep -q $LUSTRE/tests; then
270 export PATH=$LUSTRE/tests:$PATH
272 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
273 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
275 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
276 [ ! -f "$LST" ] && export LST=$(which lst)
277 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
278 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
279 export MCREATE=${MCREATE:-mcreate}
280 export MULTIOP=${MULTIOP:-multiop}
281 export MMAP_CAT=${MMAP_CAT:-mmap_cat}
282 export STATX=${STATX:-statx}
283 # Ubuntu, at least, has a truncate command in /usr/bin
284 # so fully path our truncate command.
285 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
286 export FSX=${FSX:-$LUSTRE/tests/fsx}
287 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
288 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
289 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
290 export PATH=$LUSTRE/tests/racer:$PATH:
292 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
293 export PATH=$LUSTRE/tests/mpi:$PATH
296 export LNETCTL=${LNETCTL:-"$LUSTRE/../lnet/utils/lnetctl"}
297 [ ! -f "$LNETCTL" ] && export LNETCTL=$(which lnetctl 2> /dev/null)
298 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
299 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
300 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
301 [ ! -f "$LFS" ] && export LFS=$(which lfs)
302 export KSOCKLND_CONFIG=${KSOCKLND_CONFIG:-"$LUSTRE/scripts/ksocklnd-config"}
303 [ ! -f "$KSOCKLND_CONFIG" ] &&
304 export KSOCKLND_CONFIG=$(which ksocklnd-config 2> /dev/null)
306 export PERM_CMD=$(echo ${PERM_CMD:-"$LCTL conf_param"})
308 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
309 if [ ! -f "$L_GETIDENTITY" ]; then
310 if `which l_getidentity > /dev/null 2>&1`; then
311 export L_GETIDENTITY=$(which l_getidentity)
313 export L_GETIDENTITY=NONE
316 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
317 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
318 export LL_DECODE_LINKEA=${LL_DECODE_LINKEA:-"$LUSTRE/utils/ll_decode_linkea"}
319 [ ! -f "$LL_DECODE_LINKEA" ] && export LL_DECODE_LINKEA="ll_decode_linkea"
320 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
321 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
322 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
323 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
324 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
325 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
326 [ ! -f "$LUSTRE_RMMOD" ] &&
327 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
328 export LUSTRE_ROUTES_CONVERSION=${LUSTRE_ROUTES_CONVERSION:-$LUSTRE/scripts/lustre_routes_conversion}
329 [ ! -f "$LUSTRE_ROUTES_CONVERSION" ] &&
330 export LUSTRE_ROUTES_CONVERSION=$(which lustre_routes_conversion 2> /dev/null)
331 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
332 [ ! -f "$LFS_MIGRATE" ] &&
333 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
334 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
335 [ ! -f "$LR_READER" ] &&
336 export LR_READER=$(which lr_reader 2> /dev/null)
337 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
338 export LSOM_SYNC=${LSOM_SYNC:-"$LUSTRE/utils/llsom_sync"}
339 [ ! -f "$LSOM_SYNC" ] &&
340 export LSOM_SYNC=$(which llsom_sync 2> /dev/null)
341 [ -z "$LSOM_SYNC" ] && export LSOM_SYNC="/usr/sbin/llsom_sync"
342 export NAME=${NAME:-local}
343 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
344 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] &&
345 export LGSSD=$(which lgssd)
346 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
347 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
348 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
350 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
352 export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
353 [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
355 export DMSETUP=${DMSETUP:-dmsetup}
356 export DM_DEV_PATH=${DM_DEV_PATH:-/dev/mapper}
357 export LOSETUP=${LOSETUP:-losetup}
359 if [ "$ACCEPTOR_PORT" ]; then
360 export PORT_OPT="--port $ACCEPTOR_PORT"
364 $RPC_MODE || echo "Using GSS shared-key feature"
365 which lgss_sk > /dev/null 2>&1 ||
366 error_exit "built with lgss_sk disabled! SEC=$SEC"
374 $RPC_MODE || echo "Using GSS/krb5 ptlrpc security flavor"
375 which lgss_keyring > /dev/null 2>&1 ||
376 error_exit "built with gss disabled! SEC=$SEC"
387 IDENTITY_UPCALL=false
391 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
393 # Paths on remote nodes, if different
394 export RLUSTRE=${RLUSTRE:-$LUSTRE}
395 export RPWD=${RPWD:-$PWD}
396 export I_MOUNTED=${I_MOUNTED:-"no"}
397 export AUSTER_CLEANUP=${AUSTER_CLEANUP:-false}
398 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
399 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
400 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
401 ! -f $LUSTRE/mdt/mdt.ko ]; then
402 export CLIENTMODSONLY=yes
405 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
406 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
410 while getopts "rvwf:" opt $*; do
415 w) WRITECONF=writeconf;;
420 shift $((OPTIND - 1))
423 # print the durations of each test if "true"
424 DDETAILS=${DDETAILS:-false}
425 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
430 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
432 # Constants used in more than one test script
433 export LOV_MAX_STRIPE_COUNT=2000
434 export DELETE_OLD_POOLS=${DELETE_OLD_POOLS:-false}
435 export KEEP_POOLS=${KEEP_POOLS:-false}
436 export PARALLEL=${PARALLEL:-"no"}
438 export BLCKSIZE=${BLCKSIZE:-4096}
439 export MACHINEFILE=${MACHINEFILE:-$TMP/$(basename $0 .sh).machines}
440 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
443 # use localrecov to enable recovery for local clients, LU-12722
444 [[ $MDS1_VERSION -lt $(version_code 2.13.52) ]] || {
445 export MDS_MOUNT_OPTS=${MDS_MOUNT_OPTS:-"-o localrecov"}
446 export MGS_MOUNT_OPTS=${MGS_MOUNT_OPTS:-"-o localrecov"}
449 [[ $OST1_VERSION -lt $(version_code 2.13.52) ]] ||
450 export OST_MOUNT_OPTS=${OST_MOUNT_OPTS:-"-o localrecov"}
457 ncpts=$(do_facet $facet "lctl get_param -n " \
458 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
460 if [ $ncpts -eq 0 ]; then
467 # Return a numeric version code based on a version string. The version
468 # code is useful for comparison two version strings to see which is newer.
470 # split arguments like "1.8.6-wc3" into "1", "8", "6", "3"
471 eval set -- $(tr "[:punct:][a-zA-Z]" " " <<< $*)
473 echo -n $(((${1:-0}<<24) | (${2:-0}<<16) | (${3:-0}<<8) | (${4:-0})))
476 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
477 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
479 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
481 # usage: lustre_build_version
483 # All Lustre versions support "lctl get_param" to report the version of the
484 # code running in the kernel (what our tests are interested in), but it
485 # doesn't work without modules loaded. After 2.9.53 and in upstream kernels
486 # the "version" parameter doesn't include "lustre: " at the beginning.
487 # If that fails, call "lctl lustre_build_version" which prints either (or both)
488 # the userspace and kernel build versions, but until 2.8.55 required root
489 # access to get the Lustre kernel version. If that also fails, fall back to
490 # using "lctl --version", which is easy to parse and works without the kernel
491 # modules, but was only added in 2.6.50 and only prints the lctl tool version,
492 # not the module version, though they are usually the same.
494 # Various commands and their output format for different Lustre versions:
495 # lctl get_param version: 2.9.55
496 # lctl get_param version: lustre: 2.8.53
497 # lctl get_param version: lustre: 2.6.52
498 # kernel: patchless_client
499 # build: v2_6_92_0-2.6.32-431.el6_lustre.x86_64
500 # lctl lustre_build_version: Lustre version: 2.8.53_27_gae67fc01
501 # lctl lustre_build_version: error: lustre_build_version: Permission denied
502 # (as non-root user) lctl version: v2_6_92_0-2.6.32-431.el6.x86_64
503 # lctl lustre_build_version: Lustre version: 2.5.3-2.6.32.26-175.fc12.x86_64
504 # lctl version: 2.5.3-2.6.32..26-175fc12.x86_64
505 # lctl --version: lctl 2.6.50
507 # output: prints version string to stdout in (up to 4) dotted-decimal values
508 lustre_build_version() {
509 local facet=${1:-client}
510 local facet_version=${facet}_VERSION
512 # if the global variable is already set, then use that
513 [ -n "${!facet_version}" ] && echo ${!facet_version} && return
515 # this is the currently-running version of the kernel modules
516 local ver=$(do_facet $facet "$LCTL get_param -n version 2>/dev/null")
517 # we mostly test 2.10+ systems, only try others if the above fails
518 if [ -z "$ver" ]; then
519 ver=$(do_facet $facet "$LCTL lustre_build_version 2>/dev/null")
521 if [ -z "$ver" ]; then
522 ver=$(do_facet $facet "$LCTL --version 2>/dev/null" |
525 local lver=$(egrep -i "lustre: |version: " <<<"$ver" | head -n 1)
526 [ -n "$lver" ] && ver="$lver"
528 lver=$(sed -e 's/[^:]*: //' -e 's/^v//' -e 's/[ -].*//' <<<$ver |
529 tr _ . | cut -d. -f1-4)
531 # save in global variable for the future
532 export $facet_version=$lver
537 # Report the Lustre numeric build version code for the supplied facet.
538 lustre_version_code() {
539 version_code $(lustre_build_version $1)
543 /sbin/lsmod | grep -q "^\<$1\>"
546 check_lfs_df_ret_val() {
547 # Ignore only EOPNOTSUPP (which is 95; Operation not supported) error
548 # returned by 'lfs df' for valid dentry but not a lustrefs.
550 # 'lfs df' historically always returned success(0) instead of
551 # EOPNOTSUPP. This function for compatibility reason, ignores and
552 # masquerades EOPNOTSUPP as success.
553 [[ $1 -eq 95 ]] && return 0
566 msg="$(insmod $module $args 2>&1)" && return 0 || rc=$?
569 # parallels can't load modules directly from prlfs, use /tmp instead
570 if $PRLFS || [[ "$(stat -f -c%t $module)" == "7c7c6673" ]]; then
571 local target="$(mktemp)"
573 cp "$module" "$target"
576 [[ $rc == 0 ]] && PRLFS=true
584 # Load a module on the system where this is running.
586 # usage: load_module module_name [module arguments for insmod/modprobe]
588 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
589 # will be used as the arguments. Otherwise arguments will be obtained from
590 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
593 local module=$1 # '../libcfs/libcfs/libcfs', 'obdclass/obdclass', ...
596 local base=$(basename $module $ext)
598 local -A module_is_loaded_aa
602 for mod in $(lsmod | awk '{ print $1; }'); do
603 module_is_loaded_aa[${mod//-/_}]=true
607 ${module_is_loaded_aa[${1//-/_}]:-false}
610 if module_is_loaded $base; then
614 if [[ -f $LUSTRE/$module$ext ]]; then
615 path=$LUSTRE/$module$ext
616 elif [[ "$base" == lnet_selftest ]] &&
617 [[ -f $LUSTRE/../lnet/selftest/$base$ext ]]; then
618 path=$LUSTRE/../lnet/selftest/$base$ext
623 if [[ -n "$path" ]]; then
624 # Try to load any non-Lustre modules that $module depends on.
625 for mod in $(modinfo --field=depends $path | tr ',' ' '); do
626 if ! module_is_loaded $mod; then
632 # If no module arguments were passed then get them from
633 # $MODOPTS_<MODULE>, otherwise from modprobe.conf.
634 if [ $# -eq 0 ]; then
635 # $MODOPTS_<MODULE>; we could use associative arrays, but that's
636 # not in Bash until 4.x, so we resort to eval.
637 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
638 eval set -- \$$optvar
639 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
640 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
642 opt=$(awk -v var="^options $base" '$0 ~ var \
643 {gsub("'"options $base"'",""); print}' \
645 set -- $(echo -n $opt)
647 # Ensure we have accept=all for lnet
648 if [[ "$base" == lnet ]]; then
649 # OK, this is a bit wordy...
650 local arg accept_all_present=false
653 [[ "$arg" == accept=all ]] &&
654 accept_all_present=true
657 $accept_all_present || set -- "$@" accept=all
664 [ $# -gt 0 ] && echo "${module} options: '$*'"
666 # Note that insmod will ignore anything in modprobe.conf, which is why
667 # we're passing options on the command-line. If $path does not exist
668 # then we must be testing a "make install" or"rpm" installation. Also
669 # note that failing to load ptlrpc_gss is not considered fatal.
670 if [[ -n "$path" ]]; then
671 lustre_insmod $path "$@"
672 elif [[ "$base" == ptlrpc_gss ]]; then
673 if ! modprobe $base "$@" 2>/dev/null; then
674 echo "gss/krb5 is not supported"
682 $LCTL mark "$LNETCTL $*"
688 # For kmemleak-enabled kernels we need clear all past state
689 # that obviously has nothing to do with this Lustre run
690 # Disable automatic memory scanning to avoid perf hit.
691 if [ -f /sys/kernel/debug/kmemleak ] ; then
692 echo scan=off > /sys/kernel/debug/kmemleak || true
693 echo scan > /sys/kernel/debug/kmemleak || true
694 echo clear > /sys/kernel/debug/kmemleak || true
697 echo Loading modules from $LUSTRE
701 if [ -f /sys/devices/system/cpu/online ]; then
702 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
703 echo "detected $ncpus online CPUs by sysfs"
705 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
707 if [ $rc -eq 0 ]; then
708 echo "detected $ncpus online CPUs by getconf"
710 echo "Can't detect number of CPUs"
715 # if there is only one CPU core, libcfs can only create one partition
716 # if there is more than 4 CPU cores, libcfs should create multiple CPU
717 # partitions. So we just force libcfs to create 2 partitions for
718 # system with 2 or 4 cores
719 local saved_opts="$MODOPTS_LIBCFS"
720 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
721 # force to enable multiple CPU partitions
722 echo "Force libcfs to create 2 CPU partitions"
723 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
725 echo "libcfs will create CPU partition based on online CPUs"
728 load_module ../libcfs/libcfs/libcfs
729 # Prevent local MODOPTS_LIBCFS being passed as part of environment
730 # variable to remote nodes
733 set_default_debug "neterror net nettrace malloc"
734 if [ "$1" = "config_on_load=1" ]; then
735 load_module ../lnet/lnet/lnet
737 load_module ../lnet/lnet/lnet "$@"
740 LNDPATH=${LNDPATH:-"../lnet/klnds"}
741 if [ -z "$LNETLND" ]; then
743 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
744 tcp*) LNETLND="socklnd/ksocklnd" ;;
745 kfi*) LNETLND="kfilnd/kkfilnd" ;;
746 gni*) LNETLND="gnilnd/kgnilnd" ;;
747 *) local lnd="${NETTYPE%%[0-9]}lnd"
748 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
749 LNETLND="$lnd/k$lnd" ||
750 LNETLND="socklnd/ksocklnd"
753 load_module ../lnet/klnds/$LNETLND
755 if [ "$1" = "config_on_load=1" ]; then
756 do_lnetctl lnet configure --all ||
761 load_modules_local() {
762 if [ -n "$MODPROBE" ]; then
764 echo "Using modprobe to load modules"
768 # Create special udev test rules on every node
769 if [ -f $LUSTRE/lustre/conf/99-lustre.rules ]; then {
770 sed -e 's|/usr/sbin/lctl|$LCTL|g' $LUSTRE/lustre/conf/99-lustre.rules > /etc/udev/rules.d/99-lustre-test.rules
772 echo "SUBSYSTEM==\"lustre\", ACTION==\"change\", ENV{PARAM}==\"?*\", RUN+=\"$LCTL set_param '\$env{PARAM}=\$env{SETTING}'\"" > /etc/udev/rules.d/99-lustre-test.rules
774 udevadm control --reload-rules
779 load_module obdclass/obdclass
780 if ! client_only; then
781 MODOPTS_PTLRPC=${MODOPTS_PTLRPC:-"lbug_on_grant_miscount=1"}
783 load_module ptlrpc/ptlrpc
784 load_module ptlrpc/gss/ptlrpc_gss
792 load_module obdecho/obdecho
793 if ! client_only; then
794 load_module lfsck/lfsck
795 [ "$LQUOTA" != "no" ] &&
796 load_module quota/lquota $LQUOTAOPTS
797 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
798 load_module osd-zfs/osd_zfs
799 elif [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
800 load_module ../ldiskfs/ldiskfs
801 load_module osd-ldiskfs/osd_ldiskfs
813 load_module llite/lustre
814 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
816 rm -f $OGDB/ogdb-$HOSTNAME
817 $LCTL modules > $OGDB/ogdb-$HOSTNAME
819 # 'mount' doesn't look in $PATH, just sbin
820 local mount_lustre=$LUSTRE/utils/mount.lustre
821 if [ -f $mount_lustre ]; then
822 local sbin_mount=$(readlink -f /sbin)/mount.lustre
823 if grep -qw "$sbin_mount" /proc/mounts; then
824 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
826 if ! grep -qw "$sbin_mount" /proc/mounts; then
827 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
828 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
829 cat <<- EOF > "$sbin_mount"
832 echo "This $sbin_mount just a mountpoint." 1>&2
833 echo "It is never supposed to be run." 1>&2
834 logger -p emerg -- "using stub $sbin_mount $@"
837 chmod a+x $sbin_mount
839 mount --bind $mount_lustre $sbin_mount ||
840 error "can't bind $mount_lustre to $sbin_mount"
851 # load modules on remote nodes optionally
852 # lustre-tests have to be installed on these nodes
853 if $LOAD_MODULES_REMOTE; then
854 local list=$(comma_list $(remote_nodes_list))
856 # include failover nodes in case they are not in the list yet
858 for facet in ${facets//,/ }; do
859 failover=$(facet_failover_host $facet)
860 [ -n "$list" ] && [[ ! "$list" =~ "$failover" ]] &&
861 list="$list,$failover"
864 if [ -n "$list" ]; then
865 echo "loading modules on: '$list'"
866 do_rpc_nodes "$list" load_modules_local
872 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
873 LEAK_PORTALS=$(dmesg | tail -n 20 | egrep -i "libcfs.*memory leaked" || true)
874 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
875 echo "$LEAK_LUSTRE" 1>&2
876 echo "$LEAK_PORTALS" 1>&2
877 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
878 echo "Memory leaks detected"
879 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
884 unload_modules_local() {
885 $LUSTRE_RMMOD ldiskfs || return 2
887 [ -f /etc/udev/rules.d/99-lustre-test.rules ] &&
888 rm /etc/udev/rules.d/99-lustre-test.rules
889 udevadm control --reload-rules
892 check_mem_leak || return 254
900 wait_exit_ST client # bug 12845
902 unload_modules_local || rc=$?
904 if $LOAD_MODULES_REMOTE; then
905 local list=$(comma_list $(remote_nodes_list))
906 if [ -n "$list" ]; then
907 echo "unloading modules on: '$list'"
908 do_rpc_nodes "$list" unload_modules_local
912 local sbin_mount=$(readlink -f /sbin)/mount.lustre
913 if grep -qe "$sbin_mount " /proc/mounts; then
914 umount $sbin_mount || true
915 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
919 [[ $rc -eq 0 ]] && echo "modules unloaded."
925 local facet=${1:-$SINGLEMDS}
928 case $(facet_fstype $facet) in
929 ldiskfs) size=72;; # largest seen is 64, leave some headroom
930 # grant_block_size is in bytes, allow at least 2x max blocksize
931 zfs) size=$(lctl get_param osc.$FSNAME*.import |
932 awk '/grant_block_size:/ {print $2/512; exit;}')
936 echo -n $((size * MDSCOUNT))
940 local facet=${1:-$SINGLEMDS}
941 local fstype=$(facet_fstype $facet)
944 ldiskfs) size=4;; # ~4KB per inode
945 zfs) size=11;; # 10 to 11KB per inode
951 check_gss_daemon_nodes() {
955 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
956 if [ \\\"\\\$num\\\" -ne 1 ]; then
957 echo \\\$num instance of $dname;
962 check_gss_daemon_facet() {
966 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
967 if [ $num -ne 1 ]; then
968 echo "$num instance of $dname on $facet"
977 echo Stopping $@ on $list
978 do_nodes $list "killall -2 $@ 2>/dev/null || true"
981 # start gss daemons on all nodes, or "daemon" on "nodes" if set
982 start_gss_daemons() {
986 if [ "$nodes" ] && [ "$daemon" ] ; then
987 echo "Starting gss daemon on nodes: $nodes"
988 do_nodes $nodes "$daemon" || return 8
992 nodes=$(comma_list $(mdts_nodes))
993 echo "Starting gss daemon on mds: $nodes"
995 # Start all versions, in case of switching
996 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 1
998 do_nodes $nodes "$LSVCGSSD -v" || return 1
1000 if $GSS_PIPEFS; then
1001 do_nodes $nodes "$LGSSD -v" || return 2
1004 nodes=$(comma_list $(osts_nodes))
1005 echo "Starting gss daemon on ost: $nodes"
1007 # Start all versions, in case of switching
1008 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 3
1010 do_nodes $nodes "$LSVCGSSD -v" || return 3
1012 # starting on clients
1014 local clients=${CLIENTS:-$HOSTNAME}
1015 if $GSS_PIPEFS; then
1016 echo "Starting $LGSSD on clients $clients "
1017 do_nodes $clients "$LGSSD -v" || return 4
1020 # wait daemons entering "stable" status
1024 # check daemons are running
1026 nodes=$(comma_list $(mdts_nodes) $(osts_nodes))
1027 check_gss_daemon_nodes $nodes lsvcgssd || return 5
1028 if $GSS_PIPEFS; then
1029 nodes=$(comma_list $(mdts_nodes))
1030 check_gss_daemon_nodes $nodes lgssd || return 6
1032 if $GSS_PIPEFS; then
1033 check_gss_daemon_nodes $clients lgssd || return 7
1037 stop_gss_daemons() {
1038 local nodes=$(comma_list $(mdts_nodes))
1040 send_sigint $nodes lsvcgssd lgssd
1042 nodes=$(comma_list $(osts_nodes))
1043 send_sigint $nodes lsvcgssd
1045 nodes=${CLIENTS:-$HOSTNAME}
1046 send_sigint $nodes lgssd
1050 # Add mount flags for shared key
1052 if grep -q skpath <<< "$mt_opts" ; then
1053 mt_opts=$(echo $mt_opts |
1054 sed -e "s#skpath=[^ ,]*#skpath=$SK_PATH#")
1056 if [ -z "$mt_opts" ]; then
1057 mt_opts="-o skpath=$SK_PATH"
1059 mt_opts="$mt_opts,skpath=$SK_PATH"
1069 /usr/lib/lustre/* | /usr/lib64/lustre/* | /usr/lib/lustre | \
1078 [ $from_tree = true ]
1082 if $SHARED_KEY; then
1091 if ! module_loaded ptlrpc_gss; then
1092 load_module ptlrpc/gss/ptlrpc_gss
1093 module_loaded ptlrpc_gss ||
1094 error_exit "init_gss: GSS=$GSS, but gss/krb5 missing"
1097 if $GSS_KRB5 || $GSS_SK; then
1098 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
1101 if $GSS_SK && ! $SK_NO_KEY; then
1102 echo "Loading basic SSK keys on all servers"
1103 do_nodes $(comma_list $(all_server_nodes)) \
1104 "lgss_sk -t server -l $SK_PATH/$FSNAME.key || true"
1105 do_nodes $(comma_list $(all_server_nodes)) \
1106 "keyctl show | grep lustre | cut -c1-11 |
1108 xargs -IX keyctl setperm X 0x3f3f3f3f"
1111 if $GSS_SK && $SK_NO_KEY; then
1112 local numclients=${1:-$CLIENTCOUNT}
1113 local clients=${CLIENTS:-$HOSTNAME}
1115 # security ctx config for keyring
1117 local lgssc_conf_file="/etc/request-key.d/lgssc.conf"
1119 if from_build_tree; then
1120 mkdir -p $SK_OM_PATH
1121 if grep -q request-key /proc/mounts > /dev/null; then
1122 echo "SSK: Request key already mounted."
1124 mount -o bind $SK_OM_PATH /etc/request-key.d/
1126 local lgssc_conf_line='create lgssc * * '
1127 lgssc_conf_line+=$(which lgss_keyring)
1128 lgssc_conf_line+=' %o %k %t %d %c %u %g %T %P %S'
1129 echo "$lgssc_conf_line" > $lgssc_conf_file
1132 [ -e $lgssc_conf_file ] ||
1133 error_exit "Could not find key options in $lgssc_conf_file"
1134 echo "$lgssc_conf_file content is:"
1135 cat $lgssc_conf_file
1137 if ! local_mode; then
1138 if from_build_tree; then
1139 do_nodes $(comma_list $(all_nodes)) "mkdir -p \
1141 do_nodes $(comma_list $(all_nodes)) "mount \
1142 -o bind $SK_OM_PATH \
1143 /etc/request-key.d/"
1144 do_nodes $(comma_list $(all_nodes)) "rsync \
1145 -aqv $HOSTNAME:$lgssc_conf_file \
1146 $lgssc_conf_file >/dev/null 2>&1"
1148 do_nodes $(comma_list $(all_nodes)) \
1149 "echo $lgssc_conf_file: ; \
1150 cat $lgssc_conf_file"
1154 # create shared key on all nodes
1155 mkdir -p $SK_PATH/nodemap
1156 rm -f $SK_PATH/$FSNAME.key $SK_PATH/nodemap/c*.key \
1157 $SK_PATH/$FSNAME-*.key
1158 # for nodemap testing each client may need own key,
1159 # and S2S now requires keys as well, both for "client"
1162 lgss_sk -t server -f$FSNAME -n $SK_S2SNMCLI \
1163 -w $SK_PATH/$FSNAME-nmclient.key \
1164 -d /dev/urandom >/dev/null 2>&1
1165 lgss_sk -t mgs,server -f$FSNAME -n $SK_S2SNM \
1166 -w $SK_PATH/$FSNAME-s2s-server.key \
1167 -d /dev/urandom >/dev/null 2>&1
1170 lgss_sk -t server -f$FSNAME -w $SK_PATH/$FSNAME.key \
1171 -d /dev/urandom >/dev/null 2>&1
1173 for i in $(seq 0 $((numclients - 1))); do
1174 lgss_sk -t server -f$FSNAME -n c$i \
1175 -w $SK_PATH/nodemap/c$i.key -d /dev/urandom \
1179 if ! local_mode; then
1180 for lnode in $(all_nodes); do
1181 scp -r $SK_PATH ${lnode}:$(dirname $SK_PATH)/
1184 # Set client keys to client type to generate prime P
1186 do_nodes $(all_nodes) "lgss_sk -t client,server -m \
1187 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1189 do_nodes $clients "lgss_sk -t client -m \
1190 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1191 do_nodes $clients "find $SK_PATH/nodemap -name \*.key | \
1192 xargs -IX lgss_sk -t client -m X >/dev/null 2>&1"
1194 # This is required for servers as well, if S2S in use
1196 do_nodes $(comma_list $(mdts_nodes)) \
1197 "cp $SK_PATH/$FSNAME-s2s-server.key \
1198 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
1199 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1201 do_nodes $(comma_list $(osts_nodes)) \
1202 "cp $SK_PATH/$FSNAME-s2s-server.key \
1203 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
1204 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1206 do_nodes $clients "lgss_sk -t client \
1207 -m $SK_PATH/$FSNAME-nmclient.key \
1212 # mount options for servers and clients
1213 MGS_MOUNT_OPTS=$(add_sk_mntflag $MGS_MOUNT_OPTS)
1214 MDS_MOUNT_OPTS=$(add_sk_mntflag $MDS_MOUNT_OPTS)
1215 OST_MOUNT_OPTS=$(add_sk_mntflag $OST_MOUNT_OPTS)
1216 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
1218 if [ -z "$LGSS_KEYRING_DEBUG" ]; then
1219 LGSS_KEYRING_DEBUG=4
1223 if [ -n "$LGSS_KEYRING_DEBUG" ] && \
1224 ( local_mode || from_build_tree ); then
1226 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
1227 elif [ -n "$LGSS_KEYRING_DEBUG" ]; then
1228 do_nodes $(comma_list $(all_nodes)) "modprobe ptlrpc_gss && \
1230 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG"
1237 # maybe cleanup credential cache?
1244 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNM"
1245 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNMCLI"
1246 $RPC_MODE || echo "Sleeping for 10 sec for Nodemap.."
1250 $RPC_MODE || echo "Cleaning up Shared Key.."
1251 do_nodes $(comma_list $(all_nodes)) "rm -f \
1252 $SK_PATH/$FSNAME*.key $SK_PATH/nodemap/$FSNAME*.key"
1253 do_nodes $(comma_list $(all_nodes)) "keyctl show | \
1254 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
1255 if from_build_tree; then
1256 # Remove the mount and clean up the files we added to
1258 do_nodes $(comma_list $(all_nodes)) "while grep -q \
1259 request-key.d /proc/mounts; do umount \
1260 /etc/request-key.d/; done"
1261 do_nodes $(comma_list $(all_nodes)) "rm -f \
1262 $SK_OM_PATH/lgssc.conf"
1263 do_nodes $(comma_list $(all_nodes)) "rmdir $SK_OM_PATH"
1271 local var=${facet}_svc
1279 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
1280 tr '[:lower:]' '[:upper:]'
1286 if [ $facet == mgs ] || [ $facet == client ]; then
1290 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
1298 if [ -n "${!var}" ]; then
1303 var=$(facet_type $facet)FSTYPE
1304 if [ -n "${!var}" ]; then
1309 if [ -n "$FSTYPE" ]; then
1314 if [[ $facet == mgs ]] && combined_mgs_mds; then
1326 local facets=$(get_facets)
1329 for facet in ${facets//,/ }; do
1330 if [ $node == $(facet_host $facet) ] ||
1331 [ $node == "$(facet_failover_host $facet)" ]; then
1332 fstype=$(facet_fstype $facet)
1333 if [[ $fstypes != *$fstype* ]]; then
1334 fstypes+="${fstypes:+,}$fstype"
1343 local num=$(facet_number $facet)
1346 if [[ $(facet_type $facet) = OST ]]; then
1347 index=OSTINDEX${num}
1348 if [[ -n "${!index}" ]]; then
1353 index=${OST_INDICES[num - 1]}
1356 [[ -n "$index" ]] || index=$((num - 1))
1364 local fstype=$(facet_fstype $facet)
1368 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
1370 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
1371 ${dev} 2>/dev/null");;
1373 error "unknown fstype!";;
1380 # Get the device of a facet.
1387 mgs) device=$(mgsdevname) ;;
1388 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
1389 ost*) device=$(ostdevname $(facet_number $facet)) ;;
1390 fs2mds) device=$(mdsdevname 1_2) ;;
1391 fs2ost) device=$(ostdevname 1_2) ;;
1392 fs3ost) device=$(ostdevname 2_2) ;;
1400 # Get the virtual device of a facet.
1407 mgs) device=$(mgsvdevname) ;;
1408 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
1409 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
1410 fs2mds) device=$(mdsvdevname 1_2) ;;
1411 fs2ost) device=$(ostvdevname 1_2) ;;
1412 fs3ost) device=$(ostvdevname 2_2) ;;
1420 local virt=$(virt-what 2> /dev/null)
1422 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1424 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1427 VMware|KVM|VirtualBox|Parallels|Bochs)
1428 echo $virt | tr '[A-Z]' '[a-z]' ;;
1434 # Re-read the partition table on failover partner host.
1435 # After a ZFS storage pool is created on a shared device, the partition table
1436 # on the device may change. However, the operating system on the failover
1437 # host may not notice the change automatically. Without the up-to-date partition
1438 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1439 # relative to partition rather than disk beginnings.
1441 # This function performs partprobe on the failover host to make it re-read the
1444 refresh_partition_table() {
1449 host=$(facet_passive_host $facet)
1450 if [[ -n "$host" ]]; then
1451 do_node $host "$PARTPROBE $device"
1456 # Get ZFS storage pool name.
1463 device=$(facet_device $facet)
1464 # poolname is string before "/"
1465 poolname="${device%%/*}"
1472 # Get ZFS local fsname.
1474 zfs_local_fsname() {
1476 local lfsname=$(basename $(facet_device $facet))
1482 # Create ZFS storage pool.
1489 local opts=${@:-"-o cachefile=none"}
1491 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1492 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1493 $ZPOOL create -f $opts $poolname $vdev"
1497 # Create ZFS file system.
1503 local opts=${@:-"-o mountpoint=legacy"}
1505 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1506 $ZFS create $opts $dataset"
1510 # Export ZFS storage pool.
1511 # Before exporting the pool, all datasets within the pool should be unmounted.
1519 poolname=$(zpool_name $facet)
1521 if [[ -n "$poolname" ]]; then
1522 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1523 grep -q ^$poolname/ /proc/mounts ||
1524 $ZPOOL export $opts $poolname"
1529 # Destroy ZFS storage pool.
1530 # Destroy the given pool and free up any devices for other use. This command
1531 # tries to unmount any active datasets before destroying the pool.
1532 # -f Force any active datasets contained within the pool to be unmounted.
1536 local poolname=${2:-$(zpool_name $facet)}
1538 if [[ -n "$poolname" ]]; then
1539 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1540 $ZPOOL destroy -f $poolname"
1545 # Import ZFS storage pool.
1546 # Force importing, even if the pool appears to be potentially active.
1551 local opts=${@:-"-o cachefile=none -o failmode=panic"}
1554 poolname=$(zpool_name $facet)
1556 if [[ -n "$poolname" ]]; then
1557 opts+=" -d $(dirname $(facet_vdevice $facet))"
1558 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1559 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1560 $ZPOOL import -f $opts $poolname"
1565 # Reimport ZFS storage pool with new name
1570 local opts="-o cachefile=none"
1571 local poolname=$(zpool_name $facet)
1573 opts+=" -d $(dirname $(facet_vdevice $facet))"
1574 do_facet $facet "$ZPOOL export $poolname;
1575 $ZPOOL import $opts $poolname $newpool"
1579 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1580 # is not automatically imported on system startup.
1582 # In a failover environment, this will provide resource level fencing which
1583 # will ensure that the same ZFS storage pool will not be imported concurrently
1584 # on different nodes.
1586 disable_zpool_cache() {
1590 poolname=$(zpool_name $facet)
1592 if [[ -n "$poolname" ]]; then
1593 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1598 # This and set_osd_param() shall be used to access OSD parameters
1599 # once existed under "obdfilter":
1604 # writethrough_cache_enable
1608 local device=${2:-$FSNAME-OST*}
1611 do_nodes $nodes "$LCTL get_param -n osd-*.$device.$name"
1616 local device=${2:-$FSNAME-OST*}
1620 do_nodes $nodes "$LCTL set_param -n osd-*.$device.$name=$value"
1624 local dz=${1:-$DEBUG_SIZE}
1626 if [ -f /sys/devices/system/cpu/possible ]; then
1627 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1629 local cpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1632 # bug 19944, adjust size to be -gt num_possible_cpus()
1633 # promise 2MB for every cpu at least
1634 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1637 lctl set_param debug_mb=$dz
1640 set_default_debug () {
1641 local debug=${1:-"$PTLDEBUG"}
1642 local subsys=${2:-"$SUBSYSTEM"}
1643 local debug_size=${3:-$DEBUG_SIZE}
1645 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1646 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1648 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1651 set_default_debug_nodes () {
1653 local debug="${2:-"$PTLDEBUG"}"
1654 local subsys="${3:-"$SUBSYSTEM"}"
1655 local debug_size="${4:-$DEBUG_SIZE}"
1657 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1658 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1662 [[ -z "$nodes" ]] ||
1663 do_rpc_nodes "$nodes" set_default_debug \
1664 \\\"$debug\\\" \\\"$subsys\\\" $debug_size || true
1667 set_default_debug_facet () {
1669 local debug="${2:-"$PTLDEBUG"}"
1670 local subsys="${3:-"$SUBSYSTEM"}"
1671 local debug_size="${4:-$DEBUG_SIZE}"
1672 local node=$(facet_active_host $facet)
1674 [ -n "$node" ] || error "No host defined for facet $facet"
1676 set_default_debug_nodes $node "$debug" "$subsys" $debug_size
1679 set_params_nodes () {
1680 [[ $# -ge 2 ]] || return 0
1684 do_nodes $nodes $LCTL set_param $@
1687 set_params_clients () {
1688 local clients=${1:-$CLIENTS}
1689 local params=${2:-$CLIENT_LCTL_SETPARAM_PARAM}
1691 [[ -n $params ]] || return 0
1692 set_params_nodes $clients $params
1696 local hostid=${1:-$(hostid)}
1698 if [ ! -s /etc/hostid ]; then
1699 printf $(echo -n $hostid |
1700 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1706 local facets=${1:-$(get_facets)}
1712 for facet in ${facets//,/ }; do
1713 mount_facet $facet &
1717 for ((index=0; index<$total; index++)); do
1718 wait ${mountpids[index]}
1720 [ $RC -eq 0 ] && continue
1722 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1723 skip_noexit "Restart of $facet failed!." &&
1726 error "Restart of $facet failed!"
1734 # Add argument "arg" (e.g., "loop") to the comma-separated list
1735 # of arguments for option "opt" (e.g., "-o") on command
1736 # line "opts" (e.g., "-o flock").
1742 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1744 if echo "$opts" | grep -q $opt_pattern; then
1745 opts=$(echo "$opts" | sed -e \
1746 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1748 opts+="${opts:+ }$opt $arg"
1754 # Associate loop device with a given regular file.
1755 # Return the loop device.
1757 setup_loop_device() {
1761 do_facet $facet "loop_dev=\\\$($LOSETUP -j $file | cut -d : -f 1);
1762 if [[ -z \\\$loop_dev ]]; then
1763 loop_dev=\\\$($LOSETUP -f);
1764 $LOSETUP \\\$loop_dev $file || loop_dev=;
1766 echo -n \\\$loop_dev"
1770 # Detach a loop device.
1772 cleanup_loop_device() {
1776 do_facet $facet "! $LOSETUP $loop_dev >/dev/null 2>&1 ||
1777 $LOSETUP -d $loop_dev"
1781 # Check if a given device is a block device.
1788 [[ -n "$dev" ]] || return 1
1789 do_facet $facet "test -b $dev" || return 1
1790 if [[ -n "$size" ]]; then
1791 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k \
1792 count=1 skip=$size 2>&1" |
1793 awk '($3 == "in") { print $1 }')
1794 [[ "$in" = "1+0" ]] || return 1
1799 # Check if a given device is a device-mapper device.
1805 [[ -n "$dev" ]] || return 1
1806 do_facet $facet "$DMSETUP status $dev >/dev/null 2>&1"
1810 # Check if a given device is a device-mapper flakey device.
1812 is_dm_flakey_dev() {
1817 [[ -n "$dev" ]] || return 1
1819 type=$(do_facet $facet "$DMSETUP status $dev 2>&1" |
1821 [[ $type = flakey ]] && return 0 || return 1
1825 # Check if device-mapper flakey device is supported by the kernel
1826 # of $facet node or not.
1828 dm_flakey_supported() {
1832 do_facet $facet "modprobe dm-flakey;
1833 $DMSETUP targets | grep -q flakey" &> /dev/null
1837 # Get the device-mapper flakey device name of a given facet.
1839 dm_facet_devname() {
1841 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
1843 echo -n ${facet}_flakey
1847 # Get the device-mapper flakey device of a given facet.
1848 # A device created by dmsetup will appear as /dev/mapper/<device-name>.
1850 dm_facet_devpath() {
1853 echo -n $DM_DEV_PATH/$(dm_facet_devname $facet)
1857 # Set a device-mapper device with a new table.
1859 # The table has the following format:
1860 # <logical_start_sector> <num_sectors> <target_type> <target_args>
1862 # flakey <target_args> includes:
1863 # <destination_device> <offset> <up_interval> <down_interval> \
1864 # [<num_features> [<feature_arguments>]]
1866 # linear <target_args> includes:
1867 # <destination_device> <start_sector>
1869 dm_set_dev_table() {
1872 local target_type=$3
1878 read tmp num_sectors tmp real_dev tmp \
1879 <<< $(do_facet $facet "$DMSETUP table $dm_dev")
1881 case $target_type in
1883 table="0 $num_sectors flakey $real_dev 0 0 1800 1 drop_writes"
1886 table="0 $num_sectors linear $real_dev 0"
1888 *) error "invalid target type $target_type" ;;
1891 do_facet $facet "$DMSETUP suspend --nolockfs --noflush $dm_dev" ||
1892 error "failed to suspend $dm_dev"
1893 do_facet $facet "$DMSETUP load $dm_dev --table \\\"$table\\\"" ||
1894 error "failed to load $target_type table into $dm_dev"
1895 do_facet $facet "$DMSETUP resume $dm_dev" ||
1896 error "failed to resume $dm_dev"
1900 # Set a device-mapper flakey device as "read-only" by using the "drop_writes"
1901 # feature parameter.
1904 # All write I/O is silently ignored.
1905 # Read I/O is handled correctly.
1907 dm_set_dev_readonly() {
1909 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1911 dm_set_dev_table $facet $dm_dev flakey
1915 # Set a device-mapper device to traditional linear mapping mode.
1917 dm_clear_dev_readonly() {
1919 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1921 dm_set_dev_table $facet $dm_dev linear
1925 # Set the device of a given facet as "read-only".
1927 set_dev_readonly() {
1929 local svc=${facet}_svc
1931 if [[ $(facet_fstype $facet) = zfs ]] ||
1932 ! dm_flakey_supported $facet; then
1933 do_facet $facet $LCTL --device ${!svc} readonly
1935 dm_set_dev_readonly $facet
1940 # Get size in 512-byte sectors (BLKGETSIZE64 / 512) of a given device.
1947 num_sectors=$(do_facet $facet "blockdev --getsz $dev 2>/dev/null")
1948 [[ ${PIPESTATUS[0]} = 0 && -n "$num_sectors" ]] || num_sectors=0
1949 echo -n $num_sectors
1953 # Create a device-mapper device with a given block device or regular file (will
1954 # be associated with loop device).
1955 # Return the full path of the device-mapper device.
1959 local real_dev=$2 # destination device
1960 local dm_dev_name=${3:-$(dm_facet_devname $facet)} # device name
1961 local dm_dev=$DM_DEV_PATH/$dm_dev_name # device-mapper device
1963 # check if the device-mapper device to be created already exists
1964 if is_dm_dev $facet $dm_dev; then
1965 # if the existing device was set to "read-only", then clear it
1966 ! is_dm_flakey_dev $facet $dm_dev ||
1967 dm_clear_dev_readonly $facet $dm_dev
1973 # check if the destination device is a block device, and if not,
1974 # associate it with a loop device
1975 is_blkdev $facet $real_dev ||
1976 real_dev=$(setup_loop_device $facet $real_dev)
1977 [[ -n "$real_dev" ]] || { echo -n $real_dev; return 2; }
1979 # now create the device-mapper device
1980 local num_sectors=$(get_num_sectors $facet $real_dev)
1981 local table="0 $num_sectors linear $real_dev 0"
1984 do_facet $facet "$DMSETUP create $dm_dev_name --table \\\"$table\\\"" ||
1985 { rc=${PIPESTATUS[0]}; dm_dev=; }
1986 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
1993 # Map the facet name to its device variable name.
1995 facet_device_alias() {
1997 local dev_alias=$facet
2000 fs2mds) dev_alias=mds1_2 ;;
2001 fs2ost) dev_alias=ost1_2 ;;
2002 fs3ost) dev_alias=ost2_2 ;;
2010 # Save the original value of the facet device and export the new value.
2016 local active_facet=$(facet_active $facet)
2017 local dev_alias=$(facet_device_alias $active_facet)
2018 local dev_name=${dev_alias}_dev
2019 local dev=${!dev_name}
2021 if [[ $active_facet = $facet ]]; then
2022 local failover_dev=${dev_alias}failover_dev
2023 if [[ ${!failover_dev} = $dev ]]; then
2024 eval export ${failover_dev}_saved=$dev
2025 eval export ${failover_dev}=$dm_dev
2028 dev_alias=$(facet_device_alias $facet)
2029 local facet_dev=${dev_alias}_dev
2030 if [[ ${!facet_dev} = $dev ]]; then
2031 eval export ${facet_dev}_saved=$dev
2032 eval export ${facet_dev}=$dm_dev
2036 eval export ${dev_name}_saved=$dev
2037 eval export ${dev_name}=$dm_dev
2041 # Restore the saved value of the facet device.
2046 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
2047 local dev_alias=$(facet_device_alias $facet)
2049 local saved_dev=${dev_alias}_dev_saved
2050 [[ -z ${!saved_dev} ]] ||
2051 eval export ${dev_alias}_dev=${!saved_dev}
2053 saved_dev=${dev_alias}failover_dev_saved
2054 [[ -z ${!saved_dev} ]] ||
2055 eval export ${dev_alias}failover_dev=${!saved_dev}
2059 # Remove a device-mapper device.
2060 # If the destination device is a loop device, then also detach it.
2064 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2068 is_dm_dev $facet $dm_dev || return 0
2070 read major minor <<< $(do_facet $facet "$DMSETUP table $dm_dev" |
2071 awk '{ print $4 }' | awk -F: '{ print $1" "$2 }')
2073 do_facet $facet "$DMSETUP remove $dm_dev"
2074 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
2076 unexport_dm_dev $facet
2078 # detach a loop device
2079 [[ $major -ne 7 ]] || cleanup_loop_device $facet /dev/loop$minor
2081 # unload dm-flakey module
2082 do_facet $facet "modprobe -r dm-flakey" || true
2088 local active_facet=$(facet_active $facet)
2089 local dev_alias=$(facet_device_alias $active_facet)
2090 local dev=${dev_alias}_dev
2091 local opt=${facet}_opt
2092 local mntpt=$(facet_mntpt $facet)
2093 local opts="${!opt} $@"
2094 local fstype=$(facet_fstype $facet)
2096 local dm_dev=${!dev}
2098 [[ $dev == "mgsfailover_dev" ]] && combined_mgs_mds &&
2099 dev=mds1failover_dev
2101 module_loaded lustre || load_modules
2105 if dm_flakey_supported $facet; then
2106 dm_dev=$(dm_create_dev $facet ${!dev})
2107 [[ -n "$dm_dev" ]] || dm_dev=${!dev}
2110 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
2112 devicelabel=$(do_facet ${facet} "$E2LABEL $dm_dev");;
2114 # import ZFS storage pool
2115 import_zpool $facet || return ${PIPESTATUS[0]}
2117 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
2118 lustre:svname $dm_dev");;
2120 error "unknown fstype!";;
2123 echo "Starting ${facet}: $opts $dm_dev $mntpt"
2124 # for testing LU-482 error handling in mount_facets() and test_0a()
2125 if [ -f $TMP/test-lu482-trigger ]; then
2129 "mkdir -p $mntpt; $MOUNT_CMD $opts $dm_dev $mntpt"
2133 if [ $RC -ne 0 ]; then
2134 echo "Start of $dm_dev on ${facet} failed ${RC}"
2138 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
2139 if [[ "$health" != "healthy" ]]; then
2140 error "$facet is in a unhealthy state"
2143 set_default_debug_facet $facet
2145 if [[ $opts =~ .*nosvc.* ]]; then
2146 echo "Start $dm_dev without service"
2151 wait_update_facet ${facet} "$E2LABEL $dm_dev \
2152 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
2153 "" || error "$dm_dev failed to initialize!";;
2155 wait_update_facet ${facet} "$ZFS get -H -o value \
2156 lustre:svname $dm_dev 2>/dev/null | \
2157 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
2158 error "$dm_dev failed to initialize!";;
2161 error "unknown fstype!";;
2165 # commit the device label change to disk
2166 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
2167 echo "Commit the device label on ${!dev}"
2168 do_facet $facet "sync; sleep 1; sync"
2172 label=$(devicelabel ${facet} $dm_dev)
2173 [ -z "$label" ] && echo no label for $dm_dev && exit 1
2174 eval export ${facet}_svc=${label}
2175 echo Started ${label}
2177 export_dm_dev $facet $dm_dev
2182 # start facet device options
2188 local dev_alias=$(facet_device_alias $facet)
2190 eval export ${dev_alias}_dev=${device}
2191 eval export ${facet}_opt=\"$@\"
2193 combined_mgs_mds && [[ ${dev_alias} == mds1 ]] &&
2194 eval export mgs_dev=${device}
2196 local varname=${dev_alias}failover_dev
2197 if [ -n "${!varname}" ] ; then
2198 eval export ${dev_alias}failover_dev=${!varname}
2200 eval export ${dev_alias}failover_dev=$device
2201 combined_mgs_mds && [[ ${dev_alias} == mds1 ]] &&
2202 eval export mgsfailover_dev=${device}
2206 local mntpt=$(facet_mntpt $facet)
2207 do_facet ${facet} mkdir -p $mntpt
2208 eval export ${facet}_MOUNT=$mntpt
2209 mount_facet ${facet}
2219 local HOST=$(facet_active_host $facet)
2220 [[ -z $HOST ]] && echo stop: no host for $facet && return 0
2222 local mntpt=$(facet_mntpt $facet)
2223 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts || true")
2224 if [ ${running} -ne 0 ]; then
2225 echo "Stopping $mntpt (opts:$@) on $HOST"
2226 do_facet ${facet} $UMOUNT $@ $mntpt
2229 # umount should block, but we should wait for unrelated obd's
2230 # like the MGS or MGC to also stop.
2231 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
2233 if [[ $(facet_fstype $facet) == zfs ]]; then
2234 # export ZFS storage pool
2235 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
2236 elif dm_flakey_supported $facet; then
2237 local host=${facet}_HOST
2238 local failover_host=${facet}failover_HOST
2239 if [[ -n ${!failover_host} && ${!failover_host} != ${!host} ]]||
2240 $CLEANUP_DM_DEV || [[ $facet = fs* ]]; then
2241 dm_cleanup_dev $facet
2246 # get mdt quota type
2248 local varsvc=${SINGLEMDS}_svc
2249 do_facet $SINGLEMDS $LCTL get_param -n \
2250 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
2253 # get ost quota type
2255 # All OSTs should have same quota type
2256 local varsvc=ost1_svc
2257 do_facet ost1 $LCTL get_param -n \
2258 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
2261 # restore old quota type settings
2263 if [ "$old_MDT_QUOTA_TYPE" ]; then
2264 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2265 do_facet mgs $PERM_CMD \
2266 osd-*.$FSNAME-MDT*.quota_slave.enabled = \
2269 do_facet mgs $PERM_CMD \
2270 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
2273 if [ "$old_OST_QUOTA_TYPE" ]; then
2274 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2275 do_facet mgs $PERM_CMD \
2276 osd-*.$FSNAME-OST*.quota_slave.enabled = \
2279 do_facet mgs $LCTL conf_param \
2280 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
2285 # Handle the case when there is a space in the lfs df
2286 # "filesystem summary" line the same as when there is no space.
2287 # This will allow fixing the "lfs df" summary line in the future.
2289 $LFS df $* | sed -e 's/filesystem /filesystem_/'
2290 check_lfs_df_ret_val $?
2293 # Get free inodes on the MDT specified by mdt index, free indoes on
2294 # the whole filesystem will be returned when index == -1.
2300 if [ $index -eq -1 ]; then
2303 mdt_uuid=$(mdtuuid_from_index $index)
2306 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
2311 # Get the OST device status from 'lfs df' with a given OST index.
2315 local mnt_pnt=${2:-$MOUNT}
2319 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
2320 lfs_df $opts $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
2326 # save old quota type & set new quota type
2327 local mdt_qtype=$(mdt_quota_type)
2328 local ost_qtype=$(ost_quota_type)
2330 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
2331 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
2333 export old_MDT_QUOTA_TYPE=$mdt_qtype
2334 export old_OST_QUOTA_TYPE=$ost_qtype
2336 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2337 do_facet mgs $PERM_CMD \
2338 osd-*.$FSNAME-MDT*.quota_slave.enabled=$QUOTA_TYPE
2339 do_facet mgs $PERM_CMD \
2340 osd-*.$FSNAME-OST*.quota_slave.enabled=$QUOTA_TYPE
2342 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$QUOTA_TYPE ||
2343 error "set mdt quota type failed"
2344 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$QUOTA_TYPE ||
2345 error "set ost quota type failed"
2348 local quota_usrs=$QUOTA_USERS
2350 # get_filesystem_size
2351 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
2352 local blk_soft=$((disksz + 1024))
2353 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
2355 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
2356 local i_soft=$inodes
2357 local i_hard=$((i_soft + i_soft / 20))
2359 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
2360 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
2361 "inode-hardlimit: $i_hard"
2364 for usr in $quota_usrs; do
2365 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
2367 cmd="$LFS setquota -$type $usr -b $blk_soft"
2368 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
2370 eval $cmd || error "$cmd FAILED!"
2372 # display the quota status
2373 echo "Quota settings for $usr : "
2374 $LFS quota -v -u $usr $mntpt || true
2381 local opts=${3:-$MOUNT_OPTS}
2382 opts=${opts:+-o $opts}
2383 local flags=${4:-$MOUNT_FLAGS}
2385 local device=$MGSNID:/$FSNAME$FILESET
2386 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2387 echo "Bad mount command: opt=$flags $opts dev=$device " \
2393 # update mount option with skpath
2394 opts=$(add_sk_mntflag $opts)
2397 echo "Starting client: $client: $flags $opts $device $mnt"
2398 do_node $client mkdir -p $mnt
2399 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
2400 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
2402 #disable FILESET if not supported
2403 do_nodes $client lctl get_param -n \
2404 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2405 device=$MGSNID:/$FSNAME
2406 do_node $client mkdir -p $mnt/$FILESET
2407 do_node $client "! grep -q $mnt' ' /proc/mounts ||
2410 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2411 # Mount using nodemap key
2412 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2413 if $SK_UNIQUE_NM; then
2414 mountkey=$SK_PATH/nodemap/c0.key
2416 local prunedopts=$(echo $opts |
2417 sed -e "s#skpath=[^,^ ]*#skpath=$mountkey#g")
2418 do_node $client $MOUNT_CMD $flags $prunedopts $device $mnt ||
2421 do_node $client $MOUNT_CMD $flags $opts $device $mnt ||
2425 set_default_debug_nodes $client
2426 set_params_clients $client
2437 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
2439 [ "$3" ] && force=-f
2440 [ $running -eq 0 ] && return 0
2442 echo "Stopping client $client $mnt (opts:$force)"
2443 do_node $client lsof -t $mnt || need_kill=no
2444 if [ "x$force" != "x" ] && [ "x$need_kill" != "xno" ]; then
2445 pids=$(do_node $client lsof -t $mnt | sort -u);
2446 if [ -n "$pids" ]; then
2447 do_node $client kill -9 $pids || true
2451 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") ||
2453 if [ $busy -ne 0 ] ; then
2454 echo "$mnt is still busy, wait one second" && sleep 1
2455 do_node $client umount $force $mnt
2459 # Mount the file system on the MDS
2460 mount_mds_client() {
2461 local host=$(facet_active_host $SINGLEMDS)
2463 zconf_mount $host $MOUNT2 $MOUNT_OPTS ||
2464 error "unable to mount $MOUNT2 on $host"
2467 # Unmount the file system on the MDS
2468 umount_mds_client() {
2469 local host=$(facet_active_host $SINGLEMDS)
2470 zconf_umount $host $MOUNT2
2471 do_facet $SINGLEMDS "rmdir $MOUNT2"
2474 # nodes is comma list
2475 sanity_mount_check_nodes () {
2481 # FIXME: assume that all cluster nodes run the same os
2482 [ "$(uname)" = Linux ] || return 0
2485 for mnt in $mnts ; do
2486 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
2487 mpts=\\\$(mount | grep -c $mnt' ');
2488 if [ \\\$running -ne \\\$mpts ]; then
2489 echo \\\$(hostname) env are INSANE!;
2492 [ $? -eq 0 ] || rc=1
2497 sanity_mount_check_servers () {
2498 [ -n "$CLIENTONLY" ] &&
2499 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
2500 echo Checking servers environments
2502 # FIXME: modify get_facets to display all facets wo params
2503 local facets="$(get_facets OST),$(get_facets MDS),mgs"
2507 for facet in ${facets//,/ }; do
2508 node=$(facet_host ${facet})
2509 mntpt=$(facet_mntpt $facet)
2510 sanity_mount_check_nodes $node $mntpt ||
2511 { error "server $node environments are insane!"; return 1; }
2515 sanity_mount_check_clients () {
2516 local clients=${1:-$CLIENTS}
2517 local mntpt=${2:-$MOUNT}
2518 local mntpt2=${3:-$MOUNT2}
2520 [ -z $clients ] && clients=$(hostname)
2521 echo Checking clients $clients environments
2523 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
2524 error "clients environments are insane!"
2527 sanity_mount_check () {
2528 sanity_mount_check_servers || return 1
2529 sanity_mount_check_clients || return 2
2532 # mount clients if not mouted
2533 zconf_mount_clients() {
2536 local opts=${3:-$MOUNT_OPTS}
2537 opts=${opts:+-o $opts}
2538 local flags=${4:-$MOUNT_FLAGS}
2539 local device=$MGSNID:/$FSNAME$FILESET
2540 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2541 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
2546 echo "Starting client $clients: $flags $opts $device $mnt"
2547 do_nodes $clients mkdir -p $mnt
2548 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ]; then
2549 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2550 # Mount with own nodemap key
2552 # Mount all server nodes first with per-NM keys
2553 for nmclient in ${clients//,/ }; do
2554 # do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key -n c$i"
2555 do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key"
2558 # set perms for per-nodemap keys else permission denied
2559 do_nodes $(comma_list $(all_nodes)) \
2560 "keyctl show | grep lustre | cut -c1-11 |
2562 xargs -IX keyctl setperm X 0x3f3f3f3f"
2563 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2565 for nmclient in ${clients//,/ }; do
2566 if $SK_UNIQUE_NM; then
2567 mountkey=$SK_PATH/nodemap/c$i.key
2569 do_node $nmclient "! grep -q $mnt' ' \
2570 /proc/mounts || umount $mnt"
2571 local prunedopts=$(add_sk_mntflag $prunedopts);
2572 prunedopts=$(echo $prunedopts | sed -e \
2573 "s#skpath=[^ ^,]*#skpath=$mountkey#g")
2575 do_nodes $(comma_list $(all_server_nodes)) \
2578 do_node $nmclient $MOUNT_CMD $flags \
2579 $prunedopts $MGSNID:/$FSNAME $mnt ||
2584 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2586 do_nodes $clients $MOUNT_CMD $flags $opts \
2587 $MGSNID:/$FSNAME $mnt || return 1
2589 #disable FILESET if not supported
2590 do_nodes $clients lctl get_param -n \
2591 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2592 device=$MGSNID:/$FSNAME
2593 do_nodes $clients mkdir -p $mnt/$FILESET
2594 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2598 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2599 # Mount with nodemap key
2601 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2602 for nmclient in ${clients//,/ }; do
2603 if $SK_UNIQUE_NM; then
2604 mountkey=$SK_PATH/nodemap/c$i.key
2606 local prunedopts=$(echo $opts | sed -e \
2607 "s#skpath=[^ ^,]*#skpath=$mountkey#g");
2608 do_node $nmclient "! grep -q $mnt' ' /proc/mounts ||
2611 running=\\\$(mount | grep -c $mnt' ');
2613 if [ \\\$running -eq 0 ] ; then
2615 $MOUNT_CMD $flags $prunedopts $device $mnt;
2618 lustre_mnt_count=\\\$(mount | grep $mnt' ' | \
2619 grep 'type lustre' | wc -l);
2620 if [ \\\$running -ne \\\$lustre_mnt_count ] ; then
2621 echo zconf_mount_clients FAILED: \
2622 mount count \\\$running, not matching \
2623 with mount count of 'type lustre' \
2624 \\\$lustre_mnt_count;
2628 exit \\\$rc" || return ${PIPESTATUS[0]}
2635 if $SHARED_KEY; then
2636 tmpopts=$(add_sk_mntflag $opts)
2639 running=\\\$(mount | grep -c $mnt' ');
2641 if [ \\\$running -eq 0 ] ; then
2643 $MOUNT_CMD $flags $tmpopts $device $mnt;
2646 exit \\\$rc" || return ${PIPESTATUS[0]}
2649 echo "Started clients $clients: "
2650 do_nodes $clients "mount | grep $mnt' '"
2652 set_default_debug_nodes $clients
2653 set_params_clients $clients
2658 zconf_umount_clients() {
2663 [ "$3" ] && force=-f
2665 echo "Stopping clients: $clients $mnt (opts:$force)"
2666 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
2667 if [ \\\$running -ne 0 ] ; then
2668 echo Stopping client \\\$(hostname) $mnt opts:$force;
2669 lsof $mnt || need_kill=no;
2670 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
2671 pids=\\\$(lsof -t $mnt | sort -u);
2672 if [ -n \\\"\\\$pids\\\" ]; then
2676 while umount $force $mnt 2>&1 | grep -q "busy"; do
2677 echo "$mnt is still busy, wait one second" && sleep 1;
2684 echo + $POWER_DOWN $node
2688 shutdown_node_hard () {
2690 local attempts=$SHUTDOWN_ATTEMPTS
2692 for i in $(seq $attempts) ; do
2695 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
2696 echo "waiting for $host to fail attempts=$attempts"
2697 [ $i -lt $attempts ] || \
2698 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
2704 local mnt=${2:-$MOUNT}
2707 if [ "$FAILURE_MODE" = HARD ]; then
2708 shutdown_node_hard $client
2710 zconf_umount_clients $client $mnt -f
2716 local facets="$(get_facets OST),$(get_facets MDS)"
2719 combined_mgs_mds || facets="$facets,mgs"
2721 for facet in ${facets//,/ }; do
2722 if [ $(facet_active_host $facet) == $host ]; then
2723 affected="$affected $facet"
2727 echo $(comma_list $affected)
2732 local host=${2:-$(facet_host $facet)}
2734 local label=$(convert_facet2label $facet)
2735 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
2738 facets_up_on_host () {
2740 local facets=$(facets_on_host $host)
2743 for facet in ${facets//,/ }; do
2744 if $(facet_up $facet $host); then
2745 affected_up="$affected_up $facet"
2749 echo $(comma_list $affected_up)
2754 local affected_facet
2755 local affected_facets
2757 if [[ "$FAILURE_MODE" = HARD ]]; then
2758 if [[ $(facet_fstype $facet) = ldiskfs ]] &&
2759 dm_flakey_supported $facet; then
2760 affected_facets=$(affected_facets $facet)
2761 for affected_facet in ${affected_facets//,/ }; do
2762 unexport_dm_dev $affected_facet
2766 shutdown_node_hard $(facet_active_host $facet)
2774 echo + $POWER_UP $node
2787 local node=$(facet_active_host $facet)
2788 local sleep_time=${2:-10}
2790 if [ "$FAILURE_MODE" = HARD ]; then
2800 if [ "$FAILURE_MODE" = HARD ]; then
2803 if $LOAD_MODULES_REMOTE; then
2804 echo "loading modules on $node: $facet"
2805 do_rpc_nodes $node load_modules_local
2814 for facet in ${facets//,/ }; do
2815 hosts=$(expand_list $hosts $(facet_host $facet) )
2821 _check_progs_installed () {
2825 for prog in $progs; do
2826 if ! [ "$(which $prog)" -o "${!prog}" ]; then
2827 echo $prog missing on $(hostname)
2834 check_progs_installed () {
2838 do_rpc_nodes "$nodes" _check_progs_installed $@
2841 # recovery-scale functions
2843 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
2846 start_client_load() {
2849 local var=$(node_var_name $client)_load
2850 eval export ${var}=$load
2852 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
2853 BREAK_ON_ERROR=$BREAK_ON_ERROR \
2854 END_RUN_FILE=$END_RUN_FILE \
2855 LOAD_PID_FILE=$LOAD_PID_FILE \
2856 TESTLOG_PREFIX=$TESTLOG_PREFIX \
2857 TESTNAME=$TESTNAME \
2858 DBENCH_LIB=$DBENCH_LIB \
2859 DBENCH_SRC=$DBENCH_SRC \
2860 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
2865 MPIRUN_OPTIONS=\\\"$MPIRUN_OPTIONS\\\" \
2866 MACHINEFILE_OPTION=\\\"$MACHINEFILE_OPTION\\\" \
2867 num_clients=$(get_node_count ${CLIENTS//,/ }) \
2868 ior_THREADS=$ior_THREADS ior_iteration=$ior_iteration \
2869 ior_blockSize=$ior_blockSize \
2870 ior_blockUnit=$ior_blockUnit \
2871 ior_xferSize=$ior_xferSize ior_type=$ior_type \
2872 ior_DURATION=$ior_DURATION \
2873 ior_stripe_params=\\\"$ior_stripe_params\\\" \
2874 ior_custom_params=\\\"$ior_custom_param\\\" \
2875 mpi_ior_custom_threads=$mpi_ior_custom_threads \
2878 log "Started client load: ${load} on $client"
2880 # get the children process IDs
2881 local pids=$(ps --ppid $ppid -o pid= | xargs)
2882 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
2886 start_client_loads () {
2887 local -a clients=(${1//,/ })
2888 local numloads=${#CLIENT_LOADS[@]}
2890 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
2891 local load=$((nodenum % numloads))
2892 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[load]}
2894 # bug 22169: wait the background threads to start
2898 # only for remote client
2899 check_client_load () {
2901 local var=$(node_var_name $client)_load
2902 local testload=run_${!var}.sh
2904 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
2906 # bug 18914: try to connect several times not only when
2907 # check ps, but while check_node_health also
2911 while [ $RC = 254 -a $tries -gt 0 ]; do
2915 if ! check_node_health $client; then
2917 if [ $RC -eq 254 ]; then
2918 # FIXME: not sure how long we shuold sleep here
2922 echo "check node health failed: RC=$RC "
2926 # We can continue try to connect if RC=254
2927 # Just print the warning about this
2928 if [ $RC = 254 ]; then
2929 echo "got a return status of $RC from do_node while checking " \
2930 "node health on $client"
2933 # see if the load is still on the client
2936 while [ $RC = 254 -a $tries -gt 0 ]; do
2940 if ! do_node $client \
2941 "ps auxwww | grep -v grep | grep -q $testload"; then
2946 if [ $RC = 254 ]; then
2947 echo "got a return status of $RC from do_node while checking " \
2948 "(node health and 'ps') the client load on $client"
2949 # see if we can diagnose a bit why this is
2954 check_client_loads () {
2955 local clients=${1//,/ }
2959 for client in $clients; do
2960 check_client_load $client
2962 if [ "$rc" != 0 ]; then
2963 log "Client load failed on node $client, rc=$rc"
2969 restart_client_loads () {
2970 local clients=${1//,/ }
2971 local expectedfail=${2:-""}
2975 for client in $clients; do
2976 check_client_load $client
2978 if [ "$rc" != 0 -a "$expectedfail" ]; then
2979 local var=$(node_var_name $client)_load
2980 start_client_load $client ${!var}
2981 echo "Restarted client load ${!var}: on $client. Checking ..."
2982 check_client_load $client
2984 if [ "$rc" != 0 ]; then
2985 log "Client load failed to restart on node $client, rc=$rc"
2986 # failure one client load means test fail
2987 # we do not need to check other
2996 # Start vmstat and save its process ID in a file.
3001 [ -z "$nodes" -o -z "$pid_file" ] && return 0
3004 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
3005 2>/dev/null </dev/null & echo \\\$! > $pid_file"
3008 # Display the nodes on which client loads failed.
3009 print_end_run_file() {
3013 [ -s $file ] || return 0
3015 echo "Found the END_RUN_FILE file: $file"
3018 # A client load will stop if it finds the END_RUN_FILE file.
3019 # That does not mean the client load actually failed though.
3020 # The first node in END_RUN_FILE is the one we are interested in.
3023 if [ -n "$node" ]; then
3024 local var=$(node_var_name $node)_load
3026 local prefix=$TESTLOG_PREFIX
3027 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
3028 local stdout_log=$prefix.run_${!var}_stdout.$node.log
3029 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
3031 echo "Client load ${!var} failed on node $node:"
3037 # Stop the process which had its PID saved in a file.
3042 [ -z "$nodes" -o -z "$pid_file" ] && return 0
3044 do_nodes $nodes "test -f $pid_file &&
3045 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
3048 # Stop all client loads.
3049 stop_client_loads() {
3050 local nodes=${1:-$CLIENTS}
3053 # stop the client loads
3054 stop_process $nodes $pid_file
3056 # clean up the processes that started them
3057 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
3059 # End recovery-scale functions
3062 # wait for a command to return the expected result
3064 # This will run @check on @node repeatedly until the output matches @expect
3065 # based on the supplied condition, or until @max_wait seconds have elapsed,
3066 # whichever comes first. @cond may be one of the normal bash operators,
3067 # "-gt", "-ge", "-eq", "-le", "-lt", "==", "!=", or "=~", and must be quoted
3068 # in the caller to avoid unintentional evaluation by the shell in the caller.
3070 # If @max_wait is not specified, the condition will be checked for up to 90s.
3072 # If --verbose is passed as the first argument, the result is printed on each
3073 # value change, otherwise it is only printed after every 10s interval.
3075 # If --quiet is passed as the first/second argument, the do_node() command
3076 # will not print the remote command before executing it each time.
3078 # Using wait_update_cond() or related helper function is preferable to adding
3079 # a "long enough" wait for some state to change in the background, since
3080 # "long enough" may be too short due to tunables, system config, or running in
3081 # a VM, and must by necessity wait too long for most cases or risk failure.
3083 # usage: wait_update_cond [--verbose] [--quiet] node check cond expect [max_wait]
3084 wait_update_cond() {
3088 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3089 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3095 local max_wait=${5:-90}
3099 local begin=$SECONDS
3103 while (( $waited <= $max_wait )); do
3104 result=$(do_node $quiet $node "$check")
3106 eval [[ "'$result'" $cond "'$expect'" ]]
3107 if [[ $? == 0 ]]; then
3108 [[ -z "$result" || $waited -le $sleep ]] ||
3109 echo "Updated after ${waited}s: want '$expect' got '$result'"
3112 if [[ -n "$verbose" && "$result" != "$prev_result" ]]; then
3113 [[ -n "$prev_result" ]] &&
3114 echo "Changed after ${waited}s: from '$prev_result' to '$result'"
3115 prev_result="$result"
3117 (( $waited % $print == 0 )) &&
3118 echo "Waiting $((max_wait - waited))s for '$expect'"
3120 waited=$((SECONDS - begin))
3122 echo "Update not seen after ${max_wait}s: want '$expect' got '$result'"
3126 # usage: wait_update [--verbose] [--quiet] node check expect [max_wait]
3131 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3132 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3139 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3142 # usage: wait_update_facet_cond [--verbose] facet check cond expect [max_wait]
3143 wait_update_facet_cond() {
3147 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3148 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3150 local node=$(facet_active_host $1)
3156 wait_update_cond $verbose $quiet $node "$check" "$cond" "$expect" $max_wait
3159 # usage: wait_update_facet [--verbose] facet check expect [max_wait]
3160 wait_update_facet() {
3164 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3165 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3167 local node=$(facet_active_host $1)
3172 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3176 do_nodes $(comma_list $(mdts_nodes)) \
3177 "lctl set_param -n os[cd]*.*MDT*.force_sync=1"
3178 do_nodes $(comma_list $(osts_nodes)) \
3179 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
3180 grep -v 'Found no match'
3184 local zfs_wait=${2:-5}
3186 # the occupied disk space will be released
3187 # only after TXGs are committed
3188 if [[ $(facet_fstype $1) == zfs ]]; then
3189 echo "sleep $zfs_wait for ZFS $(facet_fstype $1)"
3197 local lwm=$3 #low watermark
3198 local size_mb #how many MB should we write to pass watermark
3199 local ost_name=$(ostname_from_index $ost_idx)
3201 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3203 if (( $free_kb / 1024 > lwm )); then
3204 size_mb=$((free_kb / 1024 - lwm))
3206 #If 10% of free space cross low watermark use it
3207 if (( $free_kb / 10240 > size_mb )); then
3208 size_mb=$((free_kb / 10240))
3210 #At least we need to store 1.1 of difference between
3211 #free space and low watermark
3212 size_mb=$((size_mb + size_mb / 10))
3214 if (( lwm <= $free_kb / 1024 )) ||
3215 [ ! -f $DIR/${filename}.fill_ost$ost_idx ]; then
3216 $LFS setstripe -i $ost_idx -c1 $DIR/${filename}.fill_ost$ost_idx
3217 dd if=/dev/zero of=$DIR/${filename}.fill_ost$ost_idx bs=1M \
3218 count=$size_mb oflag=append conv=notrunc
3223 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3224 echo "OST still has $((free_kb / 1024)) MB free"
3227 # This checks only the primary MDS
3228 ost_watermarks_get() {
3230 local ost_name=$(ostname_from_index $ost_idx)
3231 local mdtosc_proc=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
3233 local hwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3234 osp.$mdtosc_proc.reserved_mb_high)
3235 local lwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3236 osp.$mdtosc_proc.reserved_mb_low)
3241 # Note that we set watermarks on all MDSes (necessary for striped dirs)
3242 ost_watermarks_set() {
3246 local ost_name=$(ostname_from_index $ost_idx)
3247 local facets=$(get_facets MDS)
3249 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param -n \
3250 osp.*$ost_name*.reserved_mb_low=$lwm \
3251 osp.*$ost_name*.reserved_mb_high=$hwm > /dev/null
3253 # sleep to ensure we see the change
3257 ost_watermarks_set_low_space() {
3259 local wms=$(ost_watermarks_get $ost_idx)
3260 local ost_name=$(ostname_from_index $ost_idx)
3262 local old_lwm=$(echo $wms | awk '{ print $1 }')
3263 local old_hwm=$(echo $wms | awk '{ print $2 }')
3265 local blocks=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3266 # minimal extension size is 64M
3268 if (( $blocks / 1024 > 50 )); then
3269 new_lwm=$((blocks / 1024 - 50))
3271 local new_hwm=$((new_lwm + 5))
3273 ost_watermarks_set $ost_idx $new_lwm $new_hwm
3274 echo "watermarks: $old_lwm $old_hwm $new_lwm $new_hwm"
3277 # Set watermarks to ~current available space & then write data to fill it
3278 # Note OST is not *actually* full after this, it just reports ENOSPC in the
3279 # internal statfs used by the stripe allocator
3281 # first parameter is the filename-prefix, which must get under t-f cleanup
3282 # requirements (rm -rf $DIR/[Rdfs][0-9]*), i.e. $tfile work fine
3283 ost_watermarks_set_enospc() {
3287 local ost_name=$(ostname_from_index $ost_idx)
3288 local facets=$(get_facets MDS)
3292 for MDS in ${facets//,/ }; do
3293 local mdtosc_proc=$(get_mdtosc_proc_path $MDS $ost_name)
3295 do_facet $MDS $LCTL get_param -n \
3296 osp.$mdtosc_proc.reserved_mb_high ||
3297 skip "remote MDS does not support reserved_mb_high"
3300 wms=$(ost_watermarks_set_low_space $ost_idx)
3301 local new_lwm=$(echo $wms | awk '{ print $4 }')
3302 fill_ost $filename $ost_idx $new_lwm
3303 #First enospc could execute orphan deletion so repeat
3304 fill_ost $filename $ost_idx $new_lwm
3308 ost_watermarks_enospc_delete_files() {
3312 rm -f $DIR/${filename}.fill_ost$ost_idx
3314 wait_delete_completed
3318 # clean up from "ost_watermarks_set_enospc"
3319 ost_watermarks_clear_enospc() {
3325 ost_watermarks_enospc_delete_files $filename $ost_idx
3326 ost_watermarks_set $ost_idx $old_lwm $old_hwm
3327 echo "set OST$ost_idx lwm back to $old_lwm, hwm back to $old_hwm"
3330 wait_delete_completed_mds() {
3331 local max_wait=${1:-20}
3333 local stime=$(date +%s)
3338 # find MDS with pending deletions
3339 for node in $(mdts_nodes); do
3340 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
3341 2>/dev/null | calc_sum)
3342 if [[ $changes -eq 0 ]]; then
3345 mds2sync="$mds2sync $node"
3347 if [ -z "$mds2sync" ]; then
3348 wait_zfs_commit $SINGLEMDS
3351 mds2sync=$(comma_list $mds2sync)
3353 # sync MDS transactions
3354 do_nodes $mds2sync "$LCTL set_param -n os[cd]*.*MD*.force_sync 1"
3356 # wait till all changes are sent and commmitted by OSTs
3357 # for ldiskfs space is released upon execution, but DMU
3358 # do this upon commit
3361 while [[ $WAIT -ne $max_wait ]]; do
3362 changes=$(do_nodes $mds2sync \
3363 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
3364 #echo "$node: $changes changes on all"
3365 if [[ $changes -eq 0 ]]; then
3366 wait_zfs_commit $SINGLEMDS
3368 # the occupied disk space will be released
3369 # only after TXGs are committed
3370 wait_zfs_commit ost1
3378 echo "Delete is not completed in $((etime - stime)) seconds"
3379 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
3386 # we can use "for" here because we are waiting the slowest
3387 for host in ${hostlist//,/ }; do
3388 check_network "$host" 900
3390 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
3397 for facet in ${facetlist//,/ }; do
3398 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
3400 wait_for_host $hostlist
3403 _wait_recovery_complete () {
3406 # Use default policy if $2 is not passed by caller.
3407 local MAX=${2:-$(max_recovery_time)}
3412 while [ $WAIT -lt $MAX ]; do
3413 STATUS=$(lctl get_param -n $param | grep status)
3415 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
3418 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
3420 echo "$param recovery not done in $MAX sec. $STATUS"
3424 wait_recovery_complete () {
3427 # with an assumption that at_max is the same on all nodes
3428 local MAX=${2:-$(max_recovery_time)}
3431 if [ "$FAILURE_MODE" = HARD ]; then
3432 facets=$(facets_on_host $(facet_active_host $facet))
3434 echo affected facets: $facets
3436 facets=${facets//,/ }
3437 # We can use "for" here because we are waiting the slowest.
3438 # The mgs not having the recovery_status proc entry, exclude it
3439 # from the facet list.
3440 for facet in ${facets//mgs/ }; do
3441 local var_svc=${facet}_svc
3442 local param="*.${!var_svc}.recovery_status"
3444 local host=$(facet_active_host $facet)
3445 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
3449 wait_mds_ost_sync () {
3450 # just because recovery is done doesn't mean we've finished
3451 # orphan cleanup. Wait for llogs to get synchronized.
3452 echo "Waiting for orphan cleanup..."
3453 # MAX value includes time needed for MDS-OST reconnection
3454 local MAX=$(( TIMEOUT * 2 ))
3455 local WAIT_TIMEOUT=${1:-$MAX}
3458 local list=$(comma_list $(mdts_nodes))
3459 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
3460 if ! do_facet $SINGLEMDS \
3461 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
3463 # old way, use mds_sync
3465 list=$(comma_list $(osts_nodes))
3466 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
3469 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
3470 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
3471 local -a sync=($(do_nodes $list "$cmd"))
3474 for ((i=0; i<${#sync[@]}; i++)); do
3476 [ ${sync[$i]} -eq 1 ] && continue
3478 [ ${sync[$i]} -eq 0 ] && continue
3480 # there is a not finished MDS-OST synchronization
3484 sleep 2 # increase waiting time and cover statfs cache
3485 [ ${con} -eq 1 ] && return 0
3486 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
3490 # show which nodes are not finished.
3491 cmd=$(echo $cmd | sed 's/-n//')
3492 do_nodes $list "$cmd"
3493 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
3497 # Wait OSTs to be active on both client and MDT side.
3499 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
3500 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
3501 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
3502 error "wait_update OSTs up on client failed"
3504 cmd="$LCTL get_param osp.$FSNAME-OST*-MDT0000.prealloc_last_id |
3505 awk '/=[1-9][0-9]/ { c += 1 } END { printf \\\"%d\\\", c }'"
3506 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
3507 error "wait_update OSTs up on MDT0000 failed"
3510 wait_destroy_complete () {
3511 echo "Waiting for MDT destroys to complete"
3512 # MAX value shouldn't be big as this mean server responsiveness
3513 # never increase this just to make test pass but investigate
3514 # why it takes so long time
3517 local list=$(comma_list $(mdts_nodes))
3518 while [ $WAIT -lt $MAX ]; do
3519 local -a RPCs=($(do_nodes $list $LCTL get_param -n osp.*.destroys_in_flight))
3523 for ((i=0; i<${#RPCs[@]}; i++)); do
3524 [ ${RPCs[$i]} -eq 0 ] && continue
3525 # there are still some destroy RPCs in flight
3530 [ ${con} -eq 1 ] && return 0 # done waiting
3531 echo "Waiting ${WAIT}s for local destroys to complete"
3534 echo "MDT destroys weren't done in $MAX sec."
3538 wait_delete_completed() {
3539 wait_delete_completed_mds $1 || return $?
3540 wait_destroy_complete || return $?
3549 # conf-sanity 31 takes a long time cleanup
3550 while [ $WAIT -lt 300 ]; do
3551 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null &&
3552 lctl dl | grep ' ST ' || true")
3553 [ -z "${running}" ] && return 0
3554 echo "waited $WAIT for${running}"
3555 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
3557 WAIT=$((WAIT + INTERVAL))
3559 echo "service didn't stop after $WAIT seconds. Still running:"
3564 wait_remote_prog () {
3570 [ "$PDSH" = "no_dsh" ] && return 0
3572 while [ $WAIT -lt $2 ]; do
3573 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
3574 [ -z "${running}" ] && return 0 || true
3575 echo "waited $WAIT for: "
3577 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
3579 WAIT=$((WAIT + INTERVAL))
3581 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
3582 [ -z "$pids" ] && return 0
3583 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
3584 # FIXME: not portable
3585 for pid in $pids; do
3586 cat /proc/${pid}/status || true
3587 cat /proc/${pid}/wchan || true
3589 kill -9 $pid || true
3598 local clients=${1:-$CLIENTS}
3601 if [ -z "$clients" ]; then
3602 $LFS df $MOUNT > /dev/null || rc=$?
3604 $PDSH $clients "$LFS df $MOUNT" > /dev/null || rc=$?
3607 check_lfs_df_ret_val $rc
3611 # not every config has many clients
3617 (( MDSCOUNT == 1 )) && return
3619 # wait so that statfs data on MDT expire
3620 local delay=$(do_facet mds1 $LCTL \
3621 get_param -n osp.*MDT*MDT0000.maxage | sort -n | tail -1)
3623 [ -n "$delay" ] || error "fail to get maxage"
3625 local nodes=$(comma_list $(mdts_nodes))
3626 # initiate statfs RPC, all to all MDTs
3627 do_nodes $nodes $LCTL get_param -N osp.*MDT*MDT*.filesfree >&/dev/null
3628 do_nodes $nodes $LCTL get_param -N osp.*MDT*MDT*.filesfree >&/dev/null
3632 # usually checked on particular client or locally
3641 client_reconnect_try() {
3642 local f=$MOUNT/recon
3645 if [ -z "$CLIENTS" ]; then
3646 $LFS df $MOUNT; uname -n >> $f
3648 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
3650 echo "Connected clients: $(cat $f)"
3651 ls -l $f > /dev/null
3655 client_reconnect() {
3656 # one client_reconnect_try call does not always do the job...
3658 client_reconnect_try && break
3663 affected_facets () {
3666 local host=$(facet_active_host $facet)
3667 local affected=$facet
3669 if [ "$FAILURE_MODE" = HARD ]; then
3670 affected=$(facets_up_on_host $host)
3676 local E2FSCK_ON_MDT0=false
3677 if [ "$1" == "--fsck" ]; then
3679 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
3691 #Because it will only get up facets, we need get affected
3692 #facets before shutdown
3693 #For HARD Failure mode, it needs make sure facets on the same
3694 #HOST will only be shutdown and reboot once
3695 for facet in ${facets//,/ }; do
3696 local affected_facet
3698 #check whether facet has been included in other affected facets
3699 for ((index=0; index<$total; index++)); do
3700 [[ ,${affecteds[index]}, == *,$facet,* ]] && skip=1
3703 if [ $skip -eq 0 ]; then
3704 affecteds[$total]=$(affected_facets $facet)
3709 for ((index=0; index<$total; index++)); do
3710 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
3711 local host=$(facet_active_host $facet)
3712 echo "Failing ${affecteds[index]} on $host"
3713 shutdown_facet $facet
3716 echo "$(date +'%H:%M:%S (%s)') shut down"
3721 for facet in ${facets//,/ }; do
3722 local host=$(facet_active_host $facet)
3724 hostlist=$(expand_list $hostlist $host)
3725 if [ $(facet_host $facet) = \
3726 $(facet_failover_host $facet) ]; then
3727 waithostlist=$(expand_list $waithostlist $host)
3731 if [ "$FAILURE_MODE" = HARD ]; then
3732 for host in ${hostlist//,/ }; do
3735 echo "$(date +'%H:%M:%S (%s)') $hostlist rebooted"
3736 # We need to wait the rebooted hosts in case if
3737 # facet_HOST == facetfailover_HOST
3738 if ! [ -z "$waithostlist" ]; then
3739 wait_for_host $waithostlist
3740 if $LOAD_MODULES_REMOTE; then
3741 echo "loading modules on $waithostlist"
3742 do_rpc_nodes $waithostlist load_modules_local
3749 if [[ " ${affecteds[@]} " =~ " $SINGLEMDS " ]]; then
3750 change_active $SINGLEMDS
3753 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
3754 $(facet_device $SINGLEMDS) "-n" || error "Running e2fsck")
3758 for ((index=0; index<$total; index++)); do
3759 if [[ ${affecteds[index]} != $SINGLEMDS ]]; then
3760 change_active ${affecteds[index]}
3764 init_facets_vars_simple
3766 # start mgs first if it is affected
3767 if ! combined_mgs_mds &&
3768 list_member ${affecteds[index]} mgs; then
3769 mount_facet mgs || error "Restart of mgs failed"
3770 affecteds[index]=$(exclude_items_from_list \
3771 ${affecteds[index]} mgs)
3773 if [ -n "${affecteds[index]}" ]; then
3774 echo mount facets: ${affecteds[index]}
3775 mount_facets ${affecteds[index]} &
3779 for ((index=0; index<$total; index++)); do
3780 if [ -n "${affecteds[index]}" ]; then
3781 wait ${mountpids[index]}
3785 do_nodes $(comma_list $(all_nodes)) \
3786 "keyctl show | grep lustre | cut -c1-11 |
3788 xargs -IX keyctl setperm X 0x3f3f3f3f"
3791 echo "$(date +'%H:%M:%S (%s)') targets are mounted"
3793 if [ "$FAILURE_MODE" = HARD ]; then
3794 hostlist=$(exclude_items_from_list $hostlist $waithostlist)
3795 if ! [ -z "$hostlist" ]; then
3796 wait_for_host $hostlist
3797 if $LOAD_MODULES_REMOTE; then
3798 echo "loading modules on $hostlist"
3799 do_rpc_nodes $hostlist load_modules_local
3804 echo "$(date +'%H:%M:%S (%s)') facet_failover done"
3809 do_facet $facet "sync; sync; sync"
3812 # make sure there will be no seq change
3813 local clients=${CLIENTS:-$HOSTNAME}
3814 local f=fsa-\\\$\(hostname\)
3815 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
3816 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
3818 local svc=${facet}_svc
3819 do_facet $facet $LCTL --device ${!svc} notransno
3821 # If a ZFS OSD is made read-only here, its pool is "freezed". This
3822 # in-memory state has to be cleared by either rebooting the host or
3823 # exporting and reimporting the pool.
3825 # Although the uberblocks are not updated when a pool is freezed,
3826 # transactions are still written to the disks. Modified blocks may be
3827 # cached in memory when tests try reading them back. The
3828 # export-and-reimport process also evicts any cached pool data from
3829 # memory to provide the correct "data loss" semantics.
3831 # In the test framework, the exporting and importing operations are
3832 # handled by stop() and mount_facet() separately, which are used
3833 # inside fail() and fail_abort().
3835 set_dev_readonly $facet
3836 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
3837 $LCTL mark "local REPLAY BARRIER on ${!svc}"
3840 replay_barrier_nodf() {
3841 local facet=$1 echo running=${running}
3842 do_facet $facet "sync; sync; sync"
3843 local svc=${facet}_svc
3844 echo Replay barrier on ${!svc}
3845 do_facet $facet $LCTL --device ${!svc} notransno
3846 set_dev_readonly $facet
3847 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
3848 $LCTL mark "local REPLAY BARRIER on ${!svc}"
3851 replay_barrier_nosync() {
3852 local facet=$1 echo running=${running}
3853 local svc=${facet}_svc
3854 echo Replay barrier on ${!svc}
3855 do_facet $facet $LCTL --device ${!svc} notransno
3856 set_dev_readonly $facet
3857 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
3858 $LCTL mark "local REPLAY BARRIER on ${!svc}"
3862 # Get Lustre client uuid for a given Lustre mount point.
3865 local mntpnt=${1:-$MOUNT}
3867 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
3868 local uuid=$($LCTL get_param -n llite.$name.uuid)
3873 mds_evict_client() {
3874 local mntpnt=${1:-$MOUNT}
3875 local uuid=$(get_client_uuid $mntpnt)
3877 do_facet $SINGLEMDS \
3878 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
3881 ost_evict_client() {
3882 local mntpnt=${1:-$MOUNT}
3883 local uuid=$(get_client_uuid $mntpnt)
3886 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
3891 local clients=${CLIENTS:-$HOSTNAME}
3893 SK_NO_KEY_save=$SK_NO_KEY
3895 export SK_NO_KEY=false
3897 facet_failover $* || error "failover: $?"
3898 export SK_NO_KEY=$SK_NO_KEY_save
3899 # to initiate all OSC idling connections
3901 wait_clients_import_state "$clients" "$facets" "\(FULL\|IDLE\)"
3902 clients_up || error "post-failover stat: $?"
3908 facet_failover $facet
3913 local abort_type=${2:-"abort_recovery"}
3916 change_active $facet
3917 wait_for_facet $facet
3918 mount_facet $facet -o $abort_type
3919 clients_up || echo "first stat failed: $?"
3920 clients_up || error "post-failover stat: $?"
3924 # LU-16159: abort recovery will cancel update logs, which may leave broken
3925 # directories in the system, remove name entry if necessary
3926 fail_abort_cleanup() {
3928 find $DIR/$tdir -depth | while read D; do
3929 rmdir "$D" || $LFS rm_entry "$D" || error "rm $D failed"
3933 host_nids_address() {
3937 do_nodes $nodes "$LCTL list_nids | grep -w $net | cut -f 1 -d @"
3941 if [ "$1" = "'*'" ]; then echo \'*\'; else
3947 if [[ -n "$NETTYPE" ]]; then
3948 h2name_or_ip "$1" "$NETTYPE"
3950 h2name_or_ip "$1" "$2"
3953 declare -fx h2nettype
3955 # Wrapper function to print the deprecation warning
3957 echo "h2tcp: deprecated, use h2nettype instead" 1>&2
3958 if [[ -n "$NETTYPE" ]]; then
3961 h2nettype "$1" "tcp"
3965 # Wrapper function to print the deprecation warning
3967 echo "h2o2ib: deprecated, use h2nettype instead" 1>&2
3968 if [[ -n "$NETTYPE" ]]; then
3971 h2nettype "$1" "o2ib"
3975 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
3976 # expressions format. As a bonus we can then just pass in those variables
3977 # to pdsh. What this function does is take a HOSTLIST type string and
3978 # expand it into a space deliminated list for us.
3986 [ -z "$hostlist" ] && return
3988 # Translate the case of [..],..,[..] to [..] .. [..]
3989 list="${hostlist/],/] }"
3991 [[ "$front" == *,* ]] && {
3994 list=${list/${old}/${new}}
3997 for item in $list; do
3998 # Test if we have any []'s at all
3999 if [ "$item" != "${item/\[/}" ]; then {
4000 # Expand the [*] into list
4004 if [ "$name" != "$item" ]; then
4005 group=${item#$name[*}
4008 for range in ${group//,/ }; do
4014 # Number of leading zeros
4017 end=$(echo $end | sed 's/0*//')
4018 [[ -z "$end" ]] && end=0
4019 [[ $padlen2 -gt $padlen ]] && {
4020 [[ $padlen2 -eq ${#end} ]] && padlen2=0
4023 begin=$(echo $begin | sed 's/0*//')
4024 [ -z $begin ] && begin=0
4026 if [ ! -z "${begin##[!0-9]*}" ]; then
4027 order=$(seq -f "%0${padlen}g" $begin $end)
4029 order=$(eval echo {$begin..$end});
4032 for num in $order; do
4033 value="${name#*,}${num}${back}"
4034 [ "$value" != "${value/\[/}" ] && {
4035 value=$(hostlist_expand "$value")
4037 myList="$myList $value"
4042 myList="$myList $item"
4045 myList=${myList//,/ }
4046 myList=${myList:1} # Remove first character which is a space
4048 # Filter any duplicates without sorting
4050 myList="${list%% *}"
4052 while [[ "$list" != ${myList##* } ]]; do
4053 local tlist=" $list"
4054 list=${tlist// ${list%% *} / }
4056 myList="$myList ${list%% *}"
4058 myList="${myList%* }";
4060 # We can select an object at an offset in the list
4063 for item in $myList; do
4065 [ $cnt -eq $offset ] && {
4069 [ $(get_node_count $myList) -ne 1 ] && myList=""
4078 [ "$facet" == client ] && echo -n $HOSTNAME && return
4079 varname=${facet}_HOST
4080 if [ -z "${!varname}" ]; then
4081 if [ "${facet:0:3}" == "ost" ]; then
4082 local fh=${facet%failover}_HOST
4083 eval export ${facet}_HOST=${!fh}
4084 if [ -z "${!varname}" ]; then
4085 eval export ${facet}_HOST=${ost_HOST}
4087 elif [ "${facet:0:3}" == "mdt" -o \
4088 "${facet:0:3}" == "mds" -o \
4089 "${facet:0:3}" == "mgs" ]; then
4091 if [ "${facet}" == "mgsfailover" ] &&
4092 [ -n "$mds1failover_HOST" ]; then
4093 temp=$mds1failover_HOST
4097 eval export ${facet}_HOST=$temp
4103 facet_failover_host() {
4107 var=${facet}failover_HOST
4108 if [ -n "${!var}" ]; then
4113 if combined_mgs_mds && [ $facet == "mgs" ] &&
4114 [ -n "$mds1failover_HOST" ]; then
4115 echo $mds1failover_HOST
4119 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
4120 "${facet:0:3}" == "mgs" ]; then
4122 eval export ${facet}failover_host=${mds_HOST}
4127 if [[ $facet == ost* ]]; then
4128 eval export ${facet}failover_host=${ost_HOST}
4136 local activevar=${facet}active
4138 if [ -f $TMP/${facet}active ] ; then
4139 source $TMP/${facet}active
4142 active=${!activevar}
4143 if [ -z "$active" ] ; then
4150 facet_active_host() {
4151 facet_host $(facet_active $1)
4154 # Get the passive failover partner host of facet.
4155 facet_passive_host() {
4157 [[ $facet = client ]] && return
4159 local host=${facet}_HOST
4160 local failover_host=${facet}failover_HOST
4161 local active_host=$(facet_active_host $facet)
4163 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
4165 if [[ $active_host = ${!host} ]]; then
4166 echo -n ${!failover_host}
4176 for facet in ${facetlist//,/ }; do
4177 local failover=${facet}failover
4178 local host=`facet_host $failover`
4180 [ -z "$host" ] && return
4182 local curactive=`facet_active $facet`
4184 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
4185 eval export ${facet}active=$facet
4187 eval export ${facet}active=$failover
4189 # save the active host for this facet
4190 local activevar=${facet}active
4192 echo "$activevar=${!activevar}" > $TMP/$activevar
4193 [[ $facet = mds1 ]] && combined_mgs_mds && \
4194 echo "mgsactive=${!activevar}" > $TMP/mgsactive
4195 local TO=`facet_active_host $facet`
4196 echo "Failover $facet to $TO"
4204 # do not strip off hostname if verbose, b=19215
4205 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4206 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4212 if [ "$HOST" = "$HOSTNAME" ]; then
4214 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
4215 echo "cannot run remote command on $HOST with $myPDSH"
4218 if $VERBOSE && [[ -z "$quiet" ]]; then
4219 echo "CMD: $HOST $*" >&2
4220 $myPDSH $HOST "$LCTL mark \"$*\"" > /dev/null 2>&1 || :
4223 if [[ "$myPDSH" == "rsh" ]] ||
4224 [[ "$myPDSH" == *pdsh* && "$myPDSH" != *-S* ]]; then
4225 # we need this because rsh and pdsh do not return
4226 # exit code of an executed command
4227 local command_status="$TMP/cs"
4228 eval $myPDSH $HOST ":> $command_status"
4229 eval $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests;
4230 PATH=\$PATH:/sbin:/usr/sbin;
4232 LUSTRE=\"$RLUSTRE\" bash -c \"$*\") ||
4233 echo command failed >$command_status"
4234 [[ -n "$($myPDSH $HOST cat $command_status)" ]] && return 1 ||
4238 if [[ -n "$verbose" ]]; then
4239 # print HOSTNAME for myPDSH="no_dsh"
4240 if [[ $myPDSH = no_dsh ]]; then
4242 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4243 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")" |
4244 sed -e "s/^/${HOSTNAME}: /"
4247 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4248 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")"
4252 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4253 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$*\")" |
4254 sed "s/^${HOST}: //"
4256 return ${PIPESTATUS[0]}
4260 # Execute exact command line on host
4262 # The \a host may be on a local or remote node, which is determined at
4263 # the time the command is run. Does careful argument quotation to
4264 # ensure that the exact command line is executed without any globbing,
4265 # substitution, or shell interpretation on the remote side. Does not
4266 # support --verbose or --quiet. Does not include "$host: " prefixes on
4267 # output. See also do_facet_vp().
4269 # usage: do_node_vp "$host" "$command" "$arg"...
4274 if [[ "$host" == "$HOSTNAME" ]]; then
4275 sh -c "$(printf -- ' %q' "$@")"
4279 if [[ "${PDSH}" != *pdsh* || "${PDSH}" != *-S* ]]; then
4280 echo "cannot run '$*' on host '${host}' with PDSH='${PDSH}'" >&2
4284 # -N Disable hostname: prefix on lines of output.
4286 $PDSH "${host}" -N "cd $RPWD; PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; export LUSTRE=$RLUSTRE; $(printf -- ' %q' "$@")"
4289 single_local_node () {
4290 [ "$1" = "$HOSTNAME" ]
4293 # Outputs environment variable assignments that should be passed to remote nodes
4297 local facets=$(get_facets)
4300 for var in ${!MODOPTS_*}; do
4301 value=${!var//\"/\\\"}
4302 echo -n " ${var}=\"$value\""
4305 for facet in ${facets//,/ }; do
4307 if [ -n "${!var}" ]; then
4308 echo -n " $var=${!var}"
4312 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
4313 if [ -n "${!var}" ]; then
4314 echo -n " $var=${!var}"
4318 for var in VERBOSE; do
4319 if [ -n "${!var}" ]; then
4320 echo -n " $var=${!var}"
4324 if [ -n "$FSTYPE" ]; then
4325 echo -n " FSTYPE=$FSTYPE"
4328 for var in LNETLND NETTYPE; do
4329 if [ -n "${!var}" ]; then
4330 echo -n " $var=${!var}"
4339 # do not strip off hostname if verbose, b=19215
4340 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4341 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4346 if single_local_node $rnodes; then
4347 do_node $verbose $quiet $rnodes "$@"
4351 # This is part from do_node
4354 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] &&
4355 echo "cannot run remote command on $rnodes with $myPDSH" &&
4358 export FANOUT=$(get_node_count "${rnodes//,/ }")
4359 if $VERBOSE && [[ -z "$quiet" ]]; then
4360 echo "CMD: $rnodes $*" >&2
4361 $myPDSH $rnodes "$LCTL mark \"$*\"" > /dev/null 2>&1 || :
4364 # do not replace anything from pdsh output if -N is used
4365 # -N Disable hostname: prefix on lines of output.
4366 if [[ -n "$verbose" || $myPDSH = *-N* ]]; then
4367 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) bash -c \"$*\")"
4369 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) bash -c \"$*\")" | sed -re "s/^[^:]*: //g"
4371 return ${PIPESTATUS[0]}
4375 # Execute commands on a single service's host
4377 # The \a facet (service) may be on a local or remote node, which is
4378 # determined at the time the command is run.
4380 # usage: do_facet $facet command [arg ...]
4385 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4386 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4390 local host=$(facet_active_host $facet)
4392 [ -z "$host" ] && echo "No host defined for facet ${facet}" && exit 1
4393 do_node $verbose $quiet $host "$@"
4397 # Execute exact command line on the host of a facet
4399 # The \a facet (service) may be on a local or remote node, which is
4400 # determined at the time the command is run. Does careful argument
4401 # quotation to ensure that the exact command line is executed without
4402 # any globbing, substitution, or shell interpretation on the remote
4403 # side. Does not support --verbose or --quiet. Does not include
4404 # "$host: " prefixes on output.
4406 # usage: do_facet_vp "$facet" "$command" "$arg"...
4409 local host=$(facet_active_host "$facet")
4412 if [[ -z "$host" ]]; then
4413 echo "no host defined for facet ${facet}" >&2
4417 do_node_vp "$host" "$@"
4420 # Function: do_facet_random_file $FACET $FILE $SIZE
4421 # Creates FILE with random content on the given FACET of given SIZE
4423 do_facet_random_file() {
4427 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
4428 do_facet $facet "$cmd 2>/dev/null"
4431 do_facet_create_file() {
4435 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
4436 do_facet $facet "$cmd 2>/dev/null"
4440 do_nodes --verbose "$@"
4446 # make sure its not already running
4448 rm -f $TMP/${facet}active
4449 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
4451 # make sure in-tree ldiskfs is loaded before mkfs
4452 if local_mode && [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
4453 load_module ../ldiskfs/ldiskfs
4456 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
4458 if [[ $(facet_fstype $facet) == zfs ]]; then
4460 # After formatting a ZFS target, "cachefile=none" property will
4461 # be set on the ZFS storage pool so that the pool is not
4462 # automatically imported on system startup. And then the pool
4463 # will be exported so as to leave the importing and exporting
4464 # operations handled by mount_facet() and stop() separately.
4466 refresh_partition_table $facet $(facet_vdevice $facet)
4467 disable_zpool_cache $facet
4472 # Device formatted as ost
4475 local DEVNAME=OSTDEV$num
4477 local fstype=$(facet_fstype ost$num)
4481 local dev=ost${num}_dev
4482 [[ -n ${!dev} ]] && eval DEVPTR=${!dev} ||
4483 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
4484 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
4486 #try $OSTZFSDEVn - independent of vdev
4487 DEVNAME=OSTZFSDEV$num
4488 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
4490 error "unknown fstype!";;
4496 # Physical device location of data
4502 local fstype=$(facet_fstype ost$num)
4506 # vdevs are not supported by ldiskfs
4509 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
4510 # Device formatted by zfs
4512 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
4514 error "unknown fstype!";;
4520 # Logical device formatted for lustre
4523 local DEVNAME=MDSDEV$num
4525 local fstype=$(facet_fstype mds$num)
4529 local dev=mds${num}_dev
4530 [[ -n ${!dev} ]] && eval DEVPTR=${!dev} ||
4531 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
4532 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
4534 # try $MDSZFSDEVn - independent of vdev
4535 DEVNAME=MDSZFSDEV$num
4536 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
4538 error "unknown fstype!";;
4544 # Physical location of data
4548 local fstype=$(facet_fstype mds$num)
4552 # vdevs are not supported by ldiskfs
4555 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
4556 # Device formatted by ZFS
4557 local DEVNAME=MDSDEV$num
4558 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
4560 error "unknown fstype!";;
4568 local fstype=$(facet_fstype mgs)
4572 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4573 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $MDSDEV1 ] ); then
4574 DEVPTR=$(mdsdevname 1)
4576 [[ -n $mgs_dev ]] && DEVPTR=$mgs_dev ||
4580 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4581 ( [ -z "$MGSZFSDEV" ] &&
4582 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
4583 DEVPTR=$(mdsdevname 1)
4585 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
4588 error "unknown fstype!";;
4597 local fstype=$(facet_fstype mgs)
4601 # vdevs are not supported by ldiskfs
4604 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4605 ( [ -z "$MGSDEV" ] &&
4606 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
4607 VDEVPTR=$(mdsvdevname 1)
4608 elif [ -n "$MGSDEV" ]; then
4612 error "unknown fstype!";;
4620 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
4622 local var=${facet}_MOUNT
4623 eval mntpt=${!var:-${MOUNT}-$facet}
4630 local dev=$(facet_device $facet)
4631 local mnt=${2:-$(facet_mntpt $facet)}
4635 if dm_flakey_supported $facet; then
4636 dm_dev=$(dm_create_dev $facet $dev)
4637 [[ -n "$dm_dev" ]] || dm_dev=$dev
4639 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
4640 export_dm_dev $facet $dm_dev
4642 do_facet $facet mount -t ldiskfs $opts $dm_dev $mnt
4647 local dev=$(facet_device $facet)
4648 local mnt=${2:-$(facet_mntpt $facet)}
4650 do_facet $facet $UMOUNT $mnt
4654 echo -n "$1" | tr -c '[:alnum:]\n' '_'
4659 local ds=$(facet_device $facet)
4660 local mnt=${2:-$(facet_mntpt $facet)}
4665 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
4666 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
4667 do_facet $facet $ZFS set canmount=noauto $ds
4669 # The "legacy" mount method is used here because "zfs unmount $mnt"
4670 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
4671 # targets are not available at the time, the stat(2) on $MOUNT will
4674 do_facet $facet $ZFS set mountpoint=legacy $ds
4675 do_facet $facet mount -t zfs $ds $mnt
4676 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
4677 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
4682 local ds=$(facet_device $facet)
4683 local mnt=${2:-$(facet_mntpt $facet)}
4684 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
4685 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
4686 local mntpt=${!var_mntpt}
4687 local canmnt=${!var_canmnt}
4691 do_facet $facet umount $mnt
4692 do_facet $facet $ZFS set mountpoint=$mntpt $ds
4693 do_facet $facet $ZFS set canmount=$canmnt $ds
4700 local fstype=$(facet_fstype $facet)
4702 mount_$fstype $facet $mnt
4708 local fstype=$(facet_fstype $facet)
4710 unmount_$fstype $facet $mnt
4717 # make sure we are using the primary server, so test-framework will
4718 # be able to clean up properly.
4719 activemds=`facet_active mds1`
4720 if [ $activemds != "mds1" ]; then
4724 local clients=$CLIENTS
4725 [ -z $clients ] && clients=$(hostname)
4727 zconf_umount_clients $clients $MOUNT "$*" || true
4728 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
4730 [ -n "$CLIENTONLY" ] && return
4732 # The add fn does rm ${facet}active file, this would be enough
4733 # if we use do_facet <facet> only after the facet added, but
4734 # currently we use do_facet mds in local.sh
4736 for num in `seq $MDSCOUNT`; do
4738 rm -f ${TMP}/mds${num}active
4740 combined_mgs_mds && rm -f $TMP/mgsactive
4742 for num in `seq $OSTCOUNT`; do
4744 rm -f $TMP/ost${num}active
4747 if ! combined_mgs_mds ; then
4751 if $SHARED_KEY; then
4752 export SK_MOUNTED=false
4758 cleanup_echo_devs () {
4761 local devs=$($LCTL dl | grep echo | awk '{print $4}')
4763 for dev in $devs; do
4764 $LCTL --device $dev cleanup
4765 $LCTL --device $dev detach
4770 nfs_client_mode && return
4771 cifs_client_mode && return
4774 CLEANUP_DM_DEV=true stopall $*
4781 combined_mgs_mds () {
4782 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
4783 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
4787 echo -n "$1" | tr '[:upper:]' '[:lower:]'
4791 echo -n "$1" | tr '[:lower:]' '[:upper:]'
4803 var=$(echo "$var" | sed -e 's/,\( \)*/,/g')
4804 for i in $(echo "$var"); do
4805 if [ "$i" == "-O" ]; then
4807 first_o=$(($first_o + 1))
4810 if [ "$i" == "-E" ]; then
4812 first_e=$(($first_e + 1 ))
4817 [ $first_o -gt 1 ] && opt_o+=",";
4821 [ $first_e -gt 1 ] && opt_e+=",";
4832 [ -n "$opt_o" ] && echo " -O $opt_o"
4833 [ -n "$opt_e" ] && echo " -E $opt_e"
4839 local fsname=${3:-"$FSNAME"}
4840 local type=$(facet_type $facet)
4841 local index=$(facet_index $facet)
4842 local fstype=$(facet_fstype $facet)
4843 local host=$(facet_host $facet)
4847 local varbs=${facet}_BLOCKSIZE
4849 if [ $type == MGS ] || ( [ $type == MDS ] &&
4850 [ "$dev" == $(mgsdevname) ] &&
4851 [ "$host" == "$(facet_host mgs)" ] ); then
4854 opts="--mgsnode=$MGSNID"
4857 if [ $type != MGS ]; then
4858 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
4862 var=${facet}failover_HOST
4863 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
4864 opts+=" --failnode=$(h2nettype ${!var})"
4867 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
4868 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
4870 if [ $type == MDS ]; then
4871 opts+=${DEF_STRIPE_SIZE:+" --param=lov.stripesize=$DEF_STRIPE_SIZE"}
4872 opts+=${DEF_STRIPE_COUNT:+" --param=lov.stripecount=$DEF_STRIPE_COUNT"}
4873 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
4875 if [ $fstype == ldiskfs ]; then
4877 if [ -n "${!var}" ]; then
4878 fs_mkfs_opts+=" -J device=${!var}"
4880 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
4882 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
4886 if [ $type == OST ]; then
4887 if [ $fstype == ldiskfs ]; then
4889 if [ -n "${!var}" ]; then
4890 fs_mkfs_opts+=" -J device=${!var}"
4892 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
4897 opts+=" --backfstype=$fstype"
4900 if [ -n "${!var}" ]; then
4901 opts+=" --device-size=${!var}"
4904 var=$(upper $fstype)_MKFS_OPTS
4905 fs_mkfs_opts+=${!var:+" ${!var}"}
4907 var=${type}_FS_MKFS_OPTS
4908 fs_mkfs_opts+=${!var:+" ${!var}"}
4910 [[ "$QUOTA_TYPE" =~ "p" ]] && fs_mkfs_opts+=" -O project"
4912 [ $fstype == ldiskfs ] && fs_mkfs_opts+=" -b ${!varbs:-$BLCKSIZE}"
4913 [ $fstype == ldiskfs ] && fs_mkfs_opts=$(squash_opt $fs_mkfs_opts)
4915 if [ -n "${fs_mkfs_opts## }" ]; then
4916 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
4920 opts+=${!var:+" ${!var}"}
4927 local type=$(facet_type $facet)
4928 local var=${type}_MOUNT_FS_OPTS
4930 if [ -n "${!var}" ]; then
4931 opts+=" --mountfsoptions=${!var}"
4936 check_ost_indices() {
4937 local index_count=${#OST_INDICES[@]}
4938 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
4940 # OST count is greater than the index count in $OST_INDEX_LIST.
4941 # We need check whether there are duplicate indices.
4945 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
4946 index=$(facet_index ost$i)
4947 for j in $(seq 0 $((index_count - 1))); do
4948 [[ $index -ne ${OST_INDICES[j]} ]] ||
4949 error "ost$i has the same index $index as ost$((j+1))"
4956 local facet_type=$1 # mgs || mds || ost
4958 local facet=${1}${2}
4961 case "$(facet_fstype $facet)" in
4963 device=$(${facet_type}devname $facet_num)
4966 device=$(${facet_type}vdevname $facet_num)
4969 error "Unhandled filesystem type"
4973 do_facet $facet "[ -e \"$device\" ]" && return
4975 # Note: the following check only works with absolute paths
4976 [[ ! "$device" =~ ^/dev/ ]] || [[ "$device" =~ ^/dev/shm/ ]] ||
4977 error "$facet: device '$device' does not exist"
4979 # zpool create doesn't like empty files
4980 [[ $(facet_fstype $facet) == zfs ]] && return 0
4982 do_facet $facet "touch \"${device}\""
4991 echo "Format mgs: $(mgsdevname)"
4992 reformat_external_journal mgs
4994 # touch "device" in case it is a loopback file for testing and needs to
4995 # be created. mkfs.lustre doesn't do this to avoid accidentally writing
4996 # to non-existent files in /dev if the admin made a typo during setup
4999 add mgs $(mkfs_opts mgs $(mgsdevname)) $(mountfs_opts mgs) --reformat \
5000 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
5010 echo "Format mds$num: $(mdsdevname $num)"
5011 reformat_external_journal mds$num
5013 __touch_device mds $num
5015 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
5016 $(mountfs_opts mds$num) --reformat $(mdsdevname $num) \
5017 $(mdsvdevname $num) ${quiet:+>/dev/null} || exit 10
5026 echo "Format ost$num: $(ostdevname $num)"
5027 reformat_external_journal ost$num
5029 __touch_device ost $num
5031 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
5032 $(mountfs_opts ost$num) --reformat $(ostdevname $num) \
5033 $(ostvdevname ${num}) ${quiet:+>/dev/null} || exit 10
5038 # Set hostid for ZFS/SPL zpool import protection
5039 # (Assumes MDS version is also OSS version)
5040 if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ];
5042 do_rpc_nodes "$(comma_list $(all_server_nodes))" set_hostid
5045 # We need ldiskfs here, may as well load them all
5047 [ -n "$CLIENTONLY" ] && return
5048 echo Formatting mgs, mds, osts
5049 if ! combined_mgs_mds ; then
5053 for num in $(seq $MDSCOUNT); do
5057 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
5059 for num in $(seq $OSTCOUNT); do
5065 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
5069 grep " $1 " /proc/mounts && zconf_umount $HOSTNAME $*
5073 # 0: success, the old identity set already.
5074 # 1: success, the old identity does not set.
5079 local j=`expr $num - 1`
5080 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
5082 if [ -z "$MDT" ]; then
5086 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
5089 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
5091 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
5094 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
5096 if [ $old = "NONE" ]; then
5105 zconf_umount $HOSTNAME $1 || error "umount failed"
5106 zconf_mount $HOSTNAME $1 || error "mount failed"
5114 rm -f $TMP/${facet}active
5115 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
5120 local mdt_count=${1:-$MDSCOUNT}
5121 local ost_count=${2:-$OSTCOUNT}
5124 for num in $(seq $mdt_count); do
5125 DEVNAME=$(mdsdevname $num)
5126 writeconf_facet mds$num $DEVNAME || rc=$?
5129 for num in $(seq $ost_count); do
5130 DEVNAME=$(ostdevname $num)
5131 writeconf_facet ost$num $DEVNAME || rc=$?
5137 if ! combined_mgs_mds ; then
5138 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
5147 for num in $(seq $MDSCOUNT); do
5148 devname=$(mdsdevname $num)
5149 start mds$num $devname $MDS_MOUNT_OPTS
5151 # We started mds$num, now we should set mds${num}_HOST
5152 # and mds${num}failover_HOST variables properly if they
5154 host=$(facet_host mds$num)
5155 for varname in mds${num}_HOST mds${num}failover_HOST; do
5156 if [[ -z "${!varname}" ]]; then
5160 if [ $IDENTITY_UPCALL != "default" ]; then
5161 switch_identity $num $IDENTITY_UPCALL
5171 for num in $(seq $OSTCOUNT); do
5172 devname=$(ostdevname $num)
5173 start ost$num $devname $OST_MOUNT_OPTS
5175 # We started ost$num, now we should set ost${num}_HOST
5176 # and ost${num}failover_HOST variables properly if they
5178 host=$(facet_host ost$num)
5179 for varname in ost${num}_HOST ost${num}failover_HOST; do
5180 if [[ -z "${!varname}" ]]; then
5188 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
5189 if [ ! -z $arg1 ]; then
5190 [ "$arg1" = "server_only" ] && return
5193 if [ -n "$CLIENTS" ]; then
5194 zconf_mount_clients $CLIENTS $MOUNT
5198 if [ "$MOUNT_2" ]; then
5199 mount_client $MOUNT2
5200 if [ -n "$CLIENTS" ]; then
5201 zconf_mount_clients $CLIENTS $MOUNT2
5206 sk_nodemap_setup() {
5207 local sk_map_name=${1:-$SK_S2SNM}
5208 local sk_map_nodes=${2:-$HOSTNAME}
5209 do_node $(mgs_node) "$LCTL nodemap_add $sk_map_name"
5210 for servernode in $sk_map_nodes; do
5211 local nids=$(do_nodes $servernode "$LCTL list_nids")
5212 for nid in $nids; do
5213 do_node $(mgs_node) "$LCTL nodemap_add_range --name \
5214 $sk_map_name --range $nid"
5222 nfs_client_mode && return
5223 cifs_client_mode && return
5225 sanity_mount_check || error "environments are insane!"
5231 if [ -z "$CLIENTONLY" ]; then
5232 echo Setup mgs, mdt, osts
5233 echo $WRITECONF | grep -q "writeconf" && writeconf_all
5235 if $SK_MOUNTED; then
5236 echo "Shared Key file system already mounted"
5241 if $SHARED_KEY; then
5242 export SK_MOUNTED=true
5246 echo "GSS_SK: setting kernel keyring perms"
5247 do_nodes $(comma_list $(all_nodes)) \
5248 "keyctl show | grep lustre | cut -c1-11 |
5250 xargs -IX keyctl setperm X 0x3f3f3f3f"
5253 # Need to start one nodemap for servers,
5254 # and one for clients.
5255 sk_nodemap_setup $SK_S2SNM \
5256 $(comma_list $(all_server_nodes))
5258 sk_nodemap_setup $SK_S2SNMCLI \
5259 ${CLIENTS:-$HOSTNAME}
5260 echo "Nodemap set up for SK S2S, remounting."
5269 # wait a while to allow sptlrpc configuration be propogated to targets,
5270 # only needed when mounting new target devices.
5278 # by remounting mdt before ost, initial connect from mdt to ost might
5279 # timeout because ost is not ready yet. wait some time to its fully
5280 # recovery. initial obd_connect timeout is 5s; in GSS case it's
5281 # preceeded by a context negotiation rpc with $TIMEOUT.
5282 # FIXME better by monitoring import status.
5285 set_rule $FSNAME any cli2mdt $SK_FLAVOR
5286 set_rule $FSNAME any cli2ost $SK_FLAVOR
5287 if $SK_SKIPFIRST; then
5288 export SK_SKIPFIRST=false
5292 "lctl set_param osc.*.idle_connect=1"
5295 wait_flavor cli2mdt $SK_FLAVOR
5296 wait_flavor cli2ost $SK_FLAVOR
5301 sleep $((TIMEOUT + 5))
5307 mounted_lustre_filesystems() {
5308 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
5311 init_facet_vars () {
5312 [ -n "$CLIENTONLY" ] && return 0
5319 eval export ${facet}_dev=${device}
5320 eval export ${facet}_opt=\"$*\"
5322 local dev=${facet}_dev
5324 # We need to loop for the label
5325 # in case its not initialized yet.
5326 for wait_time in {0,1,3,5,10}; do
5328 if [ $wait_time -gt 0 ]; then
5329 echo "${!dev} not yet initialized,"\
5330 "waiting ${wait_time} seconds."
5334 local label=$(devicelabel ${facet} ${!dev})
5336 # Check to make sure the label does
5337 # not include ffff at the end of the label.
5338 # This indicates it has not been initialized yet.
5340 if [[ $label =~ [f|F]{4}$ ]]; then
5341 # label is not initialized, unset the result
5342 # and either try again or fail
5349 [ -z "$label" ] && echo no label for ${!dev} && exit 1
5351 eval export ${facet}_svc=${label}
5353 local varname=${facet}failover_HOST
5354 if [ -z "${!varname}" ]; then
5356 if combined_mgs_mds && [ $facet == "mgs" ] &&
5357 [ -n "$mds1failover_HOST" ]; then
5358 temp=$mds1failover_HOST
5360 temp=$(facet_host $facet)
5362 eval export $varname=$temp
5365 varname=${facet}_HOST
5366 if [ -z "${!varname}" ]; then
5367 eval export $varname=$(facet_host $facet)
5370 # ${facet}failover_dev is set in cfg file
5371 varname=${facet}failover_dev
5372 if [ -n "${!varname}" ] ; then
5373 eval export ${facet}failover_dev=${!varname}
5375 eval export ${facet}failover_dev=$device
5378 # get mount point of already mounted device
5379 # is facet_dev is already mounted then use the real
5380 # mount point of this facet; otherwise use $(facet_mntpt $facet)
5381 # i.e. ${facet}_MOUNT if specified by user or default
5382 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
5383 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
5384 if [ -z $mntpt ]; then
5385 mntpt=$(facet_mntpt $facet)
5387 eval export ${facet}_MOUNT=$mntpt
5390 init_facets_vars () {
5393 if ! remote_mds_nodsh; then
5394 for num in $(seq $MDSCOUNT); do
5395 DEVNAME=$(mdsdevname $num)
5396 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
5400 init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
5402 if ! remote_ost_nodsh; then
5403 for num in $(seq $OSTCOUNT); do
5404 DEVNAME=$(ostdevname $num)
5405 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
5410 init_facets_vars_simple () {
5413 if ! remote_mds_nodsh; then
5414 for num in $(seq $MDSCOUNT); do
5415 devname=$(mdsdevname $num)
5416 eval export mds${num}_dev=${devname}
5417 eval export mds${num}_opt=\"${MDS_MOUNT_OPTS}\"
5421 if ! combined_mgs_mds ; then
5422 eval export mgs_dev=$(mgsdevname)
5423 eval export mgs_opt=\"${MGS_MOUNT_OPTS}\"
5426 if ! remote_ost_nodsh; then
5427 for num in $(seq $OSTCOUNT); do
5428 devname=$(ostdevname $num)
5429 eval export ost${num}_dev=${devname}
5430 eval export ost${num}_opt=\"${OST_MOUNT_OPTS}\"
5435 osc_ensure_active () {
5440 while [ $period -lt $timeout ]; do
5441 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
5442 if [ $count -eq 0 ]; then
5446 echo "$count OST inactive, wait $period seconds, and try again"
5448 period=$((period+3))
5451 [ $period -lt $timeout ] ||
5452 log "$count OST are inactive after $timeout seconds, give up"
5455 set_conf_param_and_check() {
5459 local ORIG=$(do_facet $myfacet "$TEST")
5460 if [ $# -gt 3 ]; then
5466 echo "Setting $PARAM from $ORIG to $FINAL"
5467 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
5468 error "conf_param $PARAM failed"
5470 wait_update_facet $myfacet "$TEST" "$FINAL" ||
5471 error "check $PARAM failed!"
5474 set_persistent_param() {
5478 local orig=$(do_facet $myfacet "$LCTL get_param -n $test_param")
5480 if [ $# -gt 3 ]; then
5487 if [[ $PERM_CMD == *"set_param -P"* ]]; then
5488 echo "Setting $test_param from $orig to $final"
5489 do_facet mgs "$PERM_CMD $test_param='$final'" ||
5490 error "$PERM_CMD $test_param failed"
5492 echo "Setting $param from $orig to $final"
5493 do_facet mgs "$PERM_CMD $param='$final'" ||
5494 error "$PERM_CMD $param failed"
5498 set_persistent_param_and_check() {
5502 local orig=$(do_facet $myfacet "$LCTL get_param -n $test_param")
5504 if [ $# -gt 3 ]; then
5511 set_persistent_param $myfacet $test_param $param "$final"
5513 wait_update_facet $myfacet "$LCTL get_param -n $test_param" "$final" ||
5514 error "check $param failed!"
5517 init_param_vars () {
5518 TIMEOUT=$(lctl get_param -n timeout)
5519 TIMEOUT=${TIMEOUT:-20}
5521 if [ -n "$arg1" ]; then
5522 [ "$arg1" = "server_only" ] && return
5525 remote_mds_nodsh && log "Using TIMEOUT=$TIMEOUT" && return 0
5527 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
5528 log "Using TIMEOUT=$TIMEOUT"
5530 # tune down to speed up testing on (usually) small setups
5531 local mgc_timeout=/sys/module/mgc/parameters/mgc_requeue_timeout_min
5532 do_nodes $(comma_list $(nodes_list)) \
5533 "[ -f $mgc_timeout ] && echo 1 > $mgc_timeout; exit 0"
5535 osc_ensure_active $SINGLEMDS $TIMEOUT
5536 osc_ensure_active client $TIMEOUT
5537 $LCTL set_param osc.*.idle_timeout=debug
5539 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
5540 local current_jobid_var=$($LCTL get_param -n jobid_var)
5542 if [ $JOBID_VAR = "existing" ]; then
5543 echo "keeping jobstats as $current_jobid_var"
5544 elif [ $current_jobid_var != $JOBID_VAR ]; then
5545 echo "setting jobstats to $JOBID_VAR"
5547 set_persistent_param_and_check client \
5548 "jobid_var" "$FSNAME.sys.jobid_var" $JOBID_VAR
5551 echo "jobstats not supported by server"
5554 if [ $QUOTA_AUTO -ne 0 ]; then
5555 if [ "$ENABLE_QUOTA" ]; then
5556 echo "enable quota as required"
5557 setup_quota $MOUNT || return 2
5559 echo "disable quota as required"
5560 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
5564 (( MDS1_VERSION <= $(version_code 2.13.52) )) ||
5565 do_facet mgs "$LCTL set_param -P lod.*.mdt_hash=crush"
5569 nfs_client_mode () {
5570 if [ "$NFSCLIENT" ]; then
5571 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
5572 local clients=$CLIENTS
5574 [ -z $clients ] && clients=$(hostname)
5576 # FIXME: remove hostname when 19215 fixed
5577 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
5578 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts |
5579 awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
5580 if [[ ${#nfsexport[@]} -eq 0 ]]; then
5581 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
5583 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
5589 cifs_client_mode () {
5590 [ x$CIFSCLIENT = xyes ] &&
5591 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
5594 check_config_client () {
5596 local mounted=$(mount | grep " $mntpt ")
5598 if [ -n "$CLIENTONLY" ]; then
5600 # CLIENTONLY should not depend on *_HOST settings
5601 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
5602 # in theory someone could create a new,
5603 # client-only config file that assumed lustre was already
5604 # configured and didn't set the MGSNID. If MGSNID is not set,
5605 # then we should use the mgs nid currently being used
5606 # as the default value. bug 18021
5607 [[ x$MGSNID = x ]] &&
5610 if [[ x$mgc != xMGC$MGSNID ]]; then
5611 if [ "$mgs_HOST" ]; then
5612 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST |
5613 grep PING | awk '{print $3}' |
5614 sed -e "s/(//g" -e "s/)//g")
5616 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
5617 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
5623 echo Checking config lustre mounted on $mntpt
5624 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
5625 mgshost=$(echo $mgshost | awk -F: '{print $1}')
5629 check_config_clients () {
5630 local clients=${CLIENTS:-$HOSTNAME}
5633 nfs_client_mode && return
5634 cifs_client_mode && return
5636 do_rpc_nodes "$clients" check_config_client $mntpt
5638 sanity_mount_check || error "environments are insane!"
5642 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
5643 local cltimeout=$(lctl get_param -n timeout)
5644 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
5645 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
5652 [ -z $mntpt ] && return 1
5653 local mounted=$(mounted_lustre_filesystems)
5655 echo $mounted' ' | grep -w -q $mntpt' '
5660 local ostsn=${2:-$OSTCOUNT}
5661 local npools=${FS_NPOOLS:-$((OSTCOUNT / ostsn))}
5664 echo ostsn=$ostsn npools=$npools
5665 if [[ $ostsn -gt $OSTCOUNT ]]; then
5666 echo "request to use $ostsn OSTs in the pool, \
5667 using max available OSTCOUNT=$OSTCOUNT"
5670 for (( n=0; n < $npools; n++ )); do
5672 if ! $DELETE_OLD_POOLS; then
5673 log "request to not delete old pools: $FSNAME.$p exist?"
5674 if ! check_pool_not_exist $FSNAME.$p; then
5675 echo "Using existing $FSNAME.$p"
5676 $LCTL pool_list $FSNAME.$p
5680 create_pool $FSNAME.$p $KEEP_POOLS ||
5681 error "create_pool $FSNAME.$p failed"
5683 local first=$(( (n * ostsn) % OSTCOUNT ))
5684 local last=$(( (first + ostsn - 1) % OSTCOUNT ))
5685 if [[ $first -le $last ]]; then
5686 pool_add_targets $p $first $last ||
5687 error "pool_add_targets $p $first $last failed"
5689 pool_add_targets $p $first $(( OSTCOUNT - 1 )) ||
5690 error "pool_add_targets $p $first \
5691 $(( OSTCOUNT - 1 )) failed"
5692 pool_add_targets $p 0 $last ||
5693 error "pool_add_targets $p 0 $last failed"
5698 set_pools_quota () {
5705 [[ $ENABLE_QUOTA ]] || error "Required Pool Quotas: \
5706 $POOLS_QUOTA_USERS_SET, but ENABLE_QUOTA not set!"
5708 # POOLS_QUOTA_USERS_SET=
5709 # "quota15_1:20M -- for all of the found pools
5710 # quota15_2:1G:gpool0
5711 # quota15_3 -- for global limit only
5712 # quota15_4:200M:gpool0
5713 # quota15_4:200M:gpool1"
5715 declare -a pq_userset=(${POOLS_QUOTA_USERS_SET="mpiuser"})
5717 declare -A pq_limits
5719 for ((i=0; i<${#pq_userset[@]}; i++)); do
5720 u=${pq_userset[i]%%:*}
5722 # user gets no pool limits if
5723 # POOLS_QUOTA_USERS_SET does not specify it
5724 [[ ${pq_userset[i]} =~ : ]] && o=${pq_userset[i]##$u:}
5725 pq_limits[$u]+=" $o"
5727 pq_users=(${!pq_limits[@]})
5732 for ((i=0; i<${#pq_users[@]}; i++)); do
5734 # set to max limit (_u64)
5735 $LFS setquota -u $u -B $((2**24 - 1))T $DIR
5736 opts=(${pq_limits[$u]})
5737 for ((j=0; j<${#opts[@]}; j++)); do
5740 # Set limit for all existing pools if
5742 if [ $p == $o ]; then
5743 p=$(list_pool $FSNAME | sed "s/$FSNAME.//")
5744 echo "No pool specified for $u,
5745 set limit $o for all existing pools"
5748 $LFS setquota -u $u -B $o --pool $pool $DIR ||
5749 error "setquota -u $u -B $o \
5750 --pool $pool failed"
5753 $LFS quota -uv $u --pool $DIR
5757 check_and_setup_lustre() {
5759 nfs_client_mode && return
5760 cifs_client_mode && return
5762 local MOUNTED=$(mounted_lustre_filesystems)
5766 # both MOUNT and MOUNT2 are not mounted
5767 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
5768 [ "$REFORMAT" = "yes" ] && CLEANUP_DM_DEV=true formatall
5769 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
5771 is_mounted $MOUNT || error "NAME=$NAME not mounted"
5772 export I_MOUNTED=yes
5776 elif is_mounted $MOUNT2; then
5778 # MOUNT2 is mounted, while MOUNT_2 is not set
5779 if ! [ "$MOUNT_2" ]; then
5780 cleanup_mount $MOUNT2
5781 export I_UMOUNTED2=yes
5784 # MOUNT2 is mounted, MOUNT_2 is set
5786 # FIXME: what to do if check_config failed?
5788 # 1) remote client has mounted other Lustre fs ?
5789 # 2) it has insane env ?
5790 # let's try umount MOUNT2 on all clients and mount it
5792 if ! check_config_clients $MOUNT2; then
5793 cleanup_mount $MOUNT2
5794 restore_mount $MOUNT2
5795 export I_MOUNTED2=yes
5799 # MOUNT is mounted MOUNT2 is not mounted
5800 elif [ "$MOUNT_2" ]; then
5801 restore_mount $MOUNT2
5802 export I_MOUNTED2=yes
5806 # FIXME: what to do if check_config failed?
5808 # 1) remote client has mounted other Lustre fs?
5809 # 2) lustre is mounted on remote_clients atall ?
5810 check_config_clients $MOUNT
5814 set_default_debug_nodes $(comma_list $(nodes_list))
5818 if [ -z "$CLIENTONLY" -a $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ]; then
5820 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
5821 facets="$(get_facets OST)"
5822 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
5823 facets="$facets,$(get_facets MDS)"
5824 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
5825 facets="$facets,mgs"
5826 local nodes="$(facets_hosts ${facets})"
5827 if [ -n "$nodes" ] ; then
5828 do_nodes $nodes "$LCTL set_param \
5829 osd-ldiskfs.track_declares_assert=1 || true"
5833 if [ -n "$fs_STRIPEPARAMS" ]; then
5834 setstripe_getstripe $MOUNT $fs_STRIPEPARAMS
5842 if $DELETE_OLD_POOLS; then
5845 if [[ -n "$FS_POOL" ]]; then
5846 create_pools $FS_POOL $FS_POOL_NOSTS
5849 if [[ -n "$POOLS_QUOTA_USERS_SET" ]]; then
5852 if [ "$ONLY" == "setup" ]; then
5858 local clients=${CLIENTS:-$HOSTNAME}
5861 zconf_mount_clients $clients $mntpt
5865 local clients=${CLIENTS:-$HOSTNAME}
5868 zconf_umount_clients $clients $mntpt
5871 cleanup_and_setup_lustre() {
5872 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
5873 lctl set_param debug=0 || true
5875 if [ "$ONLY" == "cleanup" ]; then
5879 check_and_setup_lustre
5882 # Run e2fsck on MDT or OST device.
5887 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
5888 local log=$TMP/e2fsck.log
5891 # turn on pfsck if it is supported
5892 do_node $node $E2FSCK -h 2>&1 | grep -qw -- -m && cmd+=" -m8"
5894 do_node $node $cmd 2>&1 | tee $log
5896 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
5898 if [ $MDSCOUNT -gt 1 ]; then
5899 skip_noexit "DNE mode isn't supported!"
5903 error "It's not DNE mode."
5908 [ $rc -le $FSCK_MAX_ERR ] ||
5909 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
5915 # Run resize2fs on MDT or OST device.
5924 do_facet $facet "$RESIZE2FS $opts $device $size"
5927 # verify a directory is shared among nodes.
5928 check_shared_dir() {
5930 local list=${2:-$(comma_list $(nodes_list))}
5932 [ -z "$dir" ] && return 1
5933 do_rpc_nodes "$list" check_logdir $dir
5934 check_write_access $dir "$list" || return 1
5939 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
5940 $LCTL set_param printk=+lfsck
5941 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
5943 for k in $(seq $MDSCOUNT); do
5944 # wait up to 10+1 minutes for LFSCK to complete
5945 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
5946 mdd.$(facet_svc mds${k}).lfsck_layout |
5947 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
5948 error "MDS${k} layout isn't the expected 'completed'"
5949 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
5950 mdd.$(facet_svc mds${k}).lfsck_namespace |
5951 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
5952 error "MDS${k} namespace isn't the expected 'completed'"
5954 local rep_mdt=$(do_nodes $(comma_list $(mdts_nodes)) \
5955 $LCTL get_param -n mdd.$FSNAME-*.lfsck_* |
5956 awk '/repaired/ { print $2 }' | calc_sum)
5957 local rep_ost=$(do_nodes $(comma_list $(osts_nodes)) \
5958 $LCTL get_param -n obdfilter.$FSNAME-*.lfsck_* |
5959 awk '/repaired/ { print $2 }' | calc_sum)
5960 local repaired=$((rep_mdt + rep_ost))
5961 [ $repaired -eq 0 ] ||
5962 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
5965 dump_file_contents() {
5971 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
5972 error_noexit false \
5973 "Invalid parameters for dump_file_contents()"
5976 for node in ${nodes}; do
5977 do_node $node "for i in \\\$(find $dir -type f); do
5978 echo ====\\\${i}=======================;
5980 done" >> ${logname}.${node}.log
5984 dump_command_output() {
5990 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
5991 error_noexit false \
5992 "Invalid parameters for dump_command_output()"
5996 for node in ${nodes}; do
5997 do_node $node "echo ====${cmd}=======================;
5998 $cmd" >> ${logname}.${node}.log
6005 # dump file contents from /proc/spl in case of zfs test
6006 if [ "$(facet_fstype ost1)" = "zfs" ]; then
6007 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
6008 dump_command_output \
6009 "$(osts_nodes)" "zpool events -v" "${logname}"
6012 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
6013 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
6014 dump_command_output \
6015 "$(mdts_nodes)" "zpool events -v" "${logname}"
6019 check_and_cleanup_lustre() {
6020 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "sanity-lfsck" -a \
6021 "$TESTSUITE" != "sanity-scrub" ]; then
6025 if is_mounted $MOUNT; then
6026 if $DO_CLEANUP; then
6027 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
6028 error "remove sub-test dirs failed"
6032 [ "$ENABLE_QUOTA" ] && restore_quota || true
6035 if [ "$I_UMOUNTED2" = "yes" ]; then
6036 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
6039 if [ "$I_MOUNTED2" = "yes" ]; then
6040 cleanup_mount $MOUNT2
6043 if [[ "$I_MOUNTED" = "yes" ]] && ! $AUSTER_CLEANUP; then
6044 cleanupall -f || error "cleanup failed"
6052 wait_for_function () {
6055 # suppress fn both stderr and stdout
6056 if [ "$1" = "--quiet" ]; then
6058 quiet=" > /dev/null 2>&1"
6069 eval $fn $quiet && return 0
6071 [ $wait -lt $max ] || return 1
6072 echo waiting $fn, $((max - wait)) secs left ...
6073 wait=$((wait + sleep))
6074 [ $wait -gt $max ] && ((sleep -= wait - max))
6084 [ "$host" = "$HOSTNAME" ] && return 0
6086 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep; then
6087 echo "$(date +'%H:%M:%S (%s)') waited for $host network ${max}s"
6097 # Convert a space-delimited list to a comma-delimited list. If the input is
6098 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
6100 # echo is used to convert newlines to spaces, since it doesn't
6101 # introduce a trailing space as using "tr '\n' ' '" does
6102 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
6108 echo $list | grep -qw $item
6111 # list, excluded are the comma separated lists
6112 exclude_items_from_list () {
6118 for item in ${excluded//,/ }; do
6119 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
6121 echo $(comma_list $list)
6124 # list, expand are the comma separated lists
6126 local list=${1//,/ }
6127 local expand=${2//,/ }
6130 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
6131 echo $(comma_list $expanded)
6134 testslist_filter () {
6135 local script=$LUSTRE/tests/${TESTSUITE}.sh
6137 [ -f $script ] || return 0
6139 local start_at=$START_AT
6140 local stop_at=$STOP_AT
6142 local var=${TESTSUITE//-/_}_START_AT
6143 [ x"${!var}" != x ] && start_at=${!var}
6144 var=${TESTSUITE//-/_}_STOP_AT
6145 [ x"${!var}" != x ] && stop_at=${!var}
6147 sed -n 's/^test_\([^ (]*\).*/\1/p' $script |
6148 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
6149 /^'${start_at}'$/ {flag = 0}
6150 {if (flag == 1) print $0}
6151 /^'${stop_at}'$/ { flag = 1 }'
6155 (cd `dirname $1`; echo $PWD/`basename $1`)
6159 local types=${1:-"OST MDS MGS"}
6163 for entry in $types; do
6164 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
6165 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
6168 MGS ) list="$list $name";;
6169 MDS|OST|AGT ) local count=${type}COUNT
6170 for ((i=1; i<=${!count}; i++)) do
6171 list="$list ${name}$i"
6173 * ) error "Invalid facet type"
6177 echo $(comma_list $list)
6180 ##################################
6181 # Adaptive Timeouts funcs
6184 # only check mds, we assume at_max is the same on all nodes
6185 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
6187 if [ $at_max -eq 0 ]; then
6198 # suppose that all ost-s have the same $at value set
6199 [ $facet != "ost" ] || facet=ost1
6201 do_facet $facet "lctl get_param -n $at"
6215 for facet in "$@"; do
6216 if [ $facet == "ost" ]; then
6217 facet=$(get_facets OST)
6218 elif [ $facet == "mds" ]; then
6219 facet=$(get_facets MDS)
6221 hosts=$(expand_list $hosts $(facets_hosts $facet))
6224 do_nodes $hosts lctl set_param at_max=$at_max
6227 ##################################
6231 # OBD_FAIL_MDS_ALL_REQUEST_NET
6233 do_facet $SINGLEMDS lctl set_param fail_val=0 fail_loc=0x123
6234 do_facet client "$1" || RC=$?
6235 do_facet $SINGLEMDS lctl set_param fail_loc=0
6240 # OBD_FAIL_MDS_ALL_REPLY_NET
6242 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
6244 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
6248 drop_reint_reply() {
6249 # OBD_FAIL_MDS_REINT_NET_REP
6251 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
6253 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
6257 drop_update_reply() {
6258 # OBD_FAIL_OUT_UPDATE_NET_REP
6262 do_facet mds${index} lctl set_param fail_loc=0x1701
6263 do_facet client "$@" || RC=$?
6264 do_facet mds${index} lctl set_param fail_loc=0
6269 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
6272 local timeout=${2:-0}
6273 # default is (obd_timeout / 4) if unspecified
6274 echo "timeout is $timeout/$2"
6275 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
6276 do_facet client "$1" || RC=$?
6277 do_facet client "sync"
6278 do_facet ost1 lctl set_param fail_loc=0
6282 drop_ldlm_cancel() {
6283 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
6285 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
6286 do_nodes $list lctl set_param fail_loc=0x304
6288 do_facet client "$@" || RC=$?
6290 do_nodes $list lctl set_param fail_loc=0
6294 drop_bl_callback_once() {
6296 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
6297 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
6298 do_facet client lctl set_param fail_loc=0x80000305
6299 do_facet client "$@" || rc=$?
6300 do_facet client lctl set_param fail_loc=0
6301 do_facet client lctl set_param fail_val=0
6302 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
6306 drop_bl_callback() {
6308 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
6309 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
6310 do_facet client lctl set_param fail_loc=0x305
6311 do_facet client "$@" || rc=$?
6312 do_facet client lctl set_param fail_loc=0
6313 do_facet client lctl set_param fail_val=0
6314 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
6318 drop_mdt_ldlm_reply() {
6319 #define OBD_FAIL_MDS_LDLM_REPLY_NET 0x157
6321 local list=$(comma_list $(mdts_nodes))
6323 do_nodes $list lctl set_param fail_loc=0x157
6325 do_facet client "$@" || RC=$?
6327 do_nodes $list lctl set_param fail_loc=0
6331 drop_mdt_ldlm_reply_once() {
6332 #define OBD_FAIL_MDS_LDLM_REPLY_NET 0x157
6334 local list=$(comma_list $(mdts_nodes))
6336 do_nodes $list lctl set_param fail_loc=0x80000157
6338 do_facet client "$@" || RC=$?
6340 do_nodes $list lctl set_param fail_loc=0
6348 echo "clearing fail_loc on $facet"
6349 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
6352 set_nodes_failloc () {
6354 do_nodes $(comma_list $1) lctl set_param fail_val=$fv fail_loc=$2
6357 cancel_lru_locks() {
6358 #$LCTL mark "cancel_lru_locks $1 start"
6359 $LCTL set_param -n ldlm.namespaces.*$1*.lru_size=clear
6360 $LCTL get_param ldlm.namespaces.*$1*.lock_unused_count | grep -v '=0'
6361 #$LCTL mark "cancel_lru_locks $1 stop"
6366 local nr_cpu=$(grep -c "processor" /proc/cpuinfo)
6368 echo $((100 * nr_cpu))
6373 lctl set_param ldlm.namespaces.*$1*.lru_size=0
6376 lru_resize_disable()
6379 local lru_size=${2:-$(default_lru_size)}
6381 $LCTL set_param ldlm.namespaces.*$dev*.lru_size=$lru_size
6386 local mountpath=${1:-$MOUNT}
6389 [ -z "$(mount | grep "$mountpath .*flock" | grep -v noflock)" ] && RC=1
6396 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
6397 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
6398 echo there is still data in page cache $FILE ?
6399 lctl get_param -n $FILE
6407 DEBUGSAVE="$(lctl get_param -n debug)"
6408 DEBUGSAVE_SERVER=$(do_facet $SINGLEMDS "$LCTL get_param -n debug")
6412 [ -n "$DEBUGSAVE" ] &&
6413 do_nodes $CLIENTS "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\""||
6417 [ -n "$DEBUGSAVE_SERVER" ] &&
6418 do_nodes $(comma_list $(all_server_nodes)) \
6419 "$LCTL set_param debug=\\\"${DEBUGSAVE_SERVER}\\\"" ||
6425 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
6428 debug_size_restore() {
6429 [ -n "$DEBUG_SIZE_SAVED" ] &&
6430 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
6434 start_full_debug_logging() {
6439 local debug_size=150
6440 local nodes=$(comma_list $(nodes_list))
6442 do_nodes $nodes "$LCTL set_param debug=$fulldebug debug_mb=$debug_size"
6445 stop_full_debug_logging() {
6450 # prints bash call stack
6451 print_stack_trace() {
6454 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
6455 local src=${BASH_SOURCE[$i]}
6456 local lineno=${BASH_LINENO[$i-1]}
6457 local funcname=${FUNCNAME[$i]}
6458 echo " = $src:$lineno:$funcname()"
6463 local TYPE=${TYPE:-"FAIL"}
6466 # do not dump logs if $1=false
6467 if [ "x$1" = "xfalse" ]; then
6472 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $* "
6473 (print_stack_trace 2) >&2
6475 # We need to dump the logs on all nodes
6477 gather_logs $(comma_list $(nodes_list))
6481 [ "$TESTSUITELOG" ] &&
6482 echo "$TESTSUITE: $TYPE: $TESTNAME $*" >> $TESTSUITELOG
6483 if [ -z "$*" ]; then
6484 echo "error() without useful message, please fix" > $LOGDIR/err
6486 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
6487 echo "$@" > $LOGDIR/ignore
6489 echo "$@" > $LOGDIR/err
6493 # cleanup the env for failed tests
6497 ##################################
6499 ##################################
6501 # usage: stack_trap arg sigspec
6503 # stack_trap() behaves like bash's built-in trap, except that it "stacks" the
6504 # command "arg" on top of previously defined commands for "sigspec" instead
6505 # of overwriting them.
6506 # stacked traps are executed in reverse order of their registration
6508 # arg and sigspec have the same meaning as in man (1) trap
6512 local sigspec="${2:-EXIT}"
6514 # Use "trap -p" to get the quoting right
6515 local old_trap="$(trap -p "$sigspec")"
6516 # Append ";" and remove the leading "trap -- '" added by "trap -p"
6517 old_trap="${old_trap:+"; ${old_trap#trap -- \'}"}"
6519 # Once again, use "trap -p" to get the quoting right
6520 local new_trap="$(trap -- "$arg" "$sigspec"
6522 trap -- '' "$sigspec")"
6524 # Remove the trailing "' $sigspec" part added by "trap -p" and merge
6526 # The resulting string should be safe to "eval" as it is (supposedly
6527 # correctly) quoted by "trap -p"
6528 eval "${new_trap%\' $sigspec}${old_trap:-"' $sigspec"}"
6537 local logs="$TESTSUITELOG $1"
6539 for log in $logs; do
6540 if [ -f "$log" ]; then
6541 grep -qw FAIL $log && status=1
6558 # use only if we are ignoring failures for this test, bugno required.
6559 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
6560 # e.g. error_ignore bz5494 "your message" or
6561 # error_ignore LU-5494 "your message"
6563 local TYPE="IGNORE ($1)"
6568 error_and_remount() {
6570 remount_client $MOUNT
6574 # Throw an error if it's not running in vm - usually for performance
6577 local virt=$(running_in_vm)
6578 if [[ -n "$virt" ]]; then
6579 echo "running in VM '$virt', ignore error"
6580 error_ignore env=$virt "$@"
6587 # Function: skip_env()
6588 # Purpose: to skip a test during developer testing because some tool
6589 # is missing, but fail the test in release testing because the test
6590 # environment is not configured properly".
6593 $FAIL_ON_SKIP_ENV && error false "$@" || skip "$@"
6598 log " SKIP: $TESTSUITE $TESTNAME $*"
6600 if [[ -n "$ALWAYS_SKIPPED" ]]; then
6601 skip_logged $TESTNAME "$@"
6604 echo "$@" > $LOGDIR/skip
6607 [[ -n "$TESTSUITELOG" ]] &&
6608 echo "$TESTSUITE: SKIP: $TESTNAME $*" >> $TESTSUITELOG || true
6618 # For interop testing treate EOPNOTSUPP as success
6624 echo $retstr | awk -F'|' '{print $1}' |
6625 grep -E unsupported\|"(Operation not supported)"
6626 (( $? == 0 )) || error "$retstr"
6630 # Add a list of tests to ALWAYS_EXCEPT due to an issue.
6631 # Usage: always_except LU-4815 23 42q ...
6633 function always_except() {
6634 local issue="${1:-}" # single jira style issue ("LU-4815")
6639 if ! [[ "$issue" =~ ^[[:upper:]]+-[[:digit:]]+$ ]]; then
6640 error "always_except: invalid issue '$issue' for tests '$*'"
6643 for test_num in "$@"; do
6644 ALWAYS_EXCEPT+=" $test_num"
6648 build_test_filter() {
6649 EXCEPT="$EXCEPT $(testslist_filter)"
6652 if [[ $O = [0-9]*-[0-9]* ]]; then
6653 for num in $(seq $(echo $O | tr '-' ' ')); do
6661 [ "$EXCEPT$ALWAYS_EXCEPT" ] &&
6662 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
6663 [ "$EXCEPT_SLOW" ] &&
6664 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
6665 for E in $EXCEPT; do
6666 eval EXCEPT_${E}=true
6668 for E in $ALWAYS_EXCEPT; do
6669 eval EXCEPT_ALWAYS_${E}=true
6671 for E in $EXCEPT_SLOW; do
6672 eval EXCEPT_SLOW_${E}=true
6674 for G in $GRANT_CHECK_LIST; do
6675 eval GCHECK_ONLY_${G}=true
6680 if [[ $1 = [a-z]* ]]; then
6683 echo ${1%%[a-zA-Z]*}
6687 # print a newline if the last test was skipped
6688 export LAST_SKIPPED=
6689 export ALWAYS_SKIPPED=
6691 # Main entry into test-framework. This is called with the number and
6692 # description of a test. The number is used to find the function to run
6693 # the test using "test_$name".
6695 # This supports a variety of methods of specifying specific test to
6697 # - ONLY= env variable with space-separated list of test numbers to run
6698 # - EXCEPT= env variable with space-separated list of test numbers to exclude
6704 export base=$(basetest $testnum)
6705 export TESTNAME=test_$testnum
6709 # Check the EXCEPT, ALWAYS_EXCEPT and SLOW lists to see if we
6710 # need to skip the current test. If so, set the ALWAYS_SKIPPED flag.
6711 local isexcept=EXCEPT_$testnum
6712 local isexcept_base=EXCEPT_$base
6713 if [ ${!isexcept}x != x ]; then
6715 skip_message="skipping excluded test $testnum"
6716 elif [ ${!isexcept_base}x != x ]; then
6718 skip_message="skipping excluded test $testnum (base $base)"
6721 isexcept=EXCEPT_ALWAYS_$testnum
6722 isexcept_base=EXCEPT_ALWAYS_$base
6723 if [ ${!isexcept}x != x ]; then
6725 skip_message="skipping ALWAYS excluded test $testnum"
6726 elif [ ${!isexcept_base}x != x ]; then
6728 skip_message="skipping ALWAYS excluded test $testnum (base $base)"
6731 isexcept=EXCEPT_SLOW_$testnum
6732 isexcept_base=EXCEPT_SLOW_$base
6733 if [ ${!isexcept}x != x ]; then
6735 skip_message="skipping SLOW test $testnum"
6736 elif [ ${!isexcept_base}x != x ]; then
6738 skip_message="skipping SLOW test $testnum (base $base)"
6741 # If there are tests on the ONLY list, check if the current test
6742 # is on that list and, if so, check if the test is to be skipped
6743 # and if we are supposed to honor the skip lists.
6744 if [ -n "$ONLY" ]; then
6745 local isonly=ONLY_$testnum
6746 local isonly_base=ONLY_$base
6747 if [[ ${!isonly}x != x || ${!isonly_base}x != x ]]; then
6749 if [[ -n "$ALWAYS_SKIPPED" &&
6750 -n "$HONOR_EXCEPT" ]]; then
6752 skip_noexit "$skip_message"
6755 [ -n "$LAST_SKIPPED" ] &&
6756 echo "" && LAST_SKIPPED=
6758 run_one_logged $testnum "$testmsg"
6768 if [ -n "$ALWAYS_SKIPPED" ]; then
6770 skip_noexit "$skip_message"
6773 run_one_logged $testnum "$testmsg"
6780 load_module ../libcfs/libcfs/libcfs
6793 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
6798 strace -o $TMP/$1.strace -ttt $*
6800 log "FINISHED: $*: rc $RC"
6807 banner test complete, duration $duration sec
6808 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
6809 echo duration $duration >>$TESTSUITELOG
6813 # Set TEST_STATUS here. It will be used for logging the result.
6816 if [[ -f $LOGDIR/err ]]; then
6818 elif [[ -f $LOGDIR/skip ]]; then
6821 echo "$TEST_STATUS $*" 2>&1 | tee -a $TESTSUITELOG
6825 local FFREE=$(do_node $SINGLEMDS \
6826 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
6827 local FTOTAL=$(do_node $SINGLEMDS \
6828 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
6830 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" ||
6835 #echo -n "Resetting fail_loc on all nodes..."
6836 do_nodes --quiet $(comma_list $(nodes_list)) \
6837 "lctl set_param -n fail_loc=0 fail_val=0 2>/dev/null" || true
6843 # Log a message (on all nodes) padded with "=" before and after.
6844 # Also appends a timestamp and prepends the testsuite name.
6847 # ======================================================== 15:06:12 (1624050372)
6848 EQUALS="========================================================"
6850 msg="== ${TESTSUITE} $*"
6852 [[ $last != "=" && $last != " " ]] && msg="$msg "
6853 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
6854 # always include at least == after the message
6855 log "$msg== $(date +"%H:%M:%S (%s)")"
6858 check_dmesg_for_errors() {
6860 local errors="VFS: Busy inodes after unmount of\|\
6861 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
6862 group descriptors corrupted"
6864 res=$(do_nodes -q $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
6865 [ -z "$res" ] && return 0
6866 echo "Kernel error detected: $res"
6871 # Run a single test function and cleanup after it.
6873 # This function should be run in a subshell so the test func can
6874 # exit() without stopping the whole script.
6879 local SAVE_UMASK=`umask`
6882 if ! grep -q $DIR /proc/mounts; then
6886 banner "test $testnum: $testmsg"
6887 test_${testnum} || error "test_$testnum failed with $?"
6890 check_grant ${testnum} || error "check_grant $testnum failed with $?"
6892 check_dmesg_for_errors || error "Error in dmesg detected"
6893 if [ "$PARALLEL" != "yes" ]; then
6894 ps auxww | grep -v grep | grep -q "multiop " &&
6895 error "multiop still running"
6903 # Wrapper around run_one to ensure:
6904 # - test runs in subshell
6905 # - output of test is saved to separate log file for error reporting
6906 # - test result is saved to data file
6909 local before=$SECONDS
6912 export tfile=f${testnum}.${TESTSUITE}
6913 export tdir=d${testnum}.${TESTSUITE}
6914 local test_log=$TESTLOG_PREFIX.$TESTNAME.test_log.$(hostname -s).log
6915 local zfs_debug_log=$TESTLOG_PREFIX.$TESTNAME.zfs_log
6916 local SAVE_UMASK=$(umask)
6920 rm -f $LOGDIR/err $LOGDIR/ignore $LOGDIR/skip
6922 # if ${ONLY_$testnum} set, repeat $ONLY_REPEAT times, otherwise once
6923 local isonly=ONLY_$testnum
6924 local repeat=${!isonly:+$ONLY_REPEAT}
6926 for ((testiter=0; testiter < ${repeat:-1}; testiter++)); do
6927 local before_sub=$SECONDS
6928 log_sub_test_begin $TESTNAME
6930 # remove temp files between repetitions to avoid test failures
6931 if [[ -n "$append" ]]; then
6932 [[ -n "$DIR/$tdir" ]] && rm -rvf $DIR/$tdir*
6933 [[ -n "$DIR/$tfile" ]] && rm -vf $DIR/$tfile*
6934 echo "subtest iteration $testiter/$repeat"
6936 # loop around subshell so stack_trap EXIT triggers each time
6937 (run_one $testnum "$testmsg") 2>&1 | tee -i $append $test_log
6940 local duration_sub=$((SECONDS - before_sub))
6943 [[ $rc != 0 && ! -f $LOGDIR/err ]] &&
6944 echo "$TESTNAME returned $rc" | tee $LOGDIR/err
6946 if [[ -f $LOGDIR/err ]]; then
6947 test_error=$(cat $LOGDIR/err)
6949 elif [[ -f $LOGDIR/ignore ]]; then
6950 test_error=$(cat $LOGDIR/ignore)
6951 elif [[ -f $LOGDIR/skip ]]; then
6952 test_error=$(cat $LOGDIR/skip)
6958 pass "$testnum" "(${duration_sub}s)"
6959 if [ -n "${DUMP_OK}" ]; then
6960 gather_logs $(comma_list $(nodes_list))
6963 log_sub_test_end $TEST_STATUS $duration_sub "$rc" "$test_error"
6964 [[ $rc != 0 ]] && break
6967 if [[ "$TEST_STATUS" != "SKIP" && -f $TF_SKIP ]]; then
6971 if [ -f $LOGDIR/err ]; then
6972 log_zfs_info "$zfs_debug_log"
6973 $FAIL_ON_ERROR && exit $rc
6986 # Print information of skipped tests to result.yml
6989 log_sub_test_begin $1
6991 log_sub_test_end "SKIP" "0" "0" "$@"
6994 grant_from_clients() {
6998 do_nodes $nodes "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
7002 grant_from_servers() {
7006 # which is tot_granted less grant_precreate
7007 do_nodes $nodes "$LCTL get_param obdfilter.${FSNAME}-OST*.tot_granted" \
7008 " obdfilter.${FSNAME}-OST*.tot_pending" \
7009 " obdfilter.${FSNAME}-OST*.grant_precreate" |
7010 tr '=' ' ' | awk '/tot_granted/{ total += $2 };
7011 /tot_pending/{ total -= $2 };
7012 /grant_precreate/{ total -= $2 };
7013 END { printf("%0.0f", total) }'
7017 export base=$(basetest $1)
7018 [ "$CHECK_GRANT" == "no" ] && return 0
7020 local isonly_base=GCHECK_ONLY_${base}
7021 local isonly=GCHECK_ONLY_$1
7022 [ ${!isonly_base}x == x -a ${!isonly}x == x ] && return 0
7024 echo -n "checking grant......"
7026 local osts=$(comma_list $(osts_nodes))
7027 local clients=$CLIENTS
7028 [ -z "$clients" ] && clients=$(hostname)
7030 # sync all the data and make sure no pending data on server
7031 do_nodes $clients sync
7032 do_nodes $clients $LFS df # initiate all idling connections
7035 cli_grant=$(grant_from_clients $clients)
7038 # which is tot_granted less grant_precreate
7039 srv_grant=$(grant_from_servers $osts)
7042 # check whether client grant == server grant
7043 while [[ $cli_grant != $srv_grant && count++ -lt 30 ]]; do
7044 echo "wait for client:$cli_grant == server:$srv_grant"
7046 cli_grant=$(grant_from_clients $clients)
7047 srv_grant=$(grant_from_servers $osts)
7049 if [[ $cli_grant -ne $srv_grant ]]; then
7050 do_nodes $(comma_list $(osts_nodes)) \
7051 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*" \
7052 "obdfilter.${FSNAME}-OST*.grant_*"
7053 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
7054 error "failed grant check: client:$cli_grant server:$srv_grant"
7056 echo "pass grant check: client:$cli_grant server:$srv_grant"
7060 ########################
7066 ost=`echo $1 | awk -F_ '{print $3}'`
7067 if [ -z $ost ]; then
7068 ost=`echo $1 | sed 's/-osc.*//'`
7073 ostuuid_from_index()
7075 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
7078 ostname_from_index() {
7079 local uuid=$(ostuuid_from_index $1 $2)
7084 mdtname_from_index() {
7085 local uuid=$(mdtuuid_from_index $1)
7089 mdssize_from_index () {
7090 local mdt=$(mdtname_from_index $2)
7091 $LFS df $1 | grep $mdt | awk '{ print $2 }'
7094 index_from_ostuuid()
7096 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
7099 mdtuuid_from_index()
7101 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
7105 # Return unique identifier for given hostname
7108 echo $host_name | md5sum | cut -d' ' -f1
7112 # Returns list of ip addresses for each interface
7114 ip addr | awk '/inet / {print $2}' | awk -F/ '{print $1}'
7118 # Returns list of interfaces configured for LNet
7120 local nids=( $($LCTL list_nids | xargs echo) )
7122 [[ -z ${nids[@]} ]] &&
7125 if [[ ${NETTYPE} =~ kfi* ]]; then
7126 $LNETCTL net show 2>/dev/null | awk '/ cxi[0-9]+$/{print $NF}' |
7127 sort -u | xargs echo
7131 declare -a INTERFACES
7133 for ((i = 0; i < ${#nids[@]}; i++)); do
7134 ip=$(sed 's/^\(.*\)@.*$/\1/'<<<${nids[i]})
7135 INTERFACES[i]=$(ip -o a s |
7136 awk '$4 ~ /^'$ip'\//{print $2}')
7137 INTERFACES=($(echo "${INTERFACES[@]}" | tr ' ' '\n' | uniq | tr '\n' ' '))
7138 if [[ -z ${INTERFACES[i]} ]]; then
7139 error "Can't determine interface name for NID ${nids[i]}"
7140 elif [[ 1 -ne $(wc -w <<<${INTERFACES[i]}) ]]; then
7141 error "Found $(wc -w <<<${INTERFACES[i]}) interfaces for NID ${nids[i]}. Expect 1"
7145 echo "${INTERFACES[@]}"
7152 # Cache address list to avoid mutiple execution of local_addr_list
7153 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
7155 for i in $LOCAL_ADDR_LIST ; do
7156 [[ "$i" == "$addr" ]] && return 0
7163 local is_local="IS_LOCAL_$(host_id $host_name)"
7164 if [ -z "${!is_local-}" ] ; then
7166 local host_ip=$($LUSTRE/tests/resolveip $host_name)
7167 is_local_addr "$host_ip" && eval $is_local=1
7169 [[ "${!is_local}" == "1" ]]
7174 local_node $node && return 1
7181 for node in $(mdts_nodes); do
7182 remote_node $node && return 0
7189 [ -n "$CLIENTONLY" ] && return 0 || true
7190 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
7195 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" &&
7196 MSKIPPED=1 && return 1
7203 for node in $(osts_nodes) ; do
7204 remote_node $node && return 0
7211 [ -n "$CLIENTONLY" ] && return 0 || true
7212 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
7217 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" &&
7218 OSKIPPED=1 && return 1
7224 [ -n "$CLIENTONLY" ] && return 0 || true
7226 MGS=$(facet_host mgs)
7227 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
7232 remote_mds_nodsh || remote_ost_nodsh ||
7233 $(single_local_node $(comma_list $(nodes_list)))
7237 remote_ost && remote_mds
7240 # Get the active nodes for facets.
7248 for facet in ${facets//,/ }; do
7249 nodes="$nodes $(facet_active_host $facet)"
7252 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7256 # Get name of the active MGS node.
7258 echo -n $(facets_nodes $(get_facets MGS))
7261 # Get all of the active MDS nodes.
7263 echo -n $(facets_nodes $(get_facets MDS))
7266 # Get all of the active OSS nodes.
7268 echo -n $(facets_nodes $(get_facets OST))
7271 # Get all of the client nodes and active server nodes.
7273 local nodes=$HOSTNAME
7277 # CLIENTS (if specified) contains the local client
7278 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
7280 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
7281 nodes="$nodes $(facets_nodes $(get_facets))"
7284 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7288 # Get all of the remote client nodes and remote active server nodes.
7289 remote_nodes_list () {
7290 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
7293 # Get all of the MDS nodes, including active and passive nodes.
7301 for i in $(seq $MDSCOUNT); do
7303 failover_host=mds${i}failover_HOST
7304 nodes="$nodes ${!host} ${!failover_host}"
7307 [ -n "$nodes" ] || nodes="${mds_HOST} ${mdsfailover_HOST}"
7308 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7312 # Get all of the OSS nodes, including active and passive nodes.
7320 for i in $(seq $OSTCOUNT); do
7322 failover_host=ost${i}failover_HOST
7323 nodes="$nodes ${!host} ${!failover_host}"
7326 [ -n "$nodes" ] || nodes="${ost_HOST} ${ostfailover_HOST}"
7327 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7331 # Get all of the server nodes, including active and passive nodes.
7332 all_server_nodes () {
7337 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
7339 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7343 # Get all of the client and server nodes, including active and passive nodes.
7345 local nodes=$HOSTNAME
7349 # CLIENTS (if specified) contains the local client
7350 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
7352 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
7353 nodes="$nodes $(all_server_nodes)"
7356 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7360 init_clients_lists () {
7361 # Sanity check: exclude the local client from RCLIENTS
7362 local clients=$(hostlist_expand "$RCLIENTS")
7363 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
7365 # Sanity check: exclude the dup entries
7366 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
7368 export CLIENT1=${CLIENT1:-$HOSTNAME}
7369 export SINGLECLIENT=$CLIENT1
7371 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
7373 # Sanity check: exclude the dup entries from CLIENTS
7374 # for those configs which has SINGLCLIENT set to local client
7375 clients=$(for i in $clients; do echo $i; done | sort -u)
7377 export CLIENTS=$(comma_list $clients)
7378 local -a remoteclients=($RCLIENTS)
7379 for ((i=0; $i<${#remoteclients[@]}; i++)); do
7380 varname=CLIENT$((i + 2))
7382 eval export $varname=${remoteclients[i]}
7385 export CLIENTCOUNT=$((${#remoteclients[@]} + 1))
7388 get_random_entry () {
7391 rnodes=${rnodes//,/ }
7393 local -a nodes=($rnodes)
7394 local num=${#nodes[@]}
7395 local i=$((RANDOM * num * 2 / 65536))
7401 [ -n "$CLIENTONLY" ] || [ "x$CLIENTMODSONLY" = "xyes" ]
7405 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
7406 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
7412 echo $nodes | wc -w || true
7416 local nodes=$(mdts_nodes)
7417 local mdtcount=$(get_node_count "$nodes")
7419 [ ! "$MDSCOUNT" = "$mdtcount" ]
7422 generate_machine_file() {
7423 local nodes=${1//,/ }
7424 local machinefile=$2
7427 for node in $nodes; do
7428 echo $node >>$machinefile ||
7429 { echo "can not generate machinefile $machinefile" &&
7435 local file=$1/stripe
7438 $LFS getstripe -v $file || error "getstripe $file failed"
7442 # Check and add a test group.
7448 local gid=$(getent group $group_name | cut -d: -f3)
7449 if [[ -n "$gid" ]]; then
7450 [[ "$gid" -eq "$group_id" ]] || {
7451 error_noexit "inconsistent group ID:" \
7452 "new: $group_id, old: $gid"
7456 echo "adding group $group_name:$group_id"
7457 getent group $group_name || true
7458 getent group $group_id || true
7459 groupadd -g $group_id $group_name
7466 # Check and add a test user.
7479 local uid=$(getent passwd $user_name | cut -d: -f3)
7480 if [[ -n "$uid" ]]; then
7481 if [[ "$uid" -eq "$user_id" ]]; then
7482 local dir=$(getent passwd $user_name | cut -d: -f6)
7483 if [[ "$dir" != "$home" ]]; then
7485 usermod -d $home $user_name
7489 error_noexit "inconsistent user ID:" \
7490 "new: $user_id, old: $uid"
7495 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
7502 check_runas_id_ret() {
7504 local myRUNAS_UID=$1
7505 local myRUNAS_GID=$2
7509 if [ -z "$myRUNAS" ]; then
7510 error_exit "check_runas_id_ret requires myRUNAS argument"
7514 error "Unable to execute $myRUNAS"
7516 id $myRUNAS_UID > /dev/null ||
7517 error "Invalid RUNAS_ID $myRUNAS_UID. Please set RUNAS_ID to " \
7518 "some UID which exists on MDS and client or add user " \
7519 "$myRUNAS_UID:$myRUNAS_GID on these nodes."
7522 $myRUNAS krb5_login.sh ||
7523 error "Failed to refresh krb5 TGT for UID $myRUNAS_ID."
7525 mkdir $DIR/d0_runas_test
7527 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
7528 $myRUNAS -u $myRUNAS_UID -g $myRUNAS_GID touch $DIR/d0_runas_test/f$$ ||
7530 rm -rf $DIR/d0_runas_test
7535 local myRUNAS_UID=$1
7536 local myRUNAS_GID=$2
7540 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
7541 error "unable to write to $DIR/d0_runas_test as " \
7545 # obtain the UID/GID for MPI_USER
7549 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
7550 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
7552 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
7553 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
7556 # obtain and cache Kerberos ticket-granting ticket
7557 refresh_krb5_tgt() {
7558 local myRUNAS_UID=$1
7559 local myRUNAS_GID=$2
7562 if [ -z "$myRUNAS" ]; then
7563 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
7566 CLIENTS=${CLIENTS:-$HOSTNAME}
7567 do_nodes $CLIENTS "set -x
7568 if ! $myRUNAS krb5_login.sh; then
7569 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
7574 # Run multiop in the background, but wait for it to print
7575 # "PAUSING" to its stdout before returning from this function.
7576 multiop_bg_pause() {
7577 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
7581 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
7584 echo "$MULTIOP_PROG $FILE v$ARGS"
7585 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
7587 echo "TMPPIPE=${TMPPIPE}"
7588 read -t 60 multiop_output < $TMPPIPE
7589 if [ $? -ne 0 ]; then
7594 if [ "$multiop_output" != "PAUSING" ]; then
7595 echo "Incorrect multiop output: $multiop_output"
7610 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
7612 echo $((SECONDS - start))
7616 inodes_available () {
7617 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
7618 sort -un | head -n1) || return 1
7623 mdsrate_inodes_available () {
7624 local min_inodes=$(inodes_available)
7626 echo $((min_inodes * 99 / 100))
7629 # reset stat counters
7631 local paramfile="$1"
7633 lctl set_param -n $paramfile=0
7638 local paramfile="$1"
7641 lctl get_param -n $paramfile |
7642 awk '/^'$stat'/ { sum += $2 } END { printf("%0.0f", sum) }'
7646 awk '{sum += $1} END { printf("%0.0f", sum) }'
7649 calc_osc_kbytes () {
7650 $LFS df $MOUNT > /dev/null
7651 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
7655 wait_delete_completed
7656 AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7657 echo "OST kbytes available: ${AVAIL[*]}"
7662 for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7663 #echo OST $i: ${AVAIL[i]}kb
7664 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7668 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7673 echo "Min free space: OST $MINI: $MINV"
7674 echo "Max free space: OST $MAXI: $MAXV"
7677 # save_lustre_params(comma separated facet list, parameter_mask)
7678 # generate a stream of formatted strings (<facet> <param name>=<param value>)
7679 save_lustre_params() {
7684 for facet in ${facets//,/ }; do
7685 facet_svc=$(facet_svc $facet)
7687 "params=\\\$($LCTL get_param $2);
7688 [[ -z \\\"$facet_svc\\\" ]] && param= ||
7689 param=\\\$(grep $facet_svc <<< \\\"\\\$params\\\");
7690 [[ -z \\\$param ]] && param=\\\"\\\$params\\\";
7691 while read s; do echo $facet \\\$s;
7692 done <<< \\\"\\\$param\\\""
7696 # restore lustre parameters from input stream, produces by save_lustre_params
7697 restore_lustre_params() {
7702 while IFS=" =" read facet name val; do
7703 do_facet $facet "$LCTL set_param -n $name=$val"
7707 check_node_health() {
7708 local nodes=${1:-$(comma_list $(nodes_list))}
7709 local health=$TMP/node_health.$$
7711 do_nodes -q $nodes "$LCTL get_param catastrophe 2>&1" | tee $health |
7712 grep "catastrophe=1" && error "LBUG/LASSERT detected"
7713 # Only check/report network health if get_param isn't reported, since
7714 # *clearly* the network is working if get_param returned something.
7715 if (( $(grep -c catastro $health) != $(wc -w <<< ${nodes//,/ }) )); then
7716 for node in ${nodes//,/ }; do
7717 check_network $node 5
7723 mdsrate_cleanup () {
7725 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
7726 --nfiles $3 --dir $4 --filefmt $5 $6
7731 ########################
7733 convert_facet2label() {
7736 if [ x$facet = xost ]; then
7738 elif [ x$facet = xmgs ] && combined_mgs_mds ; then
7742 local varsvc=${facet}_svc
7744 if [ -n "${!varsvc}" ]; then
7747 error "No label for $facet!"
7751 get_clientosc_proc_path() {
7752 echo "${1}-osc-[-0-9a-f]*"
7755 get_mdtosc_proc_path() {
7757 local ost_label=${2:-"*OST*"}
7759 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
7760 local mdt_label=$(convert_facet2label $mds_facet)
7761 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
7763 if [[ $ost_label = *OST* ]]; then
7764 echo "${ost_label}-osc-${mdt_index}"
7766 echo "${ost_label}-osp-${mdt_index}"
7770 get_osc_import_name() {
7773 local label=$(convert_facet2label $ost)
7775 if [ "${facet:0:3}" = "mds" ]; then
7776 get_mdtosc_proc_path $facet $label
7780 get_clientosc_proc_path $label
7784 _wait_import_state () {
7786 local CONN_PROC="$2"
7787 local maxtime=${3:-$(max_recovery_time)}
7788 local err_on_fail=${4:-1}
7792 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
7793 while ! echo "${CONN_STATE}" | egrep -q "^${expected}\$" ; do
7794 if [[ "${expected}" == "DISCONN" ]]; then
7795 # for disconn we can check after proc entry is removed
7796 [[ -z "${CONN_STATE}" ]] && return 0
7797 # with AT, we can have connect request timeout near
7798 # reconnect timeout and test can't see real disconnect
7799 [[ "${CONN_STATE}" == "CONNECTING" ]] && return 0
7801 if (( $i >= $maxtime )); then
7802 (( $err_on_fail != 0 )) &&
7803 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}"
7807 # Add uniq for multi-mount case
7808 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null |
7813 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
7817 wait_import_state() {
7820 local maxtime=${3:-$(max_recovery_time)}
7821 local err_on_fail=${4:-1}
7824 for param in ${params//,/ }; do
7825 _wait_import_state "$expected" "$param" $maxtime $err_on_fail ||
7830 wait_import_state_mount() {
7831 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
7835 wait_import_state "$@"
7838 # One client request could be timed out because server was not ready
7839 # when request was sent by client.
7840 # The request timeout calculation details :
7842 # /* We give the server rq_timeout secs to process the req, and
7843 # add the network latency for our local timeout. */
7844 # request->rq_deadline = request->rq_sent + request->rq_timeout +
7845 # ptlrpc_at_get_net_latency(request) ;
7847 # ptlrpc_connect_import ()
7848 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
7851 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
7852 # ptlrpc_at_get_net_latency(request) ->
7853 # at_get (max (iat_net_latency=0, at_min)) = at_min
7856 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
7857 # INITIAL_CONNECT_TIMEOUT + at_min
7859 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
7860 # because we can not get this value in runtime,
7861 # the value depends on configure options, and it is not stored in /proc.
7863 # #define CONNECTION_SWITCH_MIN 5U
7864 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
7866 request_timeout () {
7869 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
7870 local init_connect_timeout=$TIMEOUT
7871 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
7873 local at_min=$(at_get $facet at_min)
7875 echo $(( init_connect_timeout + at_min ))
7878 _wait_osc_import_state() {
7882 local target=$(get_osc_import_name $facet $ost_facet)
7883 local param="os[cp].${target}.ost_server_uuid"
7887 # 1. wait the deadline of client 1st request (it could be skipped)
7888 # 2. wait the deadline of client 2nd request
7889 local maxtime=$(( 2 * $(request_timeout $facet)))
7891 if [[ $facet == client* ]]; then
7892 # During setup time, the osc might not be setup, it need wait
7893 # until list_param can return valid value.
7894 params=$($LCTL list_param $param 2>/dev/null || true)
7895 while [ -z "$params" ]; do
7896 if [ $i -ge $maxtime ]; then
7897 echo "can't get $param in $maxtime secs"
7902 params=$($LCTL list_param $param 2>/dev/null || true)
7906 if [[ $ost_facet = mds* ]]; then
7907 # no OSP connection to itself
7908 if [[ $facet = $ost_facet ]]; then
7911 param="osp.${target}.mdt_server_uuid"
7915 local plist=$(comma_list $params)
7916 if ! do_rpc_nodes "$(facet_active_host $facet)" \
7917 wait_import_state $expected $plist $maxtime; then
7918 error "$facet: import is not in $expected state after $maxtime"
7925 wait_osc_import_state() {
7931 if [[ $facet = mds ]]; then
7932 for num in $(seq $MDSCOUNT); do
7933 _wait_osc_import_state mds$num "$ost_facet" "$expected"
7936 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
7940 wait_osc_import_ready() {
7941 wait_osc_import_state $1 $2 "\(FULL\|IDLE\)"
7944 _wait_mgc_import_state() {
7947 local error_on_failure=${3:-1}
7948 local param="mgc.*.mgs_server_uuid"
7952 # 1. wait the deadline of client 1st request (it could be skipped)
7953 # 2. wait the deadline of client 2nd request
7954 local maxtime=$(( 2 * $(request_timeout $facet)))
7956 if [[ $facet == client* ]]; then
7957 # During setup time, the osc might not be setup, it need wait
7958 # until list_param can return valid value. And also if there
7959 # are mulitple osc entries we should list all of them before
7961 params=$($LCTL list_param $param 2>/dev/null || true)
7962 while [ -z "$params" ]; do
7963 if [ $i -ge $maxtime ]; then
7964 echo "can't get $param in $maxtime secs"
7969 params=$($LCTL list_param $param 2>/dev/null || true)
7972 local plist=$(comma_list $params)
7973 if ! do_rpc_nodes "$(facet_active_host $facet)" \
7974 wait_import_state $expected $plist $maxtime \
7975 $error_on_failure; then
7976 if [ $error_on_failure -ne 0 ]; then
7977 error "import is not in ${expected} state"
7985 wait_mgc_import_state() {
7988 local error_on_failure=${3:-1}
7991 if [[ $facet = mds ]]; then
7992 for num in $(seq $MDSCOUNT); do
7993 _wait_mgc_import_state mds$num "$expected" \
7994 $error_on_failure || return
7997 _wait_mgc_import_state "$facet" "$expected"
7998 $error_on_failure || return
8002 wait_dne_interconnect() {
8005 if [ $MDSCOUNT -gt 1 ]; then
8006 for num in $(seq $MDSCOUNT); do
8007 wait_osc_import_ready mds mds$num
8012 get_clientmdc_proc_path() {
8016 get_clientmgc_proc_path() {
8023 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
8028 [ -z "$list" ] && return 0
8030 # Add paths to lustre tests for 32 and 64 bit systems.
8031 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
8032 local TESTPATH="$RLUSTRE/tests:"
8033 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
8034 do_nodes ${quiet:-"--verbose"} $list "${RPATH} NAME=${NAME} \
8035 TESTLOG_PREFIX=$TESTLOG_PREFIX TESTNAME=$TESTNAME \
8039 wait_clients_import_state () {
8043 local facets="$facet"
8045 if [ "$FAILURE_MODE" = HARD ]; then
8046 facets=$(for f in ${facet//,/ }; do
8047 facets_on_host $(facet_active_host $f) | tr "," "\n"
8048 done | sort -u | paste -sd , )
8051 for facet in ${facets//,/ }; do
8052 local label=$(convert_facet2label $facet)
8055 ost* ) proc_path="osc.$(get_clientosc_proc_path \
8056 $label).ost_server_uuid" ;;
8057 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
8058 $label).mds_server_uuid" ;;
8059 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
8060 $label).mgs_server_uuid" ;;
8061 *) error "unknown facet!" ;;
8064 local params=$(expand_list $params $proc_path)
8067 if ! do_rpc_nodes "$list" wait_import_state_mount "$expected" $params;
8069 error "import is not in ${expected} state"
8081 # wait until all MDTs are in the expected state
8082 for ((num = 1; num <= $MDSCOUNT; num++)); do
8083 local mdtosp=$(get_mdtosc_proc_path mds${num} ${tgt_name})
8087 if [ $facet = "mds" ]; then
8088 mproc="osp.$mdtosp.active"
8089 [ $num -eq $((tgt_idx + 1)) ] && continue
8091 mproc="osc.$mdtosp.active"
8097 local result=$(do_facet mds${num} "$LCTL get_param -n $mproc")
8100 [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $mproc"
8101 if [ $result -eq $expected ]; then
8102 echo -n "target updated after "
8103 echo "$wait sec (got $result)"
8107 if [ $wait -eq $max ]; then
8108 error "$tgt_name: wanted $expected got $result"
8110 echo "Waiting $((max - wait)) secs for $tgt_name"
8120 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
8121 $LCTL get_param obdfilter.*.kbytesavail))
8122 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
8123 $LCTL get_param -n obdfilter.*.tot_granted))
8124 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
8125 $LCTL get_param -n obdfilter.*.kbytestotal))
8126 for ((i=0; i<${#AVAILA[@]}; i++)); do
8127 local -a AVAIL1=(${AVAILA[$i]//=/ })
8128 local -a TOTAL=(${TOTALA[$i]//=/ })
8129 GRANT=$((${GRANTA[$i]}/1024))
8130 # allow 1% of total space in bavail because of delayed
8131 # allocation with ZFS which might release some free space after
8132 # txg commit. For small devices, we set a mininum of 8MB
8133 local LIMIT=$((${TOTAL} / 100 + 8000))
8134 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
8135 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
8136 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
8137 echo " FULL" || echo
8143 echo -e "$(do_facet $SINGLEMDS $LCTL pool_list $1 | sed '1d')"
8146 check_pool_not_exist() {
8147 local fsname=${1%%.*}
8148 local poolname=${1##$fsname.}
8149 [[ $# -ne 1 ]] && return 0
8150 [[ x$poolname = x ]] && return 0
8151 list_pool $fsname | grep -w $1 && return 1
8156 local fsname=${1%%.*}
8157 local poolname=${1##$fsname.}
8158 local keep_pools=${2:-false}
8160 stack_trap "destroy_test_pools $fsname" EXIT
8161 do_facet mgs lctl pool_new $1
8163 # get param should return err unless pool is created
8164 [[ $RC -ne 0 ]] && return $RC
8166 for mds_id in $(seq $MDSCOUNT); do
8167 local mdt_id=$((mds_id-1))
8168 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
8169 wait_update_facet mds$mds_id \
8170 "lctl get_param -n lod.$lodname.pools.$poolname \
8171 2>/dev/null || echo foo" "" ||
8172 error "mds$mds_id: pool_new failed $1"
8174 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
8175 2>/dev/null || echo foo" "" || error "pool_new failed $1"
8177 $keep_pools || add_pool_to_list $1
8181 add_pool_to_list () {
8182 local fsname=${1%%.*}
8183 local poolname=${1##$fsname.}
8185 local listvar=${fsname}_CREATED_POOLS
8186 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
8190 remove_pool_from_list () {
8191 local fsname=${1%%.*}
8192 local poolname=${1##$fsname.}
8194 local listvar=${fsname}_CREATED_POOLS
8195 local temp=${listvar}=$(exclude_items_from_list "${!listvar}" $poolname)
8199 # cleanup all pools exist on $FSNAME
8200 destroy_all_pools () {
8202 for i in $(list_pool $FSNAME); do
8207 destroy_pool_int() {
8209 local OSTS=$(list_pool $1)
8210 for ost in $OSTS; do
8211 do_facet mgs lctl pool_remove $1 $ost
8213 wait_update_facet $SINGLEMDS "lctl pool_list $1 | wc -l" "1" ||
8214 error "MDS: pool_list $1 failed"
8215 do_facet mgs lctl pool_destroy $1
8218 # <fsname>.<poolname> or <poolname>
8220 local fsname=${1%%.*}
8221 local poolname=${1##$fsname.}
8223 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
8227 check_pool_not_exist $fsname.$poolname && return 0 || true
8229 destroy_pool_int $fsname.$poolname
8231 [[ $RC -ne 0 ]] && return $RC
8232 for mds_id in $(seq $MDSCOUNT); do
8233 local mdt_id=$((mds_id-1))
8234 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
8235 wait_update_facet mds$mds_id \
8236 "lctl get_param -n lod.$lodname.pools.$poolname \
8237 2>/dev/null || echo foo" "foo" ||
8238 error "mds$mds_id: destroy pool failed $1"
8240 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
8241 2>/dev/null || echo foo" "foo" || error "destroy pool failed $1"
8243 remove_pool_from_list $fsname.$poolname
8249 local fsname=${1:-$FSNAME}
8251 local listvar=${fsname}_CREATED_POOLS
8253 [ x${!listvar} = x ] && return 0
8255 echo "Destroy the created pools: ${!listvar}"
8256 for poolname in ${!listvar//,/ }; do
8257 destroy_pool $fsname.$poolname
8261 destroy_test_pools () {
8263 local fsname=${1:-$FSNAME}
8264 destroy_pools $fsname || true
8270 local ts=$(date +%s)
8273 if [[ ! -f "$YAML_LOG" ]]; then
8274 # init_logging is not performed before gather_logs,
8275 # so the $LOGDIR needs to be checked here
8276 check_shared_dir $LOGDIR && touch $LOGDIR/shared
8279 [ -f $LOGDIR/shared ] && docp=false
8281 # dump lustre logs, dmesg, and journal if GSS_SK=true
8283 prefix="$TESTLOG_PREFIX.$TESTNAME"
8285 echo "Dumping lctl log to ${prefix}.*.${suffix}"
8287 if [ -n "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
8288 echo "Dumping logs only on local client."
8289 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
8290 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
8291 [ "$SHARED_KEY" = true ] && find $SK_PATH -name '*.key' -exec \
8292 lgss_sk -r {} \; &> \
8293 ${prefix}.ssk_keys.$(hostname -s).${suffix}
8294 [ "$SHARED_KEY" = true ] && lctl get_param 'nodemap.*.*' > \
8295 ${prefix}.nodemaps.$(hostname -s).${suffix}
8296 [ "$GSS_SK" = true ] && keyctl show > \
8297 ${prefix}.keyring.$(hostname -s).${suffix}
8298 [ "$GSS_SK" = true ] && journalctl -a > \
8299 ${prefix}.journal.$(hostname -s).${suffix}
8304 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
8305 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
8306 if [ "$SHARED_KEY" = true ]; then
8307 do_nodesv $list "find $SK_PATH -name '*.key' -exec \
8308 lgss_sk -r {} \; &> \
8309 ${prefix}.ssk_keys.\\\$(hostname -s).${suffix}"
8310 do_facet mds1 "lctl get_param 'nodemap.*.*' > \
8311 ${prefix}.nodemaps.\\\$(hostname -s).${suffix}"
8313 if [ "$GSS_SK" = true ]; then
8314 do_nodesv $list "keyctl show > \
8315 ${prefix}.keyring.\\\$(hostname -s).${suffix}"
8316 do_nodesv $list "journalctl -a > \
8317 ${prefix}.journal.\\\$(hostname -s).${suffix}"
8320 if [ ! -f $LOGDIR/shared ]; then
8321 local remote_nodes=$(exclude_items_from_list $list $HOSTNAME)
8323 for node in ${remote_nodes//,/ }; do
8324 rsync -az -e ssh $node:${prefix}.'*'.${suffix} $LOGDIR &
8338 for i in $(seq 0 $num_mntpts); do
8339 cmd="ls -laf ${mntpt_root}$i/$dir"
8345 for pid in $pids; do
8352 # check_and_start_recovery_timer()
8353 # service_time = at_est2timeout(service_time);
8354 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
8355 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
8357 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
8358 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
8359 #define CONNECTION_SWITCH_MIN 5
8360 #define CONNECTION_SWITCH_INC 5
8361 max_recovery_time() {
8362 local init_connect_timeout=$((TIMEOUT / 20))
8363 ((init_connect_timeout >= 5)) || init_connect_timeout=5
8365 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
8366 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
8368 echo -n $service_time
8371 recovery_time_min() {
8372 local connection_switch_min=5
8373 local connection_switch_inc=5
8374 local connection_switch_max
8375 local reconnect_delay_max
8376 local initial_connect_timeout
8380 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
8381 (($connection_switch_min > $TIMEOUT)) &&
8382 max=$connection_switch_min || max=$TIMEOUT
8383 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
8385 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
8386 timeout_20=$((TIMEOUT/20))
8387 (($connection_switch_min > $timeout_20)) &&
8388 initial_connect_timeout=$connection_switch_min ||
8389 initial_connect_timeout=$timeout_20
8391 reconnect_delay_max=$((connection_switch_max + connection_switch_inc +
8392 initial_connect_timeout))
8393 echo $((2 * reconnect_delay_max))
8396 get_clients_mount_count () {
8397 local clients=${CLIENTS:-$HOSTNAME}
8399 # we need to take into account the clients mounts and
8400 # exclude mds/ost mounts if any;
8401 do_nodes $clients cat /proc/mounts | grep lustre |
8402 grep -w $MOUNT | wc -l
8406 PROC_CLI="srpc_info"
8407 PROC_CON="srpc_contexts"
8415 if [ $M -lt $N ]; then
8419 while [ $N -lt $M ]; do
8429 calc_connection_cnt() {
8432 # MDT->MDT = 2 * C(M, 2)
8436 comb_m2=$(combination $MDSCOUNT 2)
8438 local num_clients=$(get_clients_mount_count)
8440 local cnt_mdt2mdt=$((comb_m2 * 2))
8441 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
8442 local cnt_cli2ost=$((num_clients * OSTCOUNT))
8443 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
8444 if is_mounted $MOUNT2; then
8445 cnt_cli2mdt=$((cnt_cli2mdt * 2))
8446 cnt_cli2ost=$((cnt_cli2ost * 2))
8454 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
8455 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
8456 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt \
8457 + cnt_cli2ost + cnt_cli2mdt))
8471 local cmd="$tgt.srpc.flavor"
8473 if [ $net == "any" ]; then
8478 if [ $dir != "any" ]; then
8483 log "Setting sptlrpc rule: $cmd"
8484 do_facet mgs "$LCTL conf_param $cmd"
8490 local total_ctx=$(echo "$output" | grep -c "expire.*key.*hdl")
8500 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
8501 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
8503 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
8505 if [ "x$bulkspec" != "x" ]; then
8506 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
8508 if [ "x$algs" != "x" ]; then
8509 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
8511 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
8512 if [ $bulk == "bulkn" ]; then
8513 bulk_count=`echo "$output" | grep "bulk flavor" \
8514 | grep "null/null" | wc -l`
8515 elif [ $bulk == "bulki" ]; then
8516 bulk_count=`echo "$output" | grep "bulk flavor" \
8517 | grep "/null" | grep -v "null/" | wc -l`
8519 bulk_count=`echo "$output" | grep "bulk flavor" \
8520 | grep -v "/null" | grep -v "null/" | wc -l`
8524 [ $bulk_count -lt $count ] && count=$bulk_count
8535 local clients=${CLIENTS:-$HOSTNAME}
8537 for c in ${clients//,/ }; do
8538 local output=$(do_node $c lctl get_param -n \
8539 mdc.*-*-mdc-*.$PROC_CLI 2>/dev/null)
8540 local tmpcnt=$(count_flvr "$output" $flavor)
8541 if $GSS_SK && [ $flavor != "null" ]; then
8542 # tmpcnt=min(contexts,flavors) to ensure SK context is on
8543 output=$(do_node $c lctl get_param -n \
8544 mdc.*-MDT*-mdc-*.$PROC_CON 2>/dev/null)
8545 local outcon=$(count_contexts "$output")
8546 if [ "$outcon" -lt "$tmpcnt" ]; then
8550 cnt=$((cnt + tmpcnt))
8560 local clients=${CLIENTS:-$HOSTNAME}
8562 for c in ${clients//,/ }; do
8564 do_node $c lctl set_param osc.*.idle_connect=1 >/dev/null 2>&1
8565 local output=$(do_node $c lctl get_param -n \
8566 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null)
8567 local tmpcnt=$(count_flvr "$output" $flavor)
8568 if $GSS_SK && [ $flavor != "null" ]; then
8569 # tmpcnt=min(contexts,flavors) to ensure SK context is on
8570 output=$(do_node $c lctl get_param -n \
8571 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CON 2>/dev/null)
8572 local outcon=$(count_contexts "$output")
8573 if [ "$outcon" -lt "$tmpcnt" ]; then
8577 cnt=$((cnt + tmpcnt))
8587 if [ $MDSCOUNT -le 1 ]; then
8592 for num in `seq $MDSCOUNT`; do
8593 local output=$(do_facet mds$num lctl get_param -n \
8594 osp.*-MDT*osp-MDT*.$PROC_CLI 2>/dev/null)
8595 local tmpcnt=$(count_flvr "$output" $flavor)
8596 if $GSS_SK && [ $flavor != "null" ]; then
8597 # tmpcnt=min(contexts,flavors) to ensure SK context is on
8598 output=$(do_facet mds$num lctl get_param -n \
8599 osp.*-MDT*osp-MDT*.$PROC_CON 2>/dev/null)
8600 local outcon=$(count_contexts "$output")
8601 if [ "$outcon" -lt "$tmpcnt" ]; then
8605 cnt=$((cnt + tmpcnt))
8616 for num in `seq $MDSCOUNT`; do
8617 mdtosc=$(get_mdtosc_proc_path mds$num)
8618 mdtosc=${mdtosc/-MDT*/-MDT\*}
8619 local output=$(do_facet mds$num lctl get_param -n \
8620 os[cp].$mdtosc.$PROC_CLI 2>/dev/null)
8621 local tmpcnt=$(count_flvr "$output" $flavor)
8622 if $GSS_SK && [ $flavor != "null" ]; then
8623 # tmpcnt=min(contexts,flavors) to ensure SK context is on
8624 output=$(do_facet mds$num lctl get_param -n \
8625 os[cp].$mdtosc.$PROC_CON 2>/dev/null)
8626 local outcon=$(count_contexts "$output")
8627 if [ "$outcon" -lt "$tmpcnt" ]; then
8631 cnt=$((cnt + tmpcnt))
8640 local output=$(do_facet client lctl get_param -n mgc.*.$PROC_CLI \
8642 count_flvr "$output" $flavor
8647 local dir=$1 # from to
8648 local flavor=$2 # flavor expected
8651 if [ $dir == "cli2mdt" ]; then
8652 res=`flvr_cnt_cli2mdt $flavor`
8653 elif [ $dir == "cli2ost" ]; then
8654 res=`flvr_cnt_cli2ost $flavor`
8655 elif [ $dir == "mdt2mdt" ]; then
8656 res=`flvr_cnt_mdt2mdt $flavor`
8657 elif [ $dir == "mdt2ost" ]; then
8658 res=`flvr_cnt_mdt2ost $flavor`
8659 elif [ $dir == "all2ost" ]; then
8660 res1=`flvr_cnt_mdt2ost $flavor`
8661 res2=`flvr_cnt_cli2ost $flavor`
8662 res=$((res1 + res2))
8663 elif [ $dir == "all2mdt" ]; then
8664 res1=`flvr_cnt_mdt2mdt $flavor`
8665 res2=`flvr_cnt_cli2mdt $flavor`
8666 res=$((res1 + res2))
8667 elif [ $dir == "all2all" ]; then
8668 res1=`flvr_cnt_mdt2ost $flavor`
8669 res2=`flvr_cnt_cli2ost $flavor`
8670 res3=`flvr_cnt_mdt2mdt $flavor`
8671 res4=`flvr_cnt_cli2mdt $flavor`
8672 res=$((res1 + res2 + res3 + res4))
8680 local dir=$1 # from to
8681 local flavor=$2 # flavor expected
8682 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
8683 local WAITFLAVOR_MAX=20 # how many retries before abort?
8686 for ((i = 0; i < $WAITFLAVOR_MAX; i++)); do
8687 echo -n "checking $dir..."
8688 res=$(do_check_flavor $dir $flavor)
8689 echo "found $res/$expect $flavor connections"
8690 [ $res -ge $expect ] && return 0
8694 echo "Error checking $flavor of $dir: expect $expect, actual $res"
8695 # echo "Dumping additional logs for SK debug.."
8696 do_nodes $(comma_list $(all_server_nodes)) "keyctl show"
8698 gather_logs $(comma_list $(nodes_list))
8703 restore_to_default_flavor()
8705 local proc="mgs.MGS.live.$FSNAME"
8707 echo "restoring to default flavor..."
8709 local nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
8710 grep ".srpc.flavor" | wc -l)
8712 # remove all existing rules if any
8713 if [ $nrule -ne 0 ]; then
8714 echo "$nrule existing rules"
8715 for rule in $(do_facet mgs lctl get_param -n $proc 2>/dev/null |
8716 grep ".srpc.flavor."); do
8717 echo "remove rule: $rule"
8718 spec=`echo $rule | awk -F = '{print $1}'`
8719 do_facet mgs "$LCTL conf_param -d $spec"
8723 # verify no rules left
8724 nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
8725 grep ".srpc.flavor." | wc -l)
8726 [ $nrule -ne 0 ] && error "still $nrule rules left"
8728 # wait for default flavor to be applied
8731 set_rule $FSNAME any any $SK_FLAVOR
8732 wait_flavor all2all $SK_FLAVOR
8734 set_rule $FSNAME any cli2mdt $SK_FLAVOR
8735 set_rule $FSNAME any cli2ost $SK_FLAVOR
8736 wait_flavor cli2mdt $SK_FLAVOR
8737 wait_flavor cli2ost $SK_FLAVOR
8739 echo "GSS_SK now at default flavor: $SK_FLAVOR"
8741 wait_flavor all2all null
8747 local flavor=${1:-null}
8749 echo "setting all flavor to $flavor"
8751 # FIXME need parameter to this fn
8752 # and remove global vars
8753 local cnt_all2all=$(calc_connection_cnt all2all)
8755 local res=$(do_check_flavor all2all $flavor)
8756 if [ $res -eq $cnt_all2all ]; then
8757 echo "already have total $res $flavor connections"
8761 echo "found $res $flavor out of total $cnt_all2all connections"
8762 restore_to_default_flavor
8764 [[ $flavor = null ]] && return 0
8766 if $GSS_SK && [ $flavor != "null" ]; then
8768 set_rule $FSNAME any any $flavor
8769 wait_flavor all2all $flavor
8771 set_rule $FSNAME any cli2mdt $flavor
8772 set_rule $FSNAME any cli2ost $flavor
8773 set_rule $FSNAME any mdt2ost null
8774 set_rule $FSNAME any mdt2mdt null
8775 wait_flavor cli2mdt $flavor
8776 wait_flavor cli2ost $flavor
8778 echo "GSS_SK now at flavor: $flavor"
8780 set_rule $FSNAME any any $flavor
8781 wait_flavor all2all $flavor
8788 # Checking for shared logdir
8789 if [ ! -d $dir ]; then
8790 # Not found. Create local logdir
8793 touch $dir/check_file.$(hostname -s)
8798 check_write_access() {
8800 local list=${2:-$(comma_list $(nodes_list))}
8804 for node in ${list//,/ }; do
8805 file=$dir/check_file.$(short_nodename $node)
8806 if [[ ! -f "$file" ]]; then
8807 # Logdir not accessible/writable from this node.
8810 rm -f $file || return 1
8816 [[ -n $YAML_LOG ]] && return
8817 local save_umask=$(umask)
8820 export YAML_LOG=${LOGDIR}/results.yml
8824 # If the yaml log already exists then we will just append to it
8825 if [ ! -f $YAML_LOG ]; then
8826 if check_shared_dir $LOGDIR; then
8827 touch $LOGDIR/shared
8828 echo "Logging to shared log directory: $LOGDIR"
8830 echo "Logging to local directory: $LOGDIR"
8833 yml_nodes_file $LOGDIR >> $YAML_LOG
8834 yml_results_file >> $YAML_LOG
8839 # log actual client and server versions if needed for debugging
8840 log "Client: $(lustre_build_version client)"
8841 log "MDS: $(lustre_build_version mds1)"
8842 log "OSS: $(lustre_build_version ost1)"
8846 yml_log_test $1 >> $YAML_LOG
8850 yml_log_test_status $@ >> $YAML_LOG
8853 log_sub_test_begin() {
8854 yml_log_sub_test_begin "$@" >> $YAML_LOG
8857 log_sub_test_end() {
8858 yml_log_sub_test_end "$@" >> $YAML_LOG
8864 local llverdev_opts="$*"
8865 local devname=$(basename $dev)
8866 local size=$(awk "/$devname$/ {print \$3}" /proc/partitions)
8867 # loop devices aren't in /proc/partitions
8868 [[ -z "$size" ]] && size=$(stat -c %s $dev)
8870 local size_gb=$((size / 1024 / 1024)) # Gb
8872 local partial_arg=""
8873 # Run in partial (fast) mode if the size of a partition > 1 GB
8874 (( $size == 0 || $size_gb > 1 )) && partial_arg="-p"
8876 llverdev --force $partial_arg $llverdev_opts $dev
8882 local llverfs_opts=$2
8883 local use_partial_arg=$3
8884 local partial_arg=""
8885 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
8887 # Run in partial (fast) mode if the size of a partition > 1 GB
8888 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
8890 llverfs $partial_arg $llverfs_opts $dir
8894 local devs=${1//,/ }
8897 local rslt=$TMP/sgpdd_survey
8899 # sgpdd-survey cleanups ${rslt}.* files
8901 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
8907 # returns the canonical name for an ldiskfs device
8912 do_facet $facet "dv=\\\$($LCTL get_param -n $dev);
8913 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
8914 echo dm-\\\${foo##*:};
8916 name=\\\$(basename \\\$dv);
8917 if [[ \\\$name = *flakey* ]]; then
8918 name=\\\$(lsblk -o NAME,KNAME |
8919 awk /\\\$name/'{print \\\$NF}');
8925 is_sanity_benchmark() {
8926 local benchmarks="dbench bonnie iozone fsx"
8928 for b in $benchmarks; do
8929 if [ "$b" == "$suite" ]; then
8937 $LFS df | grep OST | awk '{print $4}' | sort -un | head -1
8941 # Get the available size (KB) of a given obd target.
8948 [[ $facet != client ]] || return 0
8950 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
8955 # Get the page size (bytes) on a given facet node.
8956 # The local client page_size is directly available in PAGE_SIZE.
8960 local page_size=$(getconf PAGE_SIZE 2>/dev/null)
8962 [ -z "$CLIENTONLY" -a "$facet" != "client" ] &&
8963 page_size=$(do_facet $facet getconf PAGE_SIZE)
8964 echo -n ${page_size:-4096}
8968 # Get the block count of the filesystem.
8975 [ -z "$CLIENTONLY" ] && count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
8976 awk '/^Block count:/ {print $3}')
8980 # Check whether the "ea_inode" feature is enabled or not, to allow
8981 # ldiskfs xattrs over one block in size. Allow both the historical
8982 # Lustre feature name (large_xattr) and the upstream name (ea_inode).
8983 large_xattr_enabled() {
8984 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
8986 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
8988 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
8989 grep -E -q '(ea_inode|large_xattr)'"
8990 return ${PIPESTATUS[0]}
8993 # Get the maximum xattr size supported by the filesystem.
8995 $LCTL get_param -n llite.*.max_easize
8998 # Dump the value of the named xattr from a file.
9003 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
9006 # Generate a string with size of $size bytes.
9008 local size=${1:-1024} # in bytes
9010 echo "$(head -c $size < /dev/zero | tr '\0' y)"
9013 reformat_external_journal() {
9018 local varbs=${facet}_BLOCKSIZE
9019 if [ -n "${!var}" ]; then
9020 local rcmd="do_facet $facet"
9021 local bs=${!varbs:-$BLCKSIZE}
9024 echo "reformat external journal on $facet:${!var}"
9025 ${rcmd} mke2fs -O journal_dev $bs ${!var} || return 1
9029 # MDT file-level backup/restore
9030 mds_backup_restore() {
9033 local devname=$(mdsdevname $(facet_number $facet))
9034 local mntpt=$(facet_mntpt brpt)
9035 local rcmd="do_facet $facet"
9036 local metadata=${TMP}/backup_restore.tgz
9037 local opts=${MDS_MOUNT_FS_OPTS}
9038 local svc=${facet}_svc
9040 if ! ${rcmd} test -b ${devname}; then
9041 opts=$(csa_add "$opts" -o loop)
9044 echo "file-level backup/restore on $facet:${devname}"
9046 # step 1: build mount point
9047 ${rcmd} mkdir -p $mntpt
9048 # step 2: cleanup old backup
9049 ${rcmd} rm -f $metadata
9051 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 3
9052 if [ ! -z $igif ]; then
9053 # step 3.5: rm .lustre
9054 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 3
9056 # step 4: backup metadata
9058 ${rcmd} tar zcf $metadata --xattrs --xattrs-include="trusted.*" \
9059 --sparse -C $mntpt/ . > /dev/null 2>&1 || return 4
9061 ${rcmd} $UMOUNT $mntpt || return 5
9062 # step 6: reformat dev
9063 echo "reformat new device"
9064 format_mdt $(facet_number $facet)
9066 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
9067 # step 8: restore metadata
9069 ${rcmd} tar zxfp $metadata --xattrs --xattrs-include="trusted.*" \
9070 --sparse -C $mntpt > /dev/null 2>&1 || return 8
9071 # step 9: remove recovery logs
9072 echo "remove recovery logs"
9073 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
9074 # step 10: umount dev
9075 ${rcmd} $UMOUNT $mntpt || return 10
9076 # step 11: cleanup tmp backup
9077 ${rcmd} rm -f $metaea $metadata
9078 # step 12: reset device label - it's not virgin on
9079 ${rcmd} e2label $devname ${!svc}
9086 local devname=$(mdsdevname $(facet_number $facet))
9087 local mntpt=$(facet_mntpt brpt)
9088 local rcmd="do_facet $facet"
9089 local opts=${MDS_MOUNT_FS_OPTS}
9091 if ! ${rcmd} test -b ${devname}; then
9092 opts=$(csa_add "$opts" -o loop)
9095 echo "removing OI files on $facet: idx=${idx}"
9097 # step 1: build mount point
9098 ${rcmd} mkdir -p $mntpt
9100 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
9101 if [ -z $idx ]; then
9102 # step 3: remove all OI files
9103 ${rcmd} rm -fv $mntpt/oi.16*
9104 elif [ $idx -lt 2 ]; then
9105 ${rcmd} rm -fv $mntpt/oi.16.${idx}
9109 # others, rm oi.16.[idx, idx * idx, idx ** ...]
9110 for ((i=${idx}; i<64; i=$((i * idx)))); do
9111 ${rcmd} rm -fv $mntpt/oi.16.${i}
9115 ${rcmd} $UMOUNT $mntpt || return 2
9116 # OI files will be recreated when mounted as lustre next time.
9119 # generate maloo upload-able log file name
9120 # \param logname specify unique part of file name
9121 generate_logname() {
9122 local logname=${1:-"default_logname"}
9124 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
9127 # make directory on different MDTs
9132 local hash_name=("all_char" "fnv_1a_64" "crush")
9133 local dirstripe_count=${DIRSTRIPE_COUNT:-"2"}
9134 local dirstripe_index=${DIRSTRIPE_INDEX:-$((base % $MDSCOUNT))}
9137 (( $MDS1_VERSION > $(version_code 2.15.0) )) &&
9138 hash_name+=("crush2")
9140 while getopts "c:H:i:p" opt; do
9142 c) dirstripe_count=$OPTARG;;
9143 H) hash_type=$OPTARG;;
9144 i) dirstripe_index=$OPTARG;;
9146 \?) error "only support -c -H -i -p";;
9150 shift $((OPTIND - 1))
9151 [ $# -eq 1 ] || error "Only creating single directory is supported"
9154 local parent=$(dirname $path)
9155 if [ "$p_option" == "-p" ]; then
9156 [ -d $path ] && return 0
9157 if [ ! -d ${parent} ]; then
9158 mkdir -p ${parent} ||
9159 error "mkdir parent '$parent' failed"
9163 if [ $MDSCOUNT -le 1 ] || ! is_lustre ${parent}; then
9164 mkdir $path || error "mkdir '$path' failed"
9168 if [ $dirstripe_index -eq -1 ]; then
9169 mdt_index=$((base % MDSCOUNT))
9171 mdt_index=$dirstripe_index
9174 # randomly choose hash type
9175 [ -z "$hash_type" ] &&
9176 hash_type=${hash_name[$((RANDOM % ${#hash_name[@]}))]}
9178 if (($MDS1_VERSION >= $(version_code 2.8.0))); then
9179 if [ $dirstripe_count -eq -1 ]; then
9180 dirstripe_count=$((RANDOM % MDSCOUNT + 1))
9186 echo "striped dir -i$mdt_index -c$dirstripe_count -H $hash_type $path"
9187 $LFS mkdir -i$mdt_index -c$dirstripe_count -H $hash_type $path ||
9188 error "mkdir -i $mdt_index -c$dirstripe_count -H $hash_type $path failed"
9192 # free_fd: find the smallest and not in use file descriptor [above @last_fd]
9194 # If called many times, passing @last_fd will avoid repeated searching
9195 # already-open FDs repeatedly if we know they are still in use.
9197 # usage: free_fd [last_fd]
9200 local max_fd=$(ulimit -n)
9201 local fd=$((${1:-2} + 1))
9203 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
9206 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
9210 check_mount_and_prep()
9212 is_mounted $MOUNT || setupall
9214 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
9215 mkdir_on_mdt0 $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
9216 for idx in $(seq $MDSCOUNT); do
9217 local name="MDT$(printf '%04x' $((idx - 1)))"
9218 rm -rf $MOUNT/.lustre/lost+found/$name/*
9222 # calcule how many ost-objects to be created.
9223 precreated_ost_obj_count()
9227 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
9228 local ost_name="OST$(printf '%04x' $ost_idx)"
9229 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
9230 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
9231 osp.$proc_path.prealloc_last_id)
9232 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
9233 osp.$proc_path.prealloc_next_id)
9234 echo $((last_id - next_id + 1))
9237 check_file_in_pool()
9242 local res=$($LFS getstripe $file | grep 0x | cut -f2)
9245 for t in $tlist ; do
9246 [ "$i" -eq "$t" ] && continue 2
9249 echo "pool list: $tlist"
9250 echo "striping: $res"
9251 error_noexit "$file not allocated in $pool"
9258 echo "Creating new pool"
9261 create_pool $FSNAME.$pool ||
9262 { error_noexit "No pool created, result code $?"; return 1; }
9263 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
9264 { error_noexit "$pool not in lfs pool_list"; return 2; }
9267 pool_add_targets() {
9268 echo "Adding targets to pool"
9274 if [ -z $last ]; then
9277 local list=$(seq $first $step $last)
9280 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
9281 local tg=$(for i in $list;
9282 do printf -- "-e $FSNAME-OST%04x_UUID " $i; done)
9283 local firstx=$(printf "%04x" $first)
9284 local lastx=$(printf "%04x" $last)
9286 do_facet mgs $LCTL pool_add \
9287 $FSNAME.$pool $FSNAME-OST[$firstx-$lastx/$step]
9289 if (( $? != 0 && $? != 17 )); then
9290 error_noexit "pool_add $FSNAME-OST[$firstx-$lastx/$step] failed"
9294 # wait for OSTs to be added to the pool
9295 for mds_id in $(seq $MDSCOUNT); do
9296 local mdt_id=$((mds_id-1))
9297 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
9298 wait_update_facet mds$mds_id \
9299 "lctl get_param -n lod.$lodname.pools.$pool |
9300 grep $tg | sort -u | tr '\n' ' '" "$t" || {
9301 error_noexit "mds$mds_id: Add to pool failed"
9305 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool |
9306 grep $tg | sort -u | tr '\n' ' ' " "$t" || {
9307 error_noexit "Add to pool failed"
9315 echo "Setting pool on directory $tdir"
9317 $LFS setstripe -c 2 -p $pool $tdir && return 0
9319 error_noexit "Cannot set pool $pool to $tdir"
9326 echo "Checking pool on directory $tdir"
9328 local res=$($LFS getstripe --pool $tdir | sed "s/\s*$//")
9329 [ "$res" = "$pool" ] && return 0
9331 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
9335 pool_dir_rel_path() {
9336 echo "Testing relative path works well"
9341 mkdir -p $root/$tdir/$tdir
9343 pool_set_dir $pool $tdir || return 1
9344 pool_set_dir $pool ./$tdir || return 2
9345 pool_set_dir $pool ../$tdir || return 3
9346 pool_set_dir $pool ../$tdir/$tdir || return 4
9347 rm -rf $tdir; cd - > /dev/null
9350 pool_alloc_files() {
9351 echo "Checking files allocation from directory pool"
9358 for i in $(seq -w 1 $count)
9360 local file=$tdir/file-$i
9362 check_file_in_pool $file $pool "$tlist" || \
9363 failed=$((failed + 1))
9365 [ "$failed" = 0 ] && return 0
9367 error_noexit "$failed files not allocated in $pool"
9371 pool_create_files() {
9372 echo "Creating files in pool"
9380 for i in $(seq -w 1 $count)
9382 local file=$tdir/spoo-$i
9383 $LFS setstripe -p $pool $file
9384 check_file_in_pool $file $pool "$tlist" || \
9385 failed=$((failed + 1))
9387 [ "$failed" = 0 ] && return 0
9389 error_noexit "$failed files not allocated in $pool"
9394 echo "Checking 'lfs df' output"
9397 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
9399 local res=$($LFS df --pool $FSNAME.$pool |
9401 grep "$FSNAME-OST" |
9403 [ "$res" = "$t" ] && return 0
9405 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
9409 pool_file_rel_path() {
9410 echo "Creating files in a pool with relative pathname"
9415 { error_noexit "unable to create $tdir"; return 1 ; }
9416 local file="/..$tdir/$tfile-1"
9417 $LFS setstripe -p $pool $file ||
9418 { error_noexit "unable to create $file" ; return 2 ; }
9421 $LFS setstripe -p $pool $tfile-2 || {
9422 error_noexit "unable to create $tfile-2 in $tdir"
9427 pool_remove_first_target() {
9428 echo "Removing first target from a pool"
9429 pool_remove_target $1 -1
9432 pool_remove_target() {
9436 local pname="lov.$FSNAME-*.pools.$pool"
9437 if [ $index -eq -1 ]; then
9438 local t=$($LCTL get_param -n $pname | head -1)
9440 local t=$(printf "$FSNAME-OST%04x_UUID" $index)
9443 echo "Removing $t from $pool"
9444 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
9445 for mds_id in $(seq $MDSCOUNT); do
9446 local mdt_id=$((mds_id-1))
9447 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
9448 wait_update_facet mds$mds_id \
9449 "lctl get_param -n lod.$lodname.pools.$pool |
9451 error_noexit "mds$mds_id: $t not removed from" \
9456 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
9457 error_noexit "$t not removed from $FSNAME.$pool"
9462 pool_remove_all_targets() {
9463 echo "Removing all targets from pool"
9466 local pname="lov.$FSNAME-*.pools.$pool"
9467 for t in $($LCTL get_param -n $pname | sort -u)
9469 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
9471 for mds_id in $(seq $MDSCOUNT); do
9472 local mdt_id=$((mds_id-1))
9473 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
9474 wait_update_facet mds$mds_id "lctl get_param -n \
9475 lod.$lodname.pools.$pool" "" || {
9476 error_noexit "mds$mds_id: Pool $pool not drained"
9480 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
9481 error_noexit "Pool $FSNAME.$pool cannot be drained"
9484 # striping on an empty/nonexistant pool should fall back
9485 # to "pool of everything"
9487 error_noexit "failed to use fallback striping for empty pool"
9490 # setstripe on an empty pool should fail
9491 $LFS setstripe -p $pool $file 2>/dev/null && {
9492 error_noexit "expected failure when creating file" \
9500 echo "Destroying pool"
9504 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
9507 # striping on an empty/nonexistant pool should fall back
9508 # to "pool of everything"
9510 error_noexit "failed to use fallback striping for missing pool"
9513 # setstripe on an empty pool should fail
9514 $LFS setstripe -p $pool $file 2>/dev/null && {
9515 error_noexit "expected failure when creating file" \
9520 # get param should return err once pool is gone
9521 if wait_update $HOSTNAME "lctl get_param -n \
9522 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
9524 remove_pool_from_list $FSNAME.$pool
9527 error_noexit "Pool $FSNAME.$pool is not destroyed"
9531 # Get and check the actual stripe count of one file.
9532 # Usage: check_stripe_count <file> <expected_stripe_count>
9533 check_stripe_count() {
9538 [[ -z "$file" || -z "$expected" ]] &&
9539 error "check_stripe_count: invalid argument"
9541 local cmd="$LFS getstripe -c $file"
9542 actual=$($cmd) || error "$cmd failed"
9543 actual=${actual%% *}
9545 if [[ $actual -ne $expected ]]; then
9546 [[ $expected -eq -1 ]] || { $LFS getstripe $file;
9547 error "$cmd not expected ($expected): found $actual"; }
9548 [[ $actual -eq $OSTCOUNT ]] || { $LFS getstripe $file;
9549 error "$cmd not OST count ($OSTCOUNT): found $actual"; }
9553 # Get and check the actual list of OST indices on one file.
9554 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
9560 [[ -z "$file" || -z "$expected" ]] &&
9561 error "check_obdidx: invalid argument!"
9563 obdidx=$(comma_list $($LFS getstripe $file | grep -A $OSTCOUNT obdidx |
9564 grep -v obdidx | awk '{print $1}' | xargs))
9566 [[ $obdidx = $expected ]] ||
9567 error "list of OST indices on $file is $obdidx," \
9568 "should be $expected"
9571 # Get and check the actual OST index of the first stripe on one file.
9572 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
9573 check_start_ost_idx() {
9578 [[ -z "$file" || -z "$expected" ]] &&
9579 error "check_start_ost_idx: invalid argument!"
9581 start_ost_idx=$($LFS getstripe $file | grep -A 1 obdidx |
9582 grep -v obdidx | awk '{print $1}')
9584 [[ $start_ost_idx = $expected ]] ||
9585 error "OST index of the first stripe on $file is" \
9586 "$start_ost_idx, should be $expected"
9589 killall_process () {
9590 local clients=${1:-$(hostname)}
9595 do_nodes $clients "killall $signal $name"
9600 do_facet mgs "$LCTL snapshot_create -F $FSNAME $*"
9605 do_facet mgs "$LCTL snapshot_destroy -F $FSNAME $*"
9610 do_facet mgs "$LCTL snapshot_modify -F $FSNAME $*"
9615 do_facet mgs "$LCTL snapshot_list -F $FSNAME $*"
9620 do_facet mgs "$LCTL snapshot_mount -F $FSNAME $*"
9625 do_facet mgs "$LCTL snapshot_umount -F $FSNAME $*"
9632 do_facet mgs "cat $LSNAPSHOT_LOG"
9638 echo "Cleaning test environment ..."
9640 # Every lsnapshot command takes exclusive lock with others,
9641 # so can NOT destroy the snapshot during list with 'xargs'.
9643 local ssname=$(lsnapshot_list | grep snapshot_name |
9644 grep lss_ | awk '{ print $2 }' | head -n 1)
9645 [ -z "$ssname" ] && break
9647 lsnapshot_destroy -n $ssname -f ||
9648 lss_err "Fail to destroy $ssname by force"
9658 local host=$(facet_active_host $facet)
9659 local dir=$(dirname $(facet_vdevice $facet))
9660 local pool=$(zpool_name $facet)
9661 local lfsname=$(zfs_local_fsname $facet)
9662 local label=${FSNAME}-${role}$(printf '%04x' $idx)
9665 "echo '$host - $label zfs:${dir}/${pool}/${lfsname} - -' >> \
9671 do_facet mgs "rm -f $LSNAPSHOT_CONF"
9672 echo "Generating $LSNAPSHOT_CONF on MGS ..."
9674 if ! combined_mgs_mds ; then
9675 [ $(facet_fstype mgs) != zfs ] &&
9676 skip "Lustre snapshot 1 only works for ZFS backend"
9678 local host=$(facet_active_host mgs)
9679 local dir=$(dirname $(facet_vdevice mgs))
9680 local pool=$(zpool_name mgs)
9681 local lfsname=$(zfs_local_fsname mgs)
9684 "echo '$host - MGS zfs:${dir}/${pool}/${lfsname} - -' \
9685 >> $LSNAPSHOT_CONF" || lss_err "generate lss conf (mgs)"
9688 for num in `seq $MDSCOUNT`; do
9689 [ $(facet_fstype mds$num) != zfs ] &&
9690 skip "Lustre snapshot 1 only works for ZFS backend"
9692 lss_gen_conf_one mds$num MDT $((num - 1)) ||
9693 lss_err "generate lss conf (mds$num)"
9696 for num in `seq $OSTCOUNT`; do
9697 [ $(facet_fstype ost$num) != zfs ] &&
9698 skip "Lustre snapshot 1 only works for ZFS backend"
9700 lss_gen_conf_one ost$num OST $((num - 1)) ||
9701 lss_err "generate lss conf (ost$num)"
9704 do_facet mgs "cat $LSNAPSHOT_CONF"
9707 # Parse 'lfs getstripe -d <path_with_dir_name>' for non-composite dir
9708 parse_plain_dir_param()
9713 if [[ ${invalues[0]} =~ "stripe_count:" ]]; then
9714 param="-c ${invalues[1]}"
9716 if [[ ${invalues[2]} =~ "stripe_size:" ]]; then
9717 param="$param -S ${invalues[3]}"
9719 if [[ ${invalues[4]} =~ "pattern:" ]]; then
9720 if [[ ${invalues[5]} =~ "stripe_offset:" ]]; then
9721 param="$param -i ${invalues[6]}"
9723 param="$param -L ${invalues[5]} -i ${invalues[7]}"
9725 elif [[ ${invalues[4]} =~ "stripe_offset:" ]]; then
9726 param="$param -i ${invalues[5]}"
9734 local val=$(awk '{print $2}' <<< $line)
9736 if [[ $line =~ ^"lmm_stripe_count:" ]]; then
9738 elif [[ $line =~ ^"lmm_stripe_size:" ]]; then
9740 elif [[ $line =~ ^"lmm_stripe_offset:" && $SKIP_INDEX != yes ]]; then
9742 elif [[ $line =~ ^"lmm_pattern:" ]]; then
9747 parse_layout_param()
9754 if [[ ! -z $line ]]; then
9755 if [[ -z $mode ]]; then
9756 if [[ $line =~ ^"stripe_count:" ]]; then
9758 elif [[ $line =~ ^"lmm_stripe_count:" ]]; then
9760 elif [[ $line =~ ^"lcm_layout_gen:" ]]; then
9765 if [[ $mode = "plain_dir" ]]; then
9766 param=$(parse_plain_dir_param "$line")
9767 elif [[ $mode = "plain_file" ]]; then
9768 val=$(parse_plain_param "$line")
9769 [[ ! -z $val ]] && param="$param $val"
9770 elif [[ $mode = "pfl" ]]; then
9771 val=$(echo $line | awk '{print $2}')
9772 if [[ $line =~ ^"lcme_extent.e_end:" ]]; then
9773 if [[ $val = "EOF" ]]; then
9774 param="$param -E -1"
9776 param="$param -E $val"
9778 elif [[ $line =~ ^"stripe_count:" ]]; then
9780 val=$(parse_plain_dir_param "$line")
9784 val=$(parse_plain_param "$line")
9785 [[ ! -z $val ]] && param="$param $val"
9795 local param=$($LFS getstripe -d $1 | parse_layout_param)
9804 # Cancel locks before setting lfsck_verify_pfid so that errors are more
9806 cancel_lru_locks mdc
9807 cancel_lru_locks osc
9809 # make sure PFID is set correctly for files
9810 do_nodes $(comma_list $(osts_nodes)) \
9811 "$LCTL set_param -n obdfilter.${FSNAME}-OST*.lfsck_verify_pfid=1"
9814 cat $f &> /dev/nullA ||
9815 { rc=$?; echo "verify $f failed"; break; }
9818 do_nodes $(comma_list $(osts_nodes)) \
9819 "$LCTL set_param -n obdfilter.${FSNAME}-OST*.lfsck_verify_pfid=0"
9823 # check that clients "oscs" was evicted after "before"
9824 check_clients_evicted() {
9831 for osc in $oscs; do
9832 echo "Check state for $osc"
9833 local evicted=$(do_facet client $LCTL get_param osc.$osc.state |
9834 tail -n 5 | awk -F"[ ,]" \
9835 '/EVICTED/ { if (mx<$4) { mx=$4; } } END { print mx }')
9836 if (($? == 0)) && (($evicted > $before)); then
9837 echo "$osc is evicted at $evicted"
9840 echo "$osc was not evicted after $before:"
9841 do_facet client $LCTL get_param osc.$osc.state |
9846 [ $rc -eq 0 ] || error "client not evicted from OST"
9849 # check that clients OSCS current_state is FULL
9850 check_clients_full() {
9855 for osc in $oscs; do
9856 wait_update_facet client \
9857 "lctl get_param -n osc.$osc.state |
9858 grep 'current_state: FULL'" \
9859 "current_state: FULL" $timeout
9860 [ $? -eq 0 ] || error "$osc state is not FULL"
9865 __changelog_deregister() {
9867 local mdt="$(facet_svc $facet)"
9871 # skip cleanup if no user registered for this MDT
9872 [ -z "$cl_user" ] && echo "$mdt: no changelog user" && return 0
9873 # user is no longer registered, skip cleanup
9874 changelog_users "$facet" | grep -q "$cl_user" ||
9875 { echo "$mdt: changelog user '$cl_user' not found"; return 0; }
9877 # From this point, if any operation fails, it is an error
9878 __changelog_clear $facet $cl_user 0 ||
9879 error_noexit "$mdt: changelog_clear $cl_user 0 fail: $rc"
9880 do_facet $facet $LCTL --device $mdt changelog_deregister $cl_user ||
9881 error_noexit "$mdt: changelog_deregister '$cl_user' fail: $rc"
9884 declare -Ax CL_USERS
9885 changelog_register() {
9886 for M in $(seq $MDSCOUNT); do
9888 local mdt="$(facet_svc $facet)"
9891 cl_mask=$(do_facet $facet $LCTL get_param \
9892 mdd.${mdt}.changelog_mask -n)
9893 stack_trap "do_facet $facet $LCTL \
9894 set_param mdd.$mdt.changelog_mask=\'$cl_mask\' -n" EXIT
9895 do_facet $facet $LCTL set_param mdd.$mdt.changelog_mask=+hsm ||
9896 error "$mdt: changelog_mask=+hsm failed: $?"
9899 cl_user=$(do_facet $facet $LCTL --device $mdt \
9900 changelog_register -n $@) ||
9901 error "$mdt: register changelog user failed: $?"
9902 stack_trap "__changelog_deregister $facet $cl_user" EXIT
9904 stack_trap "CL_USERS[$facet]='${CL_USERS[$facet]}'" EXIT
9905 # Bash does not support nested arrays, but the format of a
9906 # cl_user is constrained enough to use whitespaces as separators
9907 CL_USERS[$facet]+="$cl_user "
9909 echo "Registered $MDSCOUNT changelog users: '${CL_USERS[@]% }'"
9912 changelog_deregister() {
9914 # bash assoc arrays do not guarantee to list keys in created order
9915 # so reorder to get same order than in changelog_register()
9916 local cl_facets=$(echo "${!CL_USERS[@]}" | tr " " "\n" | sort |
9919 for facet in $cl_facets; do
9920 for cl_user in ${CL_USERS[$facet]}; do
9921 __changelog_deregister $facet $cl_user || return $?
9923 unset CL_USERS[$facet]
9929 local service=$(facet_svc $facet)
9931 do_facet $facet $LCTL get_param -n mdd.$service.changelog_users
9934 changelog_user_rec() {
9937 local service=$(facet_svc $facet)
9939 changelog_users $facet | awk '$1 == "'$cl_user'" { print $2 }'
9942 changelog_chmask() {
9945 do_nodes $(comma_list $(mdts_nodes)) \
9946 $LCTL set_param mdd.*.changelog_mask="$mask"
9949 # usage: __changelog_clear FACET CL_USER [+]INDEX
9953 local mdt="$(facet_svc $facet)"
9959 # Remove the leading '+'
9961 rec+=$(changelog_user_rec $facet $cl_user)
9968 if [ $rec -eq 0 ]; then
9969 echo "$mdt: clear the changelog for $cl_user of all records"
9971 echo "$mdt: clear the changelog for $cl_user to record #$rec"
9973 $LFS changelog_clear $mdt $cl_user $rec
9976 # usage: changelog_clear [+]INDEX
9978 # If INDEX is prefixed with '+', increment every changelog user's record index
9979 # by INDEX. Otherwise, clear the changelog up to INDEX for every changelog
9983 # bash assoc arrays do not guarantee to list keys in created order
9984 # so reorder to get same order than in changelog_register()
9985 local cl_facets=$(echo "${!CL_USERS[@]}" | tr " " "\n" | sort |
9989 for facet in $cl_facets; do
9990 for cl_user in ${CL_USERS[$facet]}; do
9991 __changelog_clear $facet $cl_user $1 || rc=${rc:-$?}
10001 for M in $(seq $MDSCOUNT); do
10003 local mdt="$(facet_svc $facet)"
10007 output=$($LFS changelog $mdt)
10009 if [ $ret -ne 0 ]; then
10011 elif [ -n "$output" ]; then
10012 echo "$output" | sed -e 's/^/'$mdt'./'
10019 changelog_extract_field() {
10022 local identifier=$3
10024 changelog_dump | gawk "/$cltype.*$file$/ {
10025 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
10029 # Prints a changelog record produced by "lfs changelog" as an associative array
10032 # $> changelog2array 16 01CREAT 10:28:46.968438800 2018.03.09 0x0 \
10033 # t=[0x200000401:0x10:0x0] j=touch.501 ef=0xf u=501:501 \
10034 # nid=0@lo p=[0x200000007:0x1:0x0] blob
10035 # ([index]='16' [type]='CREAT' [time]='10:28:46.968438800'
10036 # [date]='2018.03.09' [flags]=0x0 ['target-fid']='[0x200000401:0x10:0x0]'
10037 # ['jobid']='touch.501' ['extra-flags']='0x0f' [uid]='0' ['gid']='0'
10038 # ['nid']='0@lo' ['parent-fid']='[0x200000007:0x1:0x0]')
10040 # Note that the changelog record is not quoted
10041 # Also note that the line breaks in the output were only added for readability
10043 # Typically, you want to eval the output of the command to fill an actual
10044 # associative array, like this:
10045 # $> eval declare -A changelog=$(changelog2array $entry)
10047 # It can then be accessed like any bash associative array:
10048 # $> echo "${changelog[index]}" "${changelog[type]}" "${changelog[flags]}"
10050 # $> echo "${changelog[uid]}":"${changelog[gid]}"
10058 # A changelog, as printed by "lfs changelog" typically looks like this:
10059 # <index> <type> <time> <date> <flags> <key1=value1> <key2=value2> ...
10061 # Parse the positional part of the changelog
10063 # changelog_dump() prefixes records with their mdt's name
10064 local index="${1##*.}"
10066 printf "[index]='%s' [type]='%s' [time]='%s' [date]='%s' [flags]='%s'" \
10067 "$index" "${2:2}" "$3" "$4" "$5"
10069 # Parse the key/value part of the changelog
10070 for arg in "${@:5}"; do
10071 # Check it matches a key=value syntax
10072 [[ "$arg" =~ ^[[:alpha:]]+= ]] || continue
10074 local key="${arg%%=*}"
10075 local value="${arg#*=}"
10079 # u is actually for uid AND gid: u=UID:GID
10080 printf " [uid]='%s'" "${value%:*}"
10082 value="${value#*:}"
10110 printf " ['%s']='%s'" "$key" "$value"
10117 # Format and print a changelog record
10119 # Interpreted sequences are:
10121 # %f the "flags" attribute of a changelog record
10122 __changelog_printf()
10127 for ((i = 0; i < ${#format}; i++)); do
10128 local char="${format:$i:1}"
10129 if [ "$char" != % ]; then
10130 printf '%c' "$char"
10135 char="${format:$i:1}"
10138 printf '%s' "${changelog[flags]}"
10148 # Filter changelog records
10152 local action='print'
10155 while [ $# -gt 0 ]; do
10166 filter[${1#-}]="$2"
10175 changelog_dump | { while read -r record; do
10176 eval local -A changelog=$(changelog2array $record)
10177 for key in "${!filter[@]}"; do
10180 [ "${changelog[$key]}" == "${filter[$key]}" ]
10187 case "${action:-print}" in
10189 printf '%s\n' "$record"
10192 __changelog_printf "$format"
10202 [ ! -d "$dir" ] && return
10204 [ -z "$layout" ] && {
10205 $LFS setstripe -d $dir || error "error deleting stripe '$dir'"
10209 setfattr -n trusted.lov -v $layout $dir ||
10210 error "error restoring layout '$layout' to '$dir'"
10213 # save the layout of a directory, the returned string will be used by
10214 # restore_layout() to restore the layout
10217 local str=$(getfattr -n trusted.lov --absolute-names -e hex $dir \
10218 2> /dev/null | awk -F'=' '/trusted.lov/{ print $2 }')
10222 # save layout of a directory and restore it at exit
10223 save_layout_restore_at_exit() {
10225 local layout=$(save_layout $dir)
10227 stack_trap "restore_layout $dir $layout" EXIT
10230 verify_yaml_layout() {
10234 local msg_prefix=$4
10236 echo "getstripe --yaml $src"
10237 $LFS getstripe --yaml $src > $temp || error "getstripe $src failed"
10238 echo "setstripe --yaml=$temp $dst"
10239 $LFS setstripe --yaml=$temp $dst|| error "setstripe $dst failed"
10242 local layout1=$(get_layout_param $src)
10243 local layout2=$(get_layout_param $dst)
10244 # compare their layout info
10245 [ "$layout1" == "$layout2" ] ||
10246 error "$msg_prefix $src/$dst layouts are not equal"
10249 is_project_quota_supported() {
10250 $ENABLE_PROJECT_QUOTAS || return 1
10252 [[ "$(facet_fstype $SINGLEMDS)" == "ldiskfs" &&
10253 $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.9.55) ]] &&
10254 do_facet mds1 lfs --list-commands |& grep -q project &&
10257 [[ "$(facet_fstype $SINGLEMDS)" == "zfs" &&
10258 $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.10.53) ]] &&
10259 do_facet mds1 $ZPOOL get all | grep -q project_quota && return 0
10264 # ZFS project quota enable/disable:
10265 # This feature will become active as soon as it is enabled and will never
10266 # return to being disabled. Each filesystem will be upgraded automatically
10267 # when remounted or when [a] new file is created under that filesystem. The
10268 # upgrade can also be triggered on filesystems via `zfs set version=current
10269 # <pool/fs>`. The upgrade process runs in the background and may take a
10270 # while to complete for the filesystems containing a large number of files.
10271 enable_project_quota() {
10272 is_project_quota_supported || return 0
10273 local zkeeper=${KEEP_ZPOOL}
10274 stack_trap "KEEP_ZPOOL=$zkeeper" EXIT
10276 stopall || error "failed to stopall (1)"
10278 local zfeat_en="feature@project_quota=enabled"
10279 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
10280 local facet_fstype=${facet:0:3}1_FSTYPE
10283 if [ "${!facet_fstype}" = "zfs" ]; then
10284 devname=$(zpool_name ${facet})
10285 do_facet ${facet} $ZPOOL set "$zfeat_en" $devname ||
10286 error "$ZPOOL set $zfeat_en $devname"
10288 [ ${facet:0:3} == "mds" ] &&
10289 devname=$(mdsdevname ${facet:3}) ||
10290 devname=$(ostdevname ${facet:3})
10291 do_facet ${facet} $TUNE2FS -O project $devname ||
10292 error "tune2fs $devname failed"
10296 KEEP_ZPOOL="${zkeeper}"
10301 disable_project_quota() {
10302 is_project_quota_supported || return 0
10303 [ "$mds1_FSTYPE" != "ldiskfs" ] && return 0
10304 stopall || error "failed to stopall (1)"
10306 for num in $(seq $MDSCOUNT); do
10307 do_facet mds$num $TUNE2FS -Q ^prj $(mdsdevname $num) ||
10308 error "tune2fs $(mdsdevname $num) failed"
10311 for num in $(seq $OSTCOUNT); do
10312 do_facet ost$num $TUNE2FS -Q ^prj $(ostdevname $num) ||
10313 error "tune2fs $(ostdevname $num) failed"
10321 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
10322 # the following associated variables are added:
10324 # AGTCOUNT: number of agents
10325 # AGTDEV{N}: target HSM mount point (root path of the backend)
10326 # agt{N}_HOST: hostname of the agent agt{N}
10327 # SINGLEAGT: facet of the single agent
10329 # The number of agents is initialized as the number of remote client nodes.
10330 # By default, only single copytool is started on a remote client/agent. If there
10331 # was no remote client, then the copytool will be started on the local client.
10337 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
10338 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
10340 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
10341 if [[ $CLIENTCOUNT -gt 1 ]] &&
10342 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
10343 skip_env "SHARED_DIRECTORY should be accessible"\
10344 "on all client nodes"
10348 # We used to put the HSM archive in $SHARED_DIRECTORY but that
10349 # meant NFS issues could hose sanity-hsm sessions. So now we
10350 # use $TMP instead.
10351 for n in $(seq $AGTCOUNT); do
10352 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
10353 agent=CLIENT$((n + 1))
10354 if [[ -z "${!agent}" ]]; then
10355 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
10358 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
10359 local var=agt${n}_HOST
10360 [[ ! -z "${!var}" ]] || error "agt${n}_HOST is empty!"
10363 export SINGLEAGT=${SINGLEAGT:-agt1}
10365 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
10366 export HSMTOOL_PID_FILE=${HSMTOOL_PID_FILE:-"/var/run/lhsmtool_posix.pid"}
10367 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
10368 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
10369 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
10370 export HSMTOOL_TESTDIR
10371 export HSMTOOL_ARCHIVE_FORMAT=${HSMTOOL_ARCHIVE_FORMAT:-v2}
10373 if ! [[ $HSMTOOL =~ hsmtool ]]; then
10374 echo "HSMTOOL = '$HSMTOOL' does not contain 'hsmtool', GLWT" >&2
10377 HSM_ARCHIVE_NUMBER=2
10379 # The test only support up to 10 MDTs
10380 MDT_PREFIX="mdt.$FSNAME-MDT000"
10381 HSM_PARAM="${MDT_PREFIX}0.hsm"
10383 # archive is purged at copytool setup
10384 HSM_ARCHIVE_PURGE=true
10386 # Don't allow copytool error upon start/setup
10387 HSMTOOL_NOERROR=false
10390 # Get the backend root path for the given agent facet.
10391 copytool_device() {
10393 local dev=AGTDEV$(facet_number $facet)
10398 get_mdt_devices() {
10400 # get MDT device for each mdc
10401 for mdtno in $(seq 1 $MDSCOUNT); do
10402 local idx=$(($mdtno - 1))
10403 MDT[$idx]=$($LCTL get_param -n \
10404 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
10405 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
10409 pkill_copytools() {
10413 do_nodes "$hosts" "pkill --pidfile=$HSMTOOL_PID_FILE --signal=$signal hsmtool"
10416 copytool_continue() {
10417 local agents=${1:-$(facet_active_host $SINGLEAGT)}
10419 pkill_copytools "$agents" CONT || return 0
10420 echo "Copytool is continued on $agents"
10424 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
10426 echo "Killing existing copytools on $hosts"
10427 pkill_copytools "$hosts" TERM || return 0
10428 copytool_continue "$hosts"
10431 copytool_monitor_cleanup() {
10432 local facet=${1:-$SINGLEAGT}
10433 local agent=$(facet_active_host $facet)
10435 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
10436 # Should die when the copytool dies, but just in case.
10437 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
10438 cmd+=" 2>/dev/null || true"
10439 do_node $agent "$cmd"
10440 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
10441 export HSMTOOL_MONITOR_DIR=
10444 # The pdsh should die on its own when the monitor dies. Just
10445 # in case, though, try to clean up to avoid any cruft.
10446 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
10447 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null || true
10448 export HSMTOOL_MONITOR_PDSH=
10454 local host="$(facet_host "$1")"
10455 local prefix=$TESTLOG_PREFIX
10456 [ -n "$TESTNAME" ] && prefix+=.$TESTNAME
10458 printf "${prefix}.copytool${archive_id}_log.${host}.log"
10461 __lhsmtool_rebind()
10463 do_facet $facet $HSMTOOL "${hsmtool_options[@]}" --rebind "$@" "$mountpoint"
10466 __lhsmtool_import()
10468 mkdir -p "$(dirname "$2")" ||
10469 error "cannot create directory '$(dirname "$2")'"
10470 do_facet $facet $HSMTOOL "${hsmtool_options[@]}" --import "$@" "$mountpoint"
10475 local host="$(facet_host "$facet")"
10476 local cmd="$HSMTOOL ${hsmtool_options[@]} --daemon --pid-file=$HSMTOOL_PID_FILE"
10477 [ -n "$bandwidth" ] && cmd+=" --bandwidth $bandwidth"
10478 [ -n "$archive_id" ] && cmd+=" --archive $archive_id"
10479 # [ ${#misc_options[@]} -gt 0 ] &&
10480 # cmd+=" $(IFS=" " echo "$@")"
10481 cmd+=" $@ \"$mountpoint\""
10483 echo "Starting copytool '$facet' on '$host' with cmdline '$cmd'"
10484 stack_trap "pkill_copytools $host TERM || true" EXIT
10485 do_node "$host" "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
10489 local facet="${1:-$SINGLEAGT}"
10491 printf "$(copytool_device "$facet")/${TESTSUITE}.${TESTNAME}/"
10494 # Main entry point to perform copytool related operations
10498 # setup setup a copytool to run in the background, that copytool will be
10500 # import import a file from an HSM backend
10501 # rebind rebind an archived file to a new fid
10503 # Although the semantics might suggest otherwise, one does not need to 'setup'
10504 # a copytool before a call to 'copytool import' or 'copytool rebind'.
10511 # Use default values
10512 local facet=$SINGLEAGT
10513 local mountpoint="${MOUNT2:-$MOUNT}"
10516 local fail_on_error=true
10517 local -a hsmtool_options=()
10518 local -a action_options=()
10520 if [[ -n "$HSMTOOL_ARCHIVE_FORMAT" ]]; then
10521 hsmtool_options+=("--archive-format=$HSMTOOL_ARCHIVE_FORMAT")
10524 if [[ -n "$HSMTOOL_VERBOSE" ]]; then
10525 hsmtool_options+=("$HSMTOOL_VERBOSE")
10528 while [ $# -gt 0 ]; do
10540 local archive_id="$1"
10544 local hsm_root="$1"
10548 local bandwidth="$1" # in MB/s
10551 local fail_on_error=false
10554 # Uncommon(/copytool dependent) option
10555 action_options+=("$1")
10561 local hsm_root="${hsm_root:-$(hsm_root "$facet")}"
10562 hsmtool_options+=("--hsm-root=$hsm_root")
10564 stack_trap "do_facet $facet rm -rf '$hsm_root'" EXIT
10565 do_facet $facet mkdir -p "$hsm_root" ||
10566 error "mkdir '$hsm_root' failed"
10570 local copytool=lhsmtool
10574 __${copytool}_${action} "${action_options[@]}"
10575 if [ $? -ne 0 ]; then
10580 local host="$(facet_host $facet)"
10581 error_msg="Failed to start copytool $facet on '$host'"
10584 local src="${action_options[0]}"
10585 local dest="${action_options[1]}"
10586 error_msg="Failed to import '$src' to '$dest'"
10589 error_msg="could not rebind file"
10593 $fail_on_error && error "$error_msg" || echo "$error_msg"
10598 local client_count=$1
10599 if [[ $CLIENTCOUNT -lt $client_count ]]; then
10600 skip "Need $client_count or more clients, have $CLIENTCOUNT"
10607 $LFS path2fid $1 | tr -d '[]'
10608 return ${PIPESTATUS[0]}
10616 if [[ $u == "user" ]]; then
10617 st=$($RUNAS $LFS hsm_state $f)
10620 st=$($LFS hsm_state $f)
10623 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
10625 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
10629 check_hsm_flags() {
10633 local st=$(get_hsm_flags $f)
10634 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
10643 if [[ "$value" != "" ]]; then
10646 for mdtno in $(seq 1 $MDSCOUNT); do
10647 local idx=$(($mdtno - 1))
10648 local facet=mds${mdtno}
10649 # if $arg include -P option, run 1 set_param per MDT on the MGS
10650 # else, run set_param on each MDT
10651 [[ $arg = *"-P"* ]] && facet=mgs
10652 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
10653 [[ $? != 0 ]] && rc=1
10658 mdts_check_param() {
10664 for mdtno in $(seq 1 $MDSCOUNT); do
10665 local idx=$(($mdtno - 1))
10666 wait_update_facet --verbose mds${mdtno} \
10667 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
10669 error "$key state is not '$target' on mds${mdtno}"
10673 cdt_set_mount_state() {
10674 mdts_set_param "-P" hsm_control "$1"
10675 # set_param -P is asynchronous operation and could race with set_param.
10676 # In such case configs could be retrieved and applied at mgc after
10677 # set_param -P completion. Sleep here to avoid race with set_param.
10678 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
10679 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
10680 # and 10 seconds to retrieve config from server.
10684 cdt_check_state() {
10685 mdts_check_param hsm_control "$1" 20
10688 cdt_set_sanity_policy() {
10689 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
10692 mdts_set_param "" hsm.policy "+NRA"
10693 mdts_set_param "" hsm.policy "-NBR"
10694 CDT_POLICY_HAD_CHANGED=
10702 mdts_set_param "$opt -n" "hsm.$param" "$value"
10706 wait_request_state() {
10710 # 4th arg (mdt index) is optional
10711 local mdtidx=${4:-0}
10712 local mds=mds$(($mdtidx + 1))
10714 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
10715 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
10717 wait_update_facet --verbose $mds "$cmd" "$state" 200 ||
10718 error "request on $fid is not $state on $mds"
10726 local WAIT_MAX=${4:-60}
10729 # We need to run do_node in bg, because pdsh does not exit
10730 # if child process of run script exists.
10731 # I.e. pdsh does not exit when runmultiop_bg_pause exited,
10732 # because of multiop_bg_pause -> $MULTIOP_PROG &
10733 # By the same reason we need sleep a bit after do_nodes starts
10734 # to let runmultiop_bg_pause start muliop and
10735 # update /tmp/multiop_bg.pid ;
10736 # The rm /tmp/multiop_bg.pid guarantees here that
10737 # we have the updated by runmultiop_bg_pause
10738 # /tmp/multiop_bg.pid file
10740 local pid_file=$TMP/multiop_bg.pid.$$
10742 do_node $client "MULTIOP_PID_FILE=$pid_file LUSTRE= \
10743 runmultiop_bg_pause $file $cmds" &
10747 while [[ $wait_time -lt $WAIT_MAX ]]; do
10749 wait_time=$((wait_time + 3))
10750 multiop_pid=$(do_node $client cat $pid_file)
10751 if [ -n "$multiop_pid" ]; then
10756 [ -n "$multiop_pid" ] ||
10757 error "$client : Can not get multiop_pid from $pid_file "
10759 eval export $(node_var_name $client)_multiop_pid=$multiop_pid
10760 eval export $(node_var_name $client)_do_node_pid=$pid
10761 local var=$(node_var_name $client)_multiop_pid
10762 echo client $client multiop_bg started multiop_pid=${!var}
10768 local multiop_pid=$(node_var_name $client)_multiop_pid
10769 local do_node_pid=$(node_var_name $client)_do_node_pid
10771 echo "Stopping multiop_pid=${!multiop_pid} (kill ${!multiop_pid} on $client)"
10772 do_node $client kill -USR1 ${!multiop_pid}
10774 wait ${!do_node_pid}
10778 local delay=$(do_facet $SINGLEMDS lctl get_param -n lo[vd].*.qos_maxage |
10779 awk '{ print $1 * 2; exit; }')
10783 check_component_count() {
10784 local comp_cnt=$($LFS getstripe --component-count $1)
10785 [ $comp_cnt -eq $2 ] || error "$1, component count $comp_cnt != $2"
10788 # Verify there are no init components with "extension" flag
10789 verify_no_init_extension() {
10790 local flg_opts="--component-flags init,extension"
10791 local found=$($LFS find $flg_opts $1 | wc -l)
10792 [ $found -eq 0 ] || error "$1 has component with initialized extension"
10795 # Verify there is at least one component starting at 0
10796 verify_comp_at_zero() {
10797 flg_opts="--component-flags init"
10798 found=$($LFS find --component-start 0M $flg_opts $1 | wc -l)
10799 [ $found -eq 1 ] ||
10800 error "No component starting at zero(!)"
10803 # version after which Self-Extending Layouts are available
10806 sel_layout_sanity() {
10810 verify_no_init_extension $file
10811 verify_comp_at_zero $file
10812 check_component_count $file $comp_cnt
10815 statx_supported() {
10816 $STATX --quiet --version
10820 # lfs rm_entry is disabled on native client
10821 is_rmentry_supported() {
10822 $LFS rm_entry $DIR/dir/not/exists > /dev/null
10823 # is return code ENOENT?
10828 # wrappers for createmany and unlinkmany
10829 # to set debug=0 if number of creates is high enough
10830 # this is to speedup testing
10832 function createmany() {
10836 if (( count > 100 )); then
10838 do_nodes $(comma_list $(all_nodes)) $LCTL set_param -n debug=0
10840 $LUSTRE/tests/createmany $*
10842 if (( count > 100 )); then
10849 function unlinkmany() {
10853 if (( count > 100 )); then
10855 do_nodes $(comma_list $(all_nodes)) $LCTL set_param -n debug=0
10857 $LUSTRE/tests/unlinkmany $*
10864 # Check if fallocate supported on OSTs, enable if unset, default mode=0
10865 # Optionally pass the OST fallocate mode (0=unwritten extents, 1=zero extents)
10866 function check_set_fallocate()
10868 local new_mode="$1"
10869 local osts=$(comma_list $(osts_nodes))
10870 local fa_mode="osd-ldiskfs.*.fallocate_zero_blocks"
10871 local old_mode=$(do_facet ost1 $LCTL get_param -n $fa_mode 2>/dev/null|
10874 [[ -n "$old_mode" ]] || { echo "fallocate not supported"; return 1; }
10875 [[ -z "$new_mode" && "$old_mode" != "-1" ]] &&
10876 { echo "keep default fallocate mode: $old_mode"; return 0; }
10877 [[ "$new_mode" && "$old_mode" == "$new_mode" ]] &&
10878 { echo "keep current fallocate mode: $old_mode"; return 0; }
10880 stack_trap "do_nodes $osts $LCTL set_param $fa_mode=$old_mode"
10881 do_nodes $osts $LCTL set_param $fa_mode=${new_mode:-0} ||
10882 error "set $fa_mode=$new_mode"
10885 # Check if fallocate supported on OSTs, enable if unset, skip if unavailable
10886 function check_set_fallocate_or_skip()
10888 [ "$ost1_FSTYPE" != ldiskfs ] && skip "non-ldiskfs backend"
10889 check_set_fallocate || skip "need at least 2.13.57 for fallocate"
10892 function disable_opencache()
10894 local state=$($LCTL get_param -n "llite.*.opencache_threshold_count" | head -1)
10896 test -z "${saved_OPENCACHE_value}" &&
10897 export saved_OPENCACHE_value="$state"
10899 [[ "$state" = "off" ]] && return
10901 $LCTL set_param -n "llite.*.opencache_threshold_count"=off
10904 function set_opencache()
10906 local newvalue="$1"
10907 local state=$($LCTL get_param -n "llite.*.opencache_threshold_count")
10909 [[ -n "$newvalue" ]] || return
10911 [[ -n "${saved_OPENCACHE_value}" ]] ||
10912 export saved_OPENCACHE_value="$state"
10914 $LCTL set_param -n "llite.*.opencache_threshold_count"=$newvalue
10919 function restore_opencache()
10921 [[ -z "${saved_OPENCACHE_value}" ]] ||
10922 $LCTL set_param -n "llite.*.opencache_threshold_count"=${saved_OPENCACHE_value}
10925 # LU-13417: XXX lots of tests assume the directory to be created under MDT0,
10926 # created on MDT0, use this function to create directory on specific MDT
10927 # explicitly, and set default LMV to create subdirs on the same MDT too.
10932 while getopts "i:" opt $*; do
10938 shift $((OPTIND - 1))
10940 $LFS mkdir -i $mdt -c 1 $*
10944 mkdir_on_mdt -i0 $*
10947 # Wait for nodemap synchronization
10949 local nodemap_name=$1
10954 local is_active=$(do_facet mgs $LCTL get_param -n nodemap.active)
10955 local max_retries=20
10959 local mgs_ip=$(host_nids_address $mgs_HOST $NETTYPE | cut -d' ' -f1)
10962 if [ "$nodemap_name" == "active" ]; then
10963 proc_param="active"
10964 elif [ -z "$key" ]; then
10965 proc_param=${nodemap_name}
10967 proc_param="${nodemap_name}.${key}"
10969 if [ "$opt" == "inactive" ]; then
10970 # check nm sync even if nodemap is not activated
10974 (( is_active == 0 )) && [ "$proc_param" != "active" ] && return
10976 if [ -z "$value" ]; then
10977 out1=$(do_facet mgs $LCTL get_param $opt \
10978 nodemap.${proc_param} 2>/dev/null)
10979 echo "On MGS ${mgs_ip}, ${proc_param} = $out1"
10984 # if servers run on the same node, it is impossible to tell if they get
10985 # synced with the mgs, so just wait an arbitrary 10 seconds
10986 if [ $(facet_active_host mgs) == $(facet_active_host mds) ] &&
10987 [ $(facet_active_host mgs) == $(facet_active_host ost1) ]; then
10988 echo "waiting 10 secs for sync"
10993 # wait up to 10 seconds for other servers to sync with mgs
10994 for i in $(seq 1 10); do
10995 for node in $(all_server_nodes); do
10996 local node_ip=$(host_nids_address $node $NETTYPE |
11000 if [ -z "$value" ]; then
11001 [ $node_ip == $mgs_ip ] && continue
11004 out2=$(do_node $node_ip $LCTL get_param $opt \
11005 nodemap.$proc_param 2>/dev/null)
11006 echo "On $node ${node_ip}, ${proc_param} = $out2"
11007 [ "$out1" != "$out2" ] && is_sync=false && break
11012 if ! $is_sync; then
11015 echo OTHER - IP: $node_ip
11017 error "mgs and $nodemap_name ${key} mismatch, $i attempts"
11019 echo "waited $((i - 1)) seconds for sync"
11022 consume_precreations() {
11026 local extra=${4:-2}
11027 local OST=$(ostname_from_index $OSTIDX $dir)
11029 test_mkdir -p $dir/${OST}
11030 $LFS setstripe -i $OSTIDX -c 1 ${dir}/${OST}
11033 local mdtosc_proc=$(get_mdtosc_proc_path $mfacet $OST)
11034 local last_id=$(do_facet $mfacet $LCTL get_param -n \
11035 osp.$mdtosc_proc.prealloc_last_id)
11036 local next_id=$(do_facet $mfacet $LCTL get_param -n \
11037 osp.$mdtosc_proc.prealloc_next_id)
11038 echo "Creating to objid $last_id on ost $OST..."
11039 createmany -o $dir/${OST}/f $next_id $((last_id - next_id + extra))
11042 __exhaust_precreations() {
11045 local FAILIDX=${3:-$OSTIDX}
11046 local ofacet=ost$((OSTIDX + 1))
11048 mkdir_on_mdt0 $DIR/$tdir
11049 local mdtidx=$($LFS getstripe -m $DIR/$tdir)
11050 local mfacet=mds$((mdtidx + 1))
11051 echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
11053 local mdtosc_proc=$(get_mdtosc_proc_path $mfacet)
11054 do_facet $mfacet $LCTL get_param osp.$mdtosc_proc.prealloc*
11056 #define OBD_FAIL_OST_ENOSPC 0x215
11057 do_facet $ofacet $LCTL set_param fail_val=$FAILIDX fail_loc=0x215
11059 consume_precreations $DIR/$tdir $mfacet $OSTIDX
11061 do_facet $mfacet $LCTL get_param osp.$mdtosc_proc.prealloc*
11062 do_facet $ofacet $LCTL set_param fail_loc=$FAILLOC
11065 exhaust_precreations() {
11066 __exhaust_precreations $1 $2 $3
11070 exhaust_all_precreations() {
11072 for (( i=0; i < OSTCOUNT; i++ )) ; do
11073 __exhaust_precreations $i $1 -1
11078 verify_yaml_available() {
11079 python3 -c "import yaml; yaml.safe_load('''a: b''')"
11083 python3 -c "import sys, yaml; obj = yaml.safe_load(sys.stdin)"