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
295 export RSYNC_RSH=${RSYNC_RSH:-rsh}
297 export LNETCTL=${LNETCTL:-"$LUSTRE/../lnet/utils/lnetctl"}
298 [ ! -f "$LNETCTL" ] && export LNETCTL=$(which lnetctl 2> /dev/null)
299 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
300 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
301 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
302 [ ! -f "$LFS" ] && export LFS=$(which lfs)
303 export KSOCKLND_CONFIG=${KSOCKLND_CONFIG:-"$LUSTRE/scripts/ksocklnd-config"}
304 [ ! -f "$KSOCKLND_CONFIG" ] &&
305 export KSOCKLND_CONFIG=$(which ksocklnd-config 2> /dev/null)
307 export PERM_CMD=$(echo ${PERM_CMD:-"$LCTL conf_param"})
309 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
310 if [ ! -f "$L_GETIDENTITY" ]; then
311 if `which l_getidentity > /dev/null 2>&1`; then
312 export L_GETIDENTITY=$(which l_getidentity)
314 export L_GETIDENTITY=NONE
317 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
318 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
319 export LL_DECODE_LINKEA=${LL_DECODE_LINKEA:-"$LUSTRE/utils/ll_decode_linkea"}
320 [ ! -f "$LL_DECODE_LINKEA" ] && export LL_DECODE_LINKEA="ll_decode_linkea"
321 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
322 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
323 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
324 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
325 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
326 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
327 [ ! -f "$LUSTRE_RMMOD" ] &&
328 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
329 export LUSTRE_ROUTES_CONVERSION=${LUSTRE_ROUTES_CONVERSION:-$LUSTRE/scripts/lustre_routes_conversion}
330 [ ! -f "$LUSTRE_ROUTES_CONVERSION" ] &&
331 export LUSTRE_ROUTES_CONVERSION=$(which lustre_routes_conversion 2> /dev/null)
332 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
333 [ ! -f "$LFS_MIGRATE" ] &&
334 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
335 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
336 [ ! -f "$LR_READER" ] &&
337 export LR_READER=$(which lr_reader 2> /dev/null)
338 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
339 export LSOM_SYNC=${LSOM_SYNC:-"$LUSTRE/utils/llsom_sync"}
340 [ ! -f "$LSOM_SYNC" ] &&
341 export LSOM_SYNC=$(which llsom_sync 2> /dev/null)
342 [ -z "$LSOM_SYNC" ] && export LSOM_SYNC="/usr/sbin/llsom_sync"
343 export NAME=${NAME:-local}
344 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
345 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] &&
346 export LGSSD=$(which lgssd)
347 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
348 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
349 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
351 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
353 export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
354 [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
356 export DMSETUP=${DMSETUP:-dmsetup}
357 export DM_DEV_PATH=${DM_DEV_PATH:-/dev/mapper}
358 export LOSETUP=${LOSETUP:-losetup}
360 if [ "$ACCEPTOR_PORT" ]; then
361 export PORT_OPT="--port $ACCEPTOR_PORT"
365 $RPC_MODE || echo "Using GSS shared-key feature"
366 which lgss_sk > /dev/null 2>&1 ||
367 error_exit "built with lgss_sk disabled! SEC=$SEC"
375 $RPC_MODE || echo "Using GSS/krb5 ptlrpc security flavor"
376 which lgss_keyring > /dev/null 2>&1 ||
377 error_exit "built with gss disabled! SEC=$SEC"
388 IDENTITY_UPCALL=false
392 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
394 # Paths on remote nodes, if different
395 export RLUSTRE=${RLUSTRE:-$LUSTRE}
396 export RPWD=${RPWD:-$PWD}
397 export I_MOUNTED=${I_MOUNTED:-"no"}
398 export AUSTER_CLEANUP=${AUSTER_CLEANUP:-false}
399 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
400 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
401 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
402 ! -f $LUSTRE/mdt/mdt.ko ]; then
403 export CLIENTMODSONLY=yes
406 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
407 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
411 while getopts "rvwf:" opt $*; do
416 w) WRITECONF=writeconf;;
421 shift $((OPTIND - 1))
424 # print the durations of each test if "true"
425 DDETAILS=${DDETAILS:-false}
426 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
431 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
433 # Constants used in more than one test script
434 export LOV_MAX_STRIPE_COUNT=2000
435 export DELETE_OLD_POOLS=${DELETE_OLD_POOLS:-false}
436 export KEEP_POOLS=${KEEP_POOLS:-false}
437 export PARALLEL=${PARALLEL:-"no"}
439 export BLCKSIZE=${BLCKSIZE:-4096}
440 export MACHINEFILE=${MACHINEFILE:-$TMP/$(basename $0 .sh).machines}
441 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
444 # use localrecov to enable recovery for local clients, LU-12722
445 [[ $MDS1_VERSION -lt $(version_code 2.13.52) ]] || {
446 export MDS_MOUNT_OPTS=${MDS_MOUNT_OPTS:-"-o localrecov"}
447 export MGS_MOUNT_OPTS=${MGS_MOUNT_OPTS:-"-o localrecov"}
450 [[ $OST1_VERSION -lt $(version_code 2.13.52) ]] ||
451 export OST_MOUNT_OPTS=${OST_MOUNT_OPTS:-"-o localrecov"}
458 ncpts=$(do_facet $facet "lctl get_param -n " \
459 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
461 if [ $ncpts -eq 0 ]; then
468 # Return a numeric version code based on a version string. The version
469 # code is useful for comparison two version strings to see which is newer.
471 # split arguments like "1.8.6-wc3" into "1", "8", "6", "3"
472 eval set -- $(tr "[:punct:][a-zA-Z]" " " <<< $*)
474 echo -n $(((${1:-0}<<24) | (${2:-0}<<16) | (${3:-0}<<8) | (${4:-0})))
477 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
478 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
480 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
482 # usage: lustre_build_version
484 # All Lustre versions support "lctl get_param" to report the version of the
485 # code running in the kernel (what our tests are interested in), but it
486 # doesn't work without modules loaded. After 2.9.53 and in upstream kernels
487 # the "version" parameter doesn't include "lustre: " at the beginning.
488 # If that fails, call "lctl lustre_build_version" which prints either (or both)
489 # the userspace and kernel build versions, but until 2.8.55 required root
490 # access to get the Lustre kernel version. If that also fails, fall back to
491 # using "lctl --version", which is easy to parse and works without the kernel
492 # modules, but was only added in 2.6.50 and only prints the lctl tool version,
493 # not the module version, though they are usually the same.
495 # Various commands and their output format for different Lustre versions:
496 # lctl get_param version: 2.9.55
497 # lctl get_param version: lustre: 2.8.53
498 # lctl get_param version: lustre: 2.6.52
499 # kernel: patchless_client
500 # build: v2_6_92_0-2.6.32-431.el6_lustre.x86_64
501 # lctl lustre_build_version: Lustre version: 2.8.53_27_gae67fc01
502 # lctl lustre_build_version: error: lustre_build_version: Permission denied
503 # (as non-root user) lctl version: v2_6_92_0-2.6.32-431.el6.x86_64
504 # lctl lustre_build_version: Lustre version: 2.5.3-2.6.32.26-175.fc12.x86_64
505 # lctl version: 2.5.3-2.6.32..26-175fc12.x86_64
506 # lctl --version: lctl 2.6.50
508 # output: prints version string to stdout in (up to 4) dotted-decimal values
509 lustre_build_version() {
510 local facet=${1:-client}
511 local facet_version=${facet}_VERSION
513 # if the global variable is already set, then use that
514 [ -n "${!facet_version}" ] && echo ${!facet_version} && return
516 # this is the currently-running version of the kernel modules
517 local ver=$(do_facet $facet "$LCTL get_param -n version 2>/dev/null")
518 # we mostly test 2.10+ systems, only try others if the above fails
519 if [ -z "$ver" ]; then
520 ver=$(do_facet $facet "$LCTL lustre_build_version 2>/dev/null")
522 if [ -z "$ver" ]; then
523 ver=$(do_facet $facet "$LCTL --version 2>/dev/null" |
526 local lver=$(egrep -i "lustre: |version: " <<<"$ver" | head -n 1)
527 [ -n "$lver" ] && ver="$lver"
529 lver=$(sed -e 's/[^:]*: //' -e 's/^v//' -e 's/[ -].*//' <<<$ver |
530 tr _ . | cut -d. -f1-4)
532 # save in global variable for the future
533 export $facet_version=$lver
538 # Report the Lustre numeric build version code for the supplied facet.
539 lustre_version_code() {
540 version_code $(lustre_build_version $1)
544 /sbin/lsmod | grep -q "^\<$1\>"
547 check_lfs_df_ret_val() {
548 # Ignore only EOPNOTSUPP (which is 95; Operation not supported) error
549 # returned by 'lfs df' for valid dentry but not a lustrefs.
551 # 'lfs df' historically always returned success(0) instead of
552 # EOPNOTSUPP. This function for compatibility reason, ignores and
553 # masquerades EOPNOTSUPP as success.
554 [[ $1 -eq 95 ]] && return 0
567 msg="$(insmod $module $args 2>&1)" && return 0 || rc=$?
570 # parallels can't load modules directly from prlfs, use /tmp instead
571 if $PRLFS || [[ "$(stat -f -c%t $module)" == "7c7c6673" ]]; then
572 local target="$(mktemp)"
574 cp "$module" "$target"
577 [[ $rc == 0 ]] && PRLFS=true
585 # Load a module on the system where this is running.
587 # usage: load_module module_name [module arguments for insmod/modprobe]
589 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
590 # will be used as the arguments. Otherwise arguments will be obtained from
591 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
594 local module=$1 # '../libcfs/libcfs/libcfs', 'obdclass/obdclass', ...
597 local base=$(basename $module $ext)
599 local -A module_is_loaded_aa
603 for mod in $(lsmod | awk '{ print $1; }'); do
604 module_is_loaded_aa[${mod//-/_}]=true
608 ${module_is_loaded_aa[${1//-/_}]:-false}
611 if module_is_loaded $base; then
615 if [[ -f $LUSTRE/$module$ext ]]; then
616 path=$LUSTRE/$module$ext
617 elif [[ "$base" == lnet_selftest ]] &&
618 [[ -f $LUSTRE/../lnet/selftest/$base$ext ]]; then
619 path=$LUSTRE/../lnet/selftest/$base$ext
624 if [[ -n "$path" ]]; then
625 # Try to load any non-Lustre modules that $module depends on.
626 for mod in $(modinfo --field=depends $path | tr ',' ' '); do
627 if ! module_is_loaded $mod; then
633 # If no module arguments were passed then get them from
634 # $MODOPTS_<MODULE>, otherwise from modprobe.conf.
635 if [ $# -eq 0 ]; then
636 # $MODOPTS_<MODULE>; we could use associative arrays, but that's
637 # not in Bash until 4.x, so we resort to eval.
638 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
639 eval set -- \$$optvar
640 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
641 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
643 opt=$(awk -v var="^options $base" '$0 ~ var \
644 {gsub("'"options $base"'",""); print}' \
646 set -- $(echo -n $opt)
648 # Ensure we have accept=all for lnet
649 if [[ "$base" == lnet ]]; then
650 # OK, this is a bit wordy...
651 local arg accept_all_present=false
654 [[ "$arg" == accept=all ]] &&
655 accept_all_present=true
658 $accept_all_present || set -- "$@" accept=all
665 [ $# -gt 0 ] && echo "${module} options: '$*'"
667 # Note that insmod will ignore anything in modprobe.conf, which is why
668 # we're passing options on the command-line. If $path does not exist
669 # then we must be testing a "make install" or"rpm" installation. Also
670 # note that failing to load ptlrpc_gss is not considered fatal.
671 if [[ -n "$path" ]]; then
672 lustre_insmod $path "$@"
673 elif [[ "$base" == ptlrpc_gss ]]; then
674 if ! modprobe $base "$@" 2>/dev/null; then
675 echo "gss/krb5 is not supported"
683 $LCTL mark "$LNETCTL $*"
689 # For kmemleak-enabled kernels we need clear all past state
690 # that obviously has nothing to do with this Lustre run
691 # Disable automatic memory scanning to avoid perf hit.
692 if [ -f /sys/kernel/debug/kmemleak ] ; then
693 echo scan=off > /sys/kernel/debug/kmemleak || true
694 echo scan > /sys/kernel/debug/kmemleak || true
695 echo clear > /sys/kernel/debug/kmemleak || true
698 echo Loading modules from $LUSTRE
702 if [ -f /sys/devices/system/cpu/online ]; then
703 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
704 echo "detected $ncpus online CPUs by sysfs"
706 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
708 if [ $rc -eq 0 ]; then
709 echo "detected $ncpus online CPUs by getconf"
711 echo "Can't detect number of CPUs"
716 # if there is only one CPU core, libcfs can only create one partition
717 # if there is more than 4 CPU cores, libcfs should create multiple CPU
718 # partitions. So we just force libcfs to create 2 partitions for
719 # system with 2 or 4 cores
720 local saved_opts="$MODOPTS_LIBCFS"
721 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
722 # force to enable multiple CPU partitions
723 echo "Force libcfs to create 2 CPU partitions"
724 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
726 echo "libcfs will create CPU partition based on online CPUs"
729 load_module ../libcfs/libcfs/libcfs
730 # Prevent local MODOPTS_LIBCFS being passed as part of environment
731 # variable to remote nodes
734 set_default_debug "neterror net nettrace malloc"
735 if [ "$1" = "config_on_load=1" ]; then
736 load_module ../lnet/lnet/lnet
738 load_module ../lnet/lnet/lnet "$@"
741 LNDPATH=${LNDPATH:-"../lnet/klnds"}
742 if [ -z "$LNETLND" ]; then
744 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
745 tcp*) LNETLND="socklnd/ksocklnd" ;;
746 *) local lnd="${NETTYPE%%[0-9]}lnd"
747 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
748 LNETLND="$lnd/k$lnd" ||
749 LNETLND="socklnd/ksocklnd"
752 load_module ../lnet/klnds/$LNETLND
754 if [ "$1" = "config_on_load=1" ]; then
755 do_lnetctl lnet configure --all ||
760 load_modules_local() {
761 if [ -n "$MODPROBE" ]; then
763 echo "Using modprobe to load modules"
767 # Create special udev test rules on every node
768 if [ -f $LUSTRE/lustre/conf/99-lustre.rules ]; then {
769 sed -e 's|/usr/sbin/lctl|$LCTL|g' $LUSTRE/lustre/conf/99-lustre.rules > /etc/udev/rules.d/99-lustre-test.rules
771 echo "SUBSYSTEM==\"lustre\", ACTION==\"change\", ENV{PARAM}==\"?*\", RUN+=\"$LCTL set_param '\$env{PARAM}=\$env{SETTING}'\"" > /etc/udev/rules.d/99-lustre-test.rules
773 udevadm control --reload-rules
778 load_module obdclass/obdclass
779 if ! client_only; then
780 MODOPTS_PTLRPC=${MODOPTS_PTLRPC:-"lbug_on_grant_miscount=1"}
782 load_module ptlrpc/ptlrpc
783 load_module ptlrpc/gss/ptlrpc_gss
791 load_module obdecho/obdecho
792 if ! client_only; then
793 load_module lfsck/lfsck
794 [ "$LQUOTA" != "no" ] &&
795 load_module quota/lquota $LQUOTAOPTS
796 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
797 load_module osd-zfs/osd_zfs
798 elif [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
799 load_module ../ldiskfs/ldiskfs
800 load_module osd-ldiskfs/osd_ldiskfs
812 load_module llite/lustre
813 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
815 rm -f $OGDB/ogdb-$HOSTNAME
816 $LCTL modules > $OGDB/ogdb-$HOSTNAME
818 # 'mount' doesn't look in $PATH, just sbin
819 local mount_lustre=$LUSTRE/utils/mount.lustre
820 if [ -f $mount_lustre ]; then
821 local sbin_mount=$(readlink -f /sbin)/mount.lustre
822 if grep -qw "$sbin_mount" /proc/mounts; then
823 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
825 if ! grep -qw "$sbin_mount" /proc/mounts; then
826 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
827 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
828 cat <<- EOF > "$sbin_mount"
831 echo "This $sbin_mount just a mountpoint." 1>&2
832 echo "It is never supposed to be run." 1>&2
833 logger -p emerg -- "using stub $sbin_mount $@"
836 chmod a+x $sbin_mount
838 mount --bind $mount_lustre $sbin_mount ||
839 error "can't bind $mount_lustre to $sbin_mount"
850 # load modules on remote nodes optionally
851 # lustre-tests have to be installed on these nodes
852 if $LOAD_MODULES_REMOTE; then
853 local list=$(comma_list $(remote_nodes_list))
855 # include failover nodes in case they are not in the list yet
857 for facet in ${facets//,/ }; do
858 failover=$(facet_failover_host $facet)
859 [ -n "$list" ] && [[ ! "$list" =~ "$failover" ]] &&
860 list="$list,$failover"
863 if [ -n "$list" ]; then
864 echo "loading modules on: '$list'"
865 do_rpc_nodes "$list" load_modules_local
871 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
872 LEAK_PORTALS=$(dmesg | tail -n 20 | egrep -i "libcfs.*memory leaked" || true)
873 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
874 echo "$LEAK_LUSTRE" 1>&2
875 echo "$LEAK_PORTALS" 1>&2
876 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
877 echo "Memory leaks detected"
878 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
883 unload_modules_local() {
884 $LUSTRE_RMMOD ldiskfs || return 2
886 [ -f /etc/udev/rules.d/99-lustre-test.rules ] &&
887 rm /etc/udev/rules.d/99-lustre-test.rules
888 udevadm control --reload-rules
891 check_mem_leak || return 254
899 wait_exit_ST client # bug 12845
901 unload_modules_local || rc=$?
903 if $LOAD_MODULES_REMOTE; then
904 local list=$(comma_list $(remote_nodes_list))
905 if [ -n "$list" ]; then
906 echo "unloading modules on: '$list'"
907 do_rpc_nodes "$list" unload_modules_local
911 local sbin_mount=$(readlink -f /sbin)/mount.lustre
912 if grep -qe "$sbin_mount " /proc/mounts; then
913 umount $sbin_mount || true
914 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
918 [[ $rc -eq 0 ]] && echo "modules unloaded."
924 local facet=${1:-$SINGLEMDS}
927 case $(facet_fstype $facet) in
928 ldiskfs) size=72;; # largest seen is 64, leave some headroom
929 # grant_block_size is in bytes, allow at least 2x max blocksize
930 zfs) size=$(lctl get_param osc.$FSNAME*.import |
931 awk '/grant_block_size:/ {print $2/512; exit;}')
935 echo -n $((size * MDSCOUNT))
939 local facet=${1:-$SINGLEMDS}
940 local fstype=$(facet_fstype $facet)
943 ldiskfs) size=4;; # ~4KB per inode
944 zfs) size=11;; # 10 to 11KB per inode
950 check_gss_daemon_nodes() {
954 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
955 if [ \\\"\\\$num\\\" -ne 1 ]; then
956 echo \\\$num instance of $dname;
961 check_gss_daemon_facet() {
965 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
966 if [ $num -ne 1 ]; then
967 echo "$num instance of $dname on $facet"
976 echo Stopping $@ on $list
977 do_nodes $list "killall -2 $@ 2>/dev/null || true"
980 # start gss daemons on all nodes, or "daemon" on "nodes" if set
981 start_gss_daemons() {
985 if [ "$nodes" ] && [ "$daemon" ] ; then
986 echo "Starting gss daemon on nodes: $nodes"
987 do_nodes $nodes "$daemon" || return 8
991 nodes=$(comma_list $(mdts_nodes))
992 echo "Starting gss daemon on mds: $nodes"
994 # Start all versions, in case of switching
995 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 1
997 do_nodes $nodes "$LSVCGSSD -v" || return 1
1000 do_nodes $nodes "$LGSSD -v" || return 2
1003 nodes=$(comma_list $(osts_nodes))
1004 echo "Starting gss daemon on ost: $nodes"
1006 # Start all versions, in case of switching
1007 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 3
1009 do_nodes $nodes "$LSVCGSSD -v" || return 3
1011 # starting on clients
1013 local clients=${CLIENTS:-$HOSTNAME}
1014 if $GSS_PIPEFS; then
1015 echo "Starting $LGSSD on clients $clients "
1016 do_nodes $clients "$LGSSD -v" || return 4
1019 # wait daemons entering "stable" status
1023 # check daemons are running
1025 nodes=$(comma_list $(mdts_nodes) $(osts_nodes))
1026 check_gss_daemon_nodes $nodes lsvcgssd || return 5
1027 if $GSS_PIPEFS; then
1028 nodes=$(comma_list $(mdts_nodes))
1029 check_gss_daemon_nodes $nodes lgssd || return 6
1031 if $GSS_PIPEFS; then
1032 check_gss_daemon_nodes $clients lgssd || return 7
1036 stop_gss_daemons() {
1037 local nodes=$(comma_list $(mdts_nodes))
1039 send_sigint $nodes lsvcgssd lgssd
1041 nodes=$(comma_list $(osts_nodes))
1042 send_sigint $nodes lsvcgssd
1044 nodes=${CLIENTS:-$HOSTNAME}
1045 send_sigint $nodes lgssd
1049 # Add mount flags for shared key
1051 if grep -q skpath <<< "$mt_opts" ; then
1052 mt_opts=$(echo $mt_opts |
1053 sed -e "s#skpath=[^ ,]*#skpath=$SK_PATH#")
1055 if [ -z "$mt_opts" ]; then
1056 mt_opts="-o skpath=$SK_PATH"
1058 mt_opts="$mt_opts,skpath=$SK_PATH"
1068 /usr/lib/lustre/* | /usr/lib64/lustre/* | /usr/lib/lustre | \
1077 [ $from_tree = true ]
1081 if $SHARED_KEY; then
1090 if ! module_loaded ptlrpc_gss; then
1091 load_module ptlrpc/gss/ptlrpc_gss
1092 module_loaded ptlrpc_gss ||
1093 error_exit "init_gss: GSS=$GSS, but gss/krb5 missing"
1096 if $GSS_KRB5 || $GSS_SK; then
1097 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
1100 if $GSS_SK && ! $SK_NO_KEY; then
1101 echo "Loading basic SSK keys on all servers"
1102 do_nodes $(comma_list $(all_server_nodes)) \
1103 "lgss_sk -t server -l $SK_PATH/$FSNAME.key || true"
1104 do_nodes $(comma_list $(all_server_nodes)) \
1105 "keyctl show | grep lustre | cut -c1-11 |
1107 xargs -IX keyctl setperm X 0x3f3f3f3f"
1110 if $GSS_SK && $SK_NO_KEY; then
1111 local numclients=${1:-$CLIENTCOUNT}
1112 local clients=${CLIENTS:-$HOSTNAME}
1114 # security ctx config for keyring
1116 local lgssc_conf_file="/etc/request-key.d/lgssc.conf"
1118 if from_build_tree; then
1119 mkdir -p $SK_OM_PATH
1120 if grep -q request-key /proc/mounts > /dev/null; then
1121 echo "SSK: Request key already mounted."
1123 mount -o bind $SK_OM_PATH /etc/request-key.d/
1125 local lgssc_conf_line='create lgssc * * '
1126 lgssc_conf_line+=$(which lgss_keyring)
1127 lgssc_conf_line+=' %o %k %t %d %c %u %g %T %P %S'
1128 echo "$lgssc_conf_line" > $lgssc_conf_file
1131 [ -e $lgssc_conf_file ] ||
1132 error_exit "Could not find key options in $lgssc_conf_file"
1133 echo "$lgssc_conf_file content is:"
1134 cat $lgssc_conf_file
1136 if ! local_mode; then
1137 if from_build_tree; then
1138 do_nodes $(comma_list $(all_nodes)) "mkdir -p \
1140 do_nodes $(comma_list $(all_nodes)) "mount \
1141 -o bind $SK_OM_PATH \
1142 /etc/request-key.d/"
1143 do_nodes $(comma_list $(all_nodes)) "rsync \
1144 -aqv $HOSTNAME:$lgssc_conf_file \
1145 $lgssc_conf_file >/dev/null 2>&1"
1147 do_nodes $(comma_list $(all_nodes)) \
1148 "echo $lgssc_conf_file: ; \
1149 cat $lgssc_conf_file"
1153 # create shared key on all nodes
1154 mkdir -p $SK_PATH/nodemap
1155 rm -f $SK_PATH/$FSNAME.key $SK_PATH/nodemap/c*.key \
1156 $SK_PATH/$FSNAME-*.key
1157 # for nodemap testing each client may need own key,
1158 # and S2S now requires keys as well, both for "client"
1161 lgss_sk -t server -f$FSNAME -n $SK_S2SNMCLI \
1162 -w $SK_PATH/$FSNAME-nmclient.key \
1163 -d /dev/urandom >/dev/null 2>&1
1164 lgss_sk -t mgs,server -f$FSNAME -n $SK_S2SNM \
1165 -w $SK_PATH/$FSNAME-s2s-server.key \
1166 -d /dev/urandom >/dev/null 2>&1
1169 lgss_sk -t server -f$FSNAME -w $SK_PATH/$FSNAME.key \
1170 -d /dev/urandom >/dev/null 2>&1
1172 for i in $(seq 0 $((numclients - 1))); do
1173 lgss_sk -t server -f$FSNAME -n c$i \
1174 -w $SK_PATH/nodemap/c$i.key -d /dev/urandom \
1178 if ! local_mode; then
1179 for lnode in $(all_nodes); do
1180 scp -r $SK_PATH ${lnode}:$(dirname $SK_PATH)/
1183 # Set client keys to client type to generate prime P
1185 do_nodes $(all_nodes) "lgss_sk -t client,server -m \
1186 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1188 do_nodes $clients "lgss_sk -t client -m \
1189 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1190 do_nodes $clients "find $SK_PATH/nodemap -name \*.key | \
1191 xargs -IX lgss_sk -t client -m X >/dev/null 2>&1"
1193 # This is required for servers as well, if S2S in use
1195 do_nodes $(comma_list $(mdts_nodes)) \
1196 "cp $SK_PATH/$FSNAME-s2s-server.key \
1197 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
1198 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1200 do_nodes $(comma_list $(osts_nodes)) \
1201 "cp $SK_PATH/$FSNAME-s2s-server.key \
1202 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
1203 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1205 do_nodes $clients "lgss_sk -t client \
1206 -m $SK_PATH/$FSNAME-nmclient.key \
1211 # mount options for servers and clients
1212 MGS_MOUNT_OPTS=$(add_sk_mntflag $MGS_MOUNT_OPTS)
1213 MDS_MOUNT_OPTS=$(add_sk_mntflag $MDS_MOUNT_OPTS)
1214 OST_MOUNT_OPTS=$(add_sk_mntflag $OST_MOUNT_OPTS)
1215 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
1217 if [ -z "$LGSS_KEYRING_DEBUG" ]; then
1218 LGSS_KEYRING_DEBUG=4
1222 if [ -n "$LGSS_KEYRING_DEBUG" ] && \
1223 ( local_mode || from_build_tree ); then
1225 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
1226 elif [ -n "$LGSS_KEYRING_DEBUG" ]; then
1227 do_nodes $(comma_list $(all_nodes)) "modprobe ptlrpc_gss && \
1229 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG"
1236 # maybe cleanup credential cache?
1243 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNM"
1244 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNMCLI"
1245 $RPC_MODE || echo "Sleeping for 10 sec for Nodemap.."
1249 $RPC_MODE || echo "Cleaning up Shared Key.."
1250 do_nodes $(comma_list $(all_nodes)) "rm -f \
1251 $SK_PATH/$FSNAME*.key $SK_PATH/nodemap/$FSNAME*.key"
1252 do_nodes $(comma_list $(all_nodes)) "keyctl show | \
1253 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
1254 if from_build_tree; then
1255 # Remove the mount and clean up the files we added to
1257 do_nodes $(comma_list $(all_nodes)) "while grep -q \
1258 request-key.d /proc/mounts; do umount \
1259 /etc/request-key.d/; done"
1260 do_nodes $(comma_list $(all_nodes)) "rm -f \
1261 $SK_OM_PATH/lgssc.conf"
1262 do_nodes $(comma_list $(all_nodes)) "rmdir $SK_OM_PATH"
1270 local var=${facet}_svc
1278 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
1279 tr '[:lower:]' '[:upper:]'
1285 if [ $facet == mgs ] || [ $facet == client ]; then
1289 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
1297 if [ -n "${!var}" ]; then
1302 var=$(facet_type $facet)FSTYPE
1303 if [ -n "${!var}" ]; then
1308 if [ -n "$FSTYPE" ]; then
1313 if [[ $facet == mgs ]] && combined_mgs_mds; then
1325 local facets=$(get_facets)
1328 for facet in ${facets//,/ }; do
1329 if [ $node == $(facet_host $facet) ] ||
1330 [ $node == "$(facet_failover_host $facet)" ]; then
1331 fstype=$(facet_fstype $facet)
1332 if [[ $fstypes != *$fstype* ]]; then
1333 fstypes+="${fstypes:+,}$fstype"
1342 local num=$(facet_number $facet)
1345 if [[ $(facet_type $facet) = OST ]]; then
1346 index=OSTINDEX${num}
1347 if [[ -n "${!index}" ]]; then
1352 index=${OST_INDICES[num - 1]}
1355 [[ -n "$index" ]] || index=$((num - 1))
1363 local fstype=$(facet_fstype $facet)
1367 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
1369 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
1370 ${dev} 2>/dev/null");;
1372 error "unknown fstype!";;
1379 # Get the device of a facet.
1386 mgs) device=$(mgsdevname) ;;
1387 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
1388 ost*) device=$(ostdevname $(facet_number $facet)) ;;
1389 fs2mds) device=$(mdsdevname 1_2) ;;
1390 fs2ost) device=$(ostdevname 1_2) ;;
1391 fs3ost) device=$(ostdevname 2_2) ;;
1399 # Get the virtual device of a facet.
1406 mgs) device=$(mgsvdevname) ;;
1407 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
1408 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
1409 fs2mds) device=$(mdsvdevname 1_2) ;;
1410 fs2ost) device=$(ostvdevname 1_2) ;;
1411 fs3ost) device=$(ostvdevname 2_2) ;;
1419 local virt=$(virt-what 2> /dev/null)
1421 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1423 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1426 VMware|KVM|VirtualBox|Parallels|Bochs)
1427 echo $virt | tr '[A-Z]' '[a-z]' ;;
1433 # Re-read the partition table on failover partner host.
1434 # After a ZFS storage pool is created on a shared device, the partition table
1435 # on the device may change. However, the operating system on the failover
1436 # host may not notice the change automatically. Without the up-to-date partition
1437 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1438 # relative to partition rather than disk beginnings.
1440 # This function performs partprobe on the failover host to make it re-read the
1443 refresh_partition_table() {
1448 host=$(facet_passive_host $facet)
1449 if [[ -n "$host" ]]; then
1450 do_node $host "$PARTPROBE $device"
1455 # Get ZFS storage pool name.
1462 device=$(facet_device $facet)
1463 # poolname is string before "/"
1464 poolname="${device%%/*}"
1471 # Get ZFS local fsname.
1473 zfs_local_fsname() {
1475 local lfsname=$(basename $(facet_device $facet))
1481 # Create ZFS storage pool.
1488 local opts=${@:-"-o cachefile=none"}
1490 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1491 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1492 $ZPOOL create -f $opts $poolname $vdev"
1496 # Create ZFS file system.
1502 local opts=${@:-"-o mountpoint=legacy"}
1504 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1505 $ZFS create $opts $dataset"
1509 # Export ZFS storage pool.
1510 # Before exporting the pool, all datasets within the pool should be unmounted.
1518 poolname=$(zpool_name $facet)
1520 if [[ -n "$poolname" ]]; then
1521 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1522 grep -q ^$poolname/ /proc/mounts ||
1523 $ZPOOL export $opts $poolname"
1528 # Destroy ZFS storage pool.
1529 # Destroy the given pool and free up any devices for other use. This command
1530 # tries to unmount any active datasets before destroying the pool.
1531 # -f Force any active datasets contained within the pool to be unmounted.
1535 local poolname=${2:-$(zpool_name $facet)}
1537 if [[ -n "$poolname" ]]; then
1538 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1539 $ZPOOL destroy -f $poolname"
1544 # Import ZFS storage pool.
1545 # Force importing, even if the pool appears to be potentially active.
1550 local opts=${@:-"-o cachefile=none -o failmode=panic"}
1553 poolname=$(zpool_name $facet)
1555 if [[ -n "$poolname" ]]; then
1556 opts+=" -d $(dirname $(facet_vdevice $facet))"
1557 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1558 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1559 $ZPOOL import -f $opts $poolname"
1564 # Reimport ZFS storage pool with new name
1569 local opts="-o cachefile=none"
1570 local poolname=$(zpool_name $facet)
1572 opts+=" -d $(dirname $(facet_vdevice $facet))"
1573 do_facet $facet "$ZPOOL export $poolname;
1574 $ZPOOL import $opts $poolname $newpool"
1578 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1579 # is not automatically imported on system startup.
1581 # In a failover environment, this will provide resource level fencing which
1582 # will ensure that the same ZFS storage pool will not be imported concurrently
1583 # on different nodes.
1585 disable_zpool_cache() {
1589 poolname=$(zpool_name $facet)
1591 if [[ -n "$poolname" ]]; then
1592 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1597 # This and set_osd_param() shall be used to access OSD parameters
1598 # once existed under "obdfilter":
1603 # writethrough_cache_enable
1607 local device=${2:-$FSNAME-OST*}
1610 do_nodes $nodes "$LCTL get_param -n osd-*.$device.$name"
1615 local device=${2:-$FSNAME-OST*}
1619 do_nodes $nodes "$LCTL set_param -n osd-*.$device.$name=$value"
1623 local dz=${1:-$DEBUG_SIZE}
1625 if [ -f /sys/devices/system/cpu/possible ]; then
1626 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1628 local cpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1631 # bug 19944, adjust size to be -gt num_possible_cpus()
1632 # promise 2MB for every cpu at least
1633 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1636 lctl set_param debug_mb=$dz
1639 set_default_debug () {
1640 local debug=${1:-"$PTLDEBUG"}
1641 local subsys=${2:-"$SUBSYSTEM"}
1642 local debug_size=${3:-$DEBUG_SIZE}
1644 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1645 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1647 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1650 set_default_debug_nodes () {
1652 local debug="${2:-"$PTLDEBUG"}"
1653 local subsys="${3:-"$SUBSYSTEM"}"
1654 local debug_size="${4:-$DEBUG_SIZE}"
1656 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1657 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1661 [[ -z "$nodes" ]] ||
1662 do_rpc_nodes "$nodes" set_default_debug \
1663 \\\"$debug\\\" \\\"$subsys\\\" $debug_size || true
1666 set_default_debug_facet () {
1668 local debug="${2:-"$PTLDEBUG"}"
1669 local subsys="${3:-"$SUBSYSTEM"}"
1670 local debug_size="${4:-$DEBUG_SIZE}"
1671 local node=$(facet_active_host $facet)
1673 [ -n "$node" ] || error "No host defined for facet $facet"
1675 set_default_debug_nodes $node "$debug" "$subsys" $debug_size
1678 set_params_nodes () {
1679 [[ $# -ge 2 ]] || return 0
1683 do_nodes $nodes $LCTL set_param $@
1686 set_params_clients () {
1687 local clients=${1:-$CLIENTS}
1688 local params=${2:-$CLIENT_LCTL_SETPARAM_PARAM}
1690 [[ -n $params ]] || return 0
1691 set_params_nodes $clients $params
1695 local hostid=${1:-$(hostid)}
1697 if [ ! -s /etc/hostid ]; then
1698 printf $(echo -n $hostid |
1699 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1705 local facets=${1:-$(get_facets)}
1711 for facet in ${facets//,/ }; do
1712 mount_facet $facet &
1716 for ((index=0; index<$total; index++)); do
1717 wait ${mountpids[index]}
1719 [ $RC -eq 0 ] && continue
1721 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1722 skip_noexit "Restart of $facet failed!." &&
1725 error "Restart of $facet failed!"
1733 # Add argument "arg" (e.g., "loop") to the comma-separated list
1734 # of arguments for option "opt" (e.g., "-o") on command
1735 # line "opts" (e.g., "-o flock").
1741 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1743 if echo "$opts" | grep -q $opt_pattern; then
1744 opts=$(echo "$opts" | sed -e \
1745 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1747 opts+="${opts:+ }$opt $arg"
1753 # Associate loop device with a given regular file.
1754 # Return the loop device.
1756 setup_loop_device() {
1760 do_facet $facet "loop_dev=\\\$($LOSETUP -j $file | cut -d : -f 1);
1761 if [[ -z \\\$loop_dev ]]; then
1762 loop_dev=\\\$($LOSETUP -f);
1763 $LOSETUP \\\$loop_dev $file || loop_dev=;
1765 echo -n \\\$loop_dev"
1769 # Detach a loop device.
1771 cleanup_loop_device() {
1775 do_facet $facet "! $LOSETUP $loop_dev >/dev/null 2>&1 ||
1776 $LOSETUP -d $loop_dev"
1780 # Check if a given device is a block device.
1787 [[ -n "$dev" ]] || return 1
1788 do_facet $facet "test -b $dev" || return 1
1789 if [[ -n "$size" ]]; then
1790 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k \
1791 count=1 skip=$size 2>&1" |
1792 awk '($3 == "in") { print $1 }')
1793 [[ "$in" = "1+0" ]] || return 1
1798 # Check if a given device is a device-mapper device.
1804 [[ -n "$dev" ]] || return 1
1805 do_facet $facet "$DMSETUP status $dev >/dev/null 2>&1"
1809 # Check if a given device is a device-mapper flakey device.
1811 is_dm_flakey_dev() {
1816 [[ -n "$dev" ]] || return 1
1818 type=$(do_facet $facet "$DMSETUP status $dev 2>&1" |
1820 [[ $type = flakey ]] && return 0 || return 1
1824 # Check if device-mapper flakey device is supported by the kernel
1825 # of $facet node or not.
1827 dm_flakey_supported() {
1831 do_facet $facet "modprobe dm-flakey;
1832 $DMSETUP targets | grep -q flakey" &> /dev/null
1836 # Get the device-mapper flakey device name of a given facet.
1838 dm_facet_devname() {
1840 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
1842 echo -n ${facet}_flakey
1846 # Get the device-mapper flakey device of a given facet.
1847 # A device created by dmsetup will appear as /dev/mapper/<device-name>.
1849 dm_facet_devpath() {
1852 echo -n $DM_DEV_PATH/$(dm_facet_devname $facet)
1856 # Set a device-mapper device with a new table.
1858 # The table has the following format:
1859 # <logical_start_sector> <num_sectors> <target_type> <target_args>
1861 # flakey <target_args> includes:
1862 # <destination_device> <offset> <up_interval> <down_interval> \
1863 # [<num_features> [<feature_arguments>]]
1865 # linear <target_args> includes:
1866 # <destination_device> <start_sector>
1868 dm_set_dev_table() {
1871 local target_type=$3
1877 read tmp num_sectors tmp real_dev tmp \
1878 <<< $(do_facet $facet "$DMSETUP table $dm_dev")
1880 case $target_type in
1882 table="0 $num_sectors flakey $real_dev 0 0 1800 1 drop_writes"
1885 table="0 $num_sectors linear $real_dev 0"
1887 *) error "invalid target type $target_type" ;;
1890 do_facet $facet "$DMSETUP suspend --nolockfs --noflush $dm_dev" ||
1891 error "failed to suspend $dm_dev"
1892 do_facet $facet "$DMSETUP load $dm_dev --table \\\"$table\\\"" ||
1893 error "failed to load $target_type table into $dm_dev"
1894 do_facet $facet "$DMSETUP resume $dm_dev" ||
1895 error "failed to resume $dm_dev"
1899 # Set a device-mapper flakey device as "read-only" by using the "drop_writes"
1900 # feature parameter.
1903 # All write I/O is silently ignored.
1904 # Read I/O is handled correctly.
1906 dm_set_dev_readonly() {
1908 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1910 dm_set_dev_table $facet $dm_dev flakey
1914 # Set a device-mapper device to traditional linear mapping mode.
1916 dm_clear_dev_readonly() {
1918 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1920 dm_set_dev_table $facet $dm_dev linear
1924 # Set the device of a given facet as "read-only".
1926 set_dev_readonly() {
1928 local svc=${facet}_svc
1930 if [[ $(facet_fstype $facet) = zfs ]] ||
1931 ! dm_flakey_supported $facet; then
1932 do_facet $facet $LCTL --device ${!svc} readonly
1934 dm_set_dev_readonly $facet
1939 # Get size in 512-byte sectors (BLKGETSIZE64 / 512) of a given device.
1946 num_sectors=$(do_facet $facet "blockdev --getsz $dev 2>/dev/null")
1947 [[ ${PIPESTATUS[0]} = 0 && -n "$num_sectors" ]] || num_sectors=0
1948 echo -n $num_sectors
1952 # Create a device-mapper device with a given block device or regular file (will
1953 # be associated with loop device).
1954 # Return the full path of the device-mapper device.
1958 local real_dev=$2 # destination device
1959 local dm_dev_name=${3:-$(dm_facet_devname $facet)} # device name
1960 local dm_dev=$DM_DEV_PATH/$dm_dev_name # device-mapper device
1962 # check if the device-mapper device to be created already exists
1963 if is_dm_dev $facet $dm_dev; then
1964 # if the existing device was set to "read-only", then clear it
1965 ! is_dm_flakey_dev $facet $dm_dev ||
1966 dm_clear_dev_readonly $facet $dm_dev
1972 # check if the destination device is a block device, and if not,
1973 # associate it with a loop device
1974 is_blkdev $facet $real_dev ||
1975 real_dev=$(setup_loop_device $facet $real_dev)
1976 [[ -n "$real_dev" ]] || { echo -n $real_dev; return 2; }
1978 # now create the device-mapper device
1979 local num_sectors=$(get_num_sectors $facet $real_dev)
1980 local table="0 $num_sectors linear $real_dev 0"
1983 do_facet $facet "$DMSETUP create $dm_dev_name --table \\\"$table\\\"" ||
1984 { rc=${PIPESTATUS[0]}; dm_dev=; }
1985 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
1992 # Map the facet name to its device variable name.
1994 facet_device_alias() {
1996 local dev_alias=$facet
1999 fs2mds) dev_alias=mds1_2 ;;
2000 fs2ost) dev_alias=ost1_2 ;;
2001 fs3ost) dev_alias=ost2_2 ;;
2009 # Save the original value of the facet device and export the new value.
2015 local active_facet=$(facet_active $facet)
2016 local dev_alias=$(facet_device_alias $active_facet)
2017 local dev_name=${dev_alias}_dev
2018 local dev=${!dev_name}
2020 if [[ $active_facet = $facet ]]; then
2021 local failover_dev=${dev_alias}failover_dev
2022 if [[ ${!failover_dev} = $dev ]]; then
2023 eval export ${failover_dev}_saved=$dev
2024 eval export ${failover_dev}=$dm_dev
2027 dev_alias=$(facet_device_alias $facet)
2028 local facet_dev=${dev_alias}_dev
2029 if [[ ${!facet_dev} = $dev ]]; then
2030 eval export ${facet_dev}_saved=$dev
2031 eval export ${facet_dev}=$dm_dev
2035 eval export ${dev_name}_saved=$dev
2036 eval export ${dev_name}=$dm_dev
2040 # Restore the saved value of the facet device.
2045 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
2046 local dev_alias=$(facet_device_alias $facet)
2048 local saved_dev=${dev_alias}_dev_saved
2049 [[ -z ${!saved_dev} ]] ||
2050 eval export ${dev_alias}_dev=${!saved_dev}
2052 saved_dev=${dev_alias}failover_dev_saved
2053 [[ -z ${!saved_dev} ]] ||
2054 eval export ${dev_alias}failover_dev=${!saved_dev}
2058 # Remove a device-mapper device.
2059 # If the destination device is a loop device, then also detach it.
2063 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2067 is_dm_dev $facet $dm_dev || return 0
2069 read major minor <<< $(do_facet $facet "$DMSETUP table $dm_dev" |
2070 awk '{ print $4 }' | awk -F: '{ print $1" "$2 }')
2072 do_facet $facet "$DMSETUP remove $dm_dev"
2073 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
2075 unexport_dm_dev $facet
2077 # detach a loop device
2078 [[ $major -ne 7 ]] || cleanup_loop_device $facet /dev/loop$minor
2080 # unload dm-flakey module
2081 do_facet $facet "modprobe -r dm-flakey" || true
2087 local active_facet=$(facet_active $facet)
2088 local dev_alias=$(facet_device_alias $active_facet)
2089 local dev=${dev_alias}_dev
2090 local opt=${facet}_opt
2091 local mntpt=$(facet_mntpt $facet)
2092 local opts="${!opt} $@"
2093 local fstype=$(facet_fstype $facet)
2095 local dm_dev=${!dev}
2097 [[ $dev == "mgsfailover_dev" ]] && combined_mgs_mds &&
2098 dev=mds1failover_dev
2100 module_loaded lustre || load_modules
2104 if dm_flakey_supported $facet; then
2105 dm_dev=$(dm_create_dev $facet ${!dev})
2106 [[ -n "$dm_dev" ]] || dm_dev=${!dev}
2109 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
2111 devicelabel=$(do_facet ${facet} "$E2LABEL $dm_dev");;
2113 # import ZFS storage pool
2114 import_zpool $facet || return ${PIPESTATUS[0]}
2116 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
2117 lustre:svname $dm_dev");;
2119 error "unknown fstype!";;
2122 echo "Starting ${facet}: $opts $dm_dev $mntpt"
2123 # for testing LU-482 error handling in mount_facets() and test_0a()
2124 if [ -f $TMP/test-lu482-trigger ]; then
2128 "mkdir -p $mntpt; $MOUNT_CMD $opts $dm_dev $mntpt"
2132 if [ $RC -ne 0 ]; then
2133 echo "Start of $dm_dev on ${facet} failed ${RC}"
2137 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
2138 if [[ "$health" != "healthy" ]]; then
2139 error "$facet is in a unhealthy state"
2142 set_default_debug_facet $facet
2144 if [[ $opts =~ .*nosvc.* ]]; then
2145 echo "Start $dm_dev without service"
2150 wait_update_facet ${facet} "$E2LABEL $dm_dev \
2151 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
2152 "" || error "$dm_dev failed to initialize!";;
2154 wait_update_facet ${facet} "$ZFS get -H -o value \
2155 lustre:svname $dm_dev 2>/dev/null | \
2156 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
2157 error "$dm_dev failed to initialize!";;
2160 error "unknown fstype!";;
2164 # commit the device label change to disk
2165 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
2166 echo "Commit the device label on ${!dev}"
2167 do_facet $facet "sync; sleep 1; sync"
2171 label=$(devicelabel ${facet} $dm_dev)
2172 [ -z "$label" ] && echo no label for $dm_dev && exit 1
2173 eval export ${facet}_svc=${label}
2174 echo Started ${label}
2176 export_dm_dev $facet $dm_dev
2181 # start facet device options
2187 local dev_alias=$(facet_device_alias $facet)
2189 eval export ${dev_alias}_dev=${device}
2190 eval export ${facet}_opt=\"$@\"
2192 combined_mgs_mds && [[ ${dev_alias} == mds1 ]] &&
2193 eval export mgs_dev=${device}
2195 local varname=${dev_alias}failover_dev
2196 if [ -n "${!varname}" ] ; then
2197 eval export ${dev_alias}failover_dev=${!varname}
2199 eval export ${dev_alias}failover_dev=$device
2200 combined_mgs_mds && [[ ${dev_alias} == mds1 ]] &&
2201 eval export mgsfailover_dev=${device}
2205 local mntpt=$(facet_mntpt $facet)
2206 do_facet ${facet} mkdir -p $mntpt
2207 eval export ${facet}_MOUNT=$mntpt
2208 mount_facet ${facet}
2218 local HOST=$(facet_active_host $facet)
2219 [[ -z $HOST ]] && echo stop: no host for $facet && return 0
2221 local mntpt=$(facet_mntpt $facet)
2222 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts || true")
2223 if [ ${running} -ne 0 ]; then
2224 echo "Stopping $mntpt (opts:$@) on $HOST"
2225 do_facet ${facet} $UMOUNT $@ $mntpt
2228 # umount should block, but we should wait for unrelated obd's
2229 # like the MGS or MGC to also stop.
2230 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
2232 if [[ $(facet_fstype $facet) == zfs ]]; then
2233 # export ZFS storage pool
2234 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
2235 elif dm_flakey_supported $facet; then
2236 local host=${facet}_HOST
2237 local failover_host=${facet}failover_HOST
2238 if [[ -n ${!failover_host} && ${!failover_host} != ${!host} ]]||
2239 $CLEANUP_DM_DEV || [[ $facet = fs* ]]; then
2240 dm_cleanup_dev $facet
2245 # get mdt quota type
2247 local varsvc=${SINGLEMDS}_svc
2248 do_facet $SINGLEMDS $LCTL get_param -n \
2249 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
2252 # get ost quota type
2254 # All OSTs should have same quota type
2255 local varsvc=ost1_svc
2256 do_facet ost1 $LCTL get_param -n \
2257 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
2260 # restore old quota type settings
2262 if [ "$old_MDT_QUOTA_TYPE" ]; then
2263 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2264 do_facet mgs $PERM_CMD \
2265 osd-*.$FSNAME-MDT*.quota_slave.enabled = \
2268 do_facet mgs $PERM_CMD \
2269 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
2272 if [ "$old_OST_QUOTA_TYPE" ]; then
2273 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2274 do_facet mgs $PERM_CMD \
2275 osd-*.$FSNAME-OST*.quota_slave.enabled = \
2278 do_facet mgs $LCTL conf_param \
2279 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
2284 # Handle the case when there is a space in the lfs df
2285 # "filesystem summary" line the same as when there is no space.
2286 # This will allow fixing the "lfs df" summary line in the future.
2288 $LFS df $* | sed -e 's/filesystem /filesystem_/'
2289 check_lfs_df_ret_val $?
2292 # Get free inodes on the MDT specified by mdt index, free indoes on
2293 # the whole filesystem will be returned when index == -1.
2299 if [ $index -eq -1 ]; then
2302 mdt_uuid=$(mdtuuid_from_index $index)
2305 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
2310 # Get the OST device status from 'lfs df' with a given OST index.
2314 local mnt_pnt=${2:-$MOUNT}
2318 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
2319 lfs_df $opts $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
2325 # save old quota type & set new quota type
2326 local mdt_qtype=$(mdt_quota_type)
2327 local ost_qtype=$(ost_quota_type)
2329 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
2330 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
2332 export old_MDT_QUOTA_TYPE=$mdt_qtype
2333 export old_OST_QUOTA_TYPE=$ost_qtype
2335 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2336 do_facet mgs $PERM_CMD \
2337 osd-*.$FSNAME-MDT*.quota_slave.enabled=$QUOTA_TYPE
2338 do_facet mgs $PERM_CMD \
2339 osd-*.$FSNAME-OST*.quota_slave.enabled=$QUOTA_TYPE
2341 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$QUOTA_TYPE ||
2342 error "set mdt quota type failed"
2343 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$QUOTA_TYPE ||
2344 error "set ost quota type failed"
2347 local quota_usrs=$QUOTA_USERS
2349 # get_filesystem_size
2350 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
2351 local blk_soft=$((disksz + 1024))
2352 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
2354 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
2355 local i_soft=$inodes
2356 local i_hard=$((i_soft + i_soft / 20))
2358 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
2359 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
2360 "inode-hardlimit: $i_hard"
2363 for usr in $quota_usrs; do
2364 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
2366 cmd="$LFS setquota -$type $usr -b $blk_soft"
2367 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
2369 eval $cmd || error "$cmd FAILED!"
2371 # display the quota status
2372 echo "Quota settings for $usr : "
2373 $LFS quota -v -u $usr $mntpt || true
2380 local opts=${3:-$MOUNT_OPTS}
2381 opts=${opts:+-o $opts}
2382 local flags=${4:-$MOUNT_FLAGS}
2384 local device=$MGSNID:/$FSNAME$FILESET
2385 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2386 echo "Bad mount command: opt=$flags $opts dev=$device " \
2392 # update mount option with skpath
2393 opts=$(add_sk_mntflag $opts)
2396 echo "Starting client: $client: $flags $opts $device $mnt"
2397 do_node $client mkdir -p $mnt
2398 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
2399 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
2401 #disable FILESET if not supported
2402 do_nodes $client lctl get_param -n \
2403 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2404 device=$MGSNID:/$FSNAME
2405 do_node $client mkdir -p $mnt/$FILESET
2406 do_node $client "! grep -q $mnt' ' /proc/mounts ||
2409 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2410 # Mount using nodemap key
2411 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2412 if $SK_UNIQUE_NM; then
2413 mountkey=$SK_PATH/nodemap/c0.key
2415 local prunedopts=$(echo $opts |
2416 sed -e "s#skpath=[^,^ ]*#skpath=$mountkey#g")
2417 do_node $client $MOUNT_CMD $flags $prunedopts $device $mnt ||
2420 do_node $client $MOUNT_CMD $flags $opts $device $mnt ||
2424 set_default_debug_nodes $client
2425 set_params_clients $client
2436 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
2438 [ "$3" ] && force=-f
2439 [ $running -eq 0 ] && return 0
2441 echo "Stopping client $client $mnt (opts:$force)"
2442 do_node $client lsof -t $mnt || need_kill=no
2443 if [ "x$force" != "x" ] && [ "x$need_kill" != "xno" ]; then
2444 pids=$(do_node $client lsof -t $mnt | sort -u);
2445 if [ -n "$pids" ]; then
2446 do_node $client kill -9 $pids || true
2450 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") ||
2452 if [ $busy -ne 0 ] ; then
2453 echo "$mnt is still busy, wait one second" && sleep 1
2454 do_node $client umount $force $mnt
2458 # Mount the file system on the MDS
2459 mount_mds_client() {
2460 local host=$(facet_active_host $SINGLEMDS)
2462 zconf_mount $host $MOUNT2 $MOUNT_OPTS ||
2463 error "unable to mount $MOUNT2 on $host"
2466 # Unmount the file system on the MDS
2467 umount_mds_client() {
2468 local host=$(facet_active_host $SINGLEMDS)
2469 zconf_umount $host $MOUNT2
2470 do_facet $SINGLEMDS "rmdir $MOUNT2"
2473 # nodes is comma list
2474 sanity_mount_check_nodes () {
2480 # FIXME: assume that all cluster nodes run the same os
2481 [ "$(uname)" = Linux ] || return 0
2484 for mnt in $mnts ; do
2485 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
2486 mpts=\\\$(mount | grep -c $mnt' ');
2487 if [ \\\$running -ne \\\$mpts ]; then
2488 echo \\\$(hostname) env are INSANE!;
2491 [ $? -eq 0 ] || rc=1
2496 sanity_mount_check_servers () {
2497 [ -n "$CLIENTONLY" ] &&
2498 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
2499 echo Checking servers environments
2501 # FIXME: modify get_facets to display all facets wo params
2502 local facets="$(get_facets OST),$(get_facets MDS),mgs"
2506 for facet in ${facets//,/ }; do
2507 node=$(facet_host ${facet})
2508 mntpt=$(facet_mntpt $facet)
2509 sanity_mount_check_nodes $node $mntpt ||
2510 { error "server $node environments are insane!"; return 1; }
2514 sanity_mount_check_clients () {
2515 local clients=${1:-$CLIENTS}
2516 local mntpt=${2:-$MOUNT}
2517 local mntpt2=${3:-$MOUNT2}
2519 [ -z $clients ] && clients=$(hostname)
2520 echo Checking clients $clients environments
2522 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
2523 error "clients environments are insane!"
2526 sanity_mount_check () {
2527 sanity_mount_check_servers || return 1
2528 sanity_mount_check_clients || return 2
2531 # mount clients if not mouted
2532 zconf_mount_clients() {
2535 local opts=${3:-$MOUNT_OPTS}
2536 opts=${opts:+-o $opts}
2537 local flags=${4:-$MOUNT_FLAGS}
2538 local device=$MGSNID:/$FSNAME$FILESET
2539 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2540 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
2545 echo "Starting client $clients: $flags $opts $device $mnt"
2546 do_nodes $clients mkdir -p $mnt
2547 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ]; then
2548 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2549 # Mount with own nodemap key
2551 # Mount all server nodes first with per-NM keys
2552 for nmclient in ${clients//,/ }; do
2553 # do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key -n c$i"
2554 do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key"
2557 # set perms for per-nodemap keys else permission denied
2558 do_nodes $(comma_list $(all_nodes)) \
2559 "keyctl show | grep lustre | cut -c1-11 |
2561 xargs -IX keyctl setperm X 0x3f3f3f3f"
2562 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2564 for nmclient in ${clients//,/ }; do
2565 if $SK_UNIQUE_NM; then
2566 mountkey=$SK_PATH/nodemap/c$i.key
2568 do_node $nmclient "! grep -q $mnt' ' \
2569 /proc/mounts || umount $mnt"
2570 local prunedopts=$(add_sk_mntflag $prunedopts);
2571 prunedopts=$(echo $prunedopts | sed -e \
2572 "s#skpath=[^ ^,]*#skpath=$mountkey#g")
2574 do_nodes $(comma_list $(all_server_nodes)) \
2577 do_node $nmclient $MOUNT_CMD $flags \
2578 $prunedopts $MGSNID:/$FSNAME $mnt ||
2583 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2585 do_nodes $clients $MOUNT_CMD $flags $opts \
2586 $MGSNID:/$FSNAME $mnt || return 1
2588 #disable FILESET if not supported
2589 do_nodes $clients lctl get_param -n \
2590 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2591 device=$MGSNID:/$FSNAME
2592 do_nodes $clients mkdir -p $mnt/$FILESET
2593 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2597 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2598 # Mount with nodemap key
2600 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2601 for nmclient in ${clients//,/ }; do
2602 if $SK_UNIQUE_NM; then
2603 mountkey=$SK_PATH/nodemap/c$i.key
2605 local prunedopts=$(echo $opts | sed -e \
2606 "s#skpath=[^ ^,]*#skpath=$mountkey#g");
2607 do_node $nmclient "! grep -q $mnt' ' /proc/mounts ||
2610 running=\\\$(mount | grep -c $mnt' ');
2612 if [ \\\$running -eq 0 ] ; then
2614 $MOUNT_CMD $flags $prunedopts $device $mnt;
2617 lustre_mnt_count=\\\$(mount | grep $mnt' ' | \
2618 grep 'type lustre' | wc -l);
2619 if [ \\\$running -ne \\\$lustre_mnt_count ] ; then
2620 echo zconf_mount_clients FAILED: \
2621 mount count \\\$running, not matching \
2622 with mount count of 'type lustre' \
2623 \\\$lustre_mnt_count;
2627 exit \\\$rc" || return ${PIPESTATUS[0]}
2634 if $SHARED_KEY; then
2635 tmpopts=$(add_sk_mntflag $opts)
2638 running=\\\$(mount | grep -c $mnt' ');
2640 if [ \\\$running -eq 0 ] ; then
2642 $MOUNT_CMD $flags $tmpopts $device $mnt;
2645 exit \\\$rc" || return ${PIPESTATUS[0]}
2648 echo "Started clients $clients: "
2649 do_nodes $clients "mount | grep $mnt' '"
2651 set_default_debug_nodes $clients
2652 set_params_clients $clients
2657 zconf_umount_clients() {
2662 [ "$3" ] && force=-f
2664 echo "Stopping clients: $clients $mnt (opts:$force)"
2665 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
2666 if [ \\\$running -ne 0 ] ; then
2667 echo Stopping client \\\$(hostname) $mnt opts:$force;
2668 lsof $mnt || need_kill=no;
2669 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
2670 pids=\\\$(lsof -t $mnt | sort -u);
2671 if [ -n \\\"\\\$pids\\\" ]; then
2675 while umount $force $mnt 2>&1 | grep -q "busy"; do
2676 echo "$mnt is still busy, wait one second" && sleep 1;
2683 echo + $POWER_DOWN $node
2687 shutdown_node_hard () {
2689 local attempts=$SHUTDOWN_ATTEMPTS
2691 for i in $(seq $attempts) ; do
2694 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
2695 echo "waiting for $host to fail attempts=$attempts"
2696 [ $i -lt $attempts ] || \
2697 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
2703 local mnt=${2:-$MOUNT}
2706 if [ "$FAILURE_MODE" = HARD ]; then
2707 shutdown_node_hard $client
2709 zconf_umount_clients $client $mnt -f
2715 local facets="$(get_facets OST),$(get_facets MDS)"
2718 combined_mgs_mds || facets="$facets,mgs"
2720 for facet in ${facets//,/ }; do
2721 if [ $(facet_active_host $facet) == $host ]; then
2722 affected="$affected $facet"
2726 echo $(comma_list $affected)
2731 local host=${2:-$(facet_host $facet)}
2733 local label=$(convert_facet2label $facet)
2734 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
2737 facets_up_on_host () {
2739 local facets=$(facets_on_host $host)
2742 for facet in ${facets//,/ }; do
2743 if $(facet_up $facet $host); then
2744 affected_up="$affected_up $facet"
2748 echo $(comma_list $affected_up)
2753 local affected_facet
2754 local affected_facets
2756 if [[ "$FAILURE_MODE" = HARD ]]; then
2757 if [[ $(facet_fstype $facet) = ldiskfs ]] &&
2758 dm_flakey_supported $facet; then
2759 affected_facets=$(affected_facets $facet)
2760 for affected_facet in ${affected_facets//,/ }; do
2761 unexport_dm_dev $affected_facet
2765 shutdown_node_hard $(facet_active_host $facet)
2773 echo + $POWER_UP $node
2786 local node=$(facet_active_host $facet)
2787 local sleep_time=${2:-10}
2789 if [ "$FAILURE_MODE" = HARD ]; then
2799 if [ "$FAILURE_MODE" = HARD ]; then
2802 if $LOAD_MODULES_REMOTE; then
2803 echo "loading modules on $node: $facet"
2804 do_rpc_nodes $node load_modules_local
2813 for facet in ${facets//,/ }; do
2814 hosts=$(expand_list $hosts $(facet_host $facet) )
2820 _check_progs_installed () {
2824 for prog in $progs; do
2825 if ! [ "$(which $prog)" -o "${!prog}" ]; then
2826 echo $prog missing on $(hostname)
2833 check_progs_installed () {
2837 do_rpc_nodes "$nodes" _check_progs_installed $@
2840 # recovery-scale functions
2842 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
2845 start_client_load() {
2848 local var=$(node_var_name $client)_load
2849 eval export ${var}=$load
2851 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
2852 BREAK_ON_ERROR=$BREAK_ON_ERROR \
2853 END_RUN_FILE=$END_RUN_FILE \
2854 LOAD_PID_FILE=$LOAD_PID_FILE \
2855 TESTLOG_PREFIX=$TESTLOG_PREFIX \
2856 TESTNAME=$TESTNAME \
2857 DBENCH_LIB=$DBENCH_LIB \
2858 DBENCH_SRC=$DBENCH_SRC \
2859 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
2864 MPIRUN_OPTIONS=\\\"$MPIRUN_OPTIONS\\\" \
2865 MACHINEFILE_OPTION=\\\"$MACHINEFILE_OPTION\\\" \
2866 num_clients=$(get_node_count ${CLIENTS//,/ }) \
2867 ior_THREADS=$ior_THREADS ior_iteration=$ior_iteration \
2868 ior_blockSize=$ior_blockSize \
2869 ior_blockUnit=$ior_blockUnit \
2870 ior_xferSize=$ior_xferSize ior_type=$ior_type \
2871 ior_DURATION=$ior_DURATION \
2872 ior_stripe_params=\\\"$ior_stripe_params\\\" \
2873 ior_custom_params=\\\"$ior_custom_param\\\" \
2874 mpi_ior_custom_threads=$mpi_ior_custom_threads \
2877 log "Started client load: ${load} on $client"
2879 # get the children process IDs
2880 local pids=$(ps --ppid $ppid -o pid= | xargs)
2881 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
2885 start_client_loads () {
2886 local -a clients=(${1//,/ })
2887 local numloads=${#CLIENT_LOADS[@]}
2889 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
2890 local load=$((nodenum % numloads))
2891 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[load]}
2893 # bug 22169: wait the background threads to start
2897 # only for remote client
2898 check_client_load () {
2900 local var=$(node_var_name $client)_load
2901 local testload=run_${!var}.sh
2903 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
2905 # bug 18914: try to connect several times not only when
2906 # check ps, but while check_node_health also
2910 while [ $RC = 254 -a $tries -gt 0 ]; do
2914 if ! check_node_health $client; then
2916 if [ $RC -eq 254 ]; then
2917 # FIXME: not sure how long we shuold sleep here
2921 echo "check node health failed: RC=$RC "
2925 # We can continue try to connect if RC=254
2926 # Just print the warning about this
2927 if [ $RC = 254 ]; then
2928 echo "got a return status of $RC from do_node while checking " \
2929 "node health on $client"
2932 # see if the load is still on the client
2935 while [ $RC = 254 -a $tries -gt 0 ]; do
2939 if ! do_node $client \
2940 "ps auxwww | grep -v grep | grep -q $testload"; then
2945 if [ $RC = 254 ]; then
2946 echo "got a return status of $RC from do_node while checking " \
2947 "(node health and 'ps') the client load on $client"
2948 # see if we can diagnose a bit why this is
2953 check_client_loads () {
2954 local clients=${1//,/ }
2958 for client in $clients; do
2959 check_client_load $client
2961 if [ "$rc" != 0 ]; then
2962 log "Client load failed on node $client, rc=$rc"
2968 restart_client_loads () {
2969 local clients=${1//,/ }
2970 local expectedfail=${2:-""}
2974 for client in $clients; do
2975 check_client_load $client
2977 if [ "$rc" != 0 -a "$expectedfail" ]; then
2978 local var=$(node_var_name $client)_load
2979 start_client_load $client ${!var}
2980 echo "Restarted client load ${!var}: on $client. Checking ..."
2981 check_client_load $client
2983 if [ "$rc" != 0 ]; then
2984 log "Client load failed to restart on node $client, rc=$rc"
2985 # failure one client load means test fail
2986 # we do not need to check other
2995 # Start vmstat and save its process ID in a file.
3000 [ -z "$nodes" -o -z "$pid_file" ] && return 0
3003 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
3004 2>/dev/null </dev/null & echo \\\$! > $pid_file"
3007 # Display the nodes on which client loads failed.
3008 print_end_run_file() {
3012 [ -s $file ] || return 0
3014 echo "Found the END_RUN_FILE file: $file"
3017 # A client load will stop if it finds the END_RUN_FILE file.
3018 # That does not mean the client load actually failed though.
3019 # The first node in END_RUN_FILE is the one we are interested in.
3022 if [ -n "$node" ]; then
3023 local var=$(node_var_name $node)_load
3025 local prefix=$TESTLOG_PREFIX
3026 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
3027 local stdout_log=$prefix.run_${!var}_stdout.$node.log
3028 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
3030 echo "Client load ${!var} failed on node $node:"
3036 # Stop the process which had its PID saved in a file.
3041 [ -z "$nodes" -o -z "$pid_file" ] && return 0
3043 do_nodes $nodes "test -f $pid_file &&
3044 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
3047 # Stop all client loads.
3048 stop_client_loads() {
3049 local nodes=${1:-$CLIENTS}
3052 # stop the client loads
3053 stop_process $nodes $pid_file
3055 # clean up the processes that started them
3056 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
3058 # End recovery-scale functions
3061 # wait for a command to return the expected result
3063 # This will run @check on @node repeatedly until the output matches @expect
3064 # based on the supplied condition, or until @max_wait seconds have elapsed,
3065 # whichever comes first. @cond may be one of the normal bash operators,
3066 # "-gt", "-ge", "-eq", "-le", "-lt", "==", "!=", or "=~", and must be quoted
3067 # in the caller to avoid unintentional evaluation by the shell in the caller.
3069 # If @max_wait is not specified, the condition will be checked for up to 90s.
3071 # If --verbose is passed as the first argument, the result is printed on each
3072 # value change, otherwise it is only printed after every 10s interval.
3074 # If --quiet is passed as the first/second argument, the do_node() command
3075 # will not print the remote command before executing it each time.
3077 # Using wait_update_cond() or related helper function is preferable to adding
3078 # a "long enough" wait for some state to change in the background, since
3079 # "long enough" may be too short due to tunables, system config, or running in
3080 # a VM, and must by necessity wait too long for most cases or risk failure.
3082 # usage: wait_update_cond [--verbose] [--quiet] node check cond expect [max_wait]
3083 wait_update_cond() {
3087 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3088 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3094 local max_wait=${5:-90}
3098 local begin=$SECONDS
3102 while (( $waited <= $max_wait )); do
3103 result=$(do_node $quiet $node "$check")
3105 eval [[ "'$result'" $cond "'$expect'" ]]
3106 if [[ $? == 0 ]]; then
3107 [[ -z "$result" || $waited -le $sleep ]] ||
3108 echo "Updated after ${waited}s: want '$expect' got '$result'"
3111 if [[ -n "$verbose" && "$result" != "$prev_result" ]]; then
3112 [[ -n "$prev_result" ]] &&
3113 echo "Changed after ${waited}s: from '$prev_result' to '$result'"
3114 prev_result="$result"
3116 (( $waited % $print == 0 )) &&
3117 echo "Waiting $((max_wait - waited))s for '$expect'"
3119 waited=$((SECONDS - begin))
3121 echo "Update not seen after ${max_wait}s: want '$expect' got '$result'"
3125 # usage: wait_update [--verbose] [--quiet] node check expect [max_wait]
3130 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3131 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3138 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3141 # usage: wait_update_facet_cond [--verbose] facet check cond expect [max_wait]
3142 wait_update_facet_cond() {
3146 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3147 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3149 local node=$(facet_active_host $1)
3155 wait_update_cond $verbose $quiet $node "$check" "$cond" "$expect" $max_wait
3158 # usage: wait_update_facet [--verbose] facet check expect [max_wait]
3159 wait_update_facet() {
3163 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3164 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3166 local node=$(facet_active_host $1)
3171 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3175 do_nodes $(comma_list $(mdts_nodes)) \
3176 "lctl set_param -n os[cd]*.*MDT*.force_sync=1"
3177 do_nodes $(comma_list $(osts_nodes)) \
3178 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
3179 grep -v 'Found no match'
3183 local zfs_wait=${2:-5}
3185 # the occupied disk space will be released
3186 # only after TXGs are committed
3187 if [[ $(facet_fstype $1) == zfs ]]; then
3188 echo "sleep $zfs_wait for ZFS $(facet_fstype $1)"
3196 local lwm=$3 #low watermark
3197 local size_mb #how many MB should we write to pass watermark
3198 local ost_name=$(ostname_from_index $ost_idx)
3200 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3202 if (( $free_kb / 1024 > lwm )); then
3203 size_mb=$((free_kb / 1024 - lwm))
3205 #If 10% of free space cross low watermark use it
3206 if (( $free_kb / 10240 > size_mb )); then
3207 size_mb=$((free_kb / 10240))
3209 #At least we need to store 1.1 of difference between
3210 #free space and low watermark
3211 size_mb=$((size_mb + size_mb / 10))
3213 if (( lwm <= $free_kb / 1024 )) ||
3214 [ ! -f $DIR/${filename}.fill_ost$ost_idx ]; then
3215 $LFS setstripe -i $ost_idx -c1 $DIR/${filename}.fill_ost$ost_idx
3216 dd if=/dev/zero of=$DIR/${filename}.fill_ost$ost_idx bs=1M \
3217 count=$size_mb oflag=append conv=notrunc
3222 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3223 echo "OST still has $((free_kb / 1024)) MB free"
3226 # This checks only the primary MDS
3227 ost_watermarks_get() {
3229 local ost_name=$(ostname_from_index $ost_idx)
3230 local mdtosc_proc=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
3232 local hwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3233 osp.$mdtosc_proc.reserved_mb_high)
3234 local lwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3235 osp.$mdtosc_proc.reserved_mb_low)
3240 # Note that we set watermarks on all MDSes (necessary for striped dirs)
3241 ost_watermarks_set() {
3245 local ost_name=$(ostname_from_index $ost_idx)
3246 local facets=$(get_facets MDS)
3248 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param -n \
3249 osp.*$ost_name*.reserved_mb_low=$lwm \
3250 osp.*$ost_name*.reserved_mb_high=$hwm > /dev/null
3252 # sleep to ensure we see the change
3256 ost_watermarks_set_low_space() {
3258 local wms=$(ost_watermarks_get $ost_idx)
3259 local ost_name=$(ostname_from_index $ost_idx)
3261 local old_lwm=$(echo $wms | awk '{ print $1 }')
3262 local old_hwm=$(echo $wms | awk '{ print $2 }')
3264 local blocks=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3265 # minimal extension size is 64M
3267 if (( $blocks / 1024 > 50 )); then
3268 new_lwm=$((blocks / 1024 - 50))
3270 local new_hwm=$((new_lwm + 5))
3272 ost_watermarks_set $ost_idx $new_lwm $new_hwm
3273 echo "watermarks: $old_lwm $old_hwm $new_lwm $new_hwm"
3276 # Set watermarks to ~current available space & then write data to fill it
3277 # Note OST is not *actually* full after this, it just reports ENOSPC in the
3278 # internal statfs used by the stripe allocator
3280 # first parameter is the filename-prefix, which must get under t-f cleanup
3281 # requirements (rm -rf $DIR/[Rdfs][0-9]*), i.e. $tfile work fine
3282 ost_watermarks_set_enospc() {
3286 local ost_name=$(ostname_from_index $ost_idx)
3287 local facets=$(get_facets MDS)
3291 for MDS in ${facets//,/ }; do
3292 local mdtosc_proc=$(get_mdtosc_proc_path $MDS $ost_name)
3294 do_facet $MDS $LCTL get_param -n \
3295 osp.$mdtosc_proc.reserved_mb_high ||
3296 skip "remote MDS does not support reserved_mb_high"
3299 wms=$(ost_watermarks_set_low_space $ost_idx)
3300 local new_lwm=$(echo $wms | awk '{ print $4 }')
3301 fill_ost $filename $ost_idx $new_lwm
3302 #First enospc could execute orphan deletion so repeat
3303 fill_ost $filename $ost_idx $new_lwm
3307 ost_watermarks_enospc_delete_files() {
3311 rm -f $DIR/${filename}.fill_ost$ost_idx
3313 wait_delete_completed
3317 # clean up from "ost_watermarks_set_enospc"
3318 ost_watermarks_clear_enospc() {
3324 ost_watermarks_enospc_delete_files $filename $ost_idx
3325 ost_watermarks_set $ost_idx $old_lwm $old_hwm
3326 echo "set OST$ost_idx lwm back to $old_lwm, hwm back to $old_hwm"
3329 wait_delete_completed_mds() {
3330 local max_wait=${1:-20}
3332 local stime=$(date +%s)
3337 # find MDS with pending deletions
3338 for node in $(mdts_nodes); do
3339 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
3340 2>/dev/null | calc_sum)
3341 if [[ $changes -eq 0 ]]; then
3344 mds2sync="$mds2sync $node"
3346 if [ -z "$mds2sync" ]; then
3347 wait_zfs_commit $SINGLEMDS
3350 mds2sync=$(comma_list $mds2sync)
3352 # sync MDS transactions
3353 do_nodes $mds2sync "$LCTL set_param -n os[cd]*.*MD*.force_sync 1"
3355 # wait till all changes are sent and commmitted by OSTs
3356 # for ldiskfs space is released upon execution, but DMU
3357 # do this upon commit
3360 while [[ $WAIT -ne $max_wait ]]; do
3361 changes=$(do_nodes $mds2sync \
3362 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
3363 #echo "$node: $changes changes on all"
3364 if [[ $changes -eq 0 ]]; then
3365 wait_zfs_commit $SINGLEMDS
3367 # the occupied disk space will be released
3368 # only after TXGs are committed
3369 wait_zfs_commit ost1
3377 echo "Delete is not completed in $((etime - stime)) seconds"
3378 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
3385 # we can use "for" here because we are waiting the slowest
3386 for host in ${hostlist//,/ }; do
3387 check_network "$host" 900
3389 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
3396 for facet in ${facetlist//,/ }; do
3397 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
3399 wait_for_host $hostlist
3402 _wait_recovery_complete () {
3405 # Use default policy if $2 is not passed by caller.
3406 local MAX=${2:-$(max_recovery_time)}
3411 while [ $WAIT -lt $MAX ]; do
3412 STATUS=$(lctl get_param -n $param | grep status)
3414 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
3417 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
3419 echo "$param recovery not done in $MAX sec. $STATUS"
3423 wait_recovery_complete () {
3426 # with an assumption that at_max is the same on all nodes
3427 local MAX=${2:-$(max_recovery_time)}
3430 if [ "$FAILURE_MODE" = HARD ]; then
3431 facets=$(facets_on_host $(facet_active_host $facet))
3433 echo affected facets: $facets
3435 facets=${facets//,/ }
3436 # We can use "for" here because we are waiting the slowest.
3437 # The mgs not having the recovery_status proc entry, exclude it
3438 # from the facet list.
3439 for facet in ${facets//mgs/ }; do
3440 local var_svc=${facet}_svc
3441 local param="*.${!var_svc}.recovery_status"
3443 local host=$(facet_active_host $facet)
3444 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
3448 wait_mds_ost_sync () {
3449 # just because recovery is done doesn't mean we've finished
3450 # orphan cleanup. Wait for llogs to get synchronized.
3451 echo "Waiting for orphan cleanup..."
3452 # MAX value includes time needed for MDS-OST reconnection
3453 local MAX=$(( TIMEOUT * 2 ))
3454 local WAIT_TIMEOUT=${1:-$MAX}
3457 local list=$(comma_list $(mdts_nodes))
3458 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
3459 if ! do_facet $SINGLEMDS \
3460 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
3462 # old way, use mds_sync
3464 list=$(comma_list $(osts_nodes))
3465 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
3468 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
3469 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
3470 local -a sync=($(do_nodes $list "$cmd"))
3473 for ((i=0; i<${#sync[@]}; i++)); do
3475 [ ${sync[$i]} -eq 1 ] && continue
3477 [ ${sync[$i]} -eq 0 ] && continue
3479 # there is a not finished MDS-OST synchronization
3483 sleep 2 # increase waiting time and cover statfs cache
3484 [ ${con} -eq 1 ] && return 0
3485 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
3489 # show which nodes are not finished.
3490 cmd=$(echo $cmd | sed 's/-n//')
3491 do_nodes $list "$cmd"
3492 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
3496 # Wait OSTs to be active on both client and MDT side.
3498 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
3499 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
3500 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
3501 error "wait_update OSTs up on client failed"
3503 cmd="$LCTL get_param osp.$FSNAME-OST*-MDT0000.prealloc_last_id |
3504 awk '/=[1-9][0-9]/ { c += 1 } END { printf \\\"%d\\\", c }'"
3505 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
3506 error "wait_update OSTs up on MDT0000 failed"
3509 wait_destroy_complete () {
3510 echo "Waiting for MDT destroys to complete"
3511 # MAX value shouldn't be big as this mean server responsiveness
3512 # never increase this just to make test pass but investigate
3513 # why it takes so long time
3516 local list=$(comma_list $(mdts_nodes))
3517 while [ $WAIT -lt $MAX ]; do
3518 local -a RPCs=($(do_nodes $list $LCTL get_param -n osp.*.destroys_in_flight))
3522 for ((i=0; i<${#RPCs[@]}; i++)); do
3523 [ ${RPCs[$i]} -eq 0 ] && continue
3524 # there are still some destroy RPCs in flight
3529 [ ${con} -eq 1 ] && return 0 # done waiting
3530 echo "Waiting ${WAIT}s for local destroys to complete"
3533 echo "MDT destroys weren't done in $MAX sec."
3537 wait_delete_completed() {
3538 wait_delete_completed_mds $1 || return $?
3539 wait_destroy_complete || return $?
3548 # conf-sanity 31 takes a long time cleanup
3549 while [ $WAIT -lt 300 ]; do
3550 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null &&
3551 lctl dl | grep ' ST ' || true")
3552 [ -z "${running}" ] && return 0
3553 echo "waited $WAIT for${running}"
3554 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
3556 WAIT=$((WAIT + INTERVAL))
3558 echo "service didn't stop after $WAIT seconds. Still running:"
3563 wait_remote_prog () {
3569 [ "$PDSH" = "no_dsh" ] && return 0
3571 while [ $WAIT -lt $2 ]; do
3572 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
3573 [ -z "${running}" ] && return 0 || true
3574 echo "waited $WAIT for: "
3576 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
3578 WAIT=$((WAIT + INTERVAL))
3580 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
3581 [ -z "$pids" ] && return 0
3582 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
3583 # FIXME: not portable
3584 for pid in $pids; do
3585 cat /proc/${pid}/status || true
3586 cat /proc/${pid}/wchan || true
3588 kill -9 $pid || true
3597 local clients=${1:-$CLIENTS}
3600 if [ -z "$clients" ]; then
3601 $LFS df $MOUNT > /dev/null || rc=$?
3603 $PDSH $clients "$LFS df $MOUNT" > /dev/null || rc=$?
3606 check_lfs_df_ret_val $rc
3610 # not every config has many clients
3616 (( MDSCOUNT == 1 )) && return
3618 # wait so that statfs data on MDT expire
3619 local delay=$(do_facet mds1 $LCTL \
3620 get_param -n osp.*MDT*MDT0000.maxage | sort -n | tail -1)
3622 [ -n "$delay" ] || error "fail to get maxage"
3624 local nodes=$(comma_list $(mdts_nodes))
3625 # initiate statfs RPC, all to all MDTs
3626 do_nodes $nodes $LCTL get_param -N osp.*MDT*MDT*.filesfree >&/dev/null
3627 do_nodes $nodes $LCTL get_param -N osp.*MDT*MDT*.filesfree >&/dev/null
3631 # usually checked on particular client or locally
3640 client_reconnect_try() {
3641 local f=$MOUNT/recon
3644 if [ -z "$CLIENTS" ]; then
3645 $LFS df $MOUNT; uname -n >> $f
3647 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
3649 echo "Connected clients: $(cat $f)"
3650 ls -l $f > /dev/null
3654 client_reconnect() {
3655 # one client_reconnect_try call does not always do the job...
3657 client_reconnect_try && break
3662 affected_facets () {
3665 local host=$(facet_active_host $facet)
3666 local affected=$facet
3668 if [ "$FAILURE_MODE" = HARD ]; then
3669 affected=$(facets_up_on_host $host)
3675 local E2FSCK_ON_MDT0=false
3676 if [ "$1" == "--fsck" ]; then
3678 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
3690 #Because it will only get up facets, we need get affected
3691 #facets before shutdown
3692 #For HARD Failure mode, it needs make sure facets on the same
3693 #HOST will only be shutdown and reboot once
3694 for facet in ${facets//,/ }; do
3695 local affected_facet
3697 #check whether facet has been included in other affected facets
3698 for ((index=0; index<$total; index++)); do
3699 [[ ,${affecteds[index]}, == *,$facet,* ]] && skip=1
3702 if [ $skip -eq 0 ]; then
3703 affecteds[$total]=$(affected_facets $facet)
3708 for ((index=0; index<$total; index++)); do
3709 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
3710 local host=$(facet_active_host $facet)
3711 echo "Failing ${affecteds[index]} on $host"
3712 shutdown_facet $facet
3715 echo "$(date +'%H:%M:%S (%s)') shut down"
3720 for facet in ${facets//,/ }; do
3721 local host=$(facet_active_host $facet)
3723 hostlist=$(expand_list $hostlist $host)
3724 if [ $(facet_host $facet) = \
3725 $(facet_failover_host $facet) ]; then
3726 waithostlist=$(expand_list $waithostlist $host)
3730 if [ "$FAILURE_MODE" = HARD ]; then
3731 for host in ${hostlist//,/ }; do
3734 echo "$(date +'%H:%M:%S (%s)') $hostlist rebooted"
3735 # We need to wait the rebooted hosts in case if
3736 # facet_HOST == facetfailover_HOST
3737 if ! [ -z "$waithostlist" ]; then
3738 wait_for_host $waithostlist
3739 if $LOAD_MODULES_REMOTE; then
3740 echo "loading modules on $waithostlist"
3741 do_rpc_nodes $waithostlist load_modules_local
3748 if [[ " ${affecteds[@]} " =~ " $SINGLEMDS " ]]; then
3749 change_active $SINGLEMDS
3752 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
3753 $(facet_device $SINGLEMDS) "-n" || error "Running e2fsck")
3757 for ((index=0; index<$total; index++)); do
3758 if [[ ${affecteds[index]} != $SINGLEMDS ]]; then
3759 change_active ${affecteds[index]}
3763 init_facets_vars_simple
3765 # start mgs first if it is affected
3766 if ! combined_mgs_mds &&
3767 list_member ${affecteds[index]} mgs; then
3768 mount_facet mgs || error "Restart of mgs failed"
3769 affecteds[index]=$(exclude_items_from_list \
3770 ${affecteds[index]} mgs)
3772 if [ -n "${affecteds[index]}" ]; then
3773 echo mount facets: ${affecteds[index]}
3774 mount_facets ${affecteds[index]} &
3778 for ((index=0; index<$total; index++)); do
3779 if [ -n "${affecteds[index]}" ]; then
3780 wait ${mountpids[index]}
3784 do_nodes $(comma_list $(all_nodes)) \
3785 "keyctl show | grep lustre | cut -c1-11 |
3787 xargs -IX keyctl setperm X 0x3f3f3f3f"
3790 echo "$(date +'%H:%M:%S (%s)') targets are mounted"
3792 if [ "$FAILURE_MODE" = HARD ]; then
3793 hostlist=$(exclude_items_from_list $hostlist $waithostlist)
3794 if ! [ -z "$hostlist" ]; then
3795 wait_for_host $hostlist
3796 if $LOAD_MODULES_REMOTE; then
3797 echo "loading modules on $hostlist"
3798 do_rpc_nodes $hostlist load_modules_local
3803 echo "$(date +'%H:%M:%S (%s)') facet_failover done"
3808 do_facet $facet "sync; sync; sync"
3811 # make sure there will be no seq change
3812 local clients=${CLIENTS:-$HOSTNAME}
3813 local f=fsa-\\\$\(hostname\)
3814 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
3815 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
3817 local svc=${facet}_svc
3818 do_facet $facet $LCTL --device ${!svc} notransno
3820 # If a ZFS OSD is made read-only here, its pool is "freezed". This
3821 # in-memory state has to be cleared by either rebooting the host or
3822 # exporting and reimporting the pool.
3824 # Although the uberblocks are not updated when a pool is freezed,
3825 # transactions are still written to the disks. Modified blocks may be
3826 # cached in memory when tests try reading them back. The
3827 # export-and-reimport process also evicts any cached pool data from
3828 # memory to provide the correct "data loss" semantics.
3830 # In the test framework, the exporting and importing operations are
3831 # handled by stop() and mount_facet() separately, which are used
3832 # inside fail() and fail_abort().
3834 set_dev_readonly $facet
3835 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
3836 $LCTL mark "local REPLAY BARRIER on ${!svc}"
3839 replay_barrier_nodf() {
3840 local facet=$1 echo running=${running}
3841 do_facet $facet "sync; sync; sync"
3842 local svc=${facet}_svc
3843 echo Replay barrier on ${!svc}
3844 do_facet $facet $LCTL --device ${!svc} notransno
3845 set_dev_readonly $facet
3846 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
3847 $LCTL mark "local REPLAY BARRIER on ${!svc}"
3850 replay_barrier_nosync() {
3851 local facet=$1 echo running=${running}
3852 local svc=${facet}_svc
3853 echo Replay barrier on ${!svc}
3854 do_facet $facet $LCTL --device ${!svc} notransno
3855 set_dev_readonly $facet
3856 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
3857 $LCTL mark "local REPLAY BARRIER on ${!svc}"
3861 # Get Lustre client uuid for a given Lustre mount point.
3864 local mntpnt=${1:-$MOUNT}
3866 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
3867 local uuid=$($LCTL get_param -n llite.$name.uuid)
3872 mds_evict_client() {
3873 local mntpnt=${1:-$MOUNT}
3874 local uuid=$(get_client_uuid $mntpnt)
3876 do_facet $SINGLEMDS \
3877 "$LCTL set_param -n mdt.${mds1_svc}.evict_client $uuid"
3880 ost_evict_client() {
3881 local mntpnt=${1:-$MOUNT}
3882 local uuid=$(get_client_uuid $mntpnt)
3885 "$LCTL set_param -n obdfilter.${ost1_svc}.evict_client $uuid"
3890 local clients=${CLIENTS:-$HOSTNAME}
3892 SK_NO_KEY_save=$SK_NO_KEY
3894 export SK_NO_KEY=false
3896 facet_failover $* || error "failover: $?"
3897 export SK_NO_KEY=$SK_NO_KEY_save
3898 # to initiate all OSC idling connections
3900 wait_clients_import_state "$clients" "$facets" "\(FULL\|IDLE\)"
3901 clients_up || error "post-failover stat: $?"
3907 facet_failover $facet
3912 local abort_type=${2:-"abort_recovery"}
3915 change_active $facet
3916 wait_for_facet $facet
3917 mount_facet $facet -o $abort_type
3918 clients_up || echo "first stat failed: $?"
3919 clients_up || error "post-failover stat: $?"
3923 host_nids_address() {
3927 do_nodes $nodes "$LCTL list_nids | grep -w $net | cut -f 1 -d @"
3931 if [ "$1" = "'*'" ]; then echo \'*\'; else
3937 if [[ -n "$NETTYPE" ]]; then
3938 h2name_or_ip "$1" "$NETTYPE"
3940 h2name_or_ip "$1" "$2"
3943 declare -fx h2nettype
3945 # Wrapper function to print the deprecation warning
3947 echo "h2tcp: deprecated, use h2nettype instead" 1>&2
3948 if [[ -n "$NETTYPE" ]]; then
3951 h2nettype "$1" "tcp"
3955 # Wrapper function to print the deprecation warning
3957 echo "h2o2ib: deprecated, use h2nettype instead" 1>&2
3958 if [[ -n "$NETTYPE" ]]; then
3961 h2nettype "$1" "o2ib"
3965 # This enables variables in cfg/"setup".sh files to support the pdsh HOSTLIST
3966 # expressions format. As a bonus we can then just pass in those variables
3967 # to pdsh. What this function does is take a HOSTLIST type string and
3968 # expand it into a space deliminated list for us.
3976 [ -z "$hostlist" ] && return
3978 # Translate the case of [..],..,[..] to [..] .. [..]
3979 list="${hostlist/],/] }"
3981 [[ "$front" == *,* ]] && {
3984 list=${list/${old}/${new}}
3987 for item in $list; do
3988 # Test if we have any []'s at all
3989 if [ "$item" != "${item/\[/}" ]; then {
3990 # Expand the [*] into list
3994 if [ "$name" != "$item" ]; then
3995 group=${item#$name[*}
3998 for range in ${group//,/ }; do
4004 # Number of leading zeros
4007 end=$(echo $end | sed 's/0*//')
4008 [[ -z "$end" ]] && end=0
4009 [[ $padlen2 -gt $padlen ]] && {
4010 [[ $padlen2 -eq ${#end} ]] && padlen2=0
4013 begin=$(echo $begin | sed 's/0*//')
4014 [ -z $begin ] && begin=0
4016 if [ ! -z "${begin##[!0-9]*}" ]; then
4017 order=$(seq -f "%0${padlen}g" $begin $end)
4019 order=$(eval echo {$begin..$end});
4022 for num in $order; do
4023 value="${name#*,}${num}${back}"
4024 [ "$value" != "${value/\[/}" ] && {
4025 value=$(hostlist_expand "$value")
4027 myList="$myList $value"
4032 myList="$myList $item"
4035 myList=${myList//,/ }
4036 myList=${myList:1} # Remove first character which is a space
4038 # Filter any duplicates without sorting
4040 myList="${list%% *}"
4042 while [[ "$list" != ${myList##* } ]]; do
4043 local tlist=" $list"
4044 list=${tlist// ${list%% *} / }
4046 myList="$myList ${list%% *}"
4048 myList="${myList%* }";
4050 # We can select an object at an offset in the list
4053 for item in $myList; do
4055 [ $cnt -eq $offset ] && {
4059 [ $(get_node_count $myList) -ne 1 ] && myList=""
4068 [ "$facet" == client ] && echo -n $HOSTNAME && return
4069 varname=${facet}_HOST
4070 if [ -z "${!varname}" ]; then
4071 if [ "${facet:0:3}" == "ost" ]; then
4072 local fh=${facet%failover}_HOST
4073 eval export ${facet}_HOST=${!fh}
4074 if [ -z "${!varname}" ]; then
4075 eval export ${facet}_HOST=${ost_HOST}
4077 elif [ "${facet:0:3}" == "mdt" -o \
4078 "${facet:0:3}" == "mds" -o \
4079 "${facet:0:3}" == "mgs" ]; then
4081 if [ "${facet}" == "mgsfailover" ] &&
4082 [ -n "$mds1failover_HOST" ]; then
4083 temp=$mds1failover_HOST
4087 eval export ${facet}_HOST=$temp
4093 facet_failover_host() {
4097 var=${facet}failover_HOST
4098 if [ -n "${!var}" ]; then
4103 if combined_mgs_mds && [ $facet == "mgs" ] &&
4104 [ -n "$mds1failover_HOST" ]; then
4105 echo $mds1failover_HOST
4109 if [ "${facet:0:3}" == "mdt" -o "${facet:0:3}" == "mds" -o \
4110 "${facet:0:3}" == "mgs" ]; then
4112 eval export ${facet}failover_host=${mds_HOST}
4117 if [[ $facet == ost* ]]; then
4118 eval export ${facet}failover_host=${ost_HOST}
4126 local activevar=${facet}active
4128 if [ -f $TMP/${facet}active ] ; then
4129 source $TMP/${facet}active
4132 active=${!activevar}
4133 if [ -z "$active" ] ; then
4140 facet_active_host() {
4141 facet_host $(facet_active $1)
4144 # Get the passive failover partner host of facet.
4145 facet_passive_host() {
4147 [[ $facet = client ]] && return
4149 local host=${facet}_HOST
4150 local failover_host=${facet}failover_HOST
4151 local active_host=$(facet_active_host $facet)
4153 [[ -z ${!failover_host} || ${!failover_host} = ${!host} ]] && return
4155 if [[ $active_host = ${!host} ]]; then
4156 echo -n ${!failover_host}
4166 for facet in ${facetlist//,/ }; do
4167 local failover=${facet}failover
4168 local host=`facet_host $failover`
4169 [ -z "$host" ] && return
4171 local curactive=`facet_active $facet`
4172 if [ -z "${curactive}" -o "$curactive" == "$failover" ] ; then
4173 eval export ${facet}active=$facet
4175 eval export ${facet}active=$failover
4177 # save the active host for this facet
4178 local activevar=${facet}active
4179 echo "$activevar=${!activevar}" > $TMP/$activevar
4180 [[ $facet = mds1 ]] && combined_mgs_mds && \
4181 echo "mgsactive=${!activevar}" > $TMP/mgsactive
4182 local TO=`facet_active_host $facet`
4183 echo "Failover $facet to $TO"
4191 # do not strip off hostname if verbose, b=19215
4192 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4193 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4199 if [ "$HOST" = "$HOSTNAME" ]; then
4201 elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
4202 echo "cannot run remote command on $HOST with $myPDSH"
4205 if $VERBOSE && [[ -z "$quiet" ]]; then
4206 echo "CMD: $HOST $@" >&2
4207 $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
4210 if [[ "$myPDSH" == "rsh" ]] ||
4211 [[ "$myPDSH" == *pdsh* && "$myPDSH" != *-S* ]]; then
4212 # we need this because rsh and pdsh do not return
4213 # exit code of an executed command
4214 local command_status="$TMP/cs"
4215 eval $myPDSH $HOST ":> $command_status"
4216 eval $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests;
4217 PATH=\$PATH:/sbin:/usr/sbin;
4219 LUSTRE=\"$RLUSTRE\" bash -c \"$@\") ||
4220 echo command failed >$command_status"
4221 [[ -n "$($myPDSH $HOST cat $command_status)" ]] && return 1 ||
4225 if [[ -n "$verbose" ]]; then
4226 # print HOSTNAME for myPDSH="no_dsh"
4227 if [[ $myPDSH = no_dsh ]]; then
4229 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4230 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$@\")" |
4231 sed -e "s/^/${HOSTNAME}: /"
4234 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4235 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$@\")"
4239 "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin;\
4240 cd $RPWD; LUSTRE=\"$RLUSTRE\" bash -c \"$@\")" |
4241 sed "s/^${HOST}: //"
4243 return ${PIPESTATUS[0]}
4247 # Execute exact command line on host
4249 # The \a host may be on a local or remote node, which is determined at
4250 # the time the command is run. Does careful argument quotation to
4251 # ensure that the exact command line is executed without any globbing,
4252 # substitution, or shell interpretation on the remote side. Does not
4253 # support --verbose or --quiet. Does not include "$host: " prefixes on
4254 # output. See also do_facet_vp().
4256 # usage: do_node_vp "$host" "$command" "$arg"...
4261 if [[ "$host" == "$HOSTNAME" ]]; then
4262 sh -c "$(printf -- ' %q' "$@")"
4266 if [[ "${PDSH}" != *pdsh* || "${PDSH}" != *-S* ]]; then
4267 echo "cannot run '$*' on host '${host}' with PDSH='${PDSH}'" >&2
4271 # -N Disable hostname: prefix on lines of output.
4273 $PDSH "${host}" -N "cd $RPWD; PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; export LUSTRE=$RLUSTRE; $(printf -- ' %q' "$@")"
4276 single_local_node () {
4277 [ "$1" = "$HOSTNAME" ]
4280 # Outputs environment variable assignments that should be passed to remote nodes
4284 local facets=$(get_facets)
4287 for var in ${!MODOPTS_*}; do
4288 value=${!var//\"/\\\"}
4289 echo -n " ${var}=\"$value\""
4292 for facet in ${facets//,/ }; do
4294 if [ -n "${!var}" ]; then
4295 echo -n " $var=${!var}"
4299 for var in MGSFSTYPE MDSFSTYPE OSTFSTYPE; do
4300 if [ -n "${!var}" ]; then
4301 echo -n " $var=${!var}"
4305 for var in VERBOSE; do
4306 if [ -n "${!var}" ]; then
4307 echo -n " $var=${!var}"
4311 if [ -n "$FSTYPE" ]; then
4312 echo -n " FSTYPE=$FSTYPE"
4315 for var in LNETLND NETTYPE; do
4316 if [ -n "${!var}" ]; then
4317 echo -n " $var=${!var}"
4326 # do not strip off hostname if verbose, b=19215
4327 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4328 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4333 if single_local_node $rnodes; then
4334 do_node $verbose $quiet $rnodes "$@"
4338 # This is part from do_node
4341 [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] &&
4342 echo "cannot run remote command on $rnodes with $myPDSH" &&
4345 export FANOUT=$(get_node_count "${rnodes//,/ }")
4346 if $VERBOSE && [[ -z "$quiet" ]]; then
4347 echo "CMD: $rnodes $@" >&2
4348 $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
4351 # do not replace anything from pdsh output if -N is used
4352 # -N Disable hostname: prefix on lines of output.
4353 if [[ -n "$verbose" || $myPDSH = *-N* ]]; then
4354 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) bash -c \"$@\")"
4356 $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) bash -c \"$@\")" | sed -re "s/^[^:]*: //g"
4358 return ${PIPESTATUS[0]}
4362 # Execute commands on a single service's host
4364 # The \a facet (service) may be on a local or remote node, which is
4365 # determined at the time the command is run.
4367 # usage: do_facet $facet command [arg ...]
4372 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
4373 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
4377 local host=$(facet_active_host $facet)
4379 [ -z "$host" ] && echo "No host defined for facet ${facet}" && exit 1
4380 do_node $verbose $quiet $host "$@"
4384 # Execute exact command line on the host of a facet
4386 # The \a facet (service) may be on a local or remote node, which is
4387 # determined at the time the command is run. Does careful argument
4388 # quotation to ensure that the exact command line is executed without
4389 # any globbing, substitution, or shell interpretation on the remote
4390 # side. Does not support --verbose or --quiet. Does not include
4391 # "$host: " prefixes on output.
4393 # usage: do_facet_vp "$facet" "$command" "$arg"...
4396 local host=$(facet_active_host "$facet")
4399 if [[ -z "$host" ]]; then
4400 echo "no host defined for facet ${facet}" >&2
4404 do_node_vp "$host" "$@"
4407 # Function: do_facet_random_file $FACET $FILE $SIZE
4408 # Creates FILE with random content on the given FACET of given SIZE
4410 do_facet_random_file() {
4414 local cmd="dd if=/dev/urandom of='$fpath' bs=$fsize count=1"
4415 do_facet $facet "$cmd 2>/dev/null"
4418 do_facet_create_file() {
4422 local cmd="dd if=/dev/zero of='$fpath' bs=$fsize count=1"
4423 do_facet $facet "$cmd 2>/dev/null"
4427 do_nodes --verbose "$@"
4433 # make sure its not already running
4435 rm -f $TMP/${facet}active
4436 [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
4438 # make sure in-tree ldiskfs is loaded before mkfs
4439 if local_mode && [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
4440 load_module ../ldiskfs/ldiskfs
4443 do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
4445 if [[ $(facet_fstype $facet) == zfs ]]; then
4447 # After formatting a ZFS target, "cachefile=none" property will
4448 # be set on the ZFS storage pool so that the pool is not
4449 # automatically imported on system startup. And then the pool
4450 # will be exported so as to leave the importing and exporting
4451 # operations handled by mount_facet() and stop() separately.
4453 refresh_partition_table $facet $(facet_vdevice $facet)
4454 disable_zpool_cache $facet
4459 # Device formatted as ost
4462 local DEVNAME=OSTDEV$num
4464 local fstype=$(facet_fstype ost$num)
4468 local dev=ost${num}_dev
4469 [[ -n ${!dev} ]] && eval DEVPTR=${!dev} ||
4470 #if $OSTDEVn isn't defined, default is $OSTDEVBASE + num
4471 eval DEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
4473 #try $OSTZFSDEVn - independent of vdev
4474 DEVNAME=OSTZFSDEV$num
4475 eval DEVPTR=${!DEVNAME:=${FSNAME}-ost${num}/ost${num}};;
4477 error "unknown fstype!";;
4483 # Physical device location of data
4489 local fstype=$(facet_fstype ost$num)
4493 # vdevs are not supported by ldiskfs
4496 #if $OSTDEVn isn't defined, default is $OSTDEVBASE{n}
4497 # Device formatted by zfs
4499 eval VDEVPTR=${!DEVNAME:=${OSTDEVBASE}${num}};;
4501 error "unknown fstype!";;
4507 # Logical device formatted for lustre
4510 local DEVNAME=MDSDEV$num
4512 local fstype=$(facet_fstype mds$num)
4516 local dev=mds${num}_dev
4517 [[ -n ${!dev} ]] && eval DEVPTR=${!dev} ||
4518 #if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
4519 eval DEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
4521 # try $MDSZFSDEVn - independent of vdev
4522 DEVNAME=MDSZFSDEV$num
4523 eval DEVPTR=${!DEVNAME:=${FSNAME}-mdt${num}/mdt${num}};;
4525 error "unknown fstype!";;
4531 # Physical location of data
4535 local fstype=$(facet_fstype mds$num)
4539 # vdevs are not supported by ldiskfs
4542 # if $MDSDEVn isn't defined, default is $MDSDEVBASE{n}
4543 # Device formatted by ZFS
4544 local DEVNAME=MDSDEV$num
4545 eval VDEVPTR=${!DEVNAME:=${MDSDEVBASE}${num}};;
4547 error "unknown fstype!";;
4555 local fstype=$(facet_fstype mgs)
4559 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4560 ( [ -z "$MGSDEV" ] || [ $MGSDEV = $MDSDEV1 ] ); then
4561 DEVPTR=$(mdsdevname 1)
4563 [[ -n $mgs_dev ]] && DEVPTR=$mgs_dev ||
4567 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4568 ( [ -z "$MGSZFSDEV" ] &&
4569 [ -z "$MGSDEV" -o "$MGSDEV" = $(mdsvdevname 1) ] ); then
4570 DEVPTR=$(mdsdevname 1)
4572 DEVPTR=${MGSZFSDEV:-${FSNAME}-mgs/mgs}
4575 error "unknown fstype!";;
4584 local fstype=$(facet_fstype mgs)
4588 # vdevs are not supported by ldiskfs
4591 if [ $(facet_host mgs) = $(facet_host mds1) ] &&
4592 ( [ -z "$MGSDEV" ] &&
4593 [ -z "$MGSZFSDEV" -o "$MGSZFSDEV" = $(mdsdevname 1) ]); then
4594 VDEVPTR=$(mdsvdevname 1)
4595 elif [ -n "$MGSDEV" ]; then
4599 error "unknown fstype!";;
4607 [[ $facet = mgs ]] && combined_mgs_mds && facet="mds1"
4609 local var=${facet}_MOUNT
4610 eval mntpt=${!var:-${MOUNT}-$facet}
4617 local dev=$(facet_device $facet)
4618 local mnt=${2:-$(facet_mntpt $facet)}
4622 if dm_flakey_supported $facet; then
4623 dm_dev=$(dm_create_dev $facet $dev)
4624 [[ -n "$dm_dev" ]] || dm_dev=$dev
4626 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
4627 export_dm_dev $facet $dm_dev
4629 do_facet $facet mount -t ldiskfs $opts $dm_dev $mnt
4634 local dev=$(facet_device $facet)
4635 local mnt=${2:-$(facet_mntpt $facet)}
4637 do_facet $facet $UMOUNT $mnt
4641 echo -n "$1" | tr -c '[:alnum:]\n' '_'
4646 local ds=$(facet_device $facet)
4647 local mnt=${2:-$(facet_mntpt $facet)}
4652 canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
4653 mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
4654 do_facet $facet $ZFS set canmount=noauto $ds
4656 # The "legacy" mount method is used here because "zfs unmount $mnt"
4657 # calls stat(2) on $mnt/../*, which may include $MOUNT. If certain
4658 # targets are not available at the time, the stat(2) on $MOUNT will
4661 do_facet $facet $ZFS set mountpoint=legacy $ds
4662 do_facet $facet mount -t zfs $ds $mnt
4663 eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
4664 eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
4669 local ds=$(facet_device $facet)
4670 local mnt=${2:-$(facet_mntpt $facet)}
4671 local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
4672 local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
4673 local mntpt=${!var_mntpt}
4674 local canmnt=${!var_canmnt}
4678 do_facet $facet umount $mnt
4679 do_facet $facet $ZFS set mountpoint=$mntpt $ds
4680 do_facet $facet $ZFS set canmount=$canmnt $ds
4687 local fstype=$(facet_fstype $facet)
4689 mount_$fstype $facet $mnt
4695 local fstype=$(facet_fstype $facet)
4697 unmount_$fstype $facet $mnt
4704 # make sure we are using the primary server, so test-framework will
4705 # be able to clean up properly.
4706 activemds=`facet_active mds1`
4707 if [ $activemds != "mds1" ]; then
4711 local clients=$CLIENTS
4712 [ -z $clients ] && clients=$(hostname)
4714 zconf_umount_clients $clients $MOUNT "$*" || true
4715 [ -n "$MOUNT2" ] && zconf_umount_clients $clients $MOUNT2 "$*" || true
4717 [ -n "$CLIENTONLY" ] && return
4719 # The add fn does rm ${facet}active file, this would be enough
4720 # if we use do_facet <facet> only after the facet added, but
4721 # currently we use do_facet mds in local.sh
4723 for num in `seq $MDSCOUNT`; do
4725 rm -f ${TMP}/mds${num}active
4727 combined_mgs_mds && rm -f $TMP/mgsactive
4729 for num in `seq $OSTCOUNT`; do
4731 rm -f $TMP/ost${num}active
4734 if ! combined_mgs_mds ; then
4738 if $SHARED_KEY; then
4739 export SK_MOUNTED=false
4745 cleanup_echo_devs () {
4748 local devs=$($LCTL dl | grep echo | awk '{print $4}')
4750 for dev in $devs; do
4751 $LCTL --device $dev cleanup
4752 $LCTL --device $dev detach
4757 nfs_client_mode && return
4758 cifs_client_mode && return
4761 CLEANUP_DM_DEV=true stopall $*
4768 combined_mgs_mds () {
4769 [[ "$(mdsdevname 1)" = "$(mgsdevname)" ]] &&
4770 [[ "$(facet_host mds1)" = "$(facet_host mgs)" ]]
4774 echo -n "$1" | tr '[:upper:]' '[:lower:]'
4778 echo -n "$1" | tr '[:lower:]' '[:upper:]'
4790 var=$(echo "$var" | sed -e 's/,\( \)*/,/g')
4791 for i in $(echo "$var"); do
4792 if [ "$i" == "-O" ]; then
4794 first_o=$(($first_o + 1))
4797 if [ "$i" == "-E" ]; then
4799 first_e=$(($first_e + 1 ))
4804 [ $first_o -gt 1 ] && opt_o+=",";
4808 [ $first_e -gt 1 ] && opt_e+=",";
4819 [ -n "$opt_o" ] && echo " -O $opt_o"
4820 [ -n "$opt_e" ] && echo " -E $opt_e"
4826 local fsname=${3:-"$FSNAME"}
4827 local type=$(facet_type $facet)
4828 local index=$(facet_index $facet)
4829 local fstype=$(facet_fstype $facet)
4830 local host=$(facet_host $facet)
4834 local varbs=${facet}_BLOCKSIZE
4836 if [ $type == MGS ] || ( [ $type == MDS ] &&
4837 [ "$dev" == $(mgsdevname) ] &&
4838 [ "$host" == "$(facet_host mgs)" ] ); then
4841 opts="--mgsnode=$MGSNID"
4844 if [ $type != MGS ]; then
4845 opts+=" --fsname=$fsname --$(lower ${type/MDS/MDT}) \
4849 var=${facet}failover_HOST
4850 if [ -n "${!var}" ] && [ ${!var} != $(facet_host $facet) ]; then
4851 opts+=" --failnode=$(h2nettype ${!var})"
4854 opts+=${TIMEOUT:+" --param=sys.timeout=$TIMEOUT"}
4855 opts+=${LDLM_TIMEOUT:+" --param=sys.ldlm_timeout=$LDLM_TIMEOUT"}
4857 if [ $type == MDS ]; then
4858 opts+=${DEF_STRIPE_SIZE:+" --param=lov.stripesize=$DEF_STRIPE_SIZE"}
4859 opts+=${DEF_STRIPE_COUNT:+" --param=lov.stripecount=$DEF_STRIPE_COUNT"}
4860 opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
4862 if [ $fstype == ldiskfs ]; then
4864 if [ -n "${!var}" ]; then
4865 fs_mkfs_opts+=" -J device=${!var}"
4867 fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
4869 fs_mkfs_opts+=${MDSISIZE:+" -i $MDSISIZE"}
4873 if [ $type == OST ]; then
4874 if [ $fstype == ldiskfs ]; then
4876 if [ -n "${!var}" ]; then
4877 fs_mkfs_opts+=" -J device=${!var}"
4879 fs_mkfs_opts+=${OSTJOURNALSIZE:+" -J size=$OSTJOURNALSIZE"}
4884 opts+=" --backfstype=$fstype"
4887 if [ -n "${!var}" ]; then
4888 opts+=" --device-size=${!var}"
4891 var=$(upper $fstype)_MKFS_OPTS
4892 fs_mkfs_opts+=${!var:+" ${!var}"}
4894 var=${type}_FS_MKFS_OPTS
4895 fs_mkfs_opts+=${!var:+" ${!var}"}
4897 [[ "$QUOTA_TYPE" =~ "p" ]] && fs_mkfs_opts+=" -O project"
4899 [ $fstype == ldiskfs ] && fs_mkfs_opts+=" -b ${!varbs:-$BLCKSIZE}"
4900 [ $fstype == ldiskfs ] && fs_mkfs_opts=$(squash_opt $fs_mkfs_opts)
4902 if [ -n "${fs_mkfs_opts## }" ]; then
4903 opts+=" --mkfsoptions=\\\"${fs_mkfs_opts## }\\\""
4907 opts+=${!var:+" ${!var}"}
4914 local type=$(facet_type $facet)
4915 local var=${type}_MOUNT_FS_OPTS
4917 if [ -n "${!var}" ]; then
4918 opts+=" --mountfsoptions=${!var}"
4923 check_ost_indices() {
4924 local index_count=${#OST_INDICES[@]}
4925 [[ $index_count -eq 0 || $OSTCOUNT -le $index_count ]] && return 0
4927 # OST count is greater than the index count in $OST_INDEX_LIST.
4928 # We need check whether there are duplicate indices.
4932 for i in $(seq $((index_count + 1)) $OSTCOUNT); do
4933 index=$(facet_index ost$i)
4934 for j in $(seq 0 $((index_count - 1))); do
4935 [[ $index -ne ${OST_INDICES[j]} ]] ||
4936 error "ost$i has the same index $index as ost$((j+1))"
4943 local facet_type=$1 # mgs || mds || ost
4945 local facet=${1}${2}
4948 case "$(facet_fstype $facet)" in
4950 device=$(${facet_type}devname $facet_num)
4953 device=$(${facet_type}vdevname $facet_num)
4956 error "Unhandled filesystem type"
4960 do_facet $facet "[ -e \"$device\" ]" && return
4962 # Note: the following check only works with absolute paths
4963 [[ ! "$device" =~ ^/dev/ ]] || [[ "$device" =~ ^/dev/shm/ ]] ||
4964 error "$facet: device '$device' does not exist"
4966 # zpool create doesn't like empty files
4967 [[ $(facet_fstype $facet) == zfs ]] && return 0
4969 do_facet $facet "touch \"${device}\""
4978 echo "Format mgs: $(mgsdevname)"
4979 reformat_external_journal mgs
4981 # touch "device" in case it is a loopback file for testing and needs to
4982 # be created. mkfs.lustre doesn't do this to avoid accidentally writing
4983 # to non-existent files in /dev if the admin made a typo during setup
4986 add mgs $(mkfs_opts mgs $(mgsdevname)) $(mountfs_opts mgs) --reformat \
4987 $(mgsdevname) $(mgsvdevname) ${quiet:+>/dev/null} || exit 10
4997 echo "Format mds$num: $(mdsdevname $num)"
4998 reformat_external_journal mds$num
5000 __touch_device mds $num
5002 add mds$num $(mkfs_opts mds$num $(mdsdevname ${num})) \
5003 $(mountfs_opts mds$num) --reformat $(mdsdevname $num) \
5004 $(mdsvdevname $num) ${quiet:+>/dev/null} || exit 10
5013 echo "Format ost$num: $(ostdevname $num)"
5014 reformat_external_journal ost$num
5016 __touch_device ost $num
5018 add ost$num $(mkfs_opts ost$num $(ostdevname ${num})) \
5019 $(mountfs_opts ost$num) --reformat $(ostdevname $num) \
5020 $(ostvdevname ${num}) ${quiet:+>/dev/null} || exit 10
5025 # Set hostid for ZFS/SPL zpool import protection
5026 # (Assumes MDS version is also OSS version)
5027 if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ];
5029 do_rpc_nodes "$(comma_list $(all_server_nodes))" set_hostid
5032 # We need ldiskfs here, may as well load them all
5034 [ -n "$CLIENTONLY" ] && return
5035 echo Formatting mgs, mds, osts
5036 if ! combined_mgs_mds ; then
5040 for num in $(seq $MDSCOUNT); do
5044 export OST_INDICES=($(hostlist_expand "$OST_INDEX_LIST"))
5046 for num in $(seq $OSTCOUNT); do
5052 grep " $1 " /proc/mounts || zconf_mount $HOSTNAME $*
5056 grep " $1 " /proc/mounts && zconf_umount $HOSTNAME $*
5060 # 0: success, the old identity set already.
5061 # 1: success, the old identity does not set.
5066 local j=`expr $num - 1`
5067 local MDT="`(do_facet mds$num lctl get_param -N mdt.*MDT*$j 2>/dev/null | cut -d"." -f2 2>/dev/null) || true`"
5069 if [ -z "$MDT" ]; then
5073 local old="`do_facet mds$num "lctl get_param -n mdt.$MDT.identity_upcall"`"
5076 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"$L_GETIDENTITY\""
5078 do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
5081 do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
5083 if [ $old = "NONE" ]; then
5092 zconf_umount $HOSTNAME $1 || error "umount failed"
5093 zconf_mount $HOSTNAME $1 || error "mount failed"
5101 rm -f $TMP/${facet}active
5102 do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" || return 1
5107 local mdt_count=${1:-$MDSCOUNT}
5108 local ost_count=${2:-$OSTCOUNT}
5111 for num in $(seq $mdt_count); do
5112 DEVNAME=$(mdsdevname $num)
5113 writeconf_facet mds$num $DEVNAME || rc=$?
5116 for num in $(seq $ost_count); do
5117 DEVNAME=$(ostdevname $num)
5118 writeconf_facet ost$num $DEVNAME || rc=$?
5124 if ! combined_mgs_mds ; then
5125 start mgs $(mgsdevname) $MGS_MOUNT_OPTS
5134 for num in $(seq $MDSCOUNT); do
5135 devname=$(mdsdevname $num)
5136 start mds$num $devname $MDS_MOUNT_OPTS
5138 # We started mds$num, now we should set mds${num}_HOST
5139 # and mds${num}failover_HOST variables properly if they
5141 host=$(facet_host mds$num)
5142 for varname in mds${num}_HOST mds${num}failover_HOST; do
5143 if [[ -z "${!varname}" ]]; then
5147 if [ $IDENTITY_UPCALL != "default" ]; then
5148 switch_identity $num $IDENTITY_UPCALL
5158 for num in $(seq $OSTCOUNT); do
5159 devname=$(ostdevname $num)
5160 start ost$num $devname $OST_MOUNT_OPTS
5162 # We started ost$num, now we should set ost${num}_HOST
5163 # and ost${num}failover_HOST variables properly if they
5165 host=$(facet_host ost$num)
5166 for varname in ost${num}_HOST ost${num}failover_HOST; do
5167 if [[ -z "${!varname}" ]]; then
5175 [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
5176 if [ ! -z $arg1 ]; then
5177 [ "$arg1" = "server_only" ] && return
5180 if [ -n "$CLIENTS" ]; then
5181 zconf_mount_clients $CLIENTS $MOUNT
5185 if [ "$MOUNT_2" ]; then
5186 mount_client $MOUNT2
5187 if [ -n "$CLIENTS" ]; then
5188 zconf_mount_clients $CLIENTS $MOUNT2
5193 sk_nodemap_setup() {
5194 local sk_map_name=${1:-$SK_S2SNM}
5195 local sk_map_nodes=${2:-$HOSTNAME}
5196 do_node $(mgs_node) "$LCTL nodemap_add $sk_map_name"
5197 for servernode in $sk_map_nodes; do
5198 local nids=$(do_nodes $servernode "$LCTL list_nids")
5199 for nid in $nids; do
5200 do_node $(mgs_node) "$LCTL nodemap_add_range --name \
5201 $sk_map_name --range $nid"
5209 nfs_client_mode && return
5210 cifs_client_mode && return
5212 sanity_mount_check || error "environments are insane!"
5218 if [ -z "$CLIENTONLY" ]; then
5219 echo Setup mgs, mdt, osts
5220 echo $WRITECONF | grep -q "writeconf" && writeconf_all
5222 if $SK_MOUNTED; then
5223 echo "Shared Key file system already mounted"
5228 if $SHARED_KEY; then
5229 export SK_MOUNTED=true
5233 echo "GSS_SK: setting kernel keyring perms"
5234 do_nodes $(comma_list $(all_nodes)) \
5235 "keyctl show | grep lustre | cut -c1-11 |
5237 xargs -IX keyctl setperm X 0x3f3f3f3f"
5240 # Need to start one nodemap for servers,
5241 # and one for clients.
5242 sk_nodemap_setup $SK_S2SNM \
5243 $(comma_list $(all_server_nodes))
5245 sk_nodemap_setup $SK_S2SNMCLI \
5246 ${CLIENTS:-$HOSTNAME}
5247 echo "Nodemap set up for SK S2S, remounting."
5256 # wait a while to allow sptlrpc configuration be propogated to targets,
5257 # only needed when mounting new target devices.
5265 # by remounting mdt before ost, initial connect from mdt to ost might
5266 # timeout because ost is not ready yet. wait some time to its fully
5267 # recovery. initial obd_connect timeout is 5s; in GSS case it's
5268 # preceeded by a context negotiation rpc with $TIMEOUT.
5269 # FIXME better by monitoring import status.
5272 set_rule $FSNAME any cli2mdt $SK_FLAVOR
5273 set_rule $FSNAME any cli2ost $SK_FLAVOR
5274 if $SK_SKIPFIRST; then
5275 export SK_SKIPFIRST=false
5279 "lctl set_param osc.*.idle_connect=1"
5282 wait_flavor cli2mdt $SK_FLAVOR
5283 wait_flavor cli2ost $SK_FLAVOR
5288 sleep $((TIMEOUT + 5))
5294 mounted_lustre_filesystems() {
5295 awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
5298 init_facet_vars () {
5299 [ -n "$CLIENTONLY" ] && return 0
5306 eval export ${facet}_dev=${device}
5307 eval export ${facet}_opt=\"$@\"
5309 local dev=${facet}_dev
5311 # We need to loop for the label
5312 # in case its not initialized yet.
5313 for wait_time in {0,1,3,5,10}; do
5315 if [ $wait_time -gt 0 ]; then
5316 echo "${!dev} not yet initialized,"\
5317 "waiting ${wait_time} seconds."
5321 local label=$(devicelabel ${facet} ${!dev})
5323 # Check to make sure the label does
5324 # not include ffff at the end of the label.
5325 # This indicates it has not been initialized yet.
5327 if [[ $label =~ [f|F]{4}$ ]]; then
5328 # label is not initialized, unset the result
5329 # and either try again or fail
5336 [ -z "$label" ] && echo no label for ${!dev} && exit 1
5338 eval export ${facet}_svc=${label}
5340 local varname=${facet}failover_HOST
5341 if [ -z "${!varname}" ]; then
5343 if combined_mgs_mds && [ $facet == "mgs" ] &&
5344 [ -n "$mds1failover_HOST" ]; then
5345 temp=$mds1failover_HOST
5347 temp=$(facet_host $facet)
5349 eval export $varname=$temp
5352 varname=${facet}_HOST
5353 if [ -z "${!varname}" ]; then
5354 eval export $varname=$(facet_host $facet)
5357 # ${facet}failover_dev is set in cfg file
5358 varname=${facet}failover_dev
5359 if [ -n "${!varname}" ] ; then
5360 eval export ${facet}failover_dev=${!varname}
5362 eval export ${facet}failover_dev=$device
5365 # get mount point of already mounted device
5366 # is facet_dev is already mounted then use the real
5367 # mount point of this facet; otherwise use $(facet_mntpt $facet)
5368 # i.e. ${facet}_MOUNT if specified by user or default
5369 local mntpt=$(do_facet ${facet} cat /proc/mounts | \
5370 awk '"'${!dev}'" == $1 && $3 == "lustre" { print $2 }')
5371 if [ -z $mntpt ]; then
5372 mntpt=$(facet_mntpt $facet)
5374 eval export ${facet}_MOUNT=$mntpt
5377 init_facets_vars () {
5380 if ! remote_mds_nodsh; then
5381 for num in $(seq $MDSCOUNT); do
5382 DEVNAME=$(mdsdevname $num)
5383 init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
5387 init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
5389 if ! remote_ost_nodsh; then
5390 for num in $(seq $OSTCOUNT); do
5391 DEVNAME=$(ostdevname $num)
5392 init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
5397 init_facets_vars_simple () {
5400 if ! remote_mds_nodsh; then
5401 for num in $(seq $MDSCOUNT); do
5402 devname=$(mdsdevname $num)
5403 eval export mds${num}_dev=${devname}
5404 eval export mds${num}_opt=\"${MDS_MOUNT_OPTS}\"
5408 if ! combined_mgs_mds ; then
5409 eval export mgs_dev=$(mgsdevname)
5410 eval export mgs_opt=\"${MGS_MOUNT_OPTS}\"
5413 if ! remote_ost_nodsh; then
5414 for num in $(seq $OSTCOUNT); do
5415 devname=$(ostdevname $num)
5416 eval export ost${num}_dev=${devname}
5417 eval export ost${num}_opt=\"${OST_MOUNT_OPTS}\"
5422 osc_ensure_active () {
5427 while [ $period -lt $timeout ]; do
5428 count=$(do_facet $facet "lctl dl | grep ' IN osc ' 2>/dev/null | wc -l")
5429 if [ $count -eq 0 ]; then
5433 echo "There are $count OST are inactive, wait $period seconds, and try again"
5435 period=$((period+3))
5438 [ $period -lt $timeout ] || log "$count OST are inactive after $timeout seconds, give up"
5441 set_conf_param_and_check() {
5445 local ORIG=$(do_facet $myfacet "$TEST")
5446 if [ $# -gt 3 ]; then
5452 echo "Setting $PARAM from $ORIG to $FINAL"
5453 do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
5454 error "conf_param $PARAM failed"
5456 wait_update_facet $myfacet "$TEST" "$FINAL" ||
5457 error "check $PARAM failed!"
5460 set_persistent_param() {
5464 local orig=$(do_facet $myfacet "$LCTL get_param -n $test_param")
5466 if [ $# -gt 3 ]; then
5473 if [[ $PERM_CMD == *"set_param -P"* ]]; then
5474 echo "Setting $test_param from $orig to $final"
5475 do_facet mgs "$PERM_CMD $test_param='$final'" ||
5476 error "$PERM_CMD $test_param failed"
5478 echo "Setting $param from $orig to $final"
5479 do_facet mgs "$PERM_CMD $param='$final'" ||
5480 error "$PERM_CMD $param failed"
5484 set_persistent_param_and_check() {
5488 local orig=$(do_facet $myfacet "$LCTL get_param -n $test_param")
5490 if [ $# -gt 3 ]; then
5497 set_persistent_param $myfacet $test_param $param "$final"
5499 wait_update_facet $myfacet "$LCTL get_param -n $test_param" "$final" ||
5500 error "check $param failed!"
5503 init_param_vars () {
5504 TIMEOUT=$(lctl get_param -n timeout)
5505 TIMEOUT=${TIMEOUT:-20}
5507 if [ -n "$arg1" ]; then
5508 [ "$arg1" = "server_only" ] && return
5511 remote_mds_nodsh && log "Using TIMEOUT=$TIMEOUT" && return 0
5513 TIMEOUT=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
5514 log "Using TIMEOUT=$TIMEOUT"
5516 # tune down to speed up testing on (usually) small setups
5517 local mgc_timeout=/sys/module/mgc/parameters/mgc_requeue_timeout_min
5518 do_nodes $(comma_list $(nodes_list)) \
5519 "[ -f $mgc_timeout ] && echo 1 > $mgc_timeout; exit 0"
5521 osc_ensure_active $SINGLEMDS $TIMEOUT
5522 osc_ensure_active client $TIMEOUT
5523 $LCTL set_param osc.*.idle_timeout=debug
5525 if [ -n "$(lctl get_param -n mdc.*.connect_flags|grep jobstats)" ]; then
5526 local current_jobid_var=$($LCTL get_param -n jobid_var)
5528 if [ $JOBID_VAR = "existing" ]; then
5529 echo "keeping jobstats as $current_jobid_var"
5530 elif [ $current_jobid_var != $JOBID_VAR ]; then
5531 echo "setting jobstats to $JOBID_VAR"
5533 set_persistent_param_and_check client \
5534 "jobid_var" "$FSNAME.sys.jobid_var" $JOBID_VAR
5537 echo "jobstats not supported by server"
5540 if [ $QUOTA_AUTO -ne 0 ]; then
5541 if [ "$ENABLE_QUOTA" ]; then
5542 echo "enable quota as required"
5543 setup_quota $MOUNT || return 2
5545 echo "disable quota as required"
5546 # $LFS quotaoff -ug $MOUNT > /dev/null 2>&1
5550 (( MDS1_VERSION <= $(version_code 2.13.52) )) ||
5551 do_facet mgs "$LCTL set_param -P lod.*.mdt_hash=crush"
5555 nfs_client_mode () {
5556 if [ "$NFSCLIENT" ]; then
5557 echo "NFSCLIENT mode: setup, cleanup, check config skipped"
5558 local clients=$CLIENTS
5559 [ -z $clients ] && clients=$(hostname)
5561 # FIXME: remove hostname when 19215 fixed
5562 do_nodes $clients "echo \\\$(hostname); grep ' '$MOUNT' ' /proc/mounts"
5563 declare -a nfsexport=(`grep ' '$MOUNT' ' /proc/mounts | awk '{print $1}' | awk -F: '{print $1 " " $2}'`)
5564 if [[ ${#nfsexport[@]} -eq 0 ]]; then
5565 error_exit NFSCLIENT=$NFSCLIENT mode, but no NFS export found!
5567 do_nodes ${nfsexport[0]} "echo \\\$(hostname); df -T ${nfsexport[1]}"
5573 cifs_client_mode () {
5574 [ x$CIFSCLIENT = xyes ] &&
5575 echo "CIFSCLIENT=$CIFSCLIENT mode: setup, cleanup, check config skipped"
5578 check_config_client () {
5581 local mounted=$(mount | grep " $mntpt ")
5582 if [ -n "$CLIENTONLY" ]; then
5584 # CLIENTONLY should not depend on *_HOST settings
5585 local mgc=$($LCTL device_list | awk '/MGC/ {print $4}')
5586 # in theory someone could create a new,
5587 # client-only config file that assumed lustre was already
5588 # configured and didn't set the MGSNID. If MGSNID is not set,
5589 # then we should use the mgs nid currently being used
5590 # as the default value. bug 18021
5591 [[ x$MGSNID = x ]] &&
5594 if [[ x$mgc != xMGC$MGSNID ]]; then
5595 if [ "$mgs_HOST" ]; then
5596 local mgc_ip=$(ping -q -c1 -w1 $mgs_HOST | grep PING | awk '{print $3}' | sed -e "s/(//g" -e "s/)//g")
5597 # [[ x$mgc = xMGC$mgc_ip@$NETTYPE ]] ||
5598 # error_exit "MGSNID=$MGSNID, mounted: $mounted, MGC : $mgc"
5604 echo Checking config lustre mounted on $mntpt
5605 local mgshost=$(mount | grep " $mntpt " | awk -F@ '{print $1}')
5606 mgshost=$(echo $mgshost | awk -F: '{print $1}')
5610 check_config_clients () {
5611 local clients=${CLIENTS:-$HOSTNAME}
5614 nfs_client_mode && return
5615 cifs_client_mode && return
5617 do_rpc_nodes "$clients" check_config_client $mntpt
5619 sanity_mount_check || error "environments are insane!"
5623 local mdstimeout=$(do_facet $SINGLEMDS "lctl get_param -n timeout")
5624 local cltimeout=$(lctl get_param -n timeout)
5625 if [ $mdstimeout -ne $TIMEOUT ] || [ $mdstimeout -ne $cltimeout ]; then
5626 error "timeouts are wrong! mds: $mdstimeout, client: $cltimeout, TIMEOUT=$TIMEOUT"
5633 [ -z $mntpt ] && return 1
5634 local mounted=$(mounted_lustre_filesystems)
5636 echo $mounted' ' | grep -w -q $mntpt' '
5641 local ostsn=${2:-$OSTCOUNT}
5642 local npools=${FS_NPOOLS:-$((OSTCOUNT / ostsn))}
5645 echo ostsn=$ostsn npools=$npools
5646 if [[ $ostsn -gt $OSTCOUNT ]]; then
5647 echo "request to use $ostsn OSTs in the pool, \
5648 using max available OSTCOUNT=$OSTCOUNT"
5651 for (( n=0; n < $npools; n++ )); do
5653 if ! $DELETE_OLD_POOLS; then
5654 log "request to not delete old pools: $FSNAME.$p exist?"
5655 if ! check_pool_not_exist $FSNAME.$p; then
5656 echo "Using existing $FSNAME.$p"
5657 $LCTL pool_list $FSNAME.$p
5661 create_pool $FSNAME.$p $KEEP_POOLS ||
5662 error "create_pool $FSNAME.$p failed"
5664 local first=$(( (n * ostsn) % OSTCOUNT ))
5665 local last=$(( (first + ostsn - 1) % OSTCOUNT ))
5666 if [[ $first -le $last ]]; then
5667 pool_add_targets $p $first $last ||
5668 error "pool_add_targets $p $first $last failed"
5670 pool_add_targets $p $first $(( OSTCOUNT - 1 )) ||
5671 error "pool_add_targets $p $first \
5672 $(( OSTCOUNT - 1 )) failed"
5673 pool_add_targets $p 0 $last ||
5674 error "pool_add_targets $p 0 $last failed"
5679 set_pools_quota () {
5686 [[ $ENABLE_QUOTA ]] || error "Required Pool Quotas: \
5687 $POOLS_QUOTA_USERS_SET, but ENABLE_QUOTA not set!"
5689 # POOLS_QUOTA_USERS_SET=
5690 # "quota15_1:20M -- for all of the found pools
5691 # quota15_2:1G:gpool0
5692 # quota15_3 -- for global limit only
5693 # quota15_4:200M:gpool0
5694 # quota15_4:200M:gpool1"
5696 declare -a pq_userset=(${POOLS_QUOTA_USERS_SET="mpiuser"})
5698 declare -A pq_limits
5700 for ((i=0; i<${#pq_userset[@]}; i++)); do
5701 u=${pq_userset[i]%%:*}
5703 # user gets no pool limits if
5704 # POOLS_QUOTA_USERS_SET does not specify it
5705 [[ ${pq_userset[i]} =~ : ]] && o=${pq_userset[i]##$u:}
5706 pq_limits[$u]+=" $o"
5708 pq_users=(${!pq_limits[@]})
5713 for ((i=0; i<${#pq_users[@]}; i++)); do
5715 # set to max limit (_u64)
5716 $LFS setquota -u $u -B $((2**24 - 1))T $DIR
5717 opts=(${pq_limits[$u]})
5718 for ((j=0; j<${#opts[@]}; j++)); do
5721 # Set limit for all existing pools if
5723 if [ $p == $o ]; then
5724 p=$(list_pool $FSNAME | sed "s/$FSNAME.//")
5725 echo "No pool specified for $u,
5726 set limit $o for all existing pools"
5729 $LFS setquota -u $u -B $o --pool $pool $DIR ||
5730 error "setquota -u $u -B $o \
5731 --pool $pool failed"
5734 $LFS quota -uv $u --pool $DIR
5738 check_and_setup_lustre() {
5740 nfs_client_mode && return
5741 cifs_client_mode && return
5743 local MOUNTED=$(mounted_lustre_filesystems)
5747 # both MOUNT and MOUNT2 are not mounted
5748 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
5749 [ "$REFORMAT" = "yes" ] && CLEANUP_DM_DEV=true formatall
5750 # setupall mounts both MOUNT and MOUNT2 (if MOUNT_2 is set)
5752 is_mounted $MOUNT || error "NAME=$NAME not mounted"
5753 export I_MOUNTED=yes
5757 elif is_mounted $MOUNT2; then
5759 # MOUNT2 is mounted, while MOUNT_2 is not set
5760 if ! [ "$MOUNT_2" ]; then
5761 cleanup_mount $MOUNT2
5762 export I_UMOUNTED2=yes
5765 # MOUNT2 is mounted, MOUNT_2 is set
5767 # FIXME: what to do if check_config failed?
5769 # 1) remote client has mounted other Lustre fs ?
5770 # 2) it has insane env ?
5771 # let's try umount MOUNT2 on all clients and mount it again:
5772 if ! check_config_clients $MOUNT2; then
5773 cleanup_mount $MOUNT2
5774 restore_mount $MOUNT2
5775 export I_MOUNTED2=yes
5780 # MOUNT is mounted MOUNT2 is not mounted
5781 elif [ "$MOUNT_2" ]; then
5782 restore_mount $MOUNT2
5783 export I_MOUNTED2=yes
5787 # FIXME: what to do if check_config failed?
5789 # 1) remote client has mounted other Lustre fs?
5790 # 2) lustre is mounted on remote_clients atall ?
5791 check_config_clients $MOUNT
5795 set_default_debug_nodes $(comma_list $(nodes_list))
5799 if [ -z "$CLIENTONLY" -a $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ]; then
5801 [ "$(facet_fstype ost1)" = "ldiskfs" ] &&
5802 facets="$(get_facets OST)"
5803 [ "$(facet_fstype mds1)" = "ldiskfs" ] &&
5804 facets="$facets,$(get_facets MDS)"
5805 [ "$(facet_fstype mgs)" = "ldiskfs" ] &&
5806 facets="$facets,mgs"
5807 local nodes="$(facets_hosts ${facets})"
5808 if [ -n "$nodes" ] ; then
5809 do_nodes $nodes "$LCTL set_param \
5810 osd-ldiskfs.track_declares_assert=1 || true"
5814 if [ -n "$fs_STRIPEPARAMS" ]; then
5815 setstripe_getstripe $MOUNT $fs_STRIPEPARAMS
5823 if $DELETE_OLD_POOLS; then
5826 if [[ -n "$FS_POOL" ]]; then
5827 create_pools $FS_POOL $FS_POOL_NOSTS
5830 if [[ -n "$POOLS_QUOTA_USERS_SET" ]]; then
5833 if [ "$ONLY" == "setup" ]; then
5839 local clients=${CLIENTS:-$HOSTNAME}
5842 zconf_mount_clients $clients $mntpt
5846 local clients=${CLIENTS:-$HOSTNAME}
5849 zconf_umount_clients $clients $mntpt
5852 cleanup_and_setup_lustre() {
5853 if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
5854 lctl set_param debug=0 || true
5856 if [ "$ONLY" == "cleanup" ]; then
5860 check_and_setup_lustre
5863 # Run e2fsck on MDT or OST device.
5868 local cmd="$E2FSCK -d -v -t -t -f $extra_opts $target_dev"
5869 local log=$TMP/e2fsck.log
5872 # turn on pfsck if it is supported
5873 do_node $node $E2FSCK -h 2>&1 | grep -qw -- -m && cmd+=" -m8"
5875 do_node $node $cmd 2>&1 | tee $log
5877 if [ -n "$(grep "DNE mode isn't supported" $log)" ]; then
5879 if [ $MDSCOUNT -gt 1 ]; then
5880 skip_noexit "DNE mode isn't supported!"
5884 error "It's not DNE mode."
5889 [ $rc -le $FSCK_MAX_ERR ] ||
5890 error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
5896 # Run resize2fs on MDT or OST device.
5905 do_facet $facet "$RESIZE2FS $opts $device $size"
5908 # verify a directory is shared among nodes.
5909 check_shared_dir() {
5911 local list=${2:-$(comma_list $(nodes_list))}
5913 [ -z "$dir" ] && return 1
5914 do_rpc_nodes "$list" check_logdir $dir
5915 check_write_access $dir "$list" || return 1
5920 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
5921 $LCTL set_param printk=+lfsck
5922 do_facet $SINGLEMDS "$LCTL lfsck_start -M $FSNAME-MDT0000 -r -A -t all"
5924 for k in $(seq $MDSCOUNT); do
5925 # wait up to 10+1 minutes for LFSCK to complete
5926 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
5927 mdd.$(facet_svc mds${k}).lfsck_layout |
5928 awk '/^status/ { print \\\$2 }'" "completed" 600 ||
5929 error "MDS${k} layout isn't the expected 'completed'"
5930 wait_update_facet --verbose mds${k} "$LCTL get_param -n \
5931 mdd.$(facet_svc mds${k}).lfsck_namespace |
5932 awk '/^status/ { print \\\$2 }'" "completed" 60 ||
5933 error "MDS${k} namespace isn't the expected 'completed'"
5935 local rep_mdt=$(do_nodes $(comma_list $(mdts_nodes)) \
5936 $LCTL get_param -n mdd.$FSNAME-*.lfsck_* |
5937 awk '/repaired/ { print $2 }' | calc_sum)
5938 local rep_ost=$(do_nodes $(comma_list $(osts_nodes)) \
5939 $LCTL get_param -n obdfilter.$FSNAME-*.lfsck_* |
5940 awk '/repaired/ { print $2 }' | calc_sum)
5941 local repaired=$((rep_mdt + rep_ost))
5942 [ $repaired -eq 0 ] ||
5943 error "lfsck repaired $rep_mdt MDT and $rep_ost OST errors"
5946 dump_file_contents() {
5952 if [ -z "$nodes" -o -z "$dir" -o -z "$logname" ]; then
5953 error_noexit false \
5954 "Invalid parameters for dump_file_contents()"
5957 for node in ${nodes}; do
5958 do_node $node "for i in \\\$(find $dir -type f); do
5959 echo ====\\\${i}=======================;
5961 done" >> ${logname}.${node}.log
5965 dump_command_output() {
5971 if [ -z "$nodes" -o -z "$cmd" -o -z "$logname" ]; then
5972 error_noexit false \
5973 "Invalid parameters for dump_command_output()"
5977 for node in ${nodes}; do
5978 do_node $node "echo ====${cmd}=======================;
5979 $cmd" >> ${logname}.${node}.log
5986 # dump file contents from /proc/spl in case of zfs test
5987 if [ "$(facet_fstype ost1)" = "zfs" ]; then
5988 dump_file_contents "$(osts_nodes)" "/proc/spl" "${logname}"
5989 dump_command_output \
5990 "$(osts_nodes)" "zpool events -v" "${logname}"
5993 if [ "$(facet_fstype $SINGLEMDS)" = "zfs" ]; then
5994 dump_file_contents "$(mdts_nodes)" "/proc/spl" "${logname}"
5995 dump_command_output \
5996 "$(mdts_nodes)" "zpool events -v" "${logname}"
6000 check_and_cleanup_lustre() {
6001 if [ "$LFSCK_ALWAYS" = "yes" -a "$TESTSUITE" != "sanity-lfsck" -a \
6002 "$TESTSUITE" != "sanity-scrub" ]; then
6006 if is_mounted $MOUNT; then
6007 if $DO_CLEANUP; then
6008 [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
6009 error "remove sub-test dirs failed"
6013 [ "$ENABLE_QUOTA" ] && restore_quota || true
6016 if [ "$I_UMOUNTED2" = "yes" ]; then
6017 restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
6020 if [ "$I_MOUNTED2" = "yes" ]; then
6021 cleanup_mount $MOUNT2
6024 if [[ "$I_MOUNTED" = "yes" ]] && ! $AUSTER_CLEANUP; then
6025 cleanupall -f || error "cleanup failed"
6033 wait_for_function () {
6036 # suppress fn both stderr and stdout
6037 if [ "$1" = "--quiet" ]; then
6039 quiet=" > /dev/null 2>&1"
6050 eval $fn $quiet && return 0
6052 [ $wait -lt $max ] || return 1
6053 echo waiting $fn, $((max - wait)) secs left ...
6054 wait=$((wait + sleep))
6055 [ $wait -gt $max ] && ((sleep -= wait - max))
6065 [ "$host" = "$HOSTNAME" ] && return 0
6067 if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep; then
6068 echo "$(date +'%H:%M:%S (%s)') waited for $host network ${max}s"
6078 # Convert a space-delimited list to a comma-delimited list. If the input is
6079 # only whitespace, ensure the output is empty (i.e. "") so [ -n $list ] works
6081 # echo is used to convert newlines to spaces, since it doesn't
6082 # introduce a trailing space as using "tr '\n' ' '" does
6083 echo $(tr -s " " "\n" <<< $* | sort -b -u) | tr ' ' ','
6089 echo $list | grep -qw $item
6092 # list, excluded are the comma separated lists
6093 exclude_items_from_list () {
6099 for item in ${excluded//,/ }; do
6100 list=$(echo " $list " | sed -re "s/\s+$item\s+/ /g")
6102 echo $(comma_list $list)
6105 # list, expand are the comma separated lists
6107 local list=${1//,/ }
6108 local expand=${2//,/ }
6111 expanded=$(for i in $list $expand; do echo $i; done | sort -u)
6112 echo $(comma_list $expanded)
6115 testslist_filter () {
6116 local script=$LUSTRE/tests/${TESTSUITE}.sh
6118 [ -f $script ] || return 0
6120 local start_at=$START_AT
6121 local stop_at=$STOP_AT
6123 local var=${TESTSUITE//-/_}_START_AT
6124 [ x"${!var}" != x ] && start_at=${!var}
6125 var=${TESTSUITE//-/_}_STOP_AT
6126 [ x"${!var}" != x ] && stop_at=${!var}
6128 sed -n 's/^test_\([^ (]*\).*/\1/p' $script | \
6129 awk ' BEGIN { if ("'${start_at:-0}'" != 0) flag = 1 }
6130 /^'${start_at}'$/ {flag = 0}
6131 {if (flag == 1) print $0}
6132 /^'${stop_at}'$/ { flag = 1 }'
6136 (cd `dirname $1`; echo $PWD/`basename $1`)
6140 local types=${1:-"OST MDS MGS"}
6144 for entry in $types; do
6145 local name=$(echo $entry | tr "[:upper:]" "[:lower:]")
6146 local type=$(echo $entry | tr "[:lower:]" "[:upper:]")
6149 MGS ) list="$list $name";;
6150 MDS|OST|AGT ) local count=${type}COUNT
6151 for ((i=1; i<=${!count}; i++)) do
6152 list="$list ${name}$i"
6154 * ) error "Invalid facet type"
6158 echo $(comma_list $list)
6161 ##################################
6162 # Adaptive Timeouts funcs
6165 # only check mds, we assume at_max is the same on all nodes
6166 local at_max=$(do_facet $SINGLEMDS "lctl get_param -n at_max")
6167 if [ $at_max -eq 0 ]; then
6178 # suppose that all ost-s have the same $at value set
6179 [ $facet != "ost" ] || facet=ost1
6181 do_facet $facet "lctl get_param -n $at"
6195 if [ $facet == "ost" ]; then
6196 facet=$(get_facets OST)
6197 elif [ $facet == "mds" ]; then
6198 facet=$(get_facets MDS)
6200 hosts=$(expand_list $hosts $(facets_hosts $facet))
6203 do_nodes $hosts lctl set_param at_max=$at_max
6206 ##################################
6210 # OBD_FAIL_MDS_ALL_REQUEST_NET
6212 do_facet $SINGLEMDS lctl set_param fail_val=0 fail_loc=0x123
6213 do_facet client "$1" || RC=$?
6214 do_facet $SINGLEMDS lctl set_param fail_loc=0
6219 # OBD_FAIL_MDS_ALL_REPLY_NET
6221 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x122
6223 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
6227 drop_reint_reply() {
6228 # OBD_FAIL_MDS_REINT_NET_REP
6230 do_facet $SINGLEMDS $LCTL set_param fail_loc=0x119
6232 do_facet $SINGLEMDS $LCTL set_param fail_loc=0
6236 drop_update_reply() {
6237 # OBD_FAIL_OUT_UPDATE_NET_REP
6241 do_facet mds${index} lctl set_param fail_loc=0x1701
6242 do_facet client "$@" || RC=$?
6243 do_facet mds${index} lctl set_param fail_loc=0
6248 #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
6251 local timeout=${2:-0}
6252 # default is (obd_timeout / 4) if unspecified
6253 echo "timeout is $timeout/$2"
6254 do_facet ost1 lctl set_param fail_val=$timeout fail_loc=0x80000214
6255 do_facet client "$1" || RC=$?
6256 do_facet client "sync"
6257 do_facet ost1 lctl set_param fail_loc=0
6261 drop_ldlm_cancel() {
6262 #define OBD_FAIL_LDLM_CANCEL_NET 0x304
6264 local list=$(comma_list $(mdts_nodes) $(osts_nodes))
6265 do_nodes $list lctl set_param fail_loc=0x304
6267 do_facet client "$@" || RC=$?
6269 do_nodes $list lctl set_param fail_loc=0
6273 drop_bl_callback_once() {
6275 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
6276 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
6277 do_facet client lctl set_param fail_loc=0x80000305
6278 do_facet client "$@" || rc=$?
6279 do_facet client lctl set_param fail_loc=0
6280 do_facet client lctl set_param fail_val=0
6281 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
6285 drop_bl_callback() {
6287 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=0
6288 #define OBD_FAIL_LDLM_BL_CALLBACK_NET 0x305
6289 do_facet client lctl set_param fail_loc=0x305
6290 do_facet client "$@" || rc=$?
6291 do_facet client lctl set_param fail_loc=0
6292 do_facet client lctl set_param fail_val=0
6293 do_facet client lctl set_param ldlm.namespaces.*.early_lock_cancel=1
6297 drop_mdt_ldlm_reply() {
6298 #define OBD_FAIL_MDS_LDLM_REPLY_NET 0x157
6300 local list=$(comma_list $(mdts_nodes))
6301 do_nodes $list lctl set_param fail_loc=0x157
6303 do_facet client "$@" || RC=$?
6305 do_nodes $list lctl set_param fail_loc=0
6309 drop_mdt_ldlm_reply_once() {
6310 #define OBD_FAIL_MDS_LDLM_REPLY_NET 0x157
6312 local list=$(comma_list $(mdts_nodes))
6313 do_nodes $list lctl set_param fail_loc=0x80000157
6315 do_facet client "$@" || RC=$?
6317 do_nodes $list lctl set_param fail_loc=0
6325 echo "clearing fail_loc on $facet"
6326 do_facet $facet "lctl set_param fail_loc=0 2>/dev/null || true"
6329 set_nodes_failloc () {
6331 do_nodes $(comma_list $1) lctl set_param fail_val=$fv fail_loc=$2
6334 cancel_lru_locks() {
6335 #$LCTL mark "cancel_lru_locks $1 start"
6336 $LCTL set_param -n ldlm.namespaces.*$1*.lru_size=clear
6337 $LCTL get_param ldlm.namespaces.*$1*.lock_unused_count | grep -v '=0'
6338 #$LCTL mark "cancel_lru_locks $1 stop"
6343 local nr_cpu=$(grep -c "processor" /proc/cpuinfo)
6345 echo $((100 * nr_cpu))
6350 lctl set_param ldlm.namespaces.*$1*.lru_size=0
6353 lru_resize_disable()
6356 local lru_size=${2:-$(default_lru_size)}
6358 $LCTL set_param ldlm.namespaces.*$dev*.lru_size=$lru_size
6363 local mountpath=${1:-$MOUNT}
6366 [ -z "$(mount | grep "$mountpath .*flock" | grep -v noflock)" ] && RC=1
6372 for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
6373 if [ `lctl get_param -n $FILE | wc -l` -gt 1 ]; then
6374 echo there is still data in page cache $FILE ?
6375 lctl get_param -n $FILE
6383 DEBUGSAVE="$(lctl get_param -n debug)"
6384 DEBUGSAVE_SERVER=$(do_facet $SINGLEMDS "$LCTL get_param -n debug")
6388 [ -n "$DEBUGSAVE" ] &&
6389 do_nodes $CLIENTS "$LCTL set_param debug=\\\"${DEBUGSAVE}\\\""||
6393 [ -n "$DEBUGSAVE_SERVER" ] &&
6394 do_nodes $(comma_list $(all_server_nodes)) \
6395 "$LCTL set_param debug=\\\"${DEBUGSAVE_SERVER}\\\"" ||
6401 DEBUG_SIZE_SAVED="$(lctl get_param -n debug_mb)"
6404 debug_size_restore() {
6405 [ -n "$DEBUG_SIZE_SAVED" ] && \
6406 do_nodes $(comma_list $(nodes_list)) "$LCTL set_param debug_mb=$DEBUG_SIZE_SAVED"
6410 start_full_debug_logging() {
6415 local debug_size=150
6416 local nodes=$(comma_list $(nodes_list))
6418 do_nodes $nodes "$LCTL set_param debug=$fulldebug debug_mb=$debug_size"
6421 stop_full_debug_logging() {
6426 # prints bash call stack
6427 print_stack_trace() {
6430 for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
6431 local src=${BASH_SOURCE[$i]}
6432 local lineno=${BASH_LINENO[$i-1]}
6433 local funcname=${FUNCNAME[$i]}
6434 echo " = $src:$lineno:$funcname()"
6439 local TYPE=${TYPE:-"FAIL"}
6442 # do not dump logs if $1=false
6443 if [ "x$1" = "xfalse" ]; then
6448 log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
6449 (print_stack_trace 2) >&2
6451 # We need to dump the logs on all nodes
6453 gather_logs $(comma_list $(nodes_list))
6457 [ "$TESTSUITELOG" ] &&
6458 echo "$TESTSUITE: $TYPE: $TESTNAME $@" >> $TESTSUITELOG
6459 if [ -z "$*" ]; then
6460 echo "error() without useful message, please fix" > $LOGDIR/err
6462 if [[ `echo $TYPE | grep ^IGNORE` ]]; then
6463 echo "$@" > $LOGDIR/ignore
6465 echo "$@" > $LOGDIR/err
6469 # cleanup the env for failed tests
6473 ##################################
6475 ##################################
6477 # usage: stack_trap arg sigspec
6479 # stack_trap() behaves like bash's built-in trap, except that it "stacks" the
6480 # command "arg" on top of previously defined commands for "sigspec" instead
6481 # of overwriting them.
6482 # stacked traps are executed in reverse order of their registration
6484 # arg and sigspec have the same meaning as in man (1) trap
6488 local sigspec="${2:-EXIT}"
6490 # Use "trap -p" to get the quoting right
6491 local old_trap="$(trap -p "$sigspec")"
6492 # Append ";" and remove the leading "trap -- '" added by "trap -p"
6493 old_trap="${old_trap:+"; ${old_trap#trap -- \'}"}"
6495 # Once again, use "trap -p" to get the quoting right
6496 local new_trap="$(trap -- "$arg" "$sigspec"
6498 trap -- '' "$sigspec")"
6500 # Remove the trailing "' $sigspec" part added by "trap -p" and merge
6502 # The resulting string should be safe to "eval" as it is (supposedly
6503 # correctly) quoted by "trap -p"
6504 eval "${new_trap%\' $sigspec}${old_trap:-"' $sigspec"}"
6513 local logs="$TESTSUITELOG $1"
6515 for log in $logs; do
6516 if [ -f "$log" ]; then
6517 grep -qw FAIL $log && status=1
6534 # use only if we are ignoring failures for this test, bugno required.
6535 # (like ALWAYS_EXCEPT, but run the test and ignore the results.)
6536 # e.g. error_ignore bz5494 "your message" or
6537 # error_ignore LU-5494 "your message"
6539 local TYPE="IGNORE ($1)"
6544 error_and_remount() {
6546 remount_client $MOUNT
6550 # Throw an error if it's not running in vm - usually for performance
6553 local virt=$(running_in_vm)
6554 if [[ -n "$virt" ]]; then
6555 echo "running in VM '$virt', ignore error"
6556 error_ignore env=$virt "$@"
6563 # Function: skip_env()
6564 # Purpose: to skip a test during developer testing because some tool
6565 # is missing, but fail the test in release testing because the test
6566 # environment is not configured properly".
6569 $FAIL_ON_SKIP_ENV && error false $@ || skip $@
6574 log " SKIP: $TESTSUITE $TESTNAME $@"
6576 if [[ -n "$ALWAYS_SKIPPED" ]]; then
6577 skip_logged $TESTNAME "$@"
6580 echo "$@" > $LOGDIR/skip
6583 [[ -n "$TESTSUITELOG" ]] &&
6584 echo "$TESTSUITE: SKIP: $TESTNAME $@" >> $TESTSUITELOG || true
6594 # For interop testing treate EOPNOTSUPP as success
6600 echo $retstr | awk -F'|' '{print $1}' |
6601 grep -E unsupported\|"(Operation not supported)"
6602 (( $? == 0 )) || error "$retstr"
6606 # Add a list of tests to ALWAYS_EXCEPT due to an issue.
6607 # Usage: always_except LU-4815 23 42q ...
6609 function always_except() {
6610 local issue="${1:-}" # single jira style issue ("LU-4815")
6615 if ! [[ "$issue" =~ ^[[:upper:]]+-[[:digit:]]+$ ]]; then
6616 error "always_except: invalid issue '$issue' for tests '$*'"
6619 for test_num in "$@"; do
6620 ALWAYS_EXCEPT+=" $test_num"
6624 build_test_filter() {
6625 EXCEPT="$EXCEPT $(testslist_filter)"
6628 if [[ $O = [0-9]*-[0-9]* ]]; then
6629 for num in $(seq $(echo $O | tr '-' ' ')); do
6637 [ "$EXCEPT$ALWAYS_EXCEPT" ] &&
6638 log "excepting tests: `echo $EXCEPT $ALWAYS_EXCEPT`"
6639 [ "$EXCEPT_SLOW" ] &&
6640 log "skipping tests SLOW=no: `echo $EXCEPT_SLOW`"
6641 for E in $EXCEPT; do
6642 eval EXCEPT_${E}=true
6644 for E in $ALWAYS_EXCEPT; do
6645 eval EXCEPT_ALWAYS_${E}=true
6647 for E in $EXCEPT_SLOW; do
6648 eval EXCEPT_SLOW_${E}=true
6650 for G in $GRANT_CHECK_LIST; do
6651 eval GCHECK_ONLY_${G}=true
6656 if [[ $1 = [a-z]* ]]; then
6659 echo ${1%%[a-zA-Z]*}
6663 # print a newline if the last test was skipped
6664 export LAST_SKIPPED=
6665 export ALWAYS_SKIPPED=
6667 # Main entry into test-framework. This is called with the number and
6668 # description of a test. The number is used to find the function to run
6669 # the test using "test_$name".
6671 # This supports a variety of methods of specifying specific test to
6673 # - ONLY= env variable with space-separated list of test numbers to run
6674 # - EXCEPT= env variable with space-separated list of test numbers to exclude
6680 export base=$(basetest $testnum)
6681 export TESTNAME=test_$testnum
6685 # Check the EXCEPT, ALWAYS_EXCEPT and SLOW lists to see if we
6686 # need to skip the current test. If so, set the ALWAYS_SKIPPED flag.
6687 local isexcept=EXCEPT_$testnum
6688 local isexcept_base=EXCEPT_$base
6689 if [ ${!isexcept}x != x ]; then
6691 skip_message="skipping excluded test $testnum"
6692 elif [ ${!isexcept_base}x != x ]; then
6694 skip_message="skipping excluded test $testnum (base $base)"
6697 isexcept=EXCEPT_ALWAYS_$testnum
6698 isexcept_base=EXCEPT_ALWAYS_$base
6699 if [ ${!isexcept}x != x ]; then
6701 skip_message="skipping ALWAYS excluded test $testnum"
6702 elif [ ${!isexcept_base}x != x ]; then
6704 skip_message="skipping ALWAYS excluded test $testnum (base $base)"
6707 isexcept=EXCEPT_SLOW_$testnum
6708 isexcept_base=EXCEPT_SLOW_$base
6709 if [ ${!isexcept}x != x ]; then
6711 skip_message="skipping SLOW test $testnum"
6712 elif [ ${!isexcept_base}x != x ]; then
6714 skip_message="skipping SLOW test $testnum (base $base)"
6717 # If there are tests on the ONLY list, check if the current test
6718 # is on that list and, if so, check if the test is to be skipped
6719 # and if we are supposed to honor the skip lists.
6720 if [ -n "$ONLY" ]; then
6721 local isonly=ONLY_$testnum
6722 local isonly_base=ONLY_$base
6723 if [[ ${!isonly}x != x || ${!isonly_base}x != x ]]; then
6725 if [[ -n "$ALWAYS_SKIPPED" && -n "$HONOR_EXCEPT" ]]; then
6727 skip_noexit "$skip_message"
6730 [ -n "$LAST_SKIPPED" ] &&
6731 echo "" && LAST_SKIPPED=
6733 run_one_logged $testnum "$testmsg"
6743 if [ -n "$ALWAYS_SKIPPED" ]; then
6745 skip_noexit "$skip_message"
6748 run_one_logged $testnum "$testmsg"
6755 load_module ../libcfs/libcfs/libcfs
6768 do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
6773 strace -o $TMP/$1.strace -ttt $*
6775 log "FINISHED: $*: rc $RC"
6782 banner test complete, duration $duration sec
6783 [ -f "$TESTSUITELOG" ] && egrep .FAIL $TESTSUITELOG || true
6784 echo duration $duration >>$TESTSUITELOG
6788 # Set TEST_STATUS here. It will be used for logging the result.
6791 if [[ -f $LOGDIR/err ]]; then
6793 elif [[ -f $LOGDIR/skip ]]; then
6796 echo "$TEST_STATUS $@" 2>&1 | tee -a $TESTSUITELOG
6800 local FFREE=$(do_node $SINGLEMDS \
6801 lctl get_param -n osd*.*MDT*.filesfree | calc_sum)
6802 local FTOTAL=$(do_node $SINGLEMDS \
6803 lctl get_param -n osd*.*MDT*.filestotal | calc_sum)
6805 [ $FFREE -ge $FTOTAL ] && error "files free $FFREE > total $FTOTAL" || true
6809 #echo -n "Resetting fail_loc on all nodes..."
6810 do_nodes --quiet $(comma_list $(nodes_list)) \
6811 "lctl set_param -n fail_loc=0 fail_val=0 2>/dev/null" || true
6817 # Log a message (on all nodes) padded with "=" before and after.
6818 # Also appends a timestamp and prepends the testsuite name.
6821 # ======================================================== 15:06:12 (1624050372)
6822 EQUALS="========================================================"
6824 msg="== ${TESTSUITE} $*"
6826 [[ $last != "=" && $last != " " ]] && msg="$msg "
6827 msg=$(printf '%s%.*s' "$msg" $((${#EQUALS} - ${#msg})) $EQUALS )
6828 # always include at least == after the message
6829 log "$msg== $(date +"%H:%M:%S (%s)")"
6832 check_dmesg_for_errors() {
6834 local errors="VFS: Busy inodes after unmount of\|\
6835 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
6836 group descriptors corrupted"
6838 res=$(do_nodes -q $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
6839 [ -z "$res" ] && return 0
6840 echo "Kernel error detected: $res"
6845 # Run a single test function and cleanup after it.
6847 # This function should be run in a subshell so the test func can
6848 # exit() without stopping the whole script.
6853 local SAVE_UMASK=`umask`
6856 if ! grep -q $DIR /proc/mounts; then
6860 banner "test $testnum: $testmsg"
6861 test_${testnum} || error "test_$testnum failed with $?"
6864 check_grant ${testnum} || error "check_grant $testnum failed with $?"
6866 check_dmesg_for_errors || error "Error in dmesg detected"
6867 if [ "$PARALLEL" != "yes" ]; then
6868 ps auxww | grep -v grep | grep -q "multiop " &&
6869 error "multiop still running"
6877 # Wrapper around run_one to ensure:
6878 # - test runs in subshell
6879 # - output of test is saved to separate log file for error reporting
6880 # - test result is saved to data file
6883 local before=$SECONDS
6886 export tfile=f${testnum}.${TESTSUITE}
6887 export tdir=d${testnum}.${TESTSUITE}
6888 local test_log=$TESTLOG_PREFIX.$TESTNAME.test_log.$(hostname -s).log
6889 local zfs_debug_log=$TESTLOG_PREFIX.$TESTNAME.zfs_log
6890 local SAVE_UMASK=$(umask)
6894 rm -f $LOGDIR/err $LOGDIR/ignore $LOGDIR/skip
6896 # if ${ONLY_$testnum} set, repeat $ONLY_REPEAT times, otherwise once
6897 local isonly=ONLY_$testnum
6898 local repeat=${!isonly:+$ONLY_REPEAT}
6900 for ((testiter=0; testiter < ${repeat:-1}; testiter++)); do
6901 local before_sub=$SECONDS
6902 log_sub_test_begin $TESTNAME
6904 # remove temp files between repetitions to avoid test failures
6905 if [[ -n "$append" ]]; then
6906 [[ -n "$DIR/$tdir" ]] && rm -rvf $DIR/$tdir*
6907 [[ -n "$DIR/$tfile" ]] && rm -vf $DIR/$tfile*
6908 echo "subtest iteration $testiter/$repeat"
6910 # loop around subshell so stack_trap EXIT triggers each time
6911 (run_one $testnum "$testmsg") 2>&1 | tee -i $append $test_log
6914 local duration_sub=$((SECONDS - before_sub))
6917 [[ $rc != 0 && ! -f $LOGDIR/err ]] &&
6918 echo "$TESTNAME returned $rc" | tee $LOGDIR/err
6920 if [[ -f $LOGDIR/err ]]; then
6921 test_error=$(cat $LOGDIR/err)
6923 elif [[ -f $LOGDIR/ignore ]]; then
6924 test_error=$(cat $LOGDIR/ignore)
6925 elif [[ -f $LOGDIR/skip ]]; then
6926 test_error=$(cat $LOGDIR/skip)
6932 pass "$testnum" "(${duration_sub}s)"
6933 log_sub_test_end $TEST_STATUS $duration_sub "$rc" "$test_error"
6934 [[ $rc != 0 ]] && break
6937 if [[ "$TEST_STATUS" != "SKIP" && -f $TF_SKIP ]]; then
6941 if [ -f $LOGDIR/err ]; then
6942 log_zfs_info "$zfs_debug_log"
6943 $FAIL_ON_ERROR && exit $rc
6956 # Print information of skipped tests to result.yml
6959 log_sub_test_begin $1
6961 log_sub_test_end "SKIP" "0" "0" "$@"
6964 grant_from_clients() {
6968 do_nodes $nodes "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
6972 grant_from_servers() {
6976 # which is tot_granted less grant_precreate
6977 do_nodes $nodes "$LCTL get_param obdfilter.${FSNAME}-OST*.tot_granted" \
6978 " obdfilter.${FSNAME}-OST*.tot_pending" \
6979 " obdfilter.${FSNAME}-OST*.grant_precreate" |
6980 tr '=' ' ' | awk '/tot_granted/{ total += $2 };
6981 /tot_pending/{ total -= $2 };
6982 /grant_precreate/{ total -= $2 };
6983 END { printf("%0.0f", total) }'
6987 export base=$(basetest $1)
6988 [ "$CHECK_GRANT" == "no" ] && return 0
6990 local isonly_base=GCHECK_ONLY_${base}
6991 local isonly=GCHECK_ONLY_$1
6992 [ ${!isonly_base}x == x -a ${!isonly}x == x ] && return 0
6994 echo -n "checking grant......"
6996 local osts=$(comma_list $(osts_nodes))
6997 local clients=$CLIENTS
6998 [ -z "$clients" ] && clients=$(hostname)
7000 # sync all the data and make sure no pending data on server
7001 do_nodes $clients sync
7002 do_nodes $clients $LFS df # initiate all idling connections
7005 cli_grant=$(grant_from_clients $clients)
7008 # which is tot_granted less grant_precreate
7009 srv_grant=$(grant_from_servers $osts)
7012 # check whether client grant == server grant
7013 while [[ $cli_grant != $srv_grant && count++ -lt 30 ]]; do
7014 echo "wait for client:$cli_grant == server:$srv_grant"
7016 cli_grant=$(grant_from_clients $clients)
7017 srv_grant=$(grant_from_servers $osts)
7019 if [[ $cli_grant -ne $srv_grant ]]; then
7020 do_nodes $(comma_list $(osts_nodes)) \
7021 "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*" \
7022 "obdfilter.${FSNAME}-OST*.grant_*"
7023 do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
7024 error "failed grant check: client:$cli_grant server:$srv_grant"
7026 echo "pass grant check: client:$cli_grant server:$srv_grant"
7030 ########################
7036 ost=`echo $1 | awk -F_ '{print $3}'`
7037 if [ -z $ost ]; then
7038 ost=`echo $1 | sed 's/-osc.*//'`
7043 ostuuid_from_index()
7045 $LFS osts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
7048 ostname_from_index() {
7049 local uuid=$(ostuuid_from_index $1 $2)
7053 mdtname_from_index() {
7054 local uuid=$(mdtuuid_from_index $1)
7058 mdssize_from_index () {
7059 local mdt=$(mdtname_from_index $2)
7060 $LFS df $1 | grep $mdt | awk '{ print $2 }'
7063 index_from_ostuuid()
7065 $LFS osts $2 | sed -ne "/${1}/s/\(.*\): .* .*$/\1/p"
7068 mdtuuid_from_index()
7070 $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
7074 # Return unique identifier for given hostname
7077 echo $host_name | md5sum | cut -d' ' -f1
7081 # Returns list of ip addresses for each interface
7083 ip addr | awk '/inet / {print $2}' | awk -F/ '{print $1}'
7087 # Returns list of interfaces configured for LNet
7089 local nids=( $($LCTL list_nids | xargs echo) )
7091 [[ -z ${nids[@]} ]] &&
7094 declare -a INTERFACES
7096 for ((i = 0; i < ${#nids[@]}; i++)); do
7097 ip=$(sed 's/^\(.*\)@.*$/\1/'<<<${nids[i]})
7098 INTERFACES[i]=$(ip -o a s |
7099 awk '$4 ~ /^'$ip'\//{print $2}')
7100 INTERFACES=($(echo "${INTERFACES[@]}" | tr ' ' '\n' | uniq | tr '\n' ' '))
7101 if [[ -z ${INTERFACES[i]} ]]; then
7102 error "Can't determine interface name for NID ${nids[i]}"
7103 elif [[ 1 -ne $(wc -w <<<${INTERFACES[i]}) ]]; then
7104 error "Found $(wc -w <<<${INTERFACES[i]}) interfaces for NID ${nids[i]}. Expect 1"
7108 echo "${INTERFACES[@]}"
7115 # Cache address list to avoid mutiple execution of local_addr_list
7116 LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
7118 for i in $LOCAL_ADDR_LIST ; do
7119 [[ "$i" == "$addr" ]] && return 0
7126 local is_local="IS_LOCAL_$(host_id $host_name)"
7127 if [ -z "${!is_local-}" ] ; then
7129 local host_ip=$($LUSTRE/tests/resolveip $host_name)
7130 is_local_addr "$host_ip" && eval $is_local=1
7132 [[ "${!is_local}" == "1" ]]
7137 local_node $node && return 1
7144 for node in $(mdts_nodes); do
7145 remote_node $node && return 0
7152 [ -n "$CLIENTONLY" ] && return 0 || true
7153 remote_mds && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$mds_HOST" ]
7158 remote_mds_nodsh && echo "SKIP: $TESTSUITE: remote MDS with nodsh" &&
7159 MSKIPPED=1 && return 1
7166 for node in $(osts_nodes) ; do
7167 remote_node $node && return 0
7174 [ -n "$CLIENTONLY" ] && return 0 || true
7175 remote_ost && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
7180 remote_ost_nodsh && echo "SKIP: $TESTSUITE: remote OST with nodsh" && \
7181 OSKIPPED=1 && return 1
7187 [ -n "$CLIENTONLY" ] && return 0 || true
7189 MGS=$(facet_host mgs)
7190 remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
7195 remote_mds_nodsh || remote_ost_nodsh || \
7196 $(single_local_node $(comma_list $(nodes_list)))
7200 remote_ost && remote_mds
7203 # Get the active nodes for facets.
7211 for facet in ${facets//,/ }; do
7212 nodes="$nodes $(facet_active_host $facet)"
7215 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7219 # Get name of the active MGS node.
7221 echo -n $(facets_nodes $(get_facets MGS))
7224 # Get all of the active MDS nodes.
7226 echo -n $(facets_nodes $(get_facets MDS))
7229 # Get all of the active OSS nodes.
7231 echo -n $(facets_nodes $(get_facets OST))
7234 # Get all of the client nodes and active server nodes.
7236 local nodes=$HOSTNAME
7240 # CLIENTS (if specified) contains the local client
7241 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
7243 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
7244 nodes="$nodes $(facets_nodes $(get_facets))"
7247 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7251 # Get all of the remote client nodes and remote active server nodes.
7252 remote_nodes_list () {
7253 echo -n $(nodes_list) | sed -re "s/\<$HOSTNAME\>//g"
7256 # Get all of the MDS nodes, including active and passive nodes.
7264 for i in $(seq $MDSCOUNT); do
7266 failover_host=mds${i}failover_HOST
7267 nodes="$nodes ${!host} ${!failover_host}"
7270 [ -n "$nodes" ] || nodes="${mds_HOST} ${mdsfailover_HOST}"
7271 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7275 # Get all of the OSS nodes, including active and passive nodes.
7283 for i in $(seq $OSTCOUNT); do
7285 failover_host=ost${i}failover_HOST
7286 nodes="$nodes ${!host} ${!failover_host}"
7289 [ -n "$nodes" ] || nodes="${ost_HOST} ${ostfailover_HOST}"
7290 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7294 # Get all of the server nodes, including active and passive nodes.
7295 all_server_nodes () {
7300 nodes="$mgs_HOST $mgsfailover_HOST $(all_mdts_nodes) $(all_osts_nodes)"
7302 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7306 # Get all of the client and server nodes, including active and passive nodes.
7308 local nodes=$HOSTNAME
7312 # CLIENTS (if specified) contains the local client
7313 [ -n "$CLIENTS" ] && nodes=${CLIENTS//,/ }
7315 if [ "$PDSH" -a "$PDSH" != "no_dsh" ]; then
7316 nodes="$nodes $(all_server_nodes)"
7319 nodes_sort=$(for i in $nodes; do echo $i; done | sort -u)
7323 init_clients_lists () {
7324 # Sanity check: exclude the local client from RCLIENTS
7325 local clients=$(hostlist_expand "$RCLIENTS")
7326 local rclients=$(exclude_items_from_list "$clients" $HOSTNAME)
7328 # Sanity check: exclude the dup entries
7329 RCLIENTS=$(for i in ${rclients//,/ }; do echo $i; done | sort -u)
7331 export CLIENT1=${CLIENT1:-$HOSTNAME}
7332 export SINGLECLIENT=$CLIENT1
7334 clients="$SINGLECLIENT $HOSTNAME $RCLIENTS"
7336 # Sanity check: exclude the dup entries from CLIENTS
7337 # for those configs which has SINGLCLIENT set to local client
7338 clients=$(for i in $clients; do echo $i; done | sort -u)
7340 export CLIENTS=$(comma_list $clients)
7341 local -a remoteclients=($RCLIENTS)
7342 for ((i=0; $i<${#remoteclients[@]}; i++)); do
7343 varname=CLIENT$((i + 2))
7344 eval export $varname=${remoteclients[i]}
7347 export CLIENTCOUNT=$((${#remoteclients[@]} + 1))
7350 get_random_entry () {
7353 rnodes=${rnodes//,/ }
7355 local -a nodes=($rnodes)
7356 local num=${#nodes[@]}
7357 local i=$((RANDOM * num * 2 / 65536))
7363 [ -n "$CLIENTONLY" ] || [ "x$CLIENTMODSONLY" = "xyes" ]
7367 [ "$(lustre_version_code client)" = "$(lustre_version_code $SINGLEMDS)" -a \
7368 "$(lustre_version_code client)" = "$(lustre_version_code ost1)" ]
7373 echo $nodes | wc -w || true
7377 local nodes=$(mdts_nodes)
7378 local mdtcount=$(get_node_count "$nodes")
7379 [ ! "$MDSCOUNT" = "$mdtcount" ]
7382 generate_machine_file() {
7383 local nodes=${1//,/ }
7384 local machinefile=$2
7386 for node in $nodes; do
7387 echo $node >>$machinefile || \
7388 { echo "can not generate machinefile $machinefile" && return 1; }
7393 local file=$1/stripe
7396 $LFS getstripe -v $file || error "getstripe $file failed"
7400 # Check and add a test group.
7406 local gid=$(getent group $group_name | cut -d: -f3)
7407 if [[ -n "$gid" ]]; then
7408 [[ "$gid" -eq "$group_id" ]] || {
7409 error_noexit "inconsistent group ID:" \
7410 "new: $group_id, old: $gid"
7414 groupadd -g $group_id $group_name
7421 # Check and add a test user.
7434 local uid=$(getent passwd $user_name | cut -d: -f3)
7435 if [[ -n "$uid" ]]; then
7436 if [[ "$uid" -eq "$user_id" ]]; then
7437 local dir=$(getent passwd $user_name | cut -d: -f6)
7438 if [[ "$dir" != "$home" ]]; then
7440 usermod -d $home $user_name
7444 error_noexit "inconsistent user ID:" \
7445 "new: $user_id, old: $uid"
7450 useradd -M -u $user_id -d $home -g $group_name $opts $user_name
7457 check_runas_id_ret() {
7459 local myRUNAS_UID=$1
7460 local myRUNAS_GID=$2
7464 if [ -z "$myRUNAS" ]; then
7465 error_exit "check_runas_id_ret requires myRUNAS argument"
7469 error "Unable to execute $myRUNAS"
7471 id $myRUNAS_UID > /dev/null ||
7472 error "Invalid RUNAS_ID $myRUNAS_UID. Please set RUNAS_ID to " \
7473 "some UID which exists on MDS and client or add user " \
7474 "$myRUNAS_UID:$myRUNAS_GID on these nodes."
7477 $myRUNAS krb5_login.sh ||
7478 error "Failed to refresh krb5 TGT for UID $myRUNAS_ID."
7480 mkdir $DIR/d0_runas_test
7482 chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
7483 $myRUNAS -u $myRUNAS_UID -g $myRUNAS_GID touch $DIR/d0_runas_test/f$$ ||
7485 rm -rf $DIR/d0_runas_test
7490 local myRUNAS_UID=$1
7491 local myRUNAS_GID=$2
7495 check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
7496 error "unable to write to $DIR/d0_runas_test as " \
7500 # obtain the UID/GID for MPI_USER
7504 MPI_USER_UID=$(do_facet client "getent passwd $mpi_user | cut -d: -f3;
7505 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the UID for $mpi_user"
7507 MPI_USER_GID=$(do_facet client "getent passwd $mpi_user | cut -d: -f4;
7508 exit \\\${PIPESTATUS[0]}") || error_exit "failed to get the GID for $mpi_user"
7511 # obtain and cache Kerberos ticket-granting ticket
7512 refresh_krb5_tgt() {
7513 local myRUNAS_UID=$1
7514 local myRUNAS_GID=$2
7517 if [ -z "$myRUNAS" ]; then
7518 error_exit "myRUNAS command must be specified for refresh_krb5_tgt"
7521 CLIENTS=${CLIENTS:-$HOSTNAME}
7522 do_nodes $CLIENTS "set -x
7523 if ! $myRUNAS krb5_login.sh; then
7524 echo "Failed to refresh Krb5 TGT for UID/GID $myRUNAS_UID/$myRUNAS_GID."
7529 # Run multiop in the background, but wait for it to print
7530 # "PAUSING" to its stdout before returning from this function.
7531 multiop_bg_pause() {
7532 MULTIOP_PROG=${MULTIOP_PROG:-$MULTIOP}
7536 TMPPIPE=/tmp/multiop_open_wait_pipe.$$
7539 echo "$MULTIOP_PROG $FILE v$ARGS"
7540 $MULTIOP_PROG $FILE v$ARGS > $TMPPIPE &
7542 echo "TMPPIPE=${TMPPIPE}"
7543 read -t 60 multiop_output < $TMPPIPE
7544 if [ $? -ne 0 ]; then
7549 if [ "$multiop_output" != "PAUSING" ]; then
7550 echo "Incorrect multiop output: $multiop_output"
7565 [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
7567 echo $((SECONDS - start))
7571 inodes_available () {
7572 local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
7573 sort -un | head -n1) || return 1
7577 mdsrate_inodes_available () {
7578 local min_inodes=$(inodes_available)
7579 echo $((min_inodes * 99 / 100))
7582 # reset stat counters
7584 local paramfile="$1"
7585 lctl set_param -n $paramfile=0
7590 local paramfile="$1"
7592 lctl get_param -n $paramfile |
7593 awk '/^'$stat'/ { sum += $2 } END { printf("%0.0f", sum) }'
7597 awk '{sum += $1} END { printf("%0.0f", sum) }'
7600 calc_osc_kbytes () {
7601 $LFS df $MOUNT > /dev/null
7602 $LCTL get_param -n osc.*[oO][sS][cC][-_][0-9a-f]*.$1 | calc_sum
7606 wait_delete_completed
7607 AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7608 echo "OST kbytes available: ${AVAIL[*]}"
7613 for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7614 #echo OST $i: ${AVAIL[i]}kb
7615 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7619 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7624 echo "Min free space: OST $MINI: $MINV"
7625 echo "Max free space: OST $MAXI: $MAXV"
7628 # save_lustre_params(comma separated facet list, parameter_mask)
7629 # generate a stream of formatted strings (<facet> <param name>=<param value>)
7630 save_lustre_params() {
7635 for facet in ${facets//,/ }; do
7636 facet_svc=$(facet_svc $facet)
7638 "params=\\\$($LCTL get_param $2);
7639 [[ -z \\\"$facet_svc\\\" ]] && param= ||
7640 param=\\\$(grep $facet_svc <<< \\\"\\\$params\\\");
7641 [[ -z \\\$param ]] && param=\\\"\\\$params\\\";
7642 while read s; do echo $facet \\\$s;
7643 done <<< \\\"\\\$param\\\""
7647 # restore lustre parameters from input stream, produces by save_lustre_params
7648 restore_lustre_params() {
7653 while IFS=" =" read facet name val; do
7654 do_facet $facet "$LCTL set_param -n $name=$val"
7658 check_node_health() {
7659 local nodes=${1:-$(comma_list $(nodes_list))}
7660 local health=$TMP/node_health.$$
7662 do_nodes -q $nodes "$LCTL get_param catastrophe 2>&1" | tee $health |
7663 grep "catastrophe=1" && error "LBUG/LASSERT detected"
7664 # Only check/report network health if get_param isn't reported, since
7665 # *clearly* the network is working if get_param returned something.
7666 if (( $(grep -c catastro $health) != $(wc -w <<< ${nodes//,/ }) )); then
7667 for node in ${nodes//,/ }; do
7668 check_network $node 5
7674 mdsrate_cleanup () {
7676 mpi_run ${MACHINEFILE_OPTION} $2 -np $1 ${MDSRATE} --unlink \
7677 --nfiles $3 --dir $4 --filefmt $5 $6
7682 ########################
7684 convert_facet2label() {
7687 if [ x$facet = xost ]; then
7689 elif [ x$facet = xmgs ] && combined_mgs_mds ; then
7693 local varsvc=${facet}_svc
7695 if [ -n ${!varsvc} ]; then
7698 error "No label for $facet!"
7702 get_clientosc_proc_path() {
7703 echo "${1}-osc-[-0-9a-f]*"
7706 get_mdtosc_proc_path() {
7708 local ost_label=${2:-"*OST*"}
7710 [ "$mds_facet" = "mds" ] && mds_facet=$SINGLEMDS
7711 local mdt_label=$(convert_facet2label $mds_facet)
7712 local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
7714 if [[ $ost_label = *OST* ]]; then
7715 echo "${ost_label}-osc-${mdt_index}"
7717 echo "${ost_label}-osp-${mdt_index}"
7721 get_osc_import_name() {
7724 local label=$(convert_facet2label $ost)
7726 if [ "${facet:0:3}" = "mds" ]; then
7727 get_mdtosc_proc_path $facet $label
7731 get_clientosc_proc_path $label
7735 _wait_import_state () {
7737 local CONN_PROC="$2"
7738 local maxtime=${3:-$(max_recovery_time)}
7739 local err_on_fail=${4:-1}
7743 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
7744 while ! echo "${CONN_STATE}" | egrep -q "^${expected}\$" ; do
7745 if [[ "${expected}" == "DISCONN" ]]; then
7746 # for disconn we can check after proc entry is removed
7747 [[ -z "${CONN_STATE}" ]] && return 0
7748 # with AT, we can have connect request timeout near
7749 # reconnect timeout and test can't see real disconnect
7750 [[ "${CONN_STATE}" == "CONNECTING" ]] && return 0
7752 if (( $i >= $maxtime )); then
7753 (( $err_on_fail != 0 )) &&
7754 error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}"
7758 # Add uniq for multi-mount case
7759 CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null |
7764 log "$CONN_PROC in ${CONN_STATE} state after $i sec"
7768 wait_import_state() {
7771 local maxtime=${3:-$(max_recovery_time)}
7772 local err_on_fail=${4:-1}
7775 for param in ${params//,/ }; do
7776 _wait_import_state "$expected" "$param" $maxtime $err_on_fail ||
7781 wait_import_state_mount() {
7782 if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
7786 wait_import_state "$@"
7789 # One client request could be timed out because server was not ready
7790 # when request was sent by client.
7791 # The request timeout calculation details :
7793 # /* We give the server rq_timeout secs to process the req, and
7794 # add the network latency for our local timeout. */
7795 # request->rq_deadline = request->rq_sent + request->rq_timeout +
7796 # ptlrpc_at_get_net_latency(request) ;
7798 # ptlrpc_connect_import ()
7799 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
7802 # -> at_init(&at->iat_net_latency, 0, 0) -> iat_net_latency=0
7803 # ptlrpc_at_get_net_latency(request) ->
7804 # at_get (max (iat_net_latency=0, at_min)) = at_min
7807 # request->rq_timeout + ptlrpc_at_get_net_latency(request) =
7808 # INITIAL_CONNECT_TIMEOUT + at_min
7810 # We will use obd_timeout instead of INITIAL_CONNECT_TIMEOUT
7811 # because we can not get this value in runtime,
7812 # the value depends on configure options, and it is not stored in /proc.
7814 # #define CONNECTION_SWITCH_MIN 5U
7815 # #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
7817 request_timeout () {
7820 # request->rq_timeout = INITIAL_CONNECT_TIMEOUT
7821 local init_connect_timeout=$TIMEOUT
7822 [[ $init_connect_timeout -ge 5 ]] || init_connect_timeout=5
7824 local at_min=$(at_get $facet at_min)
7826 echo $(( init_connect_timeout + at_min ))
7829 _wait_osc_import_state() {
7833 local target=$(get_osc_import_name $facet $ost_facet)
7834 local param="os[cp].${target}.ost_server_uuid"
7838 # 1. wait the deadline of client 1st request (it could be skipped)
7839 # 2. wait the deadline of client 2nd request
7840 local maxtime=$(( 2 * $(request_timeout $facet)))
7842 if [[ $facet == client* ]]; then
7843 # During setup time, the osc might not be setup, it need wait
7844 # until list_param can return valid value.
7845 params=$($LCTL list_param $param 2>/dev/null || true)
7846 while [ -z "$params" ]; do
7847 if [ $i -ge $maxtime ]; then
7848 echo "can't get $param in $maxtime secs"
7853 params=$($LCTL list_param $param 2>/dev/null || true)
7857 if [[ $ost_facet = mds* ]]; then
7858 # no OSP connection to itself
7859 if [[ $facet = $ost_facet ]]; then
7862 param="osp.${target}.mdt_server_uuid"
7866 local plist=$(comma_list $params)
7867 if ! do_rpc_nodes "$(facet_active_host $facet)" \
7868 wait_import_state $expected $plist $maxtime; then
7869 error "$facet: import is not in $expected state after $maxtime"
7876 wait_osc_import_state() {
7882 if [[ $facet = mds ]]; then
7883 for num in $(seq $MDSCOUNT); do
7884 _wait_osc_import_state mds$num "$ost_facet" "$expected"
7887 _wait_osc_import_state "$facet" "$ost_facet" "$expected"
7891 wait_osc_import_ready() {
7892 wait_osc_import_state $1 $2 "\(FULL\|IDLE\)"
7895 _wait_mgc_import_state() {
7898 local error_on_failure=${3:-1}
7899 local param="mgc.*.mgs_server_uuid"
7903 # 1. wait the deadline of client 1st request (it could be skipped)
7904 # 2. wait the deadline of client 2nd request
7905 local maxtime=$(( 2 * $(request_timeout $facet)))
7907 if [[ $facet == client* ]]; then
7908 # During setup time, the osc might not be setup, it need wait
7909 # until list_param can return valid value. And also if there
7910 # are mulitple osc entries we should list all of them before
7912 params=$($LCTL list_param $param 2>/dev/null || true)
7913 while [ -z "$params" ]; do
7914 if [ $i -ge $maxtime ]; then
7915 echo "can't get $param in $maxtime secs"
7920 params=$($LCTL list_param $param 2>/dev/null || true)
7923 local plist=$(comma_list $params)
7924 if ! do_rpc_nodes "$(facet_active_host $facet)" \
7925 wait_import_state $expected $plist $maxtime \
7926 $error_on_failure; then
7927 if [ $error_on_failure -ne 0 ]; then
7928 error "import is not in ${expected} state"
7936 wait_mgc_import_state() {
7939 local error_on_failure=${3:-1}
7942 if [[ $facet = mds ]]; then
7943 for num in $(seq $MDSCOUNT); do
7944 _wait_mgc_import_state mds$num "$expected" \
7945 $error_on_failure || return
7948 _wait_mgc_import_state "$facet" "$expected"
7949 $error_on_failure || return
7953 wait_dne_interconnect() {
7956 if [ $MDSCOUNT -gt 1 ]; then
7957 for num in $(seq $MDSCOUNT); do
7958 wait_osc_import_ready mds mds$num
7963 get_clientmdc_proc_path() {
7967 get_clientmgc_proc_path() {
7974 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
7979 [ -z "$list" ] && return 0
7981 # Add paths to lustre tests for 32 and 64 bit systems.
7982 local LIBPATH="/usr/lib/lustre/tests:/usr/lib64/lustre/tests:"
7983 local TESTPATH="$RLUSTRE/tests:"
7984 local RPATH="PATH=${TESTPATH}${LIBPATH}${PATH}:/sbin:/bin:/usr/sbin:"
7985 do_nodes ${quiet:-"--verbose"} $list "${RPATH} NAME=${NAME} bash rpc.sh $@ "
7988 wait_clients_import_state () {
7992 local facets="$facet"
7994 if [ "$FAILURE_MODE" = HARD ]; then
7995 facets=$(for f in ${facet//,/ }; do
7996 facets_on_host $(facet_active_host $f) | tr "," "\n"
7997 done | sort -u | paste -sd , )
8000 for facet in ${facets//,/ }; do
8001 local label=$(convert_facet2label $facet)
8004 ost* ) proc_path="osc.$(get_clientosc_proc_path \
8005 $label).ost_server_uuid" ;;
8006 mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
8007 $label).mds_server_uuid" ;;
8008 mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
8009 $label).mgs_server_uuid" ;;
8010 *) error "unknown facet!" ;;
8013 local params=$(expand_list $params $proc_path)
8016 if ! do_rpc_nodes "$list" wait_import_state_mount "$expected" $params;
8018 error "import is not in ${expected} state"
8030 # wait until all MDTs are in the expected state
8031 for ((num = 1; num <= $MDSCOUNT; num++)); do
8032 local mdtosp=$(get_mdtosc_proc_path mds${num} ${tgt_name})
8036 if [ $facet = "mds" ]; then
8037 mproc="osp.$mdtosp.active"
8038 [ $num -eq $((tgt_idx + 1)) ] && continue
8040 mproc="osc.$mdtosp.active"
8046 local result=$(do_facet mds${num} "$LCTL get_param -n $mproc")
8049 [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $mproc"
8050 if [ $result -eq $expected ]; then
8051 echo -n "target updated after "
8052 echo "$wait sec (got $result)"
8056 if [ $wait -eq $max ]; then
8057 error "$tgt_name: wanted $expected got $result"
8059 echo "Waiting $((max - wait)) secs for $tgt_name"
8069 AVAILA=($(do_nodes $(comma_list $(osts_nodes)) \
8070 $LCTL get_param obdfilter.*.kbytesavail))
8071 GRANTA=($(do_nodes $(comma_list $(osts_nodes)) \
8072 $LCTL get_param -n obdfilter.*.tot_granted))
8073 TOTALA=($(do_nodes $(comma_list $(osts_nodes)) \
8074 $LCTL get_param -n obdfilter.*.kbytestotal))
8075 for ((i=0; i<${#AVAILA[@]}; i++)); do
8076 local -a AVAIL1=(${AVAILA[$i]//=/ })
8077 local -a TOTAL=(${TOTALA[$i]//=/ })
8078 GRANT=$((${GRANTA[$i]}/1024))
8079 # allow 1% of total space in bavail because of delayed
8080 # allocation with ZFS which might release some free space after
8081 # txg commit. For small devices, we set a mininum of 8MB
8082 local LIMIT=$((${TOTAL} / 100 + 8000))
8083 echo -n $(echo ${AVAIL1[0]} | cut -d"." -f2) avl=${AVAIL1[1]} \
8084 grnt=$GRANT diff=$((AVAIL1[1] - GRANT)) limit=${LIMIT}
8085 [ $((AVAIL1[1] - GRANT)) -lt $LIMIT ] && OSCFULL=0 && \
8086 echo " FULL" || echo
8092 echo -e "$(do_facet $SINGLEMDS $LCTL pool_list $1 | sed '1d')"
8095 check_pool_not_exist() {
8096 local fsname=${1%%.*}
8097 local poolname=${1##$fsname.}
8098 [[ $# -ne 1 ]] && return 0
8099 [[ x$poolname = x ]] && return 0
8100 list_pool $fsname | grep -w $1 && return 1
8105 local fsname=${1%%.*}
8106 local poolname=${1##$fsname.}
8107 local keep_pools=${2:-false}
8109 stack_trap "destroy_test_pools $fsname" EXIT
8110 do_facet mgs lctl pool_new $1
8112 # get param should return err unless pool is created
8113 [[ $RC -ne 0 ]] && return $RC
8115 for mds_id in $(seq $MDSCOUNT); do
8116 local mdt_id=$((mds_id-1))
8117 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
8118 wait_update_facet mds$mds_id \
8119 "lctl get_param -n lod.$lodname.pools.$poolname \
8120 2>/dev/null || echo foo" "" ||
8121 error "mds$mds_id: pool_new failed $1"
8123 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
8124 2>/dev/null || echo foo" "" || error "pool_new failed $1"
8126 $keep_pools || add_pool_to_list $1
8130 add_pool_to_list () {
8131 local fsname=${1%%.*}
8132 local poolname=${1##$fsname.}
8134 local listvar=${fsname}_CREATED_POOLS
8135 local temp=${listvar}=$(expand_list ${!listvar} $poolname)
8139 remove_pool_from_list () {
8140 local fsname=${1%%.*}
8141 local poolname=${1##$fsname.}
8143 local listvar=${fsname}_CREATED_POOLS
8144 local temp=${listvar}=$(exclude_items_from_list "${!listvar}" $poolname)
8148 # cleanup all pools exist on $FSNAME
8149 destroy_all_pools () {
8151 for i in $(list_pool $FSNAME); do
8156 destroy_pool_int() {
8158 local OSTS=$(list_pool $1)
8159 for ost in $OSTS; do
8160 do_facet mgs lctl pool_remove $1 $ost
8162 wait_update_facet $SINGLEMDS "lctl pool_list $1 | wc -l" "1" ||
8163 error "MDS: pool_list $1 failed"
8164 do_facet mgs lctl pool_destroy $1
8167 # <fsname>.<poolname> or <poolname>
8169 local fsname=${1%%.*}
8170 local poolname=${1##$fsname.}
8172 [[ x$fsname = x$poolname ]] && fsname=$FSNAME
8176 check_pool_not_exist $fsname.$poolname && return 0 || true
8178 destroy_pool_int $fsname.$poolname
8180 [[ $RC -ne 0 ]] && return $RC
8181 for mds_id in $(seq $MDSCOUNT); do
8182 local mdt_id=$((mds_id-1))
8183 local lodname=$fsname-MDT$(printf "%04x" $mdt_id)-mdtlov
8184 wait_update_facet mds$mds_id \
8185 "lctl get_param -n lod.$lodname.pools.$poolname \
8186 2>/dev/null || echo foo" "foo" ||
8187 error "mds$mds_id: destroy pool failed $1"
8189 wait_update $HOSTNAME "lctl get_param -n lov.$fsname-*.pools.$poolname \
8190 2>/dev/null || echo foo" "foo" || error "destroy pool failed $1"
8192 remove_pool_from_list $fsname.$poolname
8198 local fsname=${1:-$FSNAME}
8200 local listvar=${fsname}_CREATED_POOLS
8202 [ x${!listvar} = x ] && return 0
8204 echo "Destroy the created pools: ${!listvar}"
8205 for poolname in ${!listvar//,/ }; do
8206 destroy_pool $fsname.$poolname
8210 destroy_test_pools () {
8212 local fsname=${1:-$FSNAME}
8213 destroy_pools $fsname || true
8219 local ts=$(date +%s)
8222 if [[ ! -f "$YAML_LOG" ]]; then
8223 # init_logging is not performed before gather_logs,
8224 # so the $LOGDIR needs to be checked here
8225 check_shared_dir $LOGDIR && touch $LOGDIR/shared
8228 [ -f $LOGDIR/shared ] && docp=false
8230 # dump lustre logs, dmesg, and journal if GSS_SK=true
8232 prefix="$TESTLOG_PREFIX.$TESTNAME"
8234 echo "Dumping lctl log to ${prefix}.*.${suffix}"
8236 if [ -n "$CLIENTONLY" -o "$PDSH" == "no_dsh" ]; then
8237 echo "Dumping logs only on local client."
8238 $LCTL dk > ${prefix}.debug_log.$(hostname -s).${suffix}
8239 dmesg > ${prefix}.dmesg.$(hostname -s).${suffix}
8240 [ "$SHARED_KEY" = true ] && find $SK_PATH -name '*.key' -exec \
8241 lgss_sk -r {} \; &> \
8242 ${prefix}.ssk_keys.$(hostname -s).${suffix}
8243 [ "$SHARED_KEY" = true ] && lctl get_param 'nodemap.*.*' > \
8244 ${prefix}.nodemaps.$(hostname -s).${suffix}
8245 [ "$GSS_SK" = true ] && keyctl show > \
8246 ${prefix}.keyring.$(hostname -s).${suffix}
8247 [ "$GSS_SK" = true ] && journalctl -a > \
8248 ${prefix}.journal.$(hostname -s).${suffix}
8253 "$LCTL dk > ${prefix}.debug_log.\\\$(hostname -s).${suffix};
8254 dmesg > ${prefix}.dmesg.\\\$(hostname -s).${suffix}"
8255 if [ "$SHARED_KEY" = true ]; then
8256 do_nodesv $list "find $SK_PATH -name '*.key' -exec \
8257 lgss_sk -r {} \; &> \
8258 ${prefix}.ssk_keys.\\\$(hostname -s).${suffix}"
8259 do_facet mds1 "lctl get_param 'nodemap.*.*' > \
8260 ${prefix}.nodemaps.\\\$(hostname -s).${suffix}"
8262 if [ "$GSS_SK" = true ]; then
8263 do_nodesv $list "keyctl show > \
8264 ${prefix}.keyring.\\\$(hostname -s).${suffix}"
8265 do_nodesv $list "journalctl -a > \
8266 ${prefix}.journal.\\\$(hostname -s).${suffix}"
8269 if [ ! -f $LOGDIR/shared ]; then
8270 local remote_nodes=$(exclude_items_from_list $list $HOSTNAME)
8272 for node in ${remote_nodes//,/ }; do
8273 rsync -az -e ssh $node:${prefix}.'*'.${suffix} $LOGDIR &
8287 for i in $(seq 0 $num_mntpts); do
8288 cmd="ls -laf ${mntpt_root}$i/$dir"
8294 for pid in $pids; do
8301 # check_and_start_recovery_timer()
8302 # service_time = at_est2timeout(service_time);
8303 # service_time += 2 * INITIAL_CONNECT_TIMEOUT;
8304 # service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC);
8306 #define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN, obd_timeout/20)
8307 #define CONNECTION_SWITCH_MAX min(50, max(CONNECTION_SWITCH_MIN, obd_timeout))
8308 #define CONNECTION_SWITCH_MIN 5
8309 #define CONNECTION_SWITCH_INC 5
8310 max_recovery_time() {
8311 local init_connect_timeout=$((TIMEOUT / 20))
8312 ((init_connect_timeout >= 5)) || init_connect_timeout=5
8314 local service_time=$(($(at_max_get client) * 9 / 4 + 5))
8315 service_time=$((service_time + 2 * (init_connect_timeout + 50 + 5)))
8317 echo -n $service_time
8320 recovery_time_min() {
8321 local connection_switch_min=5
8322 local connection_switch_inc=5
8323 local connection_switch_max
8324 local reconnect_delay_max
8325 local initial_connect_timeout
8329 #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
8330 (($connection_switch_min > $TIMEOUT)) &&
8331 max=$connection_switch_min || max=$TIMEOUT
8332 (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
8334 #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
8335 timeout_20=$((TIMEOUT/20))
8336 (($connection_switch_min > $timeout_20)) &&
8337 initial_connect_timeout=$connection_switch_min ||
8338 initial_connect_timeout=$timeout_20
8340 reconnect_delay_max=$((connection_switch_max + connection_switch_inc + \
8341 initial_connect_timeout))
8342 echo $((2 * reconnect_delay_max))
8345 get_clients_mount_count () {
8346 local clients=${CLIENTS:-$HOSTNAME}
8348 # we need to take into account the clients mounts and
8349 # exclude mds/ost mounts if any;
8350 do_nodes $clients cat /proc/mounts | grep lustre |
8351 grep -w $MOUNT | wc -l
8355 PROC_CLI="srpc_info"
8356 PROC_CON="srpc_contexts"
8364 if [ $M -lt $N ]; then
8368 while [ $N -lt $M ]; do
8378 calc_connection_cnt() {
8381 # MDT->MDT = 2 * C(M, 2)
8385 comb_m2=$(combination $MDSCOUNT 2)
8387 local num_clients=$(get_clients_mount_count)
8389 local cnt_mdt2mdt=$((comb_m2 * 2))
8390 local cnt_mdt2ost=$((MDSCOUNT * OSTCOUNT))
8391 local cnt_cli2ost=$((num_clients * OSTCOUNT))
8392 local cnt_cli2mdt=$((num_clients * MDSCOUNT))
8393 if is_mounted $MOUNT2; then
8394 cnt_cli2mdt=$((cnt_cli2mdt * 2))
8395 cnt_cli2ost=$((cnt_cli2ost * 2))
8403 local cnt_all2ost=$((cnt_mdt2ost + cnt_cli2ost))
8404 local cnt_all2mdt=$((cnt_mdt2mdt + cnt_cli2mdt))
8405 local cnt_all2all=$((cnt_mdt2ost + cnt_mdt2mdt \
8406 + cnt_cli2ost + cnt_cli2mdt))
8420 local cmd="$tgt.srpc.flavor"
8422 if [ $net == "any" ]; then
8427 if [ $dir != "any" ]; then
8432 log "Setting sptlrpc rule: $cmd"
8433 do_facet mgs "$LCTL conf_param $cmd"
8439 local total_ctx=$(echo "$output" | grep -c "expire.*key.*hdl")
8449 rpc_flvr=`echo $flavor | awk -F - '{ print $1 }'`
8450 bulkspec=`echo $flavor | awk -F - '{ print $2 }'`
8452 count=`echo "$output" | grep "rpc flavor" | grep $rpc_flvr | wc -l`
8454 if [ "x$bulkspec" != "x" ]; then
8455 algs=`echo $bulkspec | awk -F : '{ print $2 }'`
8457 if [ "x$algs" != "x" ]; then
8458 bulk_count=`echo "$output" | grep "bulk flavor" | grep $algs | wc -l`
8460 bulk=`echo $bulkspec | awk -F : '{ print $1 }'`
8461 if [ $bulk == "bulkn" ]; then
8462 bulk_count=`echo "$output" | grep "bulk flavor" \
8463 | grep "null/null" | wc -l`
8464 elif [ $bulk == "bulki" ]; then
8465 bulk_count=`echo "$output" | grep "bulk flavor" \
8466 | grep "/null" | grep -v "null/" | wc -l`
8468 bulk_count=`echo "$output" | grep "bulk flavor" \
8469 | grep -v "/null" | grep -v "null/" | wc -l`
8473 [ $bulk_count -lt $count ] && count=$bulk_count
8484 local clients=${CLIENTS:-$HOSTNAME}
8486 for c in ${clients//,/ }; do
8487 local output=$(do_node $c lctl get_param -n \
8488 mdc.*-*-mdc-*.$PROC_CLI 2>/dev/null)
8489 local tmpcnt=$(count_flvr "$output" $flavor)
8490 if $GSS_SK && [ $flavor != "null" ]; then
8491 # tmpcnt=min(contexts,flavors) to ensure SK context is on
8492 output=$(do_node $c lctl get_param -n \
8493 mdc.*-MDT*-mdc-*.$PROC_CON 2>/dev/null)
8494 local outcon=$(count_contexts "$output")
8495 if [ "$outcon" -lt "$tmpcnt" ]; then
8499 cnt=$((cnt + tmpcnt))
8509 local clients=${CLIENTS:-$HOSTNAME}
8511 for c in ${clients//,/ }; do
8513 do_node $c lctl set_param osc.*.idle_connect=1 >/dev/null 2>&1
8514 local output=$(do_node $c lctl get_param -n \
8515 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CLI 2>/dev/null)
8516 local tmpcnt=$(count_flvr "$output" $flavor)
8517 if $GSS_SK && [ $flavor != "null" ]; then
8518 # tmpcnt=min(contexts,flavors) to ensure SK context is on
8519 output=$(do_node $c lctl get_param -n \
8520 osc.*OST*-osc-[^M][^D][^T]*.$PROC_CON 2>/dev/null)
8521 local outcon=$(count_contexts "$output")
8522 if [ "$outcon" -lt "$tmpcnt" ]; then
8526 cnt=$((cnt + tmpcnt))
8536 if [ $MDSCOUNT -le 1 ]; then
8541 for num in `seq $MDSCOUNT`; do
8542 local output=$(do_facet mds$num lctl get_param -n \
8543 osp.*-MDT*osp-MDT*.$PROC_CLI 2>/dev/null)
8544 local tmpcnt=$(count_flvr "$output" $flavor)
8545 if $GSS_SK && [ $flavor != "null" ]; then
8546 # tmpcnt=min(contexts,flavors) to ensure SK context is on
8547 output=$(do_facet mds$num lctl get_param -n \
8548 osp.*-MDT*osp-MDT*.$PROC_CON 2>/dev/null)
8549 local outcon=$(count_contexts "$output")
8550 if [ "$outcon" -lt "$tmpcnt" ]; then
8554 cnt=$((cnt + tmpcnt))
8565 for num in `seq $MDSCOUNT`; do
8566 mdtosc=$(get_mdtosc_proc_path mds$num)
8567 mdtosc=${mdtosc/-MDT*/-MDT\*}
8568 local output=$(do_facet mds$num lctl get_param -n \
8569 os[cp].$mdtosc.$PROC_CLI 2>/dev/null)
8570 local tmpcnt=$(count_flvr "$output" $flavor)
8571 if $GSS_SK && [ $flavor != "null" ]; then
8572 # tmpcnt=min(contexts,flavors) to ensure SK context is on
8573 output=$(do_facet mds$num lctl get_param -n \
8574 os[cp].$mdtosc.$PROC_CON 2>/dev/null)
8575 local outcon=$(count_contexts "$output")
8576 if [ "$outcon" -lt "$tmpcnt" ]; then
8580 cnt=$((cnt + tmpcnt))
8589 local output=$(do_facet client lctl get_param -n mgc.*.$PROC_CLI \
8591 count_flvr "$output" $flavor
8596 local dir=$1 # from to
8597 local flavor=$2 # flavor expected
8600 if [ $dir == "cli2mdt" ]; then
8601 res=`flvr_cnt_cli2mdt $flavor`
8602 elif [ $dir == "cli2ost" ]; then
8603 res=`flvr_cnt_cli2ost $flavor`
8604 elif [ $dir == "mdt2mdt" ]; then
8605 res=`flvr_cnt_mdt2mdt $flavor`
8606 elif [ $dir == "mdt2ost" ]; then
8607 res=`flvr_cnt_mdt2ost $flavor`
8608 elif [ $dir == "all2ost" ]; then
8609 res1=`flvr_cnt_mdt2ost $flavor`
8610 res2=`flvr_cnt_cli2ost $flavor`
8611 res=$((res1 + res2))
8612 elif [ $dir == "all2mdt" ]; then
8613 res1=`flvr_cnt_mdt2mdt $flavor`
8614 res2=`flvr_cnt_cli2mdt $flavor`
8615 res=$((res1 + res2))
8616 elif [ $dir == "all2all" ]; then
8617 res1=`flvr_cnt_mdt2ost $flavor`
8618 res2=`flvr_cnt_cli2ost $flavor`
8619 res3=`flvr_cnt_mdt2mdt $flavor`
8620 res4=`flvr_cnt_cli2mdt $flavor`
8621 res=$((res1 + res2 + res3 + res4))
8629 local dir=$1 # from to
8630 local flavor=$2 # flavor expected
8631 local expect=${3:-$(calc_connection_cnt $dir)} # number expected
8632 local WAITFLAVOR_MAX=20 # how many retries before abort?
8635 for ((i = 0; i < $WAITFLAVOR_MAX; i++)); do
8636 echo -n "checking $dir..."
8637 res=$(do_check_flavor $dir $flavor)
8638 echo "found $res/$expect $flavor connections"
8639 [ $res -ge $expect ] && return 0
8643 echo "Error checking $flavor of $dir: expect $expect, actual $res"
8644 # echo "Dumping additional logs for SK debug.."
8645 do_nodes $(comma_list $(all_server_nodes)) "keyctl show"
8647 gather_logs $(comma_list $(nodes_list))
8652 restore_to_default_flavor()
8654 local proc="mgs.MGS.live.$FSNAME"
8656 echo "restoring to default flavor..."
8658 local nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
8659 grep ".srpc.flavor" | wc -l)
8661 # remove all existing rules if any
8662 if [ $nrule -ne 0 ]; then
8663 echo "$nrule existing rules"
8664 for rule in $(do_facet mgs lctl get_param -n $proc 2>/dev/null |
8665 grep ".srpc.flavor."); do
8666 echo "remove rule: $rule"
8667 spec=`echo $rule | awk -F = '{print $1}'`
8668 do_facet mgs "$LCTL conf_param -d $spec"
8672 # verify no rules left
8673 nrule=$(do_facet mgs lctl get_param -n $proc 2>/dev/null |
8674 grep ".srpc.flavor." | wc -l)
8675 [ $nrule -ne 0 ] && error "still $nrule rules left"
8677 # wait for default flavor to be applied
8680 set_rule $FSNAME any any $SK_FLAVOR
8681 wait_flavor all2all $SK_FLAVOR
8683 set_rule $FSNAME any cli2mdt $SK_FLAVOR
8684 set_rule $FSNAME any cli2ost $SK_FLAVOR
8685 wait_flavor cli2mdt $SK_FLAVOR
8686 wait_flavor cli2ost $SK_FLAVOR
8688 echo "GSS_SK now at default flavor: $SK_FLAVOR"
8690 wait_flavor all2all null
8696 local flavor=${1:-null}
8698 echo "setting all flavor to $flavor"
8700 # FIXME need parameter to this fn
8701 # and remove global vars
8702 local cnt_all2all=$(calc_connection_cnt all2all)
8704 local res=$(do_check_flavor all2all $flavor)
8705 if [ $res -eq $cnt_all2all ]; then
8706 echo "already have total $res $flavor connections"
8710 echo "found $res $flavor out of total $cnt_all2all connections"
8711 restore_to_default_flavor
8713 [[ $flavor = null ]] && return 0
8715 if $GSS_SK && [ $flavor != "null" ]; then
8717 set_rule $FSNAME any any $flavor
8718 wait_flavor all2all $flavor
8720 set_rule $FSNAME any cli2mdt $flavor
8721 set_rule $FSNAME any cli2ost $flavor
8722 set_rule $FSNAME any mdt2ost null
8723 set_rule $FSNAME any mdt2mdt null
8724 wait_flavor cli2mdt $flavor
8725 wait_flavor cli2ost $flavor
8727 echo "GSS_SK now at flavor: $flavor"
8729 set_rule $FSNAME any any $flavor
8730 wait_flavor all2all $flavor
8737 # Checking for shared logdir
8738 if [ ! -d $dir ]; then
8739 # Not found. Create local logdir
8742 touch $dir/check_file.$(hostname -s)
8747 check_write_access() {
8749 local list=${2:-$(comma_list $(nodes_list))}
8753 for node in ${list//,/ }; do
8754 file=$dir/check_file.$(short_nodename $node)
8755 if [[ ! -f "$file" ]]; then
8756 # Logdir not accessible/writable from this node.
8759 rm -f $file || return 1
8765 [[ -n $YAML_LOG ]] && return
8766 local save_umask=$(umask)
8769 export YAML_LOG=${LOGDIR}/results.yml
8773 # If the yaml log already exists then we will just append to it
8774 if [ ! -f $YAML_LOG ]; then
8775 if check_shared_dir $LOGDIR; then
8776 touch $LOGDIR/shared
8777 echo "Logging to shared log directory: $LOGDIR"
8779 echo "Logging to local directory: $LOGDIR"
8782 yml_nodes_file $LOGDIR >> $YAML_LOG
8783 yml_results_file >> $YAML_LOG
8788 # log actual client and server versions if needed for debugging
8789 log "Client: $(lustre_build_version client)"
8790 log "MDS: $(lustre_build_version mds1)"
8791 log "OSS: $(lustre_build_version ost1)"
8795 yml_log_test $1 >> $YAML_LOG
8799 yml_log_test_status $@ >> $YAML_LOG
8802 log_sub_test_begin() {
8803 yml_log_sub_test_begin "$@" >> $YAML_LOG
8806 log_sub_test_end() {
8807 yml_log_sub_test_end "$@" >> $YAML_LOG
8813 local llverdev_opts="$*"
8814 local devname=$(basename $dev)
8815 local size=$(awk "/$devname$/ {print \$3}" /proc/partitions)
8816 # loop devices aren't in /proc/partitions
8817 [[ -z "$size" ]] && size=$(stat -c %s $dev)
8819 local size_gb=$((size / 1024 / 1024)) # Gb
8821 local partial_arg=""
8822 # Run in partial (fast) mode if the size of a partition > 1 GB
8823 (( $size == 0 || $size_gb > 1 )) && partial_arg="-p"
8825 llverdev --force $partial_arg $llverdev_opts $dev
8831 local llverfs_opts=$2
8832 local use_partial_arg=$3
8833 local partial_arg=""
8834 local size=$(df -B G $dir |tail -n 1 |awk '{print $2}' |sed 's/G//') #GB
8836 # Run in partial (fast) mode if the size of a partition > 1 GB
8837 [ "x$use_partial_arg" != "xno" ] && [ $size -gt 1 ] && partial_arg="-p"
8839 llverfs $partial_arg $llverfs_opts $dir
8843 local devs=${1//,/ }
8846 local rslt=$TMP/sgpdd_survey
8848 # sgpdd-survey cleanups ${rslt}.* files
8850 local cmd="rslt=$rslt $params scsidevs=\"$devs\" $SGPDDSURVEY"
8856 # returns the canonical name for an ldiskfs device
8861 do_facet $facet "dv=\\\$($LCTL get_param -n $dev);
8862 if foo=\\\$(lvdisplay -c \\\$dv 2>/dev/null); then
8863 echo dm-\\\${foo##*:};
8865 name=\\\$(basename \\\$dv);
8866 if [[ \\\$name = *flakey* ]]; then
8867 name=\\\$(lsblk -o NAME,KNAME |
8868 awk /\\\$name/'{print \\\$NF}');
8874 is_sanity_benchmark() {
8875 local benchmarks="dbench bonnie iozone fsx"
8877 for b in $benchmarks; do
8878 if [ "$b" == "$suite" ]; then
8886 $LFS df | grep OST | awk '{print $4}' | sort -un | head -1
8890 # Get the available size (KB) of a given obd target.
8897 [[ $facet != client ]] || return 0
8899 size=$(do_facet $facet $LCTL get_param -n *.$obd.kbytesavail | head -n1)
8904 # Get the page size (bytes) on a given facet node.
8905 # The local client page_size is directly available in PAGE_SIZE.
8909 local page_size=$(getconf PAGE_SIZE 2>/dev/null)
8911 [ -z "$CLIENTONLY" -a "$facet" != "client" ] &&
8912 page_size=$(do_facet $facet getconf PAGE_SIZE)
8913 echo -n ${page_size:-4096}
8917 # Get the block count of the filesystem.
8924 [ -z "$CLIENTONLY" ] && count=$(do_facet $facet "$DUMPE2FS -h $device 2>&1" |
8925 awk '/^Block count:/ {print $3}')
8929 # Check whether the "ea_inode" feature is enabled or not, to allow
8930 # ldiskfs xattrs over one block in size. Allow both the historical
8931 # Lustre feature name (large_xattr) and the upstream name (ea_inode).
8932 large_xattr_enabled() {
8933 [[ $(facet_fstype $SINGLEMDS) == zfs ]] && return 0
8935 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
8937 do_facet $SINGLEMDS "$DUMPE2FS -h $mds_dev 2>&1 |
8938 grep -E -q '(ea_inode|large_xattr)'"
8939 return ${PIPESTATUS[0]}
8942 # Get the maximum xattr size supported by the filesystem.
8944 $LCTL get_param -n llite.*.max_easize
8947 # Dump the value of the named xattr from a file.
8952 echo "$(getfattr -n $xattr_name --absolute-names --only-values $file)"
8955 # Generate a string with size of $size bytes.
8957 local size=${1:-1024} # in bytes
8959 echo "$(head -c $size < /dev/zero | tr '\0' y)"
8962 reformat_external_journal() {
8967 local varbs=${facet}_BLOCKSIZE
8968 if [ -n "${!var}" ]; then
8969 local rcmd="do_facet $facet"
8970 local bs=${!varbs:-$BLCKSIZE}
8973 echo "reformat external journal on $facet:${!var}"
8974 ${rcmd} mke2fs -O journal_dev $bs ${!var} || return 1
8978 # MDT file-level backup/restore
8979 mds_backup_restore() {
8982 local devname=$(mdsdevname $(facet_number $facet))
8983 local mntpt=$(facet_mntpt brpt)
8984 local rcmd="do_facet $facet"
8985 local metadata=${TMP}/backup_restore.tgz
8986 local opts=${MDS_MOUNT_FS_OPTS}
8987 local svc=${facet}_svc
8989 if ! ${rcmd} test -b ${devname}; then
8990 opts=$(csa_add "$opts" -o loop)
8993 echo "file-level backup/restore on $facet:${devname}"
8995 # step 1: build mount point
8996 ${rcmd} mkdir -p $mntpt
8997 # step 2: cleanup old backup
8998 ${rcmd} rm -f $metadata
9000 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 3
9001 if [ ! -z $igif ]; then
9002 # step 3.5: rm .lustre
9003 ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 3
9005 # step 4: backup metadata
9007 ${rcmd} tar zcf $metadata --xattrs --xattrs-include="trusted.*" \
9008 --sparse -C $mntpt/ . > /dev/null 2>&1 || return 4
9010 ${rcmd} $UMOUNT $mntpt || return 5
9011 # step 6: reformat dev
9012 echo "reformat new device"
9013 format_mdt $(facet_number $facet)
9015 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 7
9016 # step 8: restore metadata
9018 ${rcmd} tar zxfp $metadata --xattrs --xattrs-include="trusted.*" \
9019 --sparse -C $mntpt > /dev/null 2>&1 || return 8
9020 # step 9: remove recovery logs
9021 echo "remove recovery logs"
9022 ${rcmd} rm -fv $mntpt/OBJECTS/* $mntpt/CATALOGS
9023 # step 10: umount dev
9024 ${rcmd} $UMOUNT $mntpt || return 10
9025 # step 11: cleanup tmp backup
9026 ${rcmd} rm -f $metaea $metadata
9027 # step 12: reset device label - it's not virgin on
9028 ${rcmd} e2label $devname ${!svc}
9035 local devname=$(mdsdevname $(facet_number $facet))
9036 local mntpt=$(facet_mntpt brpt)
9037 local rcmd="do_facet $facet"
9038 local opts=${MDS_MOUNT_FS_OPTS}
9040 if ! ${rcmd} test -b ${devname}; then
9041 opts=$(csa_add "$opts" -o loop)
9044 echo "removing OI files on $facet: idx=${idx}"
9046 # step 1: build mount point
9047 ${rcmd} mkdir -p $mntpt
9049 ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
9050 if [ -z $idx ]; then
9051 # step 3: remove all OI files
9052 ${rcmd} rm -fv $mntpt/oi.16*
9053 elif [ $idx -lt 2 ]; then
9054 ${rcmd} rm -fv $mntpt/oi.16.${idx}
9058 # others, rm oi.16.[idx, idx * idx, idx ** ...]
9059 for ((i=${idx}; i<64; i=$((i * idx)))); do
9060 ${rcmd} rm -fv $mntpt/oi.16.${i}
9064 ${rcmd} $UMOUNT $mntpt || return 2
9065 # OI files will be recreated when mounted as lustre next time.
9068 # generate maloo upload-able log file name
9069 # \param logname specify unique part of file name
9070 generate_logname() {
9071 local logname=${1:-"default_logname"}
9073 echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
9076 # make directory on different MDTs
9081 local hash_name=("all_char" "fnv_1a_64" "crush")
9082 local dirstripe_count=${DIRSTRIPE_COUNT:-"2"}
9083 local dirstripe_index=${DIRSTRIPE_INDEX:-$((base % $MDSCOUNT))}
9086 (( $MDS1_VERSION > $(version_code 2.15.0) )) &&
9087 hash_name+=("crush2")
9089 while getopts "c:H:i:p" opt; do
9091 c) dirstripe_count=$OPTARG;;
9092 H) hash_type=$OPTARG;;
9093 i) dirstripe_index=$OPTARG;;
9095 \?) error "only support -c -H -i -p";;
9099 shift $((OPTIND - 1))
9100 [ $# -eq 1 ] || error "Only creating single directory is supported"
9103 local parent=$(dirname $path)
9104 if [ "$p_option" == "-p" ]; then
9105 [ -d $path ] && return 0
9106 if [ ! -d ${parent} ]; then
9107 mkdir -p ${parent} ||
9108 error "mkdir parent '$parent' failed"
9112 if [ $MDSCOUNT -le 1 ] || ! is_lustre ${parent}; then
9113 mkdir $path || error "mkdir '$path' failed"
9117 if [ $dirstripe_index -eq -1 ]; then
9118 mdt_index=$((base % MDSCOUNT))
9120 mdt_index=$dirstripe_index
9123 # randomly choose hash type
9124 [ -z "$hash_type" ] &&
9125 hash_type=${hash_name[$((RANDOM % ${#hash_name[@]}))]}
9127 if (($MDS1_VERSION >= $(version_code 2.8.0))); then
9128 if [ $dirstripe_count -eq -1 ]; then
9129 dirstripe_count=$((RANDOM % MDSCOUNT + 1))
9135 echo "striped dir -i$mdt_index -c$dirstripe_count -H $hash_type $path"
9136 $LFS mkdir -i$mdt_index -c$dirstripe_count -H $hash_type $path ||
9137 error "mkdir -i $mdt_index -c$dirstripe_count -H $hash_type $path failed"
9141 # free_fd: find the smallest and not in use file descriptor [above @last_fd]
9143 # If called many times, passing @last_fd will avoid repeated searching
9144 # already-open FDs repeatedly if we know they are still in use.
9146 # usage: free_fd [last_fd]
9149 local max_fd=$(ulimit -n)
9150 local fd=$((${1:-2} + 1))
9152 while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
9155 [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
9159 check_mount_and_prep()
9161 is_mounted $MOUNT || setupall
9163 rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
9164 mkdir_on_mdt0 $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
9165 for idx in $(seq $MDSCOUNT); do
9166 local name="MDT$(printf '%04x' $((idx - 1)))"
9167 rm -rf $MOUNT/.lustre/lost+found/$name/*
9171 # calcule how many ost-objects to be created.
9172 precreated_ost_obj_count()
9176 local mdt_name="MDT$(printf '%04x' $mdt_idx)"
9177 local ost_name="OST$(printf '%04x' $ost_idx)"
9178 local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
9179 local last_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
9180 osp.$proc_path.prealloc_last_id)
9181 local next_id=$(do_facet mds$((mdt_idx + 1)) lctl get_param -n \
9182 osp.$proc_path.prealloc_next_id)
9183 echo $((last_id - next_id + 1))
9186 check_file_in_pool()
9191 local res=$($LFS getstripe $file | grep 0x | cut -f2)
9194 for t in $tlist ; do
9195 [ "$i" -eq "$t" ] && continue 2
9198 echo "pool list: $tlist"
9199 echo "striping: $res"
9200 error_noexit "$file not allocated in $pool"
9207 echo "Creating new pool"
9210 create_pool $FSNAME.$pool ||
9211 { error_noexit "No pool created, result code $?"; return 1; }
9212 [ $($LFS pool_list $FSNAME | grep -c "$FSNAME.${pool}\$") -eq 1 ] ||
9213 { error_noexit "$pool not in lfs pool_list"; return 2; }
9216 pool_add_targets() {
9217 echo "Adding targets to pool"
9223 if [ -z $last ]; then
9226 local list=$(seq $first $step $last)
9229 local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
9230 local tg=$(for i in $list;
9231 do printf -- "-e $FSNAME-OST%04x_UUID " $i; done)
9232 local firstx=$(printf "%04x" $first)
9233 local lastx=$(printf "%04x" $last)
9235 do_facet mgs $LCTL pool_add \
9236 $FSNAME.$pool $FSNAME-OST[$firstx-$lastx/$step]
9238 if (( $? != 0 && $? != 17 )); then
9239 error_noexit "pool_add $FSNAME-OST[$firstx-$lastx/$step] failed"
9243 # wait for OSTs to be added to the pool
9244 for mds_id in $(seq $MDSCOUNT); do
9245 local mdt_id=$((mds_id-1))
9246 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
9247 wait_update_facet mds$mds_id \
9248 "lctl get_param -n lod.$lodname.pools.$pool |
9249 grep $tg | sort -u | tr '\n' ' '" "$t" || {
9250 error_noexit "mds$mds_id: Add to pool failed"
9254 wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool |
9255 grep $tg | sort -u | tr '\n' ' ' " "$t" || {
9256 error_noexit "Add to pool failed"
9264 echo "Setting pool on directory $tdir"
9266 $LFS setstripe -c 2 -p $pool $tdir && return 0
9268 error_noexit "Cannot set pool $pool to $tdir"
9275 echo "Checking pool on directory $tdir"
9277 local res=$($LFS getstripe --pool $tdir | sed "s/\s*$//")
9278 [ "$res" = "$pool" ] && return 0
9280 error_noexit "Pool on '$tdir' is '$res', not '$pool'"
9284 pool_dir_rel_path() {
9285 echo "Testing relative path works well"
9290 mkdir -p $root/$tdir/$tdir
9292 pool_set_dir $pool $tdir || return 1
9293 pool_set_dir $pool ./$tdir || return 2
9294 pool_set_dir $pool ../$tdir || return 3
9295 pool_set_dir $pool ../$tdir/$tdir || return 4
9296 rm -rf $tdir; cd - > /dev/null
9299 pool_alloc_files() {
9300 echo "Checking files allocation from directory pool"
9307 for i in $(seq -w 1 $count)
9309 local file=$tdir/file-$i
9311 check_file_in_pool $file $pool "$tlist" || \
9312 failed=$((failed + 1))
9314 [ "$failed" = 0 ] && return 0
9316 error_noexit "$failed files not allocated in $pool"
9320 pool_create_files() {
9321 echo "Creating files in pool"
9329 for i in $(seq -w 1 $count)
9331 local file=$tdir/spoo-$i
9332 $LFS setstripe -p $pool $file
9333 check_file_in_pool $file $pool "$tlist" || \
9334 failed=$((failed + 1))
9336 [ "$failed" = 0 ] && return 0
9338 error_noexit "$failed files not allocated in $pool"
9343 echo "Checking 'lfs df' output"
9346 local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
9348 local res=$($LFS df --pool $FSNAME.$pool |
9350 grep "$FSNAME-OST" |
9352 [ "$res" = "$t" ] && return 0
9354 error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
9358 pool_file_rel_path() {
9359 echo "Creating files in a pool with relative pathname"
9364 { error_noexit "unable to create $tdir"; return 1 ; }
9365 local file="/..$tdir/$tfile-1"
9366 $LFS setstripe -p $pool $file ||
9367 { error_noexit "unable to create $file" ; return 2 ; }
9370 $LFS setstripe -p $pool $tfile-2 || {
9371 error_noexit "unable to create $tfile-2 in $tdir"
9376 pool_remove_first_target() {
9377 echo "Removing first target from a pool"
9378 pool_remove_target $1 -1
9381 pool_remove_target() {
9385 local pname="lov.$FSNAME-*.pools.$pool"
9386 if [ $index -eq -1 ]; then
9387 local t=$($LCTL get_param -n $pname | head -1)
9389 local t=$(printf "$FSNAME-OST%04x_UUID" $index)
9392 echo "Removing $t from $pool"
9393 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
9394 for mds_id in $(seq $MDSCOUNT); do
9395 local mdt_id=$((mds_id-1))
9396 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
9397 wait_update_facet mds$mds_id \
9398 "lctl get_param -n lod.$lodname.pools.$pool |
9400 error_noexit "mds$mds_id: $t not removed from" \
9405 wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
9406 error_noexit "$t not removed from $FSNAME.$pool"
9411 pool_remove_all_targets() {
9412 echo "Removing all targets from pool"
9415 local pname="lov.$FSNAME-*.pools.$pool"
9416 for t in $($LCTL get_param -n $pname | sort -u)
9418 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
9420 for mds_id in $(seq $MDSCOUNT); do
9421 local mdt_id=$((mds_id-1))
9422 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
9423 wait_update_facet mds$mds_id "lctl get_param -n \
9424 lod.$lodname.pools.$pool" "" || {
9425 error_noexit "mds$mds_id: Pool $pool not drained"
9429 wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
9430 error_noexit "Pool $FSNAME.$pool cannot be drained"
9433 # striping on an empty/nonexistant pool should fall back
9434 # to "pool of everything"
9436 error_noexit "failed to use fallback striping for empty pool"
9439 # setstripe on an empty pool should fail
9440 $LFS setstripe -p $pool $file 2>/dev/null && {
9441 error_noexit "expected failure when creating file" \
9449 echo "Destroying pool"
9453 do_facet mgs $LCTL pool_destroy $FSNAME.$pool
9456 # striping on an empty/nonexistant pool should fall back
9457 # to "pool of everything"
9459 error_noexit "failed to use fallback striping for missing pool"
9462 # setstripe on an empty pool should fail
9463 $LFS setstripe -p $pool $file 2>/dev/null && {
9464 error_noexit "expected failure when creating file" \
9469 # get param should return err once pool is gone
9470 if wait_update $HOSTNAME "lctl get_param -n \
9471 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
9473 remove_pool_from_list $FSNAME.$pool
9476 error_noexit "Pool $FSNAME.$pool is not destroyed"
9480 # Get and check the actual stripe count of one file.
9481 # Usage: check_stripe_count <file> <expected_stripe_count>
9482 check_stripe_count() {
9487 [[ -z "$file" || -z "$expected" ]] &&
9488 error "check_stripe_count: invalid argument"
9490 local cmd="$LFS getstripe -c $file"
9491 actual=$($cmd) || error "$cmd failed"
9492 actual=${actual%% *}
9494 if [[ $actual -ne $expected ]]; then
9495 [[ $expected -eq -1 ]] || { $LFS getstripe $file;
9496 error "$cmd not expected ($expected): found $actual"; }
9497 [[ $actual -eq $OSTCOUNT ]] || { $LFS getstripe $file;
9498 error "$cmd not OST count ($OSTCOUNT): found $actual"; }
9502 # Get and check the actual list of OST indices on one file.
9503 # Usage: check_obdidx <file> <expected_comma_separated_list_of_ost_indices>
9509 [[ -z "$file" || -z "$expected" ]] &&
9510 error "check_obdidx: invalid argument!"
9512 obdidx=$(comma_list $($LFS getstripe $file | grep -A $OSTCOUNT obdidx |
9513 grep -v obdidx | awk '{print $1}' | xargs))
9515 [[ $obdidx = $expected ]] ||
9516 error "list of OST indices on $file is $obdidx," \
9517 "should be $expected"
9520 # Get and check the actual OST index of the first stripe on one file.
9521 # Usage: check_start_ost_idx <file> <expected_start_ost_idx>
9522 check_start_ost_idx() {
9527 [[ -z "$file" || -z "$expected" ]] &&
9528 error "check_start_ost_idx: invalid argument!"
9530 start_ost_idx=$($LFS getstripe $file | grep -A 1 obdidx |
9531 grep -v obdidx | awk '{print $1}')
9533 [[ $start_ost_idx = $expected ]] ||
9534 error "OST index of the first stripe on $file is" \
9535 "$start_ost_idx, should be $expected"
9538 killall_process () {
9539 local clients=${1:-$(hostname)}
9544 do_nodes $clients "killall $signal $name"
9549 do_facet mgs "$LCTL snapshot_create -F $FSNAME $*"
9554 do_facet mgs "$LCTL snapshot_destroy -F $FSNAME $*"
9559 do_facet mgs "$LCTL snapshot_modify -F $FSNAME $*"
9564 do_facet mgs "$LCTL snapshot_list -F $FSNAME $*"
9569 do_facet mgs "$LCTL snapshot_mount -F $FSNAME $*"
9574 do_facet mgs "$LCTL snapshot_umount -F $FSNAME $*"
9581 do_facet mgs "cat $LSNAPSHOT_LOG"
9587 echo "Cleaning test environment ..."
9589 # Every lsnapshot command takes exclusive lock with others,
9590 # so can NOT destroy the snapshot during list with 'xargs'.
9592 local ssname=$(lsnapshot_list | grep snapshot_name |
9593 grep lss_ | awk '{ print $2 }' | head -n 1)
9594 [ -z "$ssname" ] && break
9596 lsnapshot_destroy -n $ssname -f ||
9597 lss_err "Fail to destroy $ssname by force"
9607 local host=$(facet_active_host $facet)
9608 local dir=$(dirname $(facet_vdevice $facet))
9609 local pool=$(zpool_name $facet)
9610 local lfsname=$(zfs_local_fsname $facet)
9611 local label=${FSNAME}-${role}$(printf '%04x' $idx)
9614 "echo '$host - $label zfs:${dir}/${pool}/${lfsname} - -' >> \
9620 do_facet mgs "rm -f $LSNAPSHOT_CONF"
9621 echo "Generating $LSNAPSHOT_CONF on MGS ..."
9623 if ! combined_mgs_mds ; then
9624 [ $(facet_fstype mgs) != zfs ] &&
9625 skip "Lustre snapshot 1 only works for ZFS backend"
9627 local host=$(facet_active_host mgs)
9628 local dir=$(dirname $(facet_vdevice mgs))
9629 local pool=$(zpool_name mgs)
9630 local lfsname=$(zfs_local_fsname mgs)
9633 "echo '$host - MGS zfs:${dir}/${pool}/${lfsname} - -' \
9634 >> $LSNAPSHOT_CONF" || lss_err "generate lss conf (mgs)"
9637 for num in `seq $MDSCOUNT`; do
9638 [ $(facet_fstype mds$num) != zfs ] &&
9639 skip "Lustre snapshot 1 only works for ZFS backend"
9641 lss_gen_conf_one mds$num MDT $((num - 1)) ||
9642 lss_err "generate lss conf (mds$num)"
9645 for num in `seq $OSTCOUNT`; do
9646 [ $(facet_fstype ost$num) != zfs ] &&
9647 skip "Lustre snapshot 1 only works for ZFS backend"
9649 lss_gen_conf_one ost$num OST $((num - 1)) ||
9650 lss_err "generate lss conf (ost$num)"
9653 do_facet mgs "cat $LSNAPSHOT_CONF"
9656 # Parse 'lfs getstripe -d <path_with_dir_name>' for non-composite dir
9657 parse_plain_dir_param()
9662 if [[ ${invalues[0]} =~ "stripe_count:" ]]; then
9663 param="-c ${invalues[1]}"
9665 if [[ ${invalues[2]} =~ "stripe_size:" ]]; then
9666 param="$param -S ${invalues[3]}"
9668 if [[ ${invalues[4]} =~ "pattern:" ]]; then
9669 if [[ ${invalues[5]} =~ "stripe_offset:" ]]; then
9670 param="$param -i ${invalues[6]}"
9672 param="$param -L ${invalues[5]} -i ${invalues[7]}"
9674 elif [[ ${invalues[4]} =~ "stripe_offset:" ]]; then
9675 param="$param -i ${invalues[5]}"
9683 local val=$(awk '{print $2}' <<< $line)
9685 if [[ $line =~ ^"lmm_stripe_count:" ]]; then
9687 elif [[ $line =~ ^"lmm_stripe_size:" ]]; then
9689 elif [[ $line =~ ^"lmm_stripe_offset:" ]]; then
9691 elif [[ $line =~ ^"lmm_pattern:" ]]; then
9696 parse_layout_param()
9703 if [[ ! -z $line ]]; then
9704 if [[ -z $mode ]]; then
9705 if [[ $line =~ ^"stripe_count:" ]]; then
9707 elif [[ $line =~ ^"lmm_stripe_count:" ]]; then
9709 elif [[ $line =~ ^"lcm_layout_gen:" ]]; then
9714 if [[ $mode = "plain_dir" ]]; then
9715 param=$(parse_plain_dir_param "$line")
9716 elif [[ $mode = "plain_file" ]]; then
9717 val=$(parse_plain_param "$line")
9718 [[ ! -z $val ]] && param="$param $val"
9719 elif [[ $mode = "pfl" ]]; then
9720 val=$(echo $line | awk '{print $2}')
9721 if [[ $line =~ ^"lcme_extent.e_end:" ]]; then
9722 if [[ $val = "EOF" ]]; then
9723 param="$param -E -1"
9725 param="$param -E $val"
9727 elif [[ $line =~ ^"stripe_count:" ]]; then
9729 val=$(parse_plain_dir_param "$line")
9733 val=$(parse_plain_param "$line")
9734 [[ ! -z $val ]] && param="$param $val"
9744 local param=$($LFS getstripe -d $1 | parse_layout_param)
9753 # Cancel locks before setting lfsck_verify_pfid so that errors are more
9755 cancel_lru_locks mdc
9756 cancel_lru_locks osc
9758 # make sure PFID is set correctly for files
9759 do_nodes $(comma_list $(osts_nodes)) \
9760 "$LCTL set_param -n obdfilter.${FSNAME}-OST*.lfsck_verify_pfid=1"
9763 cat $f &> /dev/nullA ||
9764 { rc=$?; echo "verify $f failed"; break; }
9767 do_nodes $(comma_list $(osts_nodes)) \
9768 "$LCTL set_param -n obdfilter.${FSNAME}-OST*.lfsck_verify_pfid=0"
9772 # check that clients "oscs" was evicted after "before"
9773 check_clients_evicted() {
9780 for osc in $oscs; do
9781 echo "Check state for $osc"
9782 local evicted=$(do_facet client $LCTL get_param osc.$osc.state |
9783 tail -n 5 | awk -F"[ ,]" \
9784 '/EVICTED/ { if (mx<$4) { mx=$4; } } END { print mx }')
9785 if (($? == 0)) && (($evicted > $before)); then
9786 echo "$osc is evicted at $evicted"
9789 echo "$osc was not evicted after $before:"
9790 do_facet client $LCTL get_param osc.$osc.state |
9795 [ $rc -eq 0 ] || error "client not evicted from OST"
9798 # check that clients OSCS current_state is FULL
9799 check_clients_full() {
9804 for osc in $oscs; do
9805 wait_update_facet client \
9806 "lctl get_param -n osc.$osc.state |
9807 grep 'current_state: FULL'" \
9808 "current_state: FULL" $timeout
9809 [ $? -eq 0 ] || error "$osc state is not FULL"
9814 __changelog_deregister() {
9816 local mdt="$(facet_svc $facet)"
9820 # skip cleanup if no user registered for this MDT
9821 [ -z "$cl_user" ] && echo "$mdt: no changelog user" && return 0
9822 # user is no longer registered, skip cleanup
9823 changelog_users "$facet" | grep -q "$cl_user" ||
9824 { echo "$mdt: changelog user '$cl_user' not found"; return 0; }
9826 # From this point, if any operation fails, it is an error
9827 __changelog_clear $facet $cl_user 0 ||
9828 error_noexit "$mdt: changelog_clear $cl_user 0 fail: $rc"
9829 do_facet $facet $LCTL --device $mdt changelog_deregister $cl_user ||
9830 error_noexit "$mdt: changelog_deregister '$cl_user' fail: $rc"
9833 declare -Ax CL_USERS
9834 changelog_register() {
9835 for M in $(seq $MDSCOUNT); do
9837 local mdt="$(facet_svc $facet)"
9840 cl_mask=$(do_facet $facet $LCTL get_param \
9841 mdd.${mdt}.changelog_mask -n)
9842 stack_trap "do_facet $facet $LCTL \
9843 set_param mdd.$mdt.changelog_mask=\'$cl_mask\' -n" EXIT
9844 do_facet $facet $LCTL set_param mdd.$mdt.changelog_mask=+hsm ||
9845 error "$mdt: changelog_mask=+hsm failed: $?"
9848 cl_user=$(do_facet $facet $LCTL --device $mdt \
9849 changelog_register -n $@) ||
9850 error "$mdt: register changelog user failed: $?"
9851 stack_trap "__changelog_deregister $facet $cl_user" EXIT
9853 stack_trap "CL_USERS[$facet]='${CL_USERS[$facet]}'" EXIT
9854 # Bash does not support nested arrays, but the format of a
9855 # cl_user is constrained enough to use whitespaces as separators
9856 CL_USERS[$facet]+="$cl_user "
9858 echo "Registered $MDSCOUNT changelog users: '${CL_USERS[@]% }'"
9861 changelog_deregister() {
9863 # bash assoc arrays do not guarantee to list keys in created order
9864 # so reorder to get same order than in changelog_register()
9865 local cl_facets=$(echo "${!CL_USERS[@]}" | tr " " "\n" | sort |
9868 for facet in $cl_facets; do
9869 for cl_user in ${CL_USERS[$facet]}; do
9870 __changelog_deregister $facet $cl_user || return $?
9872 unset CL_USERS[$facet]
9878 local service=$(facet_svc $facet)
9880 do_facet $facet $LCTL get_param -n mdd.$service.changelog_users
9883 changelog_user_rec() {
9886 local service=$(facet_svc $facet)
9888 changelog_users $facet | awk '$1 == "'$cl_user'" { print $2 }'
9891 changelog_chmask() {
9894 do_nodes $(comma_list $(mdts_nodes)) \
9895 $LCTL set_param mdd.*.changelog_mask="$mask"
9898 # usage: __changelog_clear FACET CL_USER [+]INDEX
9902 local mdt="$(facet_svc $facet)"
9908 # Remove the leading '+'
9910 rec+=$(changelog_user_rec $facet $cl_user)
9917 if [ $rec -eq 0 ]; then
9918 echo "$mdt: clear the changelog for $cl_user of all records"
9920 echo "$mdt: clear the changelog for $cl_user to record #$rec"
9922 $LFS changelog_clear $mdt $cl_user $rec
9925 # usage: changelog_clear [+]INDEX
9927 # If INDEX is prefixed with '+', increment every changelog user's record index
9928 # by INDEX. Otherwise, clear the changelog up to INDEX for every changelog
9932 # bash assoc arrays do not guarantee to list keys in created order
9933 # so reorder to get same order than in changelog_register()
9934 local cl_facets=$(echo "${!CL_USERS[@]}" | tr " " "\n" | sort |
9938 for facet in $cl_facets; do
9939 for cl_user in ${CL_USERS[$facet]}; do
9940 __changelog_clear $facet $cl_user $1 || rc=${rc:-$?}
9950 for M in $(seq $MDSCOUNT); do
9952 local mdt="$(facet_svc $facet)"
9956 output=$($LFS changelog $mdt)
9958 if [ $ret -ne 0 ]; then
9960 elif [ -n "$output" ]; then
9961 echo "$output" | sed -e 's/^/'$mdt'./'
9968 changelog_extract_field() {
9973 changelog_dump | gawk "/$cltype.*$file$/ {
9974 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
9978 # Prints a changelog record produced by "lfs changelog" as an associative array
9981 # $> changelog2array 16 01CREAT 10:28:46.968438800 2018.03.09 0x0 \
9982 # t=[0x200000401:0x10:0x0] j=touch.501 ef=0xf u=501:501 \
9983 # nid=0@lo p=[0x200000007:0x1:0x0] blob
9984 # ([index]='16' [type]='CREAT' [time]='10:28:46.968438800'
9985 # [date]='2018.03.09' [flags]=0x0 ['target-fid']='[0x200000401:0x10:0x0]'
9986 # ['jobid']='touch.501' ['extra-flags']='0x0f' [uid]='0' ['gid']='0'
9987 # ['nid']='0@lo' ['parent-fid']='[0x200000007:0x1:0x0]')
9989 # Note that the changelog record is not quoted
9990 # Also note that the line breaks in the output were only added for readability
9992 # Typically, you want to eval the output of the command to fill an actual
9993 # associative array, like this:
9994 # $> eval declare -A changelog=$(changelog2array $entry)
9996 # It can then be accessed like any bash associative array:
9997 # $> echo "${changelog[index]}" "${changelog[type]}" "${changelog[flags]}"
9999 # $> echo "${changelog[uid]}":"${changelog[gid]}"
10007 # A changelog, as printed by "lfs changelog" typically looks like this:
10008 # <index> <type> <time> <date> <flags> <key1=value1> <key2=value2> ...
10010 # Parse the positional part of the changelog
10012 # changelog_dump() prefixes records with their mdt's name
10013 local index="${1##*.}"
10015 printf "[index]='%s' [type]='%s' [time]='%s' [date]='%s' [flags]='%s'" \
10016 "$index" "${2:2}" "$3" "$4" "$5"
10018 # Parse the key/value part of the changelog
10019 for arg in "${@:5}"; do
10020 # Check it matches a key=value syntax
10021 [[ "$arg" =~ ^[[:alpha:]]+= ]] || continue
10023 local key="${arg%%=*}"
10024 local value="${arg#*=}"
10028 # u is actually for uid AND gid: u=UID:GID
10029 printf " [uid]='%s'" "${value%:*}"
10031 value="${value#*:}"
10059 printf " ['%s']='%s'" "$key" "$value"
10066 # Format and print a changelog record
10068 # Interpreted sequences are:
10070 # %f the "flags" attribute of a changelog record
10071 __changelog_printf()
10076 for ((i = 0; i < ${#format}; i++)); do
10077 local char="${format:$i:1}"
10078 if [ "$char" != % ]; then
10079 printf '%c' "$char"
10084 char="${format:$i:1}"
10087 printf '%s' "${changelog[flags]}"
10097 # Filter changelog records
10101 local action='print'
10104 while [ $# -gt 0 ]; do
10115 filter[${1#-}]="$2"
10124 changelog_dump | { while read -r record; do
10125 eval local -A changelog=$(changelog2array $record)
10126 for key in "${!filter[@]}"; do
10129 [ "${changelog[$key]}" == "${filter[$key]}" ]
10136 case "${action:-print}" in
10138 printf '%s\n' "$record"
10141 __changelog_printf "$format"
10151 [ ! -d "$dir" ] && return
10153 [ -z "$layout" ] && {
10154 $LFS setstripe -d $dir || error "error deleting stripe '$dir'"
10158 setfattr -n trusted.lov -v $layout $dir ||
10159 error "error restoring layout '$layout' to '$dir'"
10162 # save the layout of a directory, the returned string will be used by
10163 # restore_layout() to restore the layout
10166 local str=$(getfattr -n trusted.lov --absolute-names -e hex $dir \
10167 2> /dev/null | awk -F'=' '/trusted.lov/{ print $2 }')
10171 # save layout of a directory and restore it at exit
10172 save_layout_restore_at_exit() {
10174 local layout=$(save_layout $dir)
10176 stack_trap "restore_layout $dir $layout" EXIT
10179 verify_yaml_layout() {
10183 local msg_prefix=$4
10185 echo "getstripe --yaml $src"
10186 $LFS getstripe --yaml $src > $temp || error "getstripe $src failed"
10187 echo "setstripe --yaml=$temp $dst"
10188 $LFS setstripe --yaml=$temp $dst|| error "setstripe $dst failed"
10191 local layout1=$(get_layout_param $src)
10192 local layout2=$(get_layout_param $dst)
10193 # compare their layout info
10194 [ "$layout1" == "$layout2" ] ||
10195 error "$msg_prefix $src/$dst layouts are not equal"
10198 is_project_quota_supported() {
10199 $ENABLE_PROJECT_QUOTAS || return 1
10201 [[ "$(facet_fstype $SINGLEMDS)" == "ldiskfs" &&
10202 $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.9.55) ]] &&
10203 do_facet mds1 lfs --help |& grep -q project && return 0
10205 [[ "$(facet_fstype $SINGLEMDS)" == "zfs" &&
10206 $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.10.53) ]] &&
10207 do_facet mds1 $ZPOOL get all | grep -q project_quota && return 0
10212 # ZFS project quota enable/disable:
10213 # This feature will become active as soon as it is enabled and will never
10214 # return to being disabled. Each filesystem will be upgraded automatically
10215 # when remounted or when [a] new file is created under that filesystem. The
10216 # upgrade can also be triggered on filesystems via `zfs set version=current
10217 # <pool/fs>`. The upgrade process runs in the background and may take a
10218 # while to complete for the filesystems containing a large number of files.
10219 enable_project_quota() {
10220 is_project_quota_supported || return 0
10221 local zkeeper=${KEEP_ZPOOL}
10222 stack_trap "KEEP_ZPOOL=$zkeeper" EXIT
10224 stopall || error "failed to stopall (1)"
10226 local zfeat_en="feature@project_quota=enabled"
10227 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
10228 local facet_fstype=${facet:0:3}1_FSTYPE
10231 if [ "${!facet_fstype}" = "zfs" ]; then
10232 devname=$(zpool_name ${facet})
10233 do_facet ${facet} $ZPOOL set "$zfeat_en" $devname ||
10234 error "$ZPOOL set $zfeat_en $devname"
10236 [ ${facet:0:3} == "mds" ] &&
10237 devname=$(mdsdevname ${facet:3}) ||
10238 devname=$(ostdevname ${facet:3})
10239 do_facet ${facet} $TUNE2FS -O project $devname ||
10240 error "tune2fs $devname failed"
10244 KEEP_ZPOOL="${zkeeper}"
10249 disable_project_quota() {
10250 is_project_quota_supported || return 0
10251 [ "$mds1_FSTYPE" != "ldiskfs" ] && return 0
10252 stopall || error "failed to stopall (1)"
10254 for num in $(seq $MDSCOUNT); do
10255 do_facet mds$num $TUNE2FS -Q ^prj $(mdsdevname $num) ||
10256 error "tune2fs $(mdsdevname $num) failed"
10259 for num in $(seq $OSTCOUNT); do
10260 do_facet ost$num $TUNE2FS -Q ^prj $(ostdevname $num) ||
10261 error "tune2fs $(ostdevname $num) failed"
10269 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
10270 # the following associated variables are added:
10272 # AGTCOUNT: number of agents
10273 # AGTDEV{N}: target HSM mount point (root path of the backend)
10274 # agt{N}_HOST: hostname of the agent agt{N}
10275 # SINGLEAGT: facet of the single agent
10277 # The number of agents is initialized as the number of remote client nodes.
10278 # By default, only single copytool is started on a remote client/agent. If there
10279 # was no remote client, then the copytool will be started on the local client.
10285 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
10286 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
10288 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
10289 if [[ $CLIENTCOUNT -gt 1 ]] &&
10290 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
10291 skip_env "SHARED_DIRECTORY should be accessible"\
10292 "on all client nodes"
10296 # We used to put the HSM archive in $SHARED_DIRECTORY but that
10297 # meant NFS issues could hose sanity-hsm sessions. So now we
10298 # use $TMP instead.
10299 for n in $(seq $AGTCOUNT); do
10300 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
10301 agent=CLIENT$((n + 1))
10302 if [[ -z "${!agent}" ]]; then
10303 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
10306 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
10307 local var=agt${n}_HOST
10308 [[ ! -z "${!var}" ]] || error "agt${n}_HOST is empty!"
10311 export SINGLEAGT=${SINGLEAGT:-agt1}
10313 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
10314 export HSMTOOL_PID_FILE=${HSMTOOL_PID_FILE:-"/var/run/lhsmtool_posix.pid"}
10315 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
10316 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
10317 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
10318 export HSMTOOL_TESTDIR
10319 export HSMTOOL_ARCHIVE_FORMAT=${HSMTOOL_ARCHIVE_FORMAT:-v2}
10321 if ! [[ $HSMTOOL =~ hsmtool ]]; then
10322 echo "HSMTOOL = '$HSMTOOL' does not contain 'hsmtool', GLWT" >&2
10325 HSM_ARCHIVE_NUMBER=2
10327 # The test only support up to 10 MDTs
10328 MDT_PREFIX="mdt.$FSNAME-MDT000"
10329 HSM_PARAM="${MDT_PREFIX}0.hsm"
10331 # archive is purged at copytool setup
10332 HSM_ARCHIVE_PURGE=true
10334 # Don't allow copytool error upon start/setup
10335 HSMTOOL_NOERROR=false
10338 # Get the backend root path for the given agent facet.
10339 copytool_device() {
10341 local dev=AGTDEV$(facet_number $facet)
10346 get_mdt_devices() {
10348 # get MDT device for each mdc
10349 for mdtno in $(seq 1 $MDSCOUNT); do
10350 local idx=$(($mdtno - 1))
10351 MDT[$idx]=$($LCTL get_param -n \
10352 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
10353 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
10357 pkill_copytools() {
10361 do_nodes "$hosts" "pkill --pidfile=$HSMTOOL_PID_FILE --signal=$signal hsmtool"
10364 copytool_continue() {
10365 local agents=${1:-$(facet_active_host $SINGLEAGT)}
10367 pkill_copytools "$agents" CONT || return 0
10368 echo "Copytool is continued on $agents"
10372 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
10374 echo "Killing existing copytools on $hosts"
10375 pkill_copytools "$hosts" TERM || return 0
10376 copytool_continue "$hosts"
10379 copytool_monitor_cleanup() {
10380 local facet=${1:-$SINGLEAGT}
10381 local agent=$(facet_active_host $facet)
10383 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
10384 # Should die when the copytool dies, but just in case.
10385 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
10386 cmd+=" 2>/dev/null || true"
10387 do_node $agent "$cmd"
10388 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
10389 export HSMTOOL_MONITOR_DIR=
10392 # The pdsh should die on its own when the monitor dies. Just
10393 # in case, though, try to clean up to avoid any cruft.
10394 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
10395 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null || true
10396 export HSMTOOL_MONITOR_PDSH=
10402 local host="$(facet_host "$1")"
10403 local prefix=$TESTLOG_PREFIX
10404 [ -n "$TESTNAME" ] && prefix+=.$TESTNAME
10406 printf "${prefix}.copytool${archive_id}_log.${host}.log"
10409 __lhsmtool_rebind()
10411 do_facet $facet $HSMTOOL "${hsmtool_options[@]}" --rebind "$@" "$mountpoint"
10414 __lhsmtool_import()
10416 mkdir -p "$(dirname "$2")" ||
10417 error "cannot create directory '$(dirname "$2")'"
10418 do_facet $facet $HSMTOOL "${hsmtool_options[@]}" --import "$@" "$mountpoint"
10423 local host="$(facet_host "$facet")"
10424 local cmd="$HSMTOOL ${hsmtool_options[@]} --daemon --pid-file=$HSMTOOL_PID_FILE"
10425 [ -n "$bandwidth" ] && cmd+=" --bandwidth $bandwidth"
10426 [ -n "$archive_id" ] && cmd+=" --archive $archive_id"
10427 # [ ${#misc_options[@]} -gt 0 ] &&
10428 # cmd+=" $(IFS=" " echo "$@")"
10429 cmd+=" $@ \"$mountpoint\""
10431 echo "Starting copytool '$facet' on '$host' with cmdline '$cmd'"
10432 stack_trap "pkill_copytools $host TERM || true" EXIT
10433 do_node "$host" "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
10437 local facet="${1:-$SINGLEAGT}"
10439 printf "$(copytool_device "$facet")/${TESTSUITE}.${TESTNAME}/"
10442 # Main entry point to perform copytool related operations
10446 # setup setup a copytool to run in the background, that copytool will be
10448 # import import a file from an HSM backend
10449 # rebind rebind an archived file to a new fid
10451 # Although the semantics might suggest otherwise, one does not need to 'setup'
10452 # a copytool before a call to 'copytool import' or 'copytool rebind'.
10459 # Use default values
10460 local facet=$SINGLEAGT
10461 local mountpoint="${MOUNT2:-$MOUNT}"
10462 local hsm_root="${hsm_root:-$(hsm_root "$facet")}"
10465 local fail_on_error=true
10466 local -a hsmtool_options=("--hsm-root=$hsm_root")
10467 local -a action_options=()
10469 if [[ -n "$HSMTOOL_ARCHIVE_FORMAT" ]]; then
10470 hsmtool_options+=("--archive-format=$HSMTOOL_ARCHIVE_FORMAT")
10473 if [[ -n "$HSMTOOL_VERBOSE" ]]; then
10474 hsmtool_options+=("$HSMTOOL_VERBOSE")
10477 while [ $# -gt 0 ]; do
10489 local archive_id="$1"
10497 local bandwidth="$1" # in MB/s
10500 local fail_on_error=false
10503 # Uncommon(/copytool dependent) option
10504 action_options+=("$1")
10510 stack_trap "do_facet $facet rm -rf '$hsm_root'" EXIT
10511 do_facet $facet mkdir -p "$hsm_root" ||
10512 error "mkdir '$hsm_root' failed"
10516 local copytool=lhsmtool
10520 __${copytool}_${action} "${action_options[@]}"
10521 if [ $? -ne 0 ]; then
10526 local host="$(facet_host $facet)"
10527 error_msg="Failed to start copytool $facet on '$host'"
10530 local src="${action_options[0]}"
10531 local dest="${action_options[1]}"
10532 error_msg="Failed to import '$src' to '$dest'"
10535 error_msg="could not rebind file"
10539 $fail_on_error && error "$error_msg" || echo "$error_msg"
10544 local client_count=$1
10545 if [[ $CLIENTCOUNT -lt $client_count ]]; then
10546 skip "Need $client_count or more clients, have $CLIENTCOUNT"
10553 $LFS path2fid $1 | tr -d '[]'
10554 return ${PIPESTATUS[0]}
10562 if [[ $u == "user" ]]; then
10563 st=$($RUNAS $LFS hsm_state $f)
10566 st=$($LFS hsm_state $f)
10569 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
10571 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
10575 check_hsm_flags() {
10579 local st=$(get_hsm_flags $f)
10580 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
10589 if [[ "$value" != "" ]]; then
10592 for mdtno in $(seq 1 $MDSCOUNT); do
10593 local idx=$(($mdtno - 1))
10594 local facet=mds${mdtno}
10595 # if $arg include -P option, run 1 set_param per MDT on the MGS
10596 # else, run set_param on each MDT
10597 [[ $arg = *"-P"* ]] && facet=mgs
10598 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
10599 [[ $? != 0 ]] && rc=1
10604 mdts_check_param() {
10610 for mdtno in $(seq 1 $MDSCOUNT); do
10611 local idx=$(($mdtno - 1))
10612 wait_update_facet --verbose mds${mdtno} \
10613 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
10615 error "$key state is not '$target' on mds${mdtno}"
10619 cdt_set_mount_state() {
10620 mdts_set_param "-P" hsm_control "$1"
10621 # set_param -P is asynchronous operation and could race with set_param.
10622 # In such case configs could be retrieved and applied at mgc after
10623 # set_param -P completion. Sleep here to avoid race with set_param.
10624 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
10625 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
10626 # and 10 seconds to retrieve config from server.
10630 cdt_check_state() {
10631 mdts_check_param hsm_control "$1" 20
10634 cdt_set_sanity_policy() {
10635 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
10638 mdts_set_param "" hsm.policy "+NRA"
10639 mdts_set_param "" hsm.policy "-NBR"
10640 CDT_POLICY_HAD_CHANGED=
10648 mdts_set_param "$opt -n" "hsm.$param" "$value"
10652 wait_request_state() {
10656 # 4th arg (mdt index) is optional
10657 local mdtidx=${4:-0}
10658 local mds=mds$(($mdtidx + 1))
10660 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
10661 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
10663 wait_update_facet --verbose $mds "$cmd" "$state" 200 ||
10664 error "request on $fid is not $state on $mds"
10672 local WAIT_MAX=${4:-60}
10675 # We need to run do_node in bg, because pdsh does not exit
10676 # if child process of run script exists.
10677 # I.e. pdsh does not exit when runmultiop_bg_pause exited,
10678 # because of multiop_bg_pause -> $MULTIOP_PROG &
10679 # By the same reason we need sleep a bit after do_nodes starts
10680 # to let runmultiop_bg_pause start muliop and
10681 # update /tmp/multiop_bg.pid ;
10682 # The rm /tmp/multiop_bg.pid guarantees here that
10683 # we have the updated by runmultiop_bg_pause
10684 # /tmp/multiop_bg.pid file
10686 local pid_file=$TMP/multiop_bg.pid.$$
10688 do_node $client "MULTIOP_PID_FILE=$pid_file LUSTRE= \
10689 runmultiop_bg_pause $file $cmds" &
10693 while [[ $wait_time -lt $WAIT_MAX ]]; do
10695 wait_time=$((wait_time + 3))
10696 multiop_pid=$(do_node $client cat $pid_file)
10697 if [ -n "$multiop_pid" ]; then
10702 [ -n "$multiop_pid" ] ||
10703 error "$client : Can not get multiop_pid from $pid_file "
10705 eval export $(node_var_name $client)_multiop_pid=$multiop_pid
10706 eval export $(node_var_name $client)_do_node_pid=$pid
10707 local var=$(node_var_name $client)_multiop_pid
10708 echo client $client multiop_bg started multiop_pid=${!var}
10714 local multiop_pid=$(node_var_name $client)_multiop_pid
10715 local do_node_pid=$(node_var_name $client)_do_node_pid
10717 echo "Stopping multiop_pid=${!multiop_pid} (kill ${!multiop_pid} on $client)"
10718 do_node $client kill -USR1 ${!multiop_pid}
10720 wait ${!do_node_pid}
10724 local delay=$(do_facet $SINGLEMDS lctl get_param -n lo[vd].*.qos_maxage |
10725 awk '{ print $1 * 2; exit; }')
10729 check_component_count() {
10730 local comp_cnt=$($LFS getstripe --component-count $1)
10731 [ $comp_cnt -eq $2 ] || error "$1, component count $comp_cnt != $2"
10734 # Verify there are no init components with "extension" flag
10735 verify_no_init_extension() {
10736 local flg_opts="--component-flags init,extension"
10737 local found=$($LFS find $flg_opts $1 | wc -l)
10738 [ $found -eq 0 ] || error "$1 has component with initialized extension"
10741 # Verify there is at least one component starting at 0
10742 verify_comp_at_zero() {
10743 flg_opts="--component-flags init"
10744 found=$($LFS find --component-start 0M $flg_opts $1 | wc -l)
10745 [ $found -eq 1 ] ||
10746 error "No component starting at zero(!)"
10749 # version after which Self-Extending Layouts are available
10752 sel_layout_sanity() {
10756 verify_no_init_extension $file
10757 verify_comp_at_zero $file
10758 check_component_count $file $comp_cnt
10761 statx_supported() {
10762 $STATX --quiet --version
10767 # wrappers for createmany and unlinkmany
10768 # to set debug=0 if number of creates is high enough
10769 # this is to speedup testing
10771 function createmany() {
10775 if (( count > 100 )); then
10777 do_nodes $(comma_list $(all_nodes)) $LCTL set_param -n debug=0
10779 $LUSTRE/tests/createmany $*
10786 function unlinkmany() {
10790 if (( count > 100 )); then
10792 do_nodes $(comma_list $(all_nodes)) $LCTL set_param -n debug=0
10794 $LUSTRE/tests/unlinkmany $*
10801 # Check if fallocate supported on OSTs, enable if unset, default mode=0
10802 # Optionally pass the OST fallocate mode (0=unwritten extents, 1=zero extents)
10803 function check_set_fallocate()
10805 local new_mode="$1"
10806 local osts=$(comma_list $(osts_nodes))
10807 local fa_mode="osd-ldiskfs.*.fallocate_zero_blocks"
10808 local old_mode=$(do_facet ost1 $LCTL get_param -n $fa_mode 2>/dev/null|
10811 [[ -n "$old_mode" ]] || { echo "fallocate not supported"; return 1; }
10812 [[ -z "$new_mode" && "$old_mode" != "-1" ]] &&
10813 { echo "keep default fallocate mode: $old_mode"; return 0; }
10814 [[ "$new_mode" && "$old_mode" == "$new_mode" ]] &&
10815 { echo "keep current fallocate mode: $old_mode"; return 0; }
10817 stack_trap "do_nodes $osts $LCTL set_param $fa_mode=$old_mode"
10818 do_nodes $osts $LCTL set_param $fa_mode=${new_mode:-0} ||
10819 error "set $fa_mode=$new_mode"
10822 # Check if fallocate supported on OSTs, enable if unset, skip if unavailable
10823 function check_set_fallocate_or_skip()
10825 [ "$ost1_FSTYPE" != ldiskfs ] && skip "non-ldiskfs backend"
10826 check_set_fallocate || skip "need at least 2.13.57 for fallocate"
10829 function disable_opencache()
10831 local state=$($LCTL get_param -n "llite.*.opencache_threshold_count" | head -1)
10833 test -z "${saved_OPENCACHE_value}" &&
10834 export saved_OPENCACHE_value="$state"
10836 [[ "$state" = "off" ]] && return
10838 $LCTL set_param -n "llite.*.opencache_threshold_count"=off
10841 function set_opencache()
10843 local newvalue="$1"
10844 local state=$($LCTL get_param -n "llite.*.opencache_threshold_count")
10846 [[ -n "$newvalue" ]] || return
10848 [[ -n "${saved_OPENCACHE_value}" ]] ||
10849 export saved_OPENCACHE_value="$state"
10851 $LCTL set_param -n "llite.*.opencache_threshold_count"=$newvalue
10856 function restore_opencache()
10858 [[ -z "${saved_OPENCACHE_value}" ]] ||
10859 $LCTL set_param -n "llite.*.opencache_threshold_count"=${saved_OPENCACHE_value}
10862 # LU-13417: XXX lots of tests assume the directory to be created under MDT0,
10863 # created on MDT0, use this function to create directory on specific MDT
10864 # explicitly, and set default LMV to create subdirs on the same MDT too.
10869 while getopts "i:" opt $*; do
10875 shift $((OPTIND - 1))
10877 $LFS mkdir -i $mdt -c 1 $*
10881 mkdir_on_mdt -i0 $*
10884 # Wait for nodemap synchronization
10886 local nodemap_name=$1
10891 local is_active=$(do_facet mgs $LCTL get_param -n nodemap.active)
10892 local max_retries=20
10896 local mgs_ip=$(host_nids_address $mgs_HOST $NETTYPE | cut -d' ' -f1)
10899 if [ "$nodemap_name" == "active" ]; then
10900 proc_param="active"
10901 elif [ -z "$key" ]; then
10902 proc_param=${nodemap_name}
10904 proc_param="${nodemap_name}.${key}"
10906 if [ "$opt" == "inactive" ]; then
10907 # check nm sync even if nodemap is not activated
10911 (( is_active == 0 )) && [ "$proc_param" != "active" ] && return
10913 if [ -z "$value" ]; then
10914 out1=$(do_facet mgs $LCTL get_param $opt \
10915 nodemap.${proc_param} 2>/dev/null)
10916 echo "On MGS ${mgs_ip}, ${proc_param} = $out1"
10921 # if servers run on the same node, it is impossible to tell if they get
10922 # synced with the mgs, so just wait an arbitrary 10 seconds
10923 if [ $(facet_active_host mgs) == $(facet_active_host mds) ] &&
10924 [ $(facet_active_host mgs) == $(facet_active_host ost1) ]; then
10925 echo "waiting 10 secs for sync"
10930 # wait up to 10 seconds for other servers to sync with mgs
10931 for i in $(seq 1 10); do
10932 for node in $(all_server_nodes); do
10933 local node_ip=$(host_nids_address $node $NETTYPE |
10937 if [ -z "$value" ]; then
10938 [ $node_ip == $mgs_ip ] && continue
10941 out2=$(do_node $node_ip $LCTL get_param $opt \
10942 nodemap.$proc_param 2>/dev/null)
10943 echo "On $node ${node_ip}, ${proc_param} = $out2"
10944 [ "$out1" != "$out2" ] && is_sync=false && break
10949 if ! $is_sync; then
10952 echo OTHER - IP: $node_ip
10954 error "mgs and $nodemap_name ${key} mismatch, $i attempts"
10956 echo "waited $((i - 1)) seconds for sync"
10959 consume_precreations() {
10963 local extra=${4:-2}
10964 local OST=$(ostname_from_index $OSTIDX $dir)
10966 test_mkdir -p $dir/${OST}
10967 $LFS setstripe -i $OSTIDX -c 1 ${dir}/${OST}
10970 local mdtosc_proc=$(get_mdtosc_proc_path $mfacet $OST)
10971 local last_id=$(do_facet $mfacet $LCTL get_param -n \
10972 osp.$mdtosc_proc.prealloc_last_id)
10973 local next_id=$(do_facet $mfacet $LCTL get_param -n \
10974 osp.$mdtosc_proc.prealloc_next_id)
10975 echo "Creating to objid $last_id on ost $OST..."
10976 createmany -o $dir/${OST}/f $next_id $((last_id - next_id + extra))
10979 __exhaust_precreations() {
10982 local FAILIDX=${3:-$OSTIDX}
10983 local ofacet=ost$((OSTIDX + 1))
10985 mkdir_on_mdt0 $DIR/$tdir
10986 local mdtidx=$($LFS getstripe -m $DIR/$tdir)
10987 local mfacet=mds$((mdtidx + 1))
10988 echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
10990 local mdtosc_proc=$(get_mdtosc_proc_path $mfacet)
10991 do_facet $mfacet $LCTL get_param osp.$mdtosc_proc.prealloc*
10993 #define OBD_FAIL_OST_ENOSPC 0x215
10994 do_facet $ofacet $LCTL set_param fail_val=$FAILIDX fail_loc=0x215
10996 consume_precreations $DIR/$tdir $mfacet $OSTIDX
10998 do_facet $mfacet $LCTL get_param osp.$mdtosc_proc.prealloc*
10999 do_facet $ofacet $LCTL set_param fail_loc=$FAILLOC
11002 exhaust_precreations() {
11003 __exhaust_precreations $1 $2 $3
11007 exhaust_all_precreations() {
11009 for (( i=0; i < OSTCOUNT; i++ )) ; do
11010 __exhaust_precreations $i $1 -1