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)
168 # Prefer using "mds1" directly instead of SINGLEMDS.
169 # Keep this for compat until it is removed from scripts.
170 export SINGLEMDS=${SINGLEMDS:-mds1}
174 export LUSTRE=$(absolute_path $LUSTRE)
175 export TESTSUITE=$(basename $0 .sh)
176 export TEST_FAILED=false
177 export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
178 export RPC_MODE=${RPC_MODE:-false}
179 export DO_CLEANUP=${DO_CLEANUP:-true}
180 export KEEP_ZPOOL=${KEEP_ZPOOL:-false}
181 export CLEANUP_DM_DEV=false
182 export PAGE_SIZE=$(get_page_size client)
184 export MKE2FS=$MKE2FS
185 if [ -z "$MKE2FS" ]; then
186 if which mkfs.ldiskfs >/dev/null 2>&1; then
187 export MKE2FS=mkfs.ldiskfs
193 export DEBUGFS=$DEBUGFS
194 if [ -z "$DEBUGFS" ]; then
195 if which debugfs.ldiskfs >/dev/null 2>&1; then
196 export DEBUGFS=debugfs.ldiskfs
198 export DEBUGFS=debugfs
202 export TUNE2FS=$TUNE2FS
203 if [ -z "$TUNE2FS" ]; then
204 if which tunefs.ldiskfs >/dev/null 2>&1; then
205 export TUNE2FS=tunefs.ldiskfs
207 export TUNE2FS=tune2fs
211 export E2LABEL=$E2LABEL
212 if [ -z "$E2LABEL" ]; then
213 if which label.ldiskfs >/dev/null 2>&1; then
214 export E2LABEL=label.ldiskfs
216 export E2LABEL=e2label
220 export DUMPE2FS=$DUMPE2FS
221 if [ -z "$DUMPE2FS" ]; then
222 if which dumpfs.ldiskfs >/dev/null 2>&1; then
223 export DUMPE2FS=dumpfs.ldiskfs
225 export DUMPE2FS=dumpe2fs
229 export E2FSCK=$E2FSCK
230 if [ -z "$E2FSCK" ]; then
231 if which fsck.ldiskfs >/dev/null 2>&1; then
232 export E2FSCK=fsck.ldiskfs
238 export RESIZE2FS=$RESIZE2FS
239 if [ -z "$RESIZE2FS" ]; then
240 if which resizefs.ldiskfs >/dev/null 2>&1; then
241 export RESIZE2FS=resizefs.ldiskfs
243 export RESIZE2FS=resize2fs
247 export LFSCK_ALWAYS=${LFSCK_ALWAYS:-"no"} # check fs after test suite
248 export FSCK_MAX_ERR=4 # File system errors left uncorrected
250 export ZFS=${ZFS:-zfs}
251 export ZPOOL=${ZPOOL:-zpool}
252 export ZDB=${ZDB:-zdb}
253 export PARTPROBE=${PARTPROBE:-partprobe}
255 #[ -d /r ] && export ROOT=${ROOT:-/r}
256 export TMP=${TMP:-$ROOT/tmp}
257 export TESTSUITELOG=${TMP}/${TESTSUITE}.log
258 export LOGDIR=${LOGDIR:-${TMP}/test_logs/$(date +%s)}
259 export TESTLOG_PREFIX=$LOGDIR/$TESTSUITE
261 export HOSTNAME=${HOSTNAME:-$(hostname -s)}
262 if ! echo $PATH | grep -q $LUSTRE/utils; then
263 export PATH=$LUSTRE/utils:$PATH
265 if ! echo $PATH | grep -q $LUSTRE/utils/gss; then
266 export PATH=$LUSTRE/utils/gss:$PATH
268 if ! echo $PATH | grep -q $LUSTRE/tests; then
269 export PATH=$LUSTRE/tests:$PATH
271 if ! echo $PATH | grep -q $LUSTRE/../lustre-iokit/sgpdd-survey; then
272 export PATH=$LUSTRE/../lustre-iokit/sgpdd-survey:$PATH
274 export LST=${LST:-"$LUSTRE/../lnet/utils/lst"}
275 [ ! -f "$LST" ] && export LST=$(which lst)
276 export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
277 [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
278 export MCREATE=${MCREATE:-mcreate}
279 export MULTIOP=${MULTIOP:-multiop}
280 export MMAP_CAT=${MMAP_CAT:-mmap_cat}
281 export STATX=${STATX:-statx}
282 # Ubuntu, at least, has a truncate command in /usr/bin
283 # so fully path our truncate command.
284 export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
285 export FSX=${FSX:-$LUSTRE/tests/fsx}
286 export MDSRATE=${MDSRATE:-"$LUSTRE/tests/mpi/mdsrate"}
287 [ ! -f "$MDSRATE" ] && export MDSRATE=$(which mdsrate 2> /dev/null)
288 if ! echo $PATH | grep -q $LUSTRE/tests/racer; then
289 export PATH=$LUSTRE/tests/racer:$PATH:
291 if ! echo $PATH | grep -q $LUSTRE/tests/mpi; then
292 export PATH=$LUSTRE/tests/mpi:$PATH
294 export RSYNC_RSH=${RSYNC_RSH:-rsh}
296 export LNETCTL=${LNETCTL:-"$LUSTRE/../lnet/utils/lnetctl"}
297 [ ! -f "$LNETCTL" ] && export LNETCTL=$(which lnetctl 2> /dev/null)
298 export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
299 [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
300 export LFS=${LFS:-"$LUSTRE/utils/lfs"}
301 [ ! -f "$LFS" ] && export LFS=$(which lfs)
302 export KSOCKLND_CONFIG=${KSOCKLND_CONFIG:-"$LUSTRE/scripts/ksocklnd-config"}
303 [ ! -f "$KSOCKLND_CONFIG" ] &&
304 export KSOCKLND_CONFIG=$(which ksocklnd-config 2> /dev/null)
306 export PERM_CMD=$(echo ${PERM_CMD:-"$LCTL conf_param"})
308 export L_GETIDENTITY=${L_GETIDENTITY:-"$LUSTRE/utils/l_getidentity"}
309 if [ ! -f "$L_GETIDENTITY" ]; then
310 if `which l_getidentity > /dev/null 2>&1`; then
311 export L_GETIDENTITY=$(which l_getidentity)
313 export L_GETIDENTITY=NONE
316 export LL_DECODE_FILTER_FID=${LL_DECODE_FILTER_FID:-"$LUSTRE/utils/ll_decode_filter_fid"}
317 [ ! -f "$LL_DECODE_FILTER_FID" ] && export LL_DECODE_FILTER_FID="ll_decode_filter_fid"
318 export LL_DECODE_LINKEA=${LL_DECODE_LINKEA:-"$LUSTRE/utils/ll_decode_linkea"}
319 [ ! -f "$LL_DECODE_LINKEA" ] && export LL_DECODE_LINKEA="ll_decode_linkea"
320 export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
321 [ ! -f "$MKFS" ] && export MKFS="mkfs.lustre"
322 export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
323 [ ! -f "$TUNEFS" ] && export TUNEFS="tunefs.lustre"
324 export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
325 export LUSTRE_RMMOD=${LUSTRE_RMMOD:-$LUSTRE/scripts/lustre_rmmod}
326 [ ! -f "$LUSTRE_RMMOD" ] &&
327 export LUSTRE_RMMOD=$(which lustre_rmmod 2> /dev/null)
328 export LUSTRE_ROUTES_CONVERSION=${LUSTRE_ROUTES_CONVERSION:-$LUSTRE/scripts/lustre_routes_conversion}
329 [ ! -f "$LUSTRE_ROUTES_CONVERSION" ] &&
330 export LUSTRE_ROUTES_CONVERSION=$(which lustre_routes_conversion 2> /dev/null)
331 export LFS_MIGRATE=${LFS_MIGRATE:-$LUSTRE/scripts/lfs_migrate}
332 [ ! -f "$LFS_MIGRATE" ] &&
333 export LFS_MIGRATE=$(which lfs_migrate 2> /dev/null)
334 export LR_READER=${LR_READER:-"$LUSTRE/utils/lr_reader"}
335 [ ! -f "$LR_READER" ] &&
336 export LR_READER=$(which lr_reader 2> /dev/null)
337 [ -z "$LR_READER" ] && export LR_READER="/usr/sbin/lr_reader"
338 export LSOM_SYNC=${LSOM_SYNC:-"$LUSTRE/utils/llsom_sync"}
339 [ ! -f "$LSOM_SYNC" ] &&
340 export LSOM_SYNC=$(which llsom_sync 2> /dev/null)
341 [ -z "$LSOM_SYNC" ] && export LSOM_SYNC="/usr/sbin/llsom_sync"
342 export NAME=${NAME:-local}
343 export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
344 [ "$GSS_PIPEFS" = "true" ] && [ ! -f "$LGSSD" ] &&
345 export LGSSD=$(which lgssd)
346 export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
347 [ ! -f "$LSVCGSSD" ] && export LSVCGSSD=$(which lsvcgssd 2> /dev/null)
348 export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
350 export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
352 export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
353 [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
355 export DMSETUP=${DMSETUP:-dmsetup}
356 export DM_DEV_PATH=${DM_DEV_PATH:-/dev/mapper}
357 export LOSETUP=${LOSETUP:-losetup}
359 if [ "$ACCEPTOR_PORT" ]; then
360 export PORT_OPT="--port $ACCEPTOR_PORT"
364 $RPC_MODE || echo "Using GSS shared-key feature"
365 which lgss_sk > /dev/null 2>&1 ||
366 error_exit "built with lgss_sk disabled! SEC=$SEC"
374 $RPC_MODE || echo "Using GSS/krb5 ptlrpc security flavor"
375 which lgss_keyring > /dev/null 2>&1 ||
376 error_exit "built with gss disabled! SEC=$SEC"
387 IDENTITY_UPCALL=false
391 export LOAD_MODULES_REMOTE=${LOAD_MODULES_REMOTE:-false}
393 # Paths on remote nodes, if different
394 export RLUSTRE=${RLUSTRE:-$LUSTRE}
395 export RPWD=${RPWD:-$PWD}
396 export I_MOUNTED=${I_MOUNTED:-"no"}
397 export AUSTER_CLEANUP=${AUSTER_CLEANUP:-false}
398 if [ ! -f /lib/modules/$(uname -r)/kernel/fs/lustre/mdt.ko -a \
399 ! -f /lib/modules/$(uname -r)/updates/kernel/fs/lustre/mdt.ko -a \
400 ! -f /lib/modules/$(uname -r)/extra/kernel/fs/lustre/mdt.ko -a \
401 ! -f $LUSTRE/mdt/mdt.ko ]; then
402 export CLIENTMODSONLY=yes
405 export SHUTDOWN_ATTEMPTS=${SHUTDOWN_ATTEMPTS:-3}
406 export OSD_TRACK_DECLARES_LBUG=${OSD_TRACK_DECLARES_LBUG:-"yes"}
410 while getopts "rvwf:" opt $*; do
415 w) WRITECONF=writeconf;;
420 shift $((OPTIND - 1))
423 # print the durations of each test if "true"
424 DDETAILS=${DDETAILS:-false}
425 [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
430 export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
432 # Constants used in more than one test script
433 export LOV_MAX_STRIPE_COUNT=2000
434 export DELETE_OLD_POOLS=${DELETE_OLD_POOLS:-false}
435 export KEEP_POOLS=${KEEP_POOLS:-false}
436 export PARALLEL=${PARALLEL:-"no"}
438 export MACHINEFILE=${MACHINEFILE:-$TMP/$(basename $0 .sh).machines}
439 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
442 # use localrecov to enable recovery for local clients, LU-12722
443 [[ $MDS1_VERSION -lt $(version_code 2.13.52) ]] || {
444 export MDS_MOUNT_OPTS=${MDS_MOUNT_OPTS:-"-o localrecov"}
445 export MGS_MOUNT_OPTS=${MGS_MOUNT_OPTS:-"-o localrecov"}
448 [[ $OST1_VERSION -lt $(version_code 2.13.52) ]] ||
449 export OST_MOUNT_OPTS=${OST_MOUNT_OPTS:-"-o localrecov"}
456 ncpts=$(do_facet $facet "lctl get_param -n " \
457 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
459 if [ $ncpts -eq 0 ]; then
466 # Return a numeric version code based on a version string. The version
467 # code is useful for comparison two version strings to see which is newer.
469 # split arguments like "1.8.6-wc3" into "1", "8", "6", "3"
470 eval set -- $(tr "[:punct:][a-z]" " " <<< $*)
472 echo -n $(((${1:-0}<<24) | (${2:-0}<<16) | (${3:-0}<<8) | (${4:-0})))
475 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
476 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
478 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
480 # usage: lustre_build_version
482 # All Lustre versions support "lctl get_param" to report the version of the
483 # code running in the kernel (what our tests are interested in), but it
484 # doesn't work without modules loaded. After 2.9.53 and in upstream kernels
485 # the "version" parameter doesn't include "lustre: " at the beginning.
486 # If that fails, call "lctl lustre_build_version" which prints either (or both)
487 # the userspace and kernel build versions, but until 2.8.55 required root
488 # access to get the Lustre kernel version. If that also fails, fall back to
489 # using "lctl --version", which is easy to parse and works without the kernel
490 # modules, but was only added in 2.6.50 and only prints the lctl tool version,
491 # not the module version, though they are usually the same.
493 # Various commands and their output format for different Lustre versions:
494 # lctl get_param version: 2.9.55
495 # lctl get_param version: lustre: 2.8.53
496 # lctl get_param version: lustre: 2.6.52
497 # kernel: patchless_client
498 # build: v2_6_92_0-2.6.32-431.el6_lustre.x86_64
499 # lctl lustre_build_version: Lustre version: 2.8.53_27_gae67fc01
500 # lctl lustre_build_version: error: lustre_build_version: Permission denied
501 # (as non-root user) lctl version: v2_6_92_0-2.6.32-431.el6.x86_64
502 # lctl lustre_build_version: Lustre version: 2.5.3-2.6.32.26-175.fc12.x86_64
503 # lctl version: 2.5.3-2.6.32..26-175fc12.x86_64
504 # lctl --version: lctl 2.6.50
506 # output: prints version string to stdout in (up to 4) dotted-decimal values
507 lustre_build_version() {
508 local facet=${1:-client}
509 local facet_version=${facet}_VERSION
511 # if the global variable is already set, then use that
512 [ -n "${!facet_version}" ] && echo ${!facet_version} && return
514 # this is the currently-running version of the kernel modules
515 local ver=$(do_facet $facet "$LCTL get_param -n version 2>/dev/null")
516 # we mostly test 2.10+ systems, only try others if the above fails
517 if [ -z "$ver" ]; then
518 ver=$(do_facet $facet "$LCTL lustre_build_version 2>/dev/null")
520 if [ -z "$ver" ]; then
521 ver=$(do_facet $facet "$LCTL --version 2>/dev/null" |
524 local lver=$(egrep -i "lustre: |version: " <<<"$ver" | head -n 1)
525 [ -n "$lver" ] && ver="$lver"
527 lver=$(sed -e 's/[^:]*: //' -e 's/^v//' -e 's/[ -].*//' <<<$ver |
528 tr _ . | cut -d. -f1-4)
530 # save in global variable for the future
531 export $facet_version=$lver
536 # Report the Lustre numeric build version code for the supplied facet.
537 lustre_version_code() {
538 version_code $(lustre_build_version $1)
542 /sbin/lsmod | grep -q "^\<$1\>"
545 check_lfs_df_ret_val() {
546 # Ignore only EOPNOTSUPP (which is 95; Operation not supported) error
547 # returned by 'lfs df' for valid dentry but not a lustrefs.
549 # 'lfs df' historically always returned success(0) instead of
550 # EOPNOTSUPP. This function for compatibility reason, ignores and
551 # masquerades EOPNOTSUPP as success.
552 [[ $1 -eq 95 ]] && return 0
565 msg="$(insmod $module $args 2>&1)" && return 0 || rc=$?
568 # parallels can't load modules directly from prlfs, use /tmp instead
569 if $PRLFS || [[ "$(stat -f -c%t $module)" == "7c7c6673" ]]; then
570 local target="$(mktemp)"
572 cp "$module" "$target"
575 [[ $rc == 0 ]] && PRLFS=true
583 # Load a module on the system where this is running.
585 # usage: load_module module_name [module arguments for insmod/modprobe]
587 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
588 # will be used as the arguments. Otherwise arguments will be obtained from
589 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
592 local module=$1 # '../libcfs/libcfs/libcfs', 'obdclass/obdclass', ...
595 local base=$(basename $module $ext)
597 local -A module_is_loaded_aa
601 for mod in $(lsmod | awk '{ print $1; }'); do
602 module_is_loaded_aa[${mod//-/_}]=true
606 ${module_is_loaded_aa[${1//-/_}]:-false}
609 if module_is_loaded $base; then
613 if [[ -f $LUSTRE/$module$ext ]]; then
614 path=$LUSTRE/$module$ext
615 elif [[ "$base" == lnet_selftest ]] &&
616 [[ -f $LUSTRE/../lnet/selftest/$base$ext ]]; then
617 path=$LUSTRE/../lnet/selftest/$base$ext
622 if [[ -n "$path" ]]; then
623 # Try to load any non-Lustre modules that $module depends on.
624 for mod in $(modinfo --field=depends $path | tr ',' ' '); do
625 if ! module_is_loaded $mod; then
631 # If no module arguments were passed then get them from
632 # $MODOPTS_<MODULE>, otherwise from modprobe.conf.
633 if [ $# -eq 0 ]; then
634 # $MODOPTS_<MODULE>; we could use associative arrays, but that's
635 # not in Bash until 4.x, so we resort to eval.
636 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
637 eval set -- \$$optvar
638 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
639 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
641 opt=$(awk -v var="^options $base" '$0 ~ var \
642 {gsub("'"options $base"'",""); print}' \
644 set -- $(echo -n $opt)
646 # Ensure we have accept=all for lnet
647 if [[ "$base" == lnet ]]; then
648 # OK, this is a bit wordy...
649 local arg accept_all_present=false
652 [[ "$arg" == accept=all ]] &&
653 accept_all_present=true
656 $accept_all_present || set -- "$@" accept=all
663 [ $# -gt 0 ] && echo "${module} options: '$*'"
665 # Note that insmod will ignore anything in modprobe.conf, which is why
666 # we're passing options on the command-line. If $path does not exist
667 # then we must be testing a "make install" or"rpm" installation. Also
668 # note that failing to load ptlrpc_gss is not considered fatal.
669 if [[ -n "$path" ]]; then
670 lustre_insmod $path "$@"
671 elif [[ "$base" == ptlrpc_gss ]]; then
672 if ! modprobe $base "$@" 2>/dev/null; then
673 echo "gss/krb5 is not supported"
681 $LCTL mark "$LNETCTL $*"
687 # For kmemleak-enabled kernels we need clear all past state
688 # that obviously has nothing to do with this Lustre run
689 # Disable automatic memory scanning to avoid perf hit.
690 if [ -f /sys/kernel/debug/kmemleak ] ; then
691 echo scan=off > /sys/kernel/debug/kmemleak || true
692 echo scan > /sys/kernel/debug/kmemleak || true
693 echo clear > /sys/kernel/debug/kmemleak || true
696 echo Loading modules from $LUSTRE
700 if [ -f /sys/devices/system/cpu/online ]; then
701 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
702 echo "detected $ncpus online CPUs by sysfs"
704 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
706 if [ $rc -eq 0 ]; then
707 echo "detected $ncpus online CPUs by getconf"
709 echo "Can't detect number of CPUs"
714 # if there is only one CPU core, libcfs can only create one partition
715 # if there is more than 4 CPU cores, libcfs should create multiple CPU
716 # partitions. So we just force libcfs to create 2 partitions for
717 # system with 2 or 4 cores
718 local saved_opts="$MODOPTS_LIBCFS"
719 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
720 # force to enable multiple CPU partitions
721 echo "Force libcfs to create 2 CPU partitions"
722 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
724 echo "libcfs will create CPU partition based on online CPUs"
727 load_module ../libcfs/libcfs/libcfs
728 # Prevent local MODOPTS_LIBCFS being passed as part of environment
729 # variable to remote nodes
732 set_default_debug "neterror net nettrace malloc"
733 if [ "$1" = "config_on_load=1" ]; then
734 load_module ../lnet/lnet/lnet
736 load_module ../lnet/lnet/lnet "$@"
739 LNDPATH=${LNDPATH:-"../lnet/klnds"}
740 if [ -z "$LNETLND" ]; then
742 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
743 tcp*) LNETLND="socklnd/ksocklnd" ;;
744 *) local lnd="${NETTYPE%%[0-9]}lnd"
745 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
746 LNETLND="$lnd/k$lnd" ||
747 LNETLND="socklnd/ksocklnd"
750 load_module ../lnet/klnds/$LNETLND
752 if [ "$1" = "config_on_load=1" ]; then
753 do_lnetctl lnet configure --all ||
758 load_modules_local() {
759 if [ -n "$MODPROBE" ]; then
761 echo "Using modprobe to load modules"
765 # Create special udev test rules on every node
766 if [ -f $LUSTRE/lustre/conf/99-lustre.rules ]; then {
767 sed -e 's|/usr/sbin/lctl|$LCTL|g' $LUSTRE/lustre/conf/99-lustre.rules > /etc/udev/rules.d/99-lustre-test.rules
769 echo "SUBSYSTEM==\"lustre\", ACTION==\"change\", ENV{PARAM}==\"?*\", RUN+=\"$LCTL set_param '\$env{PARAM}=\$env{SETTING}'\"" > /etc/udev/rules.d/99-lustre-test.rules
771 udevadm control --reload-rules
776 load_module obdclass/obdclass
777 if ! client_only; then
778 MODOPTS_PTLRPC=${MODOPTS_PTLRPC:-"lbug_on_grant_miscount=1"}
780 load_module ptlrpc/ptlrpc
781 load_module ptlrpc/gss/ptlrpc_gss
789 load_module obdecho/obdecho
790 if ! client_only; then
791 load_module lfsck/lfsck
792 [ "$LQUOTA" != "no" ] &&
793 load_module quota/lquota $LQUOTAOPTS
794 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
795 load_module osd-zfs/osd_zfs
796 elif [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
797 load_module ../ldiskfs/ldiskfs
798 load_module osd-ldiskfs/osd_ldiskfs
810 load_module llite/lustre
811 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
813 rm -f $OGDB/ogdb-$HOSTNAME
814 $LCTL modules > $OGDB/ogdb-$HOSTNAME
816 # 'mount' doesn't look in $PATH, just sbin
817 local mount_lustre=$LUSTRE/utils/mount.lustre
818 if [ -f $mount_lustre ]; then
819 local sbin_mount=$(readlink -f /sbin)/mount.lustre
820 if grep -qw "$sbin_mount" /proc/mounts; then
821 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
823 if ! grep -qw "$sbin_mount" /proc/mounts; then
824 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
825 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
826 cat <<- EOF > "$sbin_mount"
829 echo "This $sbin_mount just a mountpoint." 1>&2
830 echo "It is never supposed to be run." 1>&2
831 logger -p emerg -- "using stub $sbin_mount $@"
834 chmod a+x $sbin_mount
836 mount --bind $mount_lustre $sbin_mount ||
837 error "can't bind $mount_lustre to $sbin_mount"
848 # load modules on remote nodes optionally
849 # lustre-tests have to be installed on these nodes
850 if $LOAD_MODULES_REMOTE; then
851 local list=$(comma_list $(remote_nodes_list))
853 # include failover nodes in case they are not in the list yet
855 for facet in ${facets//,/ }; do
856 failover=$(facet_failover_host $facet)
857 [ -n "$list" ] && [[ ! "$list" =~ "$failover" ]] &&
858 list="$list,$failover"
861 if [ -n "$list" ]; then
862 echo "loading modules on: '$list'"
863 do_rpc_nodes "$list" load_modules_local
869 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
870 LEAK_PORTALS=$(dmesg | tail -n 20 | egrep -i "libcfs.*memory leaked" || true)
871 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
872 echo "$LEAK_LUSTRE" 1>&2
873 echo "$LEAK_PORTALS" 1>&2
874 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
875 echo "Memory leaks detected"
876 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
881 unload_modules_local() {
882 $LUSTRE_RMMOD ldiskfs || return 2
884 [ -f /etc/udev/rules.d/99-lustre-test.rules ] &&
885 rm /etc/udev/rules.d/99-lustre-test.rules
886 udevadm control --reload-rules
889 check_mem_leak || return 254
897 wait_exit_ST client # bug 12845
899 unload_modules_local || rc=$?
901 if $LOAD_MODULES_REMOTE; then
902 local list=$(comma_list $(remote_nodes_list))
903 if [ -n "$list" ]; then
904 echo "unloading modules on: '$list'"
905 do_rpc_nodes "$list" unload_modules_local
909 local sbin_mount=$(readlink -f /sbin)/mount.lustre
910 if grep -qe "$sbin_mount " /proc/mounts; then
911 umount $sbin_mount || true
912 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
916 [[ $rc -eq 0 ]] && echo "modules unloaded."
922 local facet=${1:-$SINGLEMDS}
925 case $(facet_fstype $facet) in
926 ldiskfs) size=72;; # largest seen is 64, leave some headroom
927 # grant_block_size is in bytes, allow at least 2x max blocksize
928 zfs) size=$(lctl get_param osc.$FSNAME*.import |
929 awk '/grant_block_size:/ {print $2/512; exit;}')
933 echo -n $((size * MDSCOUNT))
937 local facet=${1:-$SINGLEMDS}
938 local fstype=$(facet_fstype $facet)
941 ldiskfs) size=4;; # ~4KB per inode
942 zfs) size=11;; # 10 to 11KB per inode
948 check_gss_daemon_nodes() {
952 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
953 if [ \\\"\\\$num\\\" -ne 1 ]; then
954 echo \\\$num instance of $dname;
959 check_gss_daemon_facet() {
963 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
964 if [ $num -ne 1 ]; then
965 echo "$num instance of $dname on $facet"
974 echo Stopping $@ on $list
975 do_nodes $list "killall -2 $@ 2>/dev/null || true"
978 # start gss daemons on all nodes, or "daemon" on "nodes" if set
979 start_gss_daemons() {
983 if [ "$nodes" ] && [ "$daemon" ] ; then
984 echo "Starting gss daemon on nodes: $nodes"
985 do_nodes $nodes "$daemon" || return 8
989 nodes=$(comma_list $(mdts_nodes))
990 echo "Starting gss daemon on mds: $nodes"
992 # Start all versions, in case of switching
993 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 1
995 do_nodes $nodes "$LSVCGSSD -v" || return 1
998 do_nodes $nodes "$LGSSD -v" || return 2
1001 nodes=$(comma_list $(osts_nodes))
1002 echo "Starting gss daemon on ost: $nodes"
1004 # Start all versions, in case of switching
1005 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 3
1007 do_nodes $nodes "$LSVCGSSD -v" || return 3
1009 # starting on clients
1011 local clients=${CLIENTS:-$HOSTNAME}
1012 if $GSS_PIPEFS; then
1013 echo "Starting $LGSSD on clients $clients "
1014 do_nodes $clients "$LGSSD -v" || return 4
1017 # wait daemons entering "stable" status
1021 # check daemons are running
1023 nodes=$(comma_list $(mdts_nodes) $(osts_nodes))
1024 check_gss_daemon_nodes $nodes lsvcgssd || return 5
1025 if $GSS_PIPEFS; then
1026 nodes=$(comma_list $(mdts_nodes))
1027 check_gss_daemon_nodes $nodes lgssd || return 6
1029 if $GSS_PIPEFS; then
1030 check_gss_daemon_nodes $clients lgssd || return 7
1034 stop_gss_daemons() {
1035 local nodes=$(comma_list $(mdts_nodes))
1037 send_sigint $nodes lsvcgssd lgssd
1039 nodes=$(comma_list $(osts_nodes))
1040 send_sigint $nodes lsvcgssd
1042 nodes=${CLIENTS:-$HOSTNAME}
1043 send_sigint $nodes lgssd
1047 # Add mount flags for shared key
1049 if grep -q skpath <<< "$mt_opts" ; then
1050 mt_opts=$(echo $mt_opts |
1051 sed -e "s#skpath=[^ ,]*#skpath=$SK_PATH#")
1053 if [ -z "$mt_opts" ]; then
1054 mt_opts="-o skpath=$SK_PATH"
1056 mt_opts="$mt_opts,skpath=$SK_PATH"
1066 /usr/lib/lustre/* | /usr/lib64/lustre/* | /usr/lib/lustre | \
1075 [ $from_tree = true ]
1079 if $SHARED_KEY; then
1088 if ! module_loaded ptlrpc_gss; then
1089 load_module ptlrpc/gss/ptlrpc_gss
1090 module_loaded ptlrpc_gss ||
1091 error_exit "init_gss: GSS=$GSS, but gss/krb5 missing"
1094 if $GSS_KRB5 || $GSS_SK; then
1095 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
1098 if $GSS_SK && ! $SK_NO_KEY; then
1099 echo "Loading basic SSK keys on all servers"
1100 do_nodes $(comma_list $(all_server_nodes)) \
1101 "lgss_sk -t server -l $SK_PATH/$FSNAME.key || true"
1102 do_nodes $(comma_list $(all_server_nodes)) \
1103 "keyctl show | grep lustre | cut -c1-11 |
1105 xargs -IX keyctl setperm X 0x3f3f3f3f"
1108 if $GSS_SK && $SK_NO_KEY; then
1109 local numclients=${1:-$CLIENTCOUNT}
1110 local clients=${CLIENTS:-$HOSTNAME}
1112 # security ctx config for keyring
1114 local lgssc_conf_file="/etc/request-key.d/lgssc.conf"
1116 if from_build_tree; then
1117 mkdir -p $SK_OM_PATH
1118 if grep -q request-key /proc/mounts > /dev/null; then
1119 echo "SSK: Request key already mounted."
1121 mount -o bind $SK_OM_PATH /etc/request-key.d/
1123 local lgssc_conf_line='create lgssc * * '
1124 lgssc_conf_line+=$(which lgss_keyring)
1125 lgssc_conf_line+=' %o %k %t %d %c %u %g %T %P %S'
1126 echo "$lgssc_conf_line" > $lgssc_conf_file
1129 [ -e $lgssc_conf_file ] ||
1130 error_exit "Could not find key options in $lgssc_conf_file"
1131 echo "$lgssc_conf_file content is:"
1132 cat $lgssc_conf_file
1134 if ! local_mode; then
1135 if from_build_tree; then
1136 do_nodes $(comma_list $(all_nodes)) "mkdir -p \
1138 do_nodes $(comma_list $(all_nodes)) "mount \
1139 -o bind $SK_OM_PATH \
1140 /etc/request-key.d/"
1141 do_nodes $(comma_list $(all_nodes)) "rsync \
1142 -aqv $HOSTNAME:$lgssc_conf_file \
1143 $lgssc_conf_file >/dev/null 2>&1"
1145 do_nodes $(comma_list $(all_nodes)) \
1146 "echo $lgssc_conf_file: ; \
1147 cat $lgssc_conf_file"
1151 # create shared key on all nodes
1152 mkdir -p $SK_PATH/nodemap
1153 rm -f $SK_PATH/$FSNAME.key $SK_PATH/nodemap/c*.key \
1154 $SK_PATH/$FSNAME-*.key
1155 # for nodemap testing each client may need own key,
1156 # and S2S now requires keys as well, both for "client"
1159 lgss_sk -t server -f$FSNAME -n $SK_S2SNMCLI \
1160 -w $SK_PATH/$FSNAME-nmclient.key \
1161 -d /dev/urandom >/dev/null 2>&1
1162 lgss_sk -t mgs,server -f$FSNAME -n $SK_S2SNM \
1163 -w $SK_PATH/$FSNAME-s2s-server.key \
1164 -d /dev/urandom >/dev/null 2>&1
1167 lgss_sk -t server -f$FSNAME -w $SK_PATH/$FSNAME.key \
1168 -d /dev/urandom >/dev/null 2>&1
1170 for i in $(seq 0 $((numclients - 1))); do
1171 lgss_sk -t server -f$FSNAME -n c$i \
1172 -w $SK_PATH/nodemap/c$i.key -d /dev/urandom \
1176 if ! local_mode; then
1177 for lnode in $(all_nodes); do
1178 scp -r $SK_PATH ${lnode}:$(dirname $SK_PATH)/
1181 # Set client keys to client type to generate prime P
1183 do_nodes $(all_nodes) "lgss_sk -t client,server -m \
1184 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1186 do_nodes $clients "lgss_sk -t client -m \
1187 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1188 do_nodes $clients "find $SK_PATH/nodemap -name \*.key | \
1189 xargs -IX lgss_sk -t client -m X >/dev/null 2>&1"
1191 # This is required for servers as well, if S2S in use
1193 do_nodes $(comma_list $(mdts_nodes)) \
1194 "cp $SK_PATH/$FSNAME-s2s-server.key \
1195 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
1196 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1198 do_nodes $(comma_list $(osts_nodes)) \
1199 "cp $SK_PATH/$FSNAME-s2s-server.key \
1200 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
1201 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1203 do_nodes $clients "lgss_sk -t client \
1204 -m $SK_PATH/$FSNAME-nmclient.key \
1209 # mount options for servers and clients
1210 MGS_MOUNT_OPTS=$(add_sk_mntflag $MGS_MOUNT_OPTS)
1211 MDS_MOUNT_OPTS=$(add_sk_mntflag $MDS_MOUNT_OPTS)
1212 OST_MOUNT_OPTS=$(add_sk_mntflag $OST_MOUNT_OPTS)
1213 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
1215 if [ -z "$LGSS_KEYRING_DEBUG" ]; then
1216 LGSS_KEYRING_DEBUG=4
1220 if [ -n "$LGSS_KEYRING_DEBUG" ] && \
1221 ( local_mode || from_build_tree ); then
1223 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
1224 elif [ -n "$LGSS_KEYRING_DEBUG" ]; then
1225 do_nodes $(comma_list $(all_nodes)) "modprobe ptlrpc_gss && \
1227 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG"
1234 # maybe cleanup credential cache?
1241 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNM"
1242 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNMCLI"
1243 $RPC_MODE || echo "Sleeping for 10 sec for Nodemap.."
1247 $RPC_MODE || echo "Cleaning up Shared Key.."
1248 do_nodes $(comma_list $(all_nodes)) "rm -f \
1249 $SK_PATH/$FSNAME*.key $SK_PATH/nodemap/$FSNAME*.key"
1250 do_nodes $(comma_list $(all_nodes)) "keyctl show | \
1251 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
1252 if from_build_tree; then
1253 # Remove the mount and clean up the files we added to
1255 do_nodes $(comma_list $(all_nodes)) "while grep -q \
1256 request-key.d /proc/mounts; do umount \
1257 /etc/request-key.d/; done"
1258 do_nodes $(comma_list $(all_nodes)) "rm -f \
1259 $SK_OM_PATH/lgssc.conf"
1260 do_nodes $(comma_list $(all_nodes)) "rmdir $SK_OM_PATH"
1268 local var=${facet}_svc
1276 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
1277 tr '[:lower:]' '[:upper:]'
1283 if [ $facet == mgs ] || [ $facet == client ]; then
1287 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
1295 if [ -n "${!var}" ]; then
1300 var=$(facet_type $facet)FSTYPE
1301 if [ -n "${!var}" ]; then
1306 if [ -n "$FSTYPE" ]; then
1311 if [[ $facet == mgs ]] && combined_mgs_mds; then
1323 local facets=$(get_facets)
1326 for facet in ${facets//,/ }; do
1327 if [ $node == $(facet_host $facet) ] ||
1328 [ $node == "$(facet_failover_host $facet)" ]; then
1329 fstype=$(facet_fstype $facet)
1330 if [[ $fstypes != *$fstype* ]]; then
1331 fstypes+="${fstypes:+,}$fstype"
1340 local num=$(facet_number $facet)
1343 if [[ $(facet_type $facet) = OST ]]; then
1344 index=OSTINDEX${num}
1345 if [[ -n "${!index}" ]]; then
1350 index=${OST_INDICES[num - 1]}
1353 [[ -n "$index" ]] || index=$((num - 1))
1361 local fstype=$(facet_fstype $facet)
1365 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
1367 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
1368 ${dev} 2>/dev/null");;
1370 error "unknown fstype!";;
1377 # Get the device of a facet.
1384 mgs) device=$(mgsdevname) ;;
1385 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
1386 ost*) device=$(ostdevname $(facet_number $facet)) ;;
1387 fs2mds) device=$(mdsdevname 1_2) ;;
1388 fs2ost) device=$(ostdevname 1_2) ;;
1389 fs3ost) device=$(ostdevname 2_2) ;;
1397 # Get the virtual device of a facet.
1404 mgs) device=$(mgsvdevname) ;;
1405 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
1406 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
1407 fs2mds) device=$(mdsvdevname 1_2) ;;
1408 fs2ost) device=$(ostvdevname 1_2) ;;
1409 fs3ost) device=$(ostvdevname 2_2) ;;
1417 local virt=$(virt-what 2> /dev/null)
1419 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1421 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1424 VMware|KVM|VirtualBox|Parallels|Bochs)
1425 echo $virt | tr '[A-Z]' '[a-z]' ;;
1431 # Re-read the partition table on failover partner host.
1432 # After a ZFS storage pool is created on a shared device, the partition table
1433 # on the device may change. However, the operating system on the failover
1434 # host may not notice the change automatically. Without the up-to-date partition
1435 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1436 # relative to partition rather than disk beginnings.
1438 # This function performs partprobe on the failover host to make it re-read the
1441 refresh_partition_table() {
1446 host=$(facet_passive_host $facet)
1447 if [[ -n "$host" ]]; then
1448 do_node $host "$PARTPROBE $device"
1453 # Get ZFS storage pool name.
1460 device=$(facet_device $facet)
1461 # poolname is string before "/"
1462 poolname="${device%%/*}"
1469 # Get ZFS local fsname.
1471 zfs_local_fsname() {
1473 local lfsname=$(basename $(facet_device $facet))
1479 # Create ZFS storage pool.
1486 local opts=${@:-"-o cachefile=none"}
1488 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1489 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1490 $ZPOOL create -f $opts $poolname $vdev"
1494 # Create ZFS file system.
1500 local opts=${@:-"-o mountpoint=legacy"}
1502 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1503 $ZFS create $opts $dataset"
1507 # Export ZFS storage pool.
1508 # Before exporting the pool, all datasets within the pool should be unmounted.
1516 poolname=$(zpool_name $facet)
1518 if [[ -n "$poolname" ]]; then
1519 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1520 grep -q ^$poolname/ /proc/mounts ||
1521 $ZPOOL export $opts $poolname"
1526 # Destroy ZFS storage pool.
1527 # Destroy the given pool and free up any devices for other use. This command
1528 # tries to unmount any active datasets before destroying the pool.
1529 # -f Force any active datasets contained within the pool to be unmounted.
1533 local poolname=${2:-$(zpool_name $facet)}
1535 if [[ -n "$poolname" ]]; then
1536 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1537 $ZPOOL destroy -f $poolname"
1542 # Import ZFS storage pool.
1543 # Force importing, even if the pool appears to be potentially active.
1548 local opts=${@:-"-o cachefile=none -o failmode=panic"}
1551 poolname=$(zpool_name $facet)
1553 if [[ -n "$poolname" ]]; then
1554 opts+=" -d $(dirname $(facet_vdevice $facet))"
1555 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1556 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1557 $ZPOOL import -f $opts $poolname"
1562 # Reimport ZFS storage pool with new name
1567 local opts="-o cachefile=none"
1568 local poolname=$(zpool_name $facet)
1570 opts+=" -d $(dirname $(facet_vdevice $facet))"
1571 do_facet $facet "$ZPOOL export $poolname;
1572 $ZPOOL import $opts $poolname $newpool"
1576 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1577 # is not automatically imported on system startup.
1579 # In a failover environment, this will provide resource level fencing which
1580 # will ensure that the same ZFS storage pool will not be imported concurrently
1581 # on different nodes.
1583 disable_zpool_cache() {
1587 poolname=$(zpool_name $facet)
1589 if [[ -n "$poolname" ]]; then
1590 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1595 # This and set_osd_param() shall be used to access OSD parameters
1596 # once existed under "obdfilter":
1601 # writethrough_cache_enable
1605 local device=${2:-$FSNAME-OST*}
1608 do_nodes $nodes "$LCTL get_param -n osd-*.$device.$name"
1613 local device=${2:-$FSNAME-OST*}
1617 do_nodes $nodes "$LCTL set_param -n osd-*.$device.$name=$value"
1621 local dz=${1:-$DEBUG_SIZE}
1623 if [ -f /sys/devices/system/cpu/possible ]; then
1624 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1626 local cpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1629 # bug 19944, adjust size to be -gt num_possible_cpus()
1630 # promise 2MB for every cpu at least
1631 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1634 lctl set_param debug_mb=$dz
1637 set_default_debug () {
1638 local debug=${1:-"$PTLDEBUG"}
1639 local subsys=${2:-"$SUBSYSTEM"}
1640 local debug_size=${3:-$DEBUG_SIZE}
1642 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1643 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1645 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1648 set_default_debug_nodes () {
1650 local debug="${2:-"$PTLDEBUG"}"
1651 local subsys="${3:-"$SUBSYSTEM"}"
1652 local debug_size="${4:-$DEBUG_SIZE}"
1654 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1655 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1659 [[ -z "$nodes" ]] ||
1660 do_rpc_nodes "$nodes" set_default_debug \
1661 \\\"$debug\\\" \\\"$subsys\\\" $debug_size || true
1664 set_default_debug_facet () {
1666 local debug="${2:-"$PTLDEBUG"}"
1667 local subsys="${3:-"$SUBSYSTEM"}"
1668 local debug_size="${4:-$DEBUG_SIZE}"
1669 local node=$(facet_active_host $facet)
1671 [ -n "$node" ] || error "No host defined for facet $facet"
1673 set_default_debug_nodes $node "$debug" "$subsys" $debug_size
1676 set_params_nodes () {
1677 [[ $# -ge 2 ]] || return 0
1681 do_nodes $nodes $LCTL set_param $@
1684 set_params_clients () {
1685 local clients=${1:-$CLIENTS}
1686 local params=${2:-$CLIENT_LCTL_SETPARAM_PARAM}
1688 [[ -n $params ]] || return 0
1689 set_params_nodes $clients $params
1693 local hostid=${1:-$(hostid)}
1695 if [ ! -s /etc/hostid ]; then
1696 printf $(echo -n $hostid |
1697 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1703 local facets=${1:-$(get_facets)}
1706 for facet in ${facets//,/ }; do
1709 [ $RC -eq 0 ] && continue
1711 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1712 skip_noexit "Restart of $facet failed!." &&
1715 error "Restart of $facet failed!"
1722 # Add argument "arg" (e.g., "loop") to the comma-separated list
1723 # of arguments for option "opt" (e.g., "-o") on command
1724 # line "opts" (e.g., "-o flock").
1730 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1732 if echo "$opts" | grep -q $opt_pattern; then
1733 opts=$(echo "$opts" | sed -e \
1734 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1736 opts+="${opts:+ }$opt $arg"
1742 # Associate loop device with a given regular file.
1743 # Return the loop device.
1745 setup_loop_device() {
1749 do_facet $facet "loop_dev=\\\$($LOSETUP -j $file | cut -d : -f 1);
1750 if [[ -z \\\$loop_dev ]]; then
1751 loop_dev=\\\$($LOSETUP -f);
1752 $LOSETUP \\\$loop_dev $file || loop_dev=;
1754 echo -n \\\$loop_dev"
1758 # Detach a loop device.
1760 cleanup_loop_device() {
1764 do_facet $facet "! $LOSETUP $loop_dev >/dev/null 2>&1 ||
1765 $LOSETUP -d $loop_dev"
1769 # Check if a given device is a block device.
1776 [[ -n "$dev" ]] || return 1
1777 do_facet $facet "test -b $dev" || return 1
1778 if [[ -n "$size" ]]; then
1779 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k \
1780 count=1 skip=$size 2>&1" |
1781 awk '($3 == "in") { print $1 }')
1782 [[ "$in" = "1+0" ]] || return 1
1787 # Check if a given device is a device-mapper device.
1793 [[ -n "$dev" ]] || return 1
1794 do_facet $facet "$DMSETUP status $dev >/dev/null 2>&1"
1798 # Check if a given device is a device-mapper flakey device.
1800 is_dm_flakey_dev() {
1805 [[ -n "$dev" ]] || return 1
1807 type=$(do_facet $facet "$DMSETUP status $dev 2>&1" |
1809 [[ $type = flakey ]] && return 0 || return 1
1813 # Check if device-mapper flakey device is supported by the kernel
1814 # of $facet node or not.
1816 dm_flakey_supported() {
1820 do_facet $facet "modprobe dm-flakey;
1821 $DMSETUP targets | grep -q flakey" &> /dev/null
1825 # Get the device-mapper flakey device name of a given facet.
1827 dm_facet_devname() {
1829 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
1831 echo -n ${facet}_flakey
1835 # Get the device-mapper flakey device of a given facet.
1836 # A device created by dmsetup will appear as /dev/mapper/<device-name>.
1838 dm_facet_devpath() {
1841 echo -n $DM_DEV_PATH/$(dm_facet_devname $facet)
1845 # Set a device-mapper device with a new table.
1847 # The table has the following format:
1848 # <logical_start_sector> <num_sectors> <target_type> <target_args>
1850 # flakey <target_args> includes:
1851 # <destination_device> <offset> <up_interval> <down_interval> \
1852 # [<num_features> [<feature_arguments>]]
1854 # linear <target_args> includes:
1855 # <destination_device> <start_sector>
1857 dm_set_dev_table() {
1860 local target_type=$3
1866 read tmp num_sectors tmp real_dev tmp \
1867 <<< $(do_facet $facet "$DMSETUP table $dm_dev")
1869 case $target_type in
1871 table="0 $num_sectors flakey $real_dev 0 0 1800 1 drop_writes"
1874 table="0 $num_sectors linear $real_dev 0"
1876 *) error "invalid target type $target_type" ;;
1879 do_facet $facet "$DMSETUP suspend --nolockfs --noflush $dm_dev" ||
1880 error "failed to suspend $dm_dev"
1881 do_facet $facet "$DMSETUP load $dm_dev --table \\\"$table\\\"" ||
1882 error "failed to load $target_type table into $dm_dev"
1883 do_facet $facet "$DMSETUP resume $dm_dev" ||
1884 error "failed to resume $dm_dev"
1888 # Set a device-mapper flakey device as "read-only" by using the "drop_writes"
1889 # feature parameter.
1892 # All write I/O is silently ignored.
1893 # Read I/O is handled correctly.
1895 dm_set_dev_readonly() {
1897 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1899 dm_set_dev_table $facet $dm_dev flakey
1903 # Set a device-mapper device to traditional linear mapping mode.
1905 dm_clear_dev_readonly() {
1907 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1909 dm_set_dev_table $facet $dm_dev linear
1913 # Set the device of a given facet as "read-only".
1915 set_dev_readonly() {
1917 local svc=${facet}_svc
1919 if [[ $(facet_fstype $facet) = zfs ]] ||
1920 ! dm_flakey_supported $facet; then
1921 do_facet $facet $LCTL --device ${!svc} readonly
1923 dm_set_dev_readonly $facet
1928 # Get size in 512-byte sectors (BLKGETSIZE64 / 512) of a given device.
1935 num_sectors=$(do_facet $facet "blockdev --getsz $dev 2>/dev/null")
1936 [[ ${PIPESTATUS[0]} = 0 && -n "$num_sectors" ]] || num_sectors=0
1937 echo -n $num_sectors
1941 # Create a device-mapper device with a given block device or regular file (will
1942 # be associated with loop device).
1943 # Return the full path of the device-mapper device.
1947 local real_dev=$2 # destination device
1948 local dm_dev_name=${3:-$(dm_facet_devname $facet)} # device name
1949 local dm_dev=$DM_DEV_PATH/$dm_dev_name # device-mapper device
1951 # check if the device-mapper device to be created already exists
1952 if is_dm_dev $facet $dm_dev; then
1953 # if the existing device was set to "read-only", then clear it
1954 ! is_dm_flakey_dev $facet $dm_dev ||
1955 dm_clear_dev_readonly $facet $dm_dev
1961 # check if the destination device is a block device, and if not,
1962 # associate it with a loop device
1963 is_blkdev $facet $real_dev ||
1964 real_dev=$(setup_loop_device $facet $real_dev)
1965 [[ -n "$real_dev" ]] || { echo -n $real_dev; return 2; }
1967 # now create the device-mapper device
1968 local num_sectors=$(get_num_sectors $facet $real_dev)
1969 local table="0 $num_sectors linear $real_dev 0"
1972 do_facet $facet "$DMSETUP create $dm_dev_name --table \\\"$table\\\"" ||
1973 { rc=${PIPESTATUS[0]}; dm_dev=; }
1974 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
1981 # Map the facet name to its device variable name.
1983 facet_device_alias() {
1985 local dev_alias=$facet
1988 fs2mds) dev_alias=mds1_2 ;;
1989 fs2ost) dev_alias=ost1_2 ;;
1990 fs3ost) dev_alias=ost2_2 ;;
1998 # Save the original value of the facet device and export the new value.
2004 local active_facet=$(facet_active $facet)
2005 local dev_alias=$(facet_device_alias $active_facet)
2006 local dev_name=${dev_alias}_dev
2007 local dev=${!dev_name}
2009 if [[ $active_facet = $facet ]]; then
2010 local failover_dev=${dev_alias}failover_dev
2011 if [[ ${!failover_dev} = $dev ]]; then
2012 eval export ${failover_dev}_saved=$dev
2013 eval export ${failover_dev}=$dm_dev
2016 dev_alias=$(facet_device_alias $facet)
2017 local facet_dev=${dev_alias}_dev
2018 if [[ ${!facet_dev} = $dev ]]; then
2019 eval export ${facet_dev}_saved=$dev
2020 eval export ${facet_dev}=$dm_dev
2024 eval export ${dev_name}_saved=$dev
2025 eval export ${dev_name}=$dm_dev
2029 # Restore the saved value of the facet device.
2034 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
2035 local dev_alias=$(facet_device_alias $facet)
2037 local saved_dev=${dev_alias}_dev_saved
2038 [[ -z ${!saved_dev} ]] ||
2039 eval export ${dev_alias}_dev=${!saved_dev}
2041 saved_dev=${dev_alias}failover_dev_saved
2042 [[ -z ${!saved_dev} ]] ||
2043 eval export ${dev_alias}failover_dev=${!saved_dev}
2047 # Remove a device-mapper device.
2048 # If the destination device is a loop device, then also detach it.
2052 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2056 is_dm_dev $facet $dm_dev || return 0
2058 read major minor <<< $(do_facet $facet "$DMSETUP table $dm_dev" |
2059 awk '{ print $4 }' | awk -F: '{ print $1" "$2 }')
2061 do_facet $facet "$DMSETUP remove $dm_dev"
2062 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
2064 unexport_dm_dev $facet
2066 # detach a loop device
2067 [[ $major -ne 7 ]] || cleanup_loop_device $facet /dev/loop$minor
2069 # unload dm-flakey module
2070 do_facet $facet "modprobe -r dm-flakey" || true
2076 local active_facet=$(facet_active $facet)
2077 local dev_alias=$(facet_device_alias $active_facet)
2078 local dev=${dev_alias}_dev
2079 local opt=${facet}_opt
2080 local mntpt=$(facet_mntpt $facet)
2081 local opts="${!opt} $@"
2082 local fstype=$(facet_fstype $facet)
2084 local dm_dev=${!dev}
2086 [[ $dev == "mgsfailover_dev" ]] && combined_mgs_mds &&
2087 dev=mds1failover_dev
2089 module_loaded lustre || load_modules
2093 if dm_flakey_supported $facet; then
2094 dm_dev=$(dm_create_dev $facet ${!dev})
2095 [[ -n "$dm_dev" ]] || dm_dev=${!dev}
2098 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
2100 devicelabel=$(do_facet ${facet} "$E2LABEL $dm_dev");;
2102 # import ZFS storage pool
2103 import_zpool $facet || return ${PIPESTATUS[0]}
2105 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
2106 lustre:svname $dm_dev");;
2108 error "unknown fstype!";;
2111 echo "Starting ${facet}: $opts $dm_dev $mntpt"
2112 # for testing LU-482 error handling in mount_facets() and test_0a()
2113 if [ -f $TMP/test-lu482-trigger ]; then
2117 "mkdir -p $mntpt; $MOUNT_CMD $opts $dm_dev $mntpt"
2121 if [ $RC -ne 0 ]; then
2122 echo "Start of $dm_dev on ${facet} failed ${RC}"
2126 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
2127 if [[ "$health" != "healthy" ]]; then
2128 error "$facet is in a unhealthy state"
2131 set_default_debug_facet $facet
2133 if [[ $opts =~ .*nosvc.* ]]; then
2134 echo "Start $dm_dev without service"
2139 wait_update_facet ${facet} "$E2LABEL $dm_dev \
2140 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
2141 "" || error "$dm_dev failed to initialize!";;
2143 wait_update_facet ${facet} "$ZFS get -H -o value \
2144 lustre:svname $dm_dev 2>/dev/null | \
2145 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
2146 error "$dm_dev failed to initialize!";;
2149 error "unknown fstype!";;
2153 # commit the device label change to disk
2154 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
2155 echo "Commit the device label on ${!dev}"
2156 do_facet $facet "sync; sleep 1; sync"
2160 label=$(devicelabel ${facet} $dm_dev)
2161 [ -z "$label" ] && echo no label for $dm_dev && exit 1
2162 eval export ${facet}_svc=${label}
2163 echo Started ${label}
2165 export_dm_dev $facet $dm_dev
2170 # start facet device options
2176 local dev_alias=$(facet_device_alias $facet)
2178 eval export ${dev_alias}_dev=${device}
2179 eval export ${facet}_opt=\"$@\"
2181 combined_mgs_mds && [[ ${dev_alias} == mds1 ]] &&
2182 eval export mgs_dev=${device}
2184 local varname=${dev_alias}failover_dev
2185 if [ -n "${!varname}" ] ; then
2186 eval export ${dev_alias}failover_dev=${!varname}
2188 eval export ${dev_alias}failover_dev=$device
2189 combined_mgs_mds && [[ ${dev_alias} == mds1 ]] &&
2190 eval export mgsfailover_dev=${device}
2194 local mntpt=$(facet_mntpt $facet)
2195 do_facet ${facet} mkdir -p $mntpt
2196 eval export ${facet}_MOUNT=$mntpt
2197 mount_facet ${facet}
2207 local HOST=$(facet_active_host $facet)
2208 [[ -z $HOST ]] && echo stop: no host for $facet && return 0
2210 local mntpt=$(facet_mntpt $facet)
2211 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts || true")
2212 if [ ${running} -ne 0 ]; then
2213 echo "Stopping $mntpt (opts:$@) on $HOST"
2214 do_facet ${facet} $UMOUNT $@ $mntpt
2217 # umount should block, but we should wait for unrelated obd's
2218 # like the MGS or MGC to also stop.
2219 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
2221 if [[ $(facet_fstype $facet) == zfs ]]; then
2222 # export ZFS storage pool
2223 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
2224 elif dm_flakey_supported $facet; then
2225 local host=${facet}_HOST
2226 local failover_host=${facet}failover_HOST
2227 if [[ -n ${!failover_host} && ${!failover_host} != ${!host} ]]||
2228 $CLEANUP_DM_DEV || [[ $facet = fs* ]]; then
2229 dm_cleanup_dev $facet
2234 # get mdt quota type
2236 local varsvc=${SINGLEMDS}_svc
2237 do_facet $SINGLEMDS $LCTL get_param -n \
2238 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
2241 # get ost quota type
2243 # All OSTs should have same quota type
2244 local varsvc=ost1_svc
2245 do_facet ost1 $LCTL get_param -n \
2246 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
2249 # restore old quota type settings
2251 if [ "$old_MDT_QUOTA_TYPE" ]; then
2252 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2253 do_facet mgs $PERM_CMD \
2254 osd-*.$FSNAME-MDT*.quota_slave.enabled = \
2257 do_facet mgs $PERM_CMD \
2258 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
2261 if [ "$old_OST_QUOTA_TYPE" ]; then
2262 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2263 do_facet mgs $PERM_CMD \
2264 osd-*.$FSNAME-OST*.quota_slave.enabled = \
2267 do_facet mgs $LCTL conf_param \
2268 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
2273 # Handle the case when there is a space in the lfs df
2274 # "filesystem summary" line the same as when there is no space.
2275 # This will allow fixing the "lfs df" summary line in the future.
2277 $LFS df $* | sed -e 's/filesystem /filesystem_/'
2278 check_lfs_df_ret_val $?
2281 # Get free inodes on the MDT specified by mdt index, free indoes on
2282 # the whole filesystem will be returned when index == -1.
2288 if [ $index -eq -1 ]; then
2291 mdt_uuid=$(mdtuuid_from_index $index)
2294 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
2299 # Get the OST device status from 'lfs df' with a given OST index.
2303 local mnt_pnt=${2:-$MOUNT}
2307 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
2308 lfs_df $opts $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
2314 # save old quota type & set new quota type
2315 local mdt_qtype=$(mdt_quota_type)
2316 local ost_qtype=$(ost_quota_type)
2318 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
2319 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
2321 export old_MDT_QUOTA_TYPE=$mdt_qtype
2322 export old_OST_QUOTA_TYPE=$ost_qtype
2324 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2325 do_facet mgs $PERM_CMD \
2326 osd-*.$FSNAME-MDT*.quota_slave.enabled=$QUOTA_TYPE
2327 do_facet mgs $PERM_CMD \
2328 osd-*.$FSNAME-OST*.quota_slave.enabled=$QUOTA_TYPE
2330 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$QUOTA_TYPE ||
2331 error "set mdt quota type failed"
2332 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$QUOTA_TYPE ||
2333 error "set ost quota type failed"
2336 local quota_usrs=$QUOTA_USERS
2338 # get_filesystem_size
2339 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
2340 local blk_soft=$((disksz + 1024))
2341 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
2343 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
2344 local i_soft=$inodes
2345 local i_hard=$((i_soft + i_soft / 20))
2347 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
2348 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
2349 "inode-hardlimit: $i_hard"
2352 for usr in $quota_usrs; do
2353 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
2355 cmd="$LFS setquota -$type $usr -b $blk_soft"
2356 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
2358 eval $cmd || error "$cmd FAILED!"
2360 # display the quota status
2361 echo "Quota settings for $usr : "
2362 $LFS quota -v -u $usr $mntpt || true
2369 local opts=${3:-$MOUNT_OPTS}
2370 opts=${opts:+-o $opts}
2371 local flags=${4:-$MOUNT_FLAGS}
2373 local device=$MGSNID:/$FSNAME$FILESET
2374 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2375 echo "Bad mount command: opt=$flags $opts dev=$device " \
2381 # update mount option with skpath
2382 opts=$(add_sk_mntflag $opts)
2385 echo "Starting client: $client: $flags $opts $device $mnt"
2386 do_node $client mkdir -p $mnt
2387 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
2388 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
2390 #disable FILESET if not supported
2391 do_nodes $client lctl get_param -n \
2392 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2393 device=$MGSNID:/$FSNAME
2394 do_node $client mkdir -p $mnt/$FILESET
2395 do_node $client "! grep -q $mnt' ' /proc/mounts ||
2398 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2399 # Mount using nodemap key
2400 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2401 if $SK_UNIQUE_NM; then
2402 mountkey=$SK_PATH/nodemap/c0.key
2404 local prunedopts=$(echo $opts |
2405 sed -e "s#skpath=[^,^ ]*#skpath=$mountkey#g")
2406 do_node $client $MOUNT_CMD $flags $prunedopts $device $mnt ||
2409 do_node $client $MOUNT_CMD $flags $opts $device $mnt ||
2413 set_default_debug_nodes $client
2414 set_params_clients $client
2425 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
2427 [ "$3" ] && force=-f
2428 [ $running -eq 0 ] && return 0
2430 echo "Stopping client $client $mnt (opts:$force)"
2431 do_node $client lsof -t $mnt || need_kill=no
2432 if [ "x$force" != "x" ] && [ "x$need_kill" != "xno" ]; then
2433 pids=$(do_node $client lsof -t $mnt | sort -u);
2434 if [ -n "$pids" ]; then
2435 do_node $client kill -9 $pids || true
2439 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") ||
2441 if [ $busy -ne 0 ] ; then
2442 echo "$mnt is still busy, wait one second" && sleep 1
2443 do_node $client umount $force $mnt
2447 # Mount the file system on the MDS
2448 mount_mds_client() {
2449 local host=$(facet_active_host $SINGLEMDS)
2451 zconf_mount $host $MOUNT2 $MOUNT_OPTS ||
2452 error "unable to mount $MOUNT2 on $host"
2455 # Unmount the file system on the MDS
2456 umount_mds_client() {
2457 local host=$(facet_active_host $SINGLEMDS)
2458 zconf_umount $host $MOUNT2
2459 do_facet $SINGLEMDS "rmdir $MOUNT2"
2462 # nodes is comma list
2463 sanity_mount_check_nodes () {
2469 # FIXME: assume that all cluster nodes run the same os
2470 [ "$(uname)" = Linux ] || return 0
2473 for mnt in $mnts ; do
2474 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
2475 mpts=\\\$(mount | grep -c $mnt' ');
2476 if [ \\\$running -ne \\\$mpts ]; then
2477 echo \\\$(hostname) env are INSANE!;
2480 [ $? -eq 0 ] || rc=1
2485 sanity_mount_check_servers () {
2486 [ -n "$CLIENTONLY" ] &&
2487 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
2488 echo Checking servers environments
2490 # FIXME: modify get_facets to display all facets wo params
2491 local facets="$(get_facets OST),$(get_facets MDS),mgs"
2495 for facet in ${facets//,/ }; do
2496 node=$(facet_host ${facet})
2497 mntpt=$(facet_mntpt $facet)
2498 sanity_mount_check_nodes $node $mntpt ||
2499 { error "server $node environments are insane!"; return 1; }
2503 sanity_mount_check_clients () {
2504 local clients=${1:-$CLIENTS}
2505 local mntpt=${2:-$MOUNT}
2506 local mntpt2=${3:-$MOUNT2}
2508 [ -z $clients ] && clients=$(hostname)
2509 echo Checking clients $clients environments
2511 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
2512 error "clients environments are insane!"
2515 sanity_mount_check () {
2516 sanity_mount_check_servers || return 1
2517 sanity_mount_check_clients || return 2
2520 # mount clients if not mouted
2521 zconf_mount_clients() {
2524 local opts=${3:-$MOUNT_OPTS}
2525 opts=${opts:+-o $opts}
2526 local flags=${4:-$MOUNT_FLAGS}
2527 local device=$MGSNID:/$FSNAME$FILESET
2528 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2529 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
2534 echo "Starting client $clients: $flags $opts $device $mnt"
2535 do_nodes $clients mkdir -p $mnt
2536 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ]; then
2537 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2538 # Mount with own nodemap key
2540 # Mount all server nodes first with per-NM keys
2541 for nmclient in ${clients//,/ }; do
2542 # do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key -n c$i"
2543 do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key"
2546 # set perms for per-nodemap keys else permission denied
2547 do_nodes $(comma_list $(all_nodes)) \
2548 "keyctl show | grep lustre | cut -c1-11 |
2550 xargs -IX keyctl setperm X 0x3f3f3f3f"
2551 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2553 for nmclient in ${clients//,/ }; do
2554 if $SK_UNIQUE_NM; then
2555 mountkey=$SK_PATH/nodemap/c$i.key
2557 do_node $nmclient "! grep -q $mnt' ' \
2558 /proc/mounts || umount $mnt"
2559 local prunedopts=$(add_sk_mntflag $prunedopts);
2560 prunedopts=$(echo $prunedopts | sed -e \
2561 "s#skpath=[^ ^,]*#skpath=$mountkey#g")
2563 do_nodes $(comma_list $(all_server_nodes)) \
2566 do_node $nmclient $MOUNT_CMD $flags \
2567 $prunedopts $MGSNID:/$FSNAME $mnt ||
2572 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2574 do_nodes $clients $MOUNT_CMD $flags $opts \
2575 $MGSNID:/$FSNAME $mnt || return 1
2577 #disable FILESET if not supported
2578 do_nodes $clients lctl get_param -n \
2579 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2580 device=$MGSNID:/$FSNAME
2581 do_nodes $clients mkdir -p $mnt/$FILESET
2582 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2586 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2587 # Mount with nodemap key
2589 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2590 for nmclient in ${clients//,/ }; do
2591 if $SK_UNIQUE_NM; then
2592 mountkey=$SK_PATH/nodemap/c$i.key
2594 local prunedopts=$(echo $opts | sed -e \
2595 "s#skpath=[^ ^,]*#skpath=$mountkey#g");
2596 do_node $nmclient "! grep -q $mnt' ' /proc/mounts ||
2599 running=\\\$(mount | grep -c $mnt' ');
2601 if [ \\\$running -eq 0 ] ; then
2603 $MOUNT_CMD $flags $prunedopts $device $mnt;
2606 lustre_mnt_count=\\\$(mount | grep $mnt' ' | \
2607 grep 'type lustre' | wc -l);
2608 if [ \\\$running -ne \\\$lustre_mnt_count ] ; then
2609 echo zconf_mount_clients FAILED: \
2610 mount count \\\$running, not matching \
2611 with mount count of 'type lustre' \
2612 \\\$lustre_mnt_count;
2616 exit \\\$rc" || return ${PIPESTATUS[0]}
2623 if $SHARED_KEY; then
2624 tmpopts=$(add_sk_mntflag $opts)
2627 running=\\\$(mount | grep -c $mnt' ');
2629 if [ \\\$running -eq 0 ] ; then
2631 $MOUNT_CMD $flags $tmpopts $device $mnt;
2634 exit \\\$rc" || return ${PIPESTATUS[0]}
2637 echo "Started clients $clients: "
2638 do_nodes $clients "mount | grep $mnt' '"
2640 set_default_debug_nodes $clients
2641 set_params_clients $clients
2646 zconf_umount_clients() {
2651 [ "$3" ] && force=-f
2653 echo "Stopping clients: $clients $mnt (opts:$force)"
2654 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
2655 if [ \\\$running -ne 0 ] ; then
2656 echo Stopping client \\\$(hostname) $mnt opts:$force;
2657 lsof $mnt || need_kill=no;
2658 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
2659 pids=\\\$(lsof -t $mnt | sort -u);
2660 if [ -n \\\"\\\$pids\\\" ]; then
2664 while umount $force $mnt 2>&1 | grep -q "busy"; do
2665 echo "$mnt is still busy, wait one second" && sleep 1;
2672 echo + $POWER_DOWN $node
2676 shutdown_node_hard () {
2678 local attempts=$SHUTDOWN_ATTEMPTS
2680 for i in $(seq $attempts) ; do
2683 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
2684 echo "waiting for $host to fail attempts=$attempts"
2685 [ $i -lt $attempts ] || \
2686 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
2692 local mnt=${2:-$MOUNT}
2695 if [ "$FAILURE_MODE" = HARD ]; then
2696 shutdown_node_hard $client
2698 zconf_umount_clients $client $mnt -f
2704 local facets="$(get_facets OST),$(get_facets MDS)"
2707 combined_mgs_mds || facets="$facets,mgs"
2709 for facet in ${facets//,/ }; do
2710 if [ $(facet_active_host $facet) == $host ]; then
2711 affected="$affected $facet"
2715 echo $(comma_list $affected)
2720 local host=${2:-$(facet_host $facet)}
2722 local label=$(convert_facet2label $facet)
2723 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
2726 facets_up_on_host () {
2728 local facets=$(facets_on_host $host)
2731 for facet in ${facets//,/ }; do
2732 if $(facet_up $facet $host); then
2733 affected_up="$affected_up $facet"
2737 echo $(comma_list $affected_up)
2742 local affected_facet
2743 local affected_facets
2745 if [[ "$FAILURE_MODE" = HARD ]]; then
2746 if [[ $(facet_fstype $facet) = ldiskfs ]] &&
2747 dm_flakey_supported $facet; then
2748 affected_facets=$(affected_facets $facet)
2749 for affected_facet in ${affected_facets//,/ }; do
2750 unexport_dm_dev $affected_facet
2754 shutdown_node_hard $(facet_active_host $facet)
2762 echo + $POWER_UP $node
2775 local node=$(facet_active_host $facet)
2776 local sleep_time=${2:-10}
2778 if [ "$FAILURE_MODE" = HARD ]; then
2788 if [ "$FAILURE_MODE" = HARD ]; then
2791 if $LOAD_MODULES_REMOTE; then
2792 echo "loading modules on $node: $facet"
2793 do_rpc_nodes $node load_modules_local
2802 for facet in ${facets//,/ }; do
2803 hosts=$(expand_list $hosts $(facet_host $facet) )
2809 _check_progs_installed () {
2813 for prog in $progs; do
2814 if ! [ "$(which $prog)" -o "${!prog}" ]; then
2815 echo $prog missing on $(hostname)
2822 check_progs_installed () {
2826 do_rpc_nodes "$nodes" _check_progs_installed $@
2829 # recovery-scale functions
2831 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
2834 start_client_load() {
2837 local var=$(node_var_name $client)_load
2838 eval export ${var}=$load
2840 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
2841 BREAK_ON_ERROR=$BREAK_ON_ERROR \
2842 END_RUN_FILE=$END_RUN_FILE \
2843 LOAD_PID_FILE=$LOAD_PID_FILE \
2844 TESTLOG_PREFIX=$TESTLOG_PREFIX \
2845 TESTNAME=$TESTNAME \
2846 DBENCH_LIB=$DBENCH_LIB \
2847 DBENCH_SRC=$DBENCH_SRC \
2848 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
2853 MPIRUN_OPTIONS=\\\"$MPIRUN_OPTIONS\\\" \
2854 MACHINEFILE_OPTION=\\\"$MACHINEFILE_OPTION\\\" \
2855 num_clients=$(get_node_count ${CLIENTS//,/ }) \
2856 ior_THREADS=$ior_THREADS ior_iteration=$ior_iteration \
2857 ior_blockSize=$ior_blockSize \
2858 ior_blockUnit=$ior_blockUnit \
2859 ior_xferSize=$ior_xferSize ior_type=$ior_type \
2860 ior_DURATION=$ior_DURATION \
2861 ior_stripe_params=\\\"$ior_stripe_params\\\" \
2862 ior_custom_params=\\\"$ior_custom_param\\\" \
2863 mpi_ior_custom_threads=$mpi_ior_custom_threads \
2866 log "Started client load: ${load} on $client"
2868 # get the children process IDs
2869 local pids=$(ps --ppid $ppid -o pid= | xargs)
2870 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
2874 start_client_loads () {
2875 local -a clients=(${1//,/ })
2876 local numloads=${#CLIENT_LOADS[@]}
2878 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
2879 local load=$((nodenum % numloads))
2880 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[load]}
2882 # bug 22169: wait the background threads to start
2886 # only for remote client
2887 check_client_load () {
2889 local var=$(node_var_name $client)_load
2890 local testload=run_${!var}.sh
2892 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
2894 # bug 18914: try to connect several times not only when
2895 # check ps, but while check_node_health also
2899 while [ $RC = 254 -a $tries -gt 0 ]; do
2903 if ! check_node_health $client; then
2905 if [ $RC -eq 254 ]; then
2906 # FIXME: not sure how long we shuold sleep here
2910 echo "check node health failed: RC=$RC "
2914 # We can continue try to connect if RC=254
2915 # Just print the warning about this
2916 if [ $RC = 254 ]; then
2917 echo "got a return status of $RC from do_node while checking " \
2918 "node health on $client"
2921 # see if the load is still on the client
2924 while [ $RC = 254 -a $tries -gt 0 ]; do
2928 if ! do_node $client \
2929 "ps auxwww | grep -v grep | grep -q $testload"; then
2934 if [ $RC = 254 ]; then
2935 echo "got a return status of $RC from do_node while checking " \
2936 "(node health and 'ps') the client load on $client"
2937 # see if we can diagnose a bit why this is
2942 check_client_loads () {
2943 local clients=${1//,/ }
2947 for client in $clients; do
2948 check_client_load $client
2950 if [ "$rc" != 0 ]; then
2951 log "Client load failed on node $client, rc=$rc"
2957 restart_client_loads () {
2958 local clients=${1//,/ }
2959 local expectedfail=${2:-""}
2963 for client in $clients; do
2964 check_client_load $client
2966 if [ "$rc" != 0 -a "$expectedfail" ]; then
2967 local var=$(node_var_name $client)_load
2968 start_client_load $client ${!var}
2969 echo "Restarted client load ${!var}: on $client. Checking ..."
2970 check_client_load $client
2972 if [ "$rc" != 0 ]; then
2973 log "Client load failed to restart on node $client, rc=$rc"
2974 # failure one client load means test fail
2975 # we do not need to check other
2984 # Start vmstat and save its process ID in a file.
2989 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2992 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
2993 2>/dev/null </dev/null & echo \\\$! > $pid_file"
2996 # Display the nodes on which client loads failed.
2997 print_end_run_file() {
3001 [ -s $file ] || return 0
3003 echo "Found the END_RUN_FILE file: $file"
3006 # A client load will stop if it finds the END_RUN_FILE file.
3007 # That does not mean the client load actually failed though.
3008 # The first node in END_RUN_FILE is the one we are interested in.
3011 if [ -n "$node" ]; then
3012 local var=$(node_var_name $node)_load
3014 local prefix=$TESTLOG_PREFIX
3015 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
3016 local stdout_log=$prefix.run_${!var}_stdout.$node.log
3017 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
3019 echo "Client load ${!var} failed on node $node:"
3025 # Stop the process which had its PID saved in a file.
3030 [ -z "$nodes" -o -z "$pid_file" ] && return 0
3032 do_nodes $nodes "test -f $pid_file &&
3033 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
3036 # Stop all client loads.
3037 stop_client_loads() {
3038 local nodes=${1:-$CLIENTS}
3041 # stop the client loads
3042 stop_process $nodes $pid_file
3044 # clean up the processes that started them
3045 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
3047 # End recovery-scale functions
3050 # wait for a command to return the expected result
3052 # This will run @check on @node repeatedly until the output matches @expect
3053 # based on the supplied condition, or until @max_wait seconds have elapsed,
3054 # whichever comes first. @cond may be one of the normal bash operators,
3055 # "-gt", "-ge", "-eq", "-le", "-lt", "==", "!=", or "=~", and must be quoted
3056 # in the caller to avoid unintentional evaluation by the shell in the caller.
3058 # If @max_wait is not specified, the condition will be checked for up to 90s.
3060 # If --verbose is passed as the first argument, the result is printed on each
3061 # value change, otherwise it is only printed after every 10s interval.
3063 # If --quiet is passed as the first/second argument, the do_node() command
3064 # will not print the remote command before executing it each time.
3066 # Using wait_update_cond() or related helper function is preferable to adding
3067 # a "long enough" wait for some state to change in the background, since
3068 # "long enough" may be too short due to tunables, system config, or running in
3069 # a VM, and must by necessity wait too long for most cases or risk failure.
3071 # usage: wait_update_cond [--verbose] [--quiet] node check cond expect [max_wait]
3072 wait_update_cond() {
3076 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3077 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3083 local max_wait=${5:-90}
3087 local begin=$SECONDS
3091 while (( $waited <= $max_wait )); do
3092 result=$(do_node $quiet $node "$check")
3094 eval [[ "'$result'" $cond "'$expect'" ]]
3095 if [[ $? == 0 ]]; then
3096 [[ -z "$result" || $waited -le $sleep ]] ||
3097 echo "Updated after ${waited}s: want '$expect' got '$result'"
3100 if [[ -n "$verbose" && "$result" != "$prev_result" ]]; then
3101 [[ -n "$prev_result" ]] &&
3102 echo "Changed after ${waited}s: from '$prev_result' to '$result'"
3103 prev_result="$result"
3105 (( $waited % $print == 0 )) &&
3106 echo "Waiting $((max_wait - waited))s for '$expect'"
3108 waited=$((SECONDS - begin))
3110 echo "Update not seen after ${max_wait}s: want '$expect' got '$result'"
3114 # usage: wait_update [--verbose] [--quiet] node check expect [max_wait]
3119 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3120 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3127 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3130 # usage: wait_update_facet_cond [--verbose] facet check cond expect [max_wait]
3131 wait_update_facet_cond() {
3135 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3136 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3138 local node=$(facet_active_host $1)
3144 wait_update_cond $verbose $quiet $node "$check" "$cond" "$expect" $max_wait
3147 # usage: wait_update_facet [--verbose] facet check expect [max_wait]
3148 wait_update_facet() {
3152 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3153 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3155 local node=$(facet_active_host $1)
3160 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3164 do_nodes $(comma_list $(mdts_nodes)) \
3165 "lctl set_param -n os[cd]*.*MDT*.force_sync=1"
3166 do_nodes $(comma_list $(osts_nodes)) \
3167 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
3168 grep -v 'Found no match'
3172 local zfs_wait=${2:-5}
3174 # the occupied disk space will be released
3175 # only after TXGs are committed
3176 if [[ $(facet_fstype $1) == zfs ]]; then
3177 echo "sleep $zfs_wait for ZFS $(facet_fstype $1)"
3185 local lwm=$3 #low watermark
3186 local size_mb #how many MB should we write to pass watermark
3187 local ost_name=$(ostname_from_index $ost_idx)
3189 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3191 if (( $free_kb / 1024 > lwm )); then
3192 size_mb=$((free_kb / 1024 - lwm))
3194 #If 10% of free space cross low watermark use it
3195 if (( $free_kb / 10240 > size_mb )); then
3196 size_mb=$((free_kb / 10240))
3198 #At least we need to store 1.1 of difference between
3199 #free space and low watermark
3200 size_mb=$((size_mb + size_mb / 10))
3202 if (( lwm <= $free_kb / 1024 )) ||
3203 [ ! -f $DIR/${filename}.fill_ost$ost_idx ]; then
3204 $LFS setstripe -i $ost_idx -c1 $DIR/${filename}.fill_ost$ost_idx
3205 dd if=/dev/zero of=$DIR/${filename}.fill_ost$ost_idx bs=1M \
3206 count=$size_mb oflag=append conv=notrunc
3211 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3212 echo "OST still has $((free_kb / 1024)) MB free"
3215 # This checks only the primary MDS
3216 ost_watermarks_get() {
3218 local ost_name=$(ostname_from_index $ost_idx)
3219 local mdtosc_proc=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
3221 local hwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3222 osp.$mdtosc_proc.reserved_mb_high)
3223 local lwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3224 osp.$mdtosc_proc.reserved_mb_low)
3229 # Note that we set watermarks on all MDSes (necessary for striped dirs)
3230 ost_watermarks_set() {
3234 local ost_name=$(ostname_from_index $ost_idx)
3235 local facets=$(get_facets MDS)
3237 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param -n \
3238 osp.*$ost_name*.reserved_mb_low=$lwm \
3239 osp.*$ost_name*.reserved_mb_high=$hwm > /dev/null
3241 # sleep to ensure we see the change
3245 ost_watermarks_set_low_space() {
3247 local wms=$(ost_watermarks_get $ost_idx)
3248 local ost_name=$(ostname_from_index $ost_idx)
3250 local old_lwm=$(echo $wms | awk '{ print $1 }')
3251 local old_hwm=$(echo $wms | awk '{ print $2 }')
3253 local blocks=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3254 # minimal extension size is 64M
3256 if (( $blocks / 1024 > 50 )); then
3257 new_lwm=$((blocks / 1024 - 50))
3259 local new_hwm=$((new_lwm + 5))
3261 ost_watermarks_set $ost_idx $new_lwm $new_hwm
3262 echo "watermarks: $old_lwm $old_hwm $new_lwm $new_hwm"
3265 # Set watermarks to ~current available space & then write data to fill it
3266 # Note OST is not *actually* full after this, it just reports ENOSPC in the
3267 # internal statfs used by the stripe allocator
3269 # first parameter is the filename-prefix, which must get under t-f cleanup
3270 # requirements (rm -rf $DIR/[Rdfs][0-9]*), i.e. $tfile work fine
3271 ost_watermarks_set_enospc() {
3275 local ost_name=$(ostname_from_index $ost_idx)
3276 local facets=$(get_facets MDS)
3280 for MDS in ${facets//,/ }; do
3281 local mdtosc_proc=$(get_mdtosc_proc_path $MDS $ost_name)
3283 do_facet $MDS $LCTL get_param -n \
3284 osp.$mdtosc_proc.reserved_mb_high ||
3285 skip "remote MDS does not support reserved_mb_high"
3288 wms=$(ost_watermarks_set_low_space $ost_idx)
3289 local new_lwm=$(echo $wms | awk '{ print $4 }')
3290 fill_ost $filename $ost_idx $new_lwm
3291 #First enospc could execute orphan deletion so repeat
3292 fill_ost $filename $ost_idx $new_lwm
3296 ost_watermarks_enospc_delete_files() {
3300 rm -f $DIR/${filename}.fill_ost$ost_idx
3302 wait_delete_completed
3306 # clean up from "ost_watermarks_set_enospc"
3307 ost_watermarks_clear_enospc() {
3313 ost_watermarks_enospc_delete_files $filename $ost_idx
3314 ost_watermarks_set $ost_idx $old_lwm $old_hwm
3315 echo "set OST$ost_idx lwm back to $old_lwm, hwm back to $old_hwm"
3318 wait_delete_completed_mds() {
3319 local max_wait=${1:-20}
3321 local stime=$(date +%s)
3326 # find MDS with pending deletions
3327 for node in $(mdts_nodes); do
3328 changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
3329 2>/dev/null | calc_sum)
3330 if [[ $changes -eq 0 ]]; then
3333 mds2sync="$mds2sync $node"
3335 if [ -z "$mds2sync" ]; then
3336 wait_zfs_commit $SINGLEMDS
3339 mds2sync=$(comma_list $mds2sync)
3341 # sync MDS transactions
3342 do_nodes $mds2sync "$LCTL set_param -n os[cd]*.*MD*.force_sync 1"
3344 # wait till all changes are sent and commmitted by OSTs
3345 # for ldiskfs space is released upon execution, but DMU
3346 # do this upon commit
3349 while [[ $WAIT -ne $max_wait ]]; do
3350 changes=$(do_nodes $mds2sync \
3351 "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
3352 #echo "$node: $changes changes on all"
3353 if [[ $changes -eq 0 ]]; then
3354 wait_zfs_commit $SINGLEMDS
3356 # the occupied disk space will be released
3357 # only after TXGs are committed
3358 wait_zfs_commit ost1
3366 echo "Delete is not completed in $((etime - stime)) seconds"
3367 do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
3374 # we can use "for" here because we are waiting the slowest
3375 for host in ${hostlist//,/ }; do
3376 check_network "$host" 900
3378 while ! do_nodes $hostlist hostname > /dev/null; do sleep 5; done
3385 for facet in ${facetlist//,/ }; do
3386 hostlist=$(expand_list $hostlist $(facet_active_host $facet))
3388 wait_for_host $hostlist
3391 _wait_recovery_complete () {
3394 # Use default policy if $2 is not passed by caller.
3395 local MAX=${2:-$(max_recovery_time)}
3400 while [ $WAIT -lt $MAX ]; do
3401 STATUS=$(lctl get_param -n $param | grep status)
3403 [[ $STATUS = "status: COMPLETE" || $STATUS = "status: INACTIVE" ]] && return 0
3406 echo "Waiting $((MAX - WAIT)) secs for $param recovery done. $STATUS"
3408 echo "$param recovery not done in $MAX sec. $STATUS"
3412 wait_recovery_complete () {
3415 # with an assumption that at_max is the same on all nodes
3416 local MAX=${2:-$(max_recovery_time)}
3419 if [ "$FAILURE_MODE" = HARD ]; then
3420 facets=$(facets_on_host $(facet_active_host $facet))
3422 echo affected facets: $facets
3424 facets=${facets//,/ }
3425 # We can use "for" here because we are waiting the slowest.
3426 # The mgs not having the recovery_status proc entry, exclude it
3427 # from the facet list.
3428 for facet in ${facets//mgs/ }; do
3429 local var_svc=${facet}_svc
3430 local param="*.${!var_svc}.recovery_status"
3432 local host=$(facet_active_host $facet)
3433 do_rpc_nodes "$host" _wait_recovery_complete $param $MAX
3437 wait_mds_ost_sync () {
3438 # just because recovery is done doesn't mean we've finished
3439 # orphan cleanup. Wait for llogs to get synchronized.
3440 echo "Waiting for orphan cleanup..."
3441 # MAX value includes time needed for MDS-OST reconnection
3442 local MAX=$(( TIMEOUT * 2 ))
3443 local WAIT_TIMEOUT=${1:-$MAX}
3446 local list=$(comma_list $(mdts_nodes))
3447 local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
3448 if ! do_facet $SINGLEMDS \
3449 "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
3451 # old way, use mds_sync
3453 list=$(comma_list $(osts_nodes))
3454 cmd="$LCTL get_param -n obdfilter.*.mds_sync"
3457 echo "wait $WAIT_TIMEOUT secs maximumly for $list mds-ost sync done."
3458 while [ $WAIT -lt $WAIT_TIMEOUT ]; do
3459 local -a sync=($(do_nodes $list "$cmd"))
3462 for ((i=0; i<${#sync[@]}; i++)); do
3464 [ ${sync[$i]} -eq 1 ] && continue
3466 [ ${sync[$i]} -eq 0 ] && continue
3468 # there is a not finished MDS-OST synchronization
3472 sleep 2 # increase waiting time and cover statfs cache
3473 [ ${con} -eq 1 ] && return 0
3474 echo "Waiting $WAIT secs for $list $i mds-ost sync done."
3478 # show which nodes are not finished.
3479 cmd=$(echo $cmd | sed 's/-n//')
3480 do_nodes $list "$cmd"
3481 echo "$facet recovery node $i not done in $WAIT_TIMEOUT sec. $STATUS"
3485 # Wait OSTs to be active on both client and MDT side.
3487 local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
3488 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
3489 wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
3490 error "wait_update OSTs up on client failed"
3492 cmd="$LCTL get_param osp.$FSNAME-OST*-MDT0000.prealloc_last_id |
3493 awk '/=[1-9][0-9]/ { c += 1 } END { printf \\\"%d\\\", c }'"
3494 wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
3495 error "wait_update OSTs up on MDT0000 failed"
3498 wait_destroy_complete () {
3499 echo "Waiting for MDT destroys to complete"
3500 # MAX value shouldn't be big as this mean server responsiveness
3501 # never increase this just to make test pass but investigate
3502 # why it takes so long time
3505 local list=$(comma_list $(mdts_nodes))
3506 while [ $WAIT -lt $MAX ]; do
3507 local -a RPCs=($(do_nodes $list $LCTL get_param -n osp.*.destroys_in_flight))
3511 for ((i=0; i<${#RPCs[@]}; i++)); do
3512 [ ${RPCs[$i]} -eq 0 ] && continue
3513 # there are still some destroy RPCs in flight
3518 [ ${con} -eq 1 ] && return 0 # done waiting
3519 echo "Waiting ${WAIT}s for local destroys to complete"
3522 echo "MDT destroys weren't done in $MAX sec."
3526 wait_delete_completed() {
3527 wait_delete_completed_mds $1 || return $?
3528 wait_destroy_complete || return $?
3537 # conf-sanity 31 takes a long time cleanup
3538 while [ $WAIT -lt 300 ]; do
3539 running=$(do_facet ${facet} "lsmod | grep lnet > /dev/null &&
3540 lctl dl | grep ' ST ' || true")
3541 [ -z "${running}" ] && return 0
3542 echo "waited $WAIT for${running}"
3543 [ $INTERVAL -lt 64 ] && INTERVAL=$((INTERVAL + INTERVAL))
3545 WAIT=$((WAIT + INTERVAL))
3547 echo "service didn't stop after $WAIT seconds. Still running:"
3552 wait_remote_prog () {
3558 [ "$PDSH" = "no_dsh" ] && return 0
3560 while [ $WAIT -lt $2 ]; do
3561 running=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep) || true
3562 [ -z "${running}" ] && return 0 || true
3563 echo "waited $WAIT for: "
3565 [ $INTERVAL -lt 60 ] && INTERVAL=$((INTERVAL + INTERVAL))
3567 WAIT=$((WAIT + INTERVAL))
3569 local pids=$(ps uax | grep "$PDSH.*$prog.*$MOUNT" | grep -v grep | awk '{print $2}')
3570 [ -z "$pids" ] && return 0
3571 echo "$PDSH processes still exists after $WAIT seconds. Still running: $pids"
3572 # FIXME: not portable
3573 for pid in $pids; do
3574 cat /proc/${pid}/status || true
3575 cat /proc/${pid}/wchan || true
3577 kill -9 $pid || true
3586 local clients=${1:-$CLIENTS}
3589 if [ -z "$clients" ]; then
3590 $LFS df $MOUNT > /dev/null || rc=$?
3592 $PDSH $clients "$LFS df $MOUNT" > /dev/null || rc=$?
3595 check_lfs_df_ret_val $rc
3599 # not every config has many clients
3605 (( MDSCOUNT == 1 )) && return
3607 # wait so that statfs data on MDT expire
3608 local delay=$(do_facet mds1 $LCTL \
3609 get_param -n osp.*MDT*MDT0000.maxage | sort -n | tail -1)
3611 [ -n "$delay" ] || error "fail to get maxage"
3613 local nodes=$(comma_list $(mdts_nodes))
3614 # initiate statfs RPC, all to all MDTs
3615 do_nodes $nodes $LCTL get_param -N osp.*MDT*MDT*.filesfree >&/dev/null
3616 do_nodes $nodes $LCTL get_param -N osp.*MDT*MDT*.filesfree >&/dev/null
3620 # usually checked on particular client or locally
3629 client_reconnect_try() {
3630 local f=$MOUNT/recon
3633 if [ -z "$CLIENTS" ]; then
3634 $LFS df $MOUNT; uname -n >> $f
3636 do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
3638 echo "Connected clients: $(cat $f)"
3639 ls -l $f > /dev/null
3643 client_reconnect() {
3644 # one client_reconnect_try call does not always do the job...
3646 client_reconnect_try && break
3651 affected_facets () {
3654 local host=$(facet_active_host $facet)
3655 local affected=$facet
3657 if [ "$FAILURE_MODE" = HARD ]; then
3658 affected=$(facets_up_on_host $host)
3664 local E2FSCK_ON_MDT0=false
3665 if [ "$1" == "--fsck" ]; then
3667 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
3679 #Because it will only get up facets, we need get affected
3680 #facets before shutdown
3681 #For HARD Failure mode, it needs make sure facets on the same
3682 #HOST will only be shutdown and reboot once
3683 for facet in ${facets//,/ }; do
3684 local affected_facet
3686 #check whether facet has been included in other affected facets
3687 for ((index=0; index<$total; index++)); do
3688 [[ *,$facet,* == ,${affecteds[index]}, ]] && skip=1
3691 if [ $skip -eq 0 ]; then
3692 affecteds[$total]=$(affected_facets $facet)
3697 for ((index=0; index<$total; index++)); do
3698 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
3699 local host=$(facet_active_host $facet)
3700 echo "Failing ${affecteds[index]} on $host"
3701 shutdown_facet $facet
3704 $E2FSCK_ON_MDT0 && (run_e2fsck $(facet_active_host $SINGLEMDS) \
3705 $(mdsdevname 1) "-n" || error "Running e2fsck")
3707 for ((index=0; index<$total; index++)); do
3708 facet=$(echo ${affecteds[index]} | tr -s " " | cut -d"," -f 1)
3709 echo reboot facets: ${affecteds[index]}
3711 reboot_facet $facet $sleep_time
3713 change_active ${affecteds[index]}
3715 wait_for_facet ${affecteds[index]}
3718 init_facets_vars_simple
3720 # start mgs first if it is affected
3721 if ! combined_mgs_mds &&
3722 list_member ${affecteds[index]} mgs; then
3723 mount_facet mgs || error "Restart of mgs failed"
3724 affecteds[index]=$(exclude_items_from_list \
3725 ${affecteds[index]} mgs)
3727 # FIXME; has to be changed to mount all facets concurrently
3728 if [ -n "${affecteds[index]}" ]; then
3729 echo mount facets: ${affecteds[index]}
3730 mount_facets ${affecteds[index]}
3733 do_nodes $(comma_list $(all_nodes)) \
3734 "keyctl show | grep lustre | cut -c1-11 |
3736 xargs -IX keyctl setperm X 0x3f3f3f3f"
3743 do_facet $facet "sync; sync; sync"
3746 # make sure there will be no seq change
3747 local clients=${CLIENTS:-$HOSTNAME}
3748 local f=fsa-\\\$\(hostname\)
3749 do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
3750 do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
3752 local svc=${facet}_svc
3753 do_facet $facet $LCTL --device ${!svc} notransno
3755 # If a ZFS OSD is made read-only here, its pool is "freezed". This
3756 # in-memory state has to be cleared by either rebooting the host or
3757 # exporting and reimporting the pool.
3759 # Although the uberblocks are not updated when a pool is freezed,
3760 # transactions are still written to the disks. Modified blocks may be
3761 # cached in memory when tests try reading them back. The
3762 # export-and-reimport process also evicts any cached pool data from
3763 # memory to provide the correct "data loss" semantics.
3765 # In the test framework, the exporting and importing operations are
3766 # handled by stop() and mount_facet() separately, which are used
3767 # inside fail() and fail_abort().
3769 set_dev_readonly $facet
3770 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
3771 $LCTL mark "local REPLAY BARRIER on ${!svc}"
3774 replay_barrier_nodf() {
3775 local facet=$1 echo running=${running}
3776 do_facet $facet "sync; sync; sync"
3777 local svc=${facet}_svc
3778 echo Replay barrier on ${!svc}
3779 do_facet $facet $LCTL --device ${!svc} notransno
3780 set_dev_readonly $facet
3781 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
3782 $LCTL mark "local REPLAY BARRIER on ${!svc}"
3785 replay_barrier_nosync() {
3786 local facet=$1 echo running=${running}
3787 local svc=${facet}_svc
3788 echo Replay barrier on ${!svc}
3789 do_facet $facet $LCTL --device ${!svc} notransno
3790 set_dev_readonly $facet
3791 do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
3792 $LCTL mark "local REPLAY BARRIER on ${!svc}"
3796 # Get Lustre client uuid for a given Lustre mount point.
3799 local mntpnt=${1:-$MOUNT}
3801 local name=$($LFS getname $mntpnt | cut -d' ' -f1)
3802 local uuid=$($LCTL get_param -n llite.$name.uuid)
3807 mds_evict_client() {
3808 local mntpnt=${1:-$MOUNT}