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=${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}
437 export MACHINEFILE=${MACHINEFILE:-$TMP/$(basename $0 .sh).machines}
438 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
441 # use localrecov to enable recovery for local clients, LU-12722
442 [[ $MDS1_VERSION -lt $(version_code 2.13.52) ]] || {
443 export MDS_MOUNT_OPTS=${MDS_MOUNT_OPTS:-"-o localrecov"}
444 export MGS_MOUNT_OPTS=${MGS_MOUNT_OPTS:-"-o localrecov"}
447 [[ $OST1_VERSION -lt $(version_code 2.13.52) ]] ||
448 export OST_MOUNT_OPTS=${OST_MOUNT_OPTS:-"-o localrecov"}
455 ncpts=$(do_facet $facet "lctl get_param -n " \
456 "cpu_partition_table 2>/dev/null| wc -l" || echo 1)
458 if [ $ncpts -eq 0 ]; then
465 # Return a numeric version code based on a version string. The version
466 # code is useful for comparison two version strings to see which is newer.
468 # split arguments like "1.8.6-wc3" into "1", "8", "6", "3"
469 eval set -- $(tr "[:punct:][a-z]" " " <<< $*)
471 echo -n $(((${1:-0}<<24) | (${2:-0}<<16) | (${3:-0}<<8) | (${4:-0})))
474 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
475 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
477 # Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
479 # usage: lustre_build_version
481 # All Lustre versions support "lctl get_param" to report the version of the
482 # code running in the kernel (what our tests are interested in), but it
483 # doesn't work without modules loaded. After 2.9.53 and in upstream kernels
484 # the "version" parameter doesn't include "lustre: " at the beginning.
485 # If that fails, call "lctl lustre_build_version" which prints either (or both)
486 # the userspace and kernel build versions, but until 2.8.55 required root
487 # access to get the Lustre kernel version. If that also fails, fall back to
488 # using "lctl --version", which is easy to parse and works without the kernel
489 # modules, but was only added in 2.6.50 and only prints the lctl tool version,
490 # not the module version, though they are usually the same.
492 # Various commands and their output format for different Lustre versions:
493 # lctl get_param version: 2.9.55
494 # lctl get_param version: lustre: 2.8.53
495 # lctl get_param version: lustre: 2.6.52
496 # kernel: patchless_client
497 # build: v2_6_92_0-2.6.32-431.el6_lustre.x86_64
498 # lctl lustre_build_version: Lustre version: 2.8.53_27_gae67fc01
499 # lctl lustre_build_version: error: lustre_build_version: Permission denied
500 # (as non-root user) lctl version: v2_6_92_0-2.6.32-431.el6.x86_64
501 # lctl lustre_build_version: Lustre version: 2.5.3-2.6.32.26-175.fc12.x86_64
502 # lctl version: 2.5.3-2.6.32..26-175fc12.x86_64
503 # lctl --version: lctl 2.6.50
505 # output: prints version string to stdout in (up to 4) dotted-decimal values
506 lustre_build_version() {
507 local facet=${1:-client}
508 local facet_version=${facet}_VERSION
510 # if the global variable is already set, then use that
511 [ -n "${!facet_version}" ] && echo ${!facet_version} && return
513 # this is the currently-running version of the kernel modules
514 local ver=$(do_facet $facet "$LCTL get_param -n version 2>/dev/null")
515 # we mostly test 2.10+ systems, only try others if the above fails
516 if [ -z "$ver" ]; then
517 ver=$(do_facet $facet "$LCTL lustre_build_version 2>/dev/null")
519 if [ -z "$ver" ]; then
520 ver=$(do_facet $facet "$LCTL --version 2>/dev/null" |
523 local lver=$(egrep -i "lustre: |version: " <<<"$ver" | head -n 1)
524 [ -n "$lver" ] && ver="$lver"
526 lver=$(sed -e 's/[^:]*: //' -e 's/^v//' -e 's/[ -].*//' <<<$ver |
527 tr _ . | cut -d. -f1-4)
529 # save in global variable for the future
530 export $facet_version=$lver
535 # Report the Lustre numeric build version code for the supplied facet.
536 lustre_version_code() {
537 version_code $(lustre_build_version $1)
541 /sbin/lsmod | grep -q "^\<$1\>"
544 check_lfs_df_ret_val() {
545 # Ignore only EOPNOTSUPP (which is 95; Operation not supported) error
546 # returned by 'lfs df' for valid dentry but not a lustrefs.
548 # 'lfs df' historically always returned success(0) instead of
549 # EOPNOTSUPP. This function for compatibility reason, ignores and
550 # masquerades EOPNOTSUPP as success.
551 [[ $1 -eq 95 ]] && return 0
564 msg="$(insmod $module $args 2>&1)" && return 0 || rc=$?
567 # parallels can't load modules directly from prlfs, use /tmp instead
568 if $PRLFS || [[ "$(stat -f -c%t $module)" == "7c7c6673" ]]; then
569 local target="$(mktemp)"
571 cp "$module" "$target"
574 [[ $rc == 0 ]] && PRLFS=true
582 # Load a module on the system where this is running.
584 # usage: load_module module_name [module arguments for insmod/modprobe]
586 # If module arguments are not given but MODOPTS_<MODULE> is set, then its value
587 # will be used as the arguments. Otherwise arguments will be obtained from
588 # /etc/modprobe.conf, from /etc/modprobe.d/Lustre, or else none will be used.
591 local module=$1 # '../libcfs/libcfs/libcfs', 'obdclass/obdclass', ...
594 local base=$(basename $module $ext)
596 local -A module_is_loaded_aa
600 for mod in $(lsmod | awk '{ print $1; }'); do
601 module_is_loaded_aa[${mod//-/_}]=true
605 ${module_is_loaded_aa[${1//-/_}]:-false}
608 if module_is_loaded $base; then
612 if [[ -f $LUSTRE/$module$ext ]]; then
613 path=$LUSTRE/$module$ext
614 elif [[ "$base" == lnet_selftest ]] &&
615 [[ -f $LUSTRE/../lnet/selftest/$base$ext ]]; then
616 path=$LUSTRE/../lnet/selftest/$base$ext
621 if [[ -n "$path" ]]; then
622 # Try to load any non-Lustre modules that $module depends on.
623 for mod in $(modinfo --field=depends $path | tr ',' ' '); do
624 if ! module_is_loaded $mod; then
630 # If no module arguments were passed then get them from
631 # $MODOPTS_<MODULE>, otherwise from modprobe.conf.
632 if [ $# -eq 0 ]; then
633 # $MODOPTS_<MODULE>; we could use associative arrays, but that's
634 # not in Bash until 4.x, so we resort to eval.
635 optvar="MODOPTS_$(basename $module | tr a-z A-Z)"
636 eval set -- \$$optvar
637 if [ $# -eq 0 -a -n "$MODPROBECONF" ]; then
638 # Nothing in $MODOPTS_<MODULE>; try modprobe.conf
640 opt=$(awk -v var="^options $base" '$0 ~ var \
641 {gsub("'"options $base"'",""); print}' \
643 set -- $(echo -n $opt)
645 # Ensure we have accept=all for lnet
646 if [[ "$base" == lnet ]]; then
647 # OK, this is a bit wordy...
648 local arg accept_all_present=false
651 [[ "$arg" == accept=all ]] &&
652 accept_all_present=true
655 $accept_all_present || set -- "$@" accept=all
662 [ $# -gt 0 ] && echo "${module} options: '$*'"
664 # Note that insmod will ignore anything in modprobe.conf, which is why
665 # we're passing options on the command-line. If $path does not exist
666 # then we must be testing a "make install" or"rpm" installation. Also
667 # note that failing to load ptlrpc_gss is not considered fatal.
668 if [[ -n "$path" ]]; then
669 lustre_insmod $path "$@"
670 elif [[ "$base" == ptlrpc_gss ]]; then
671 if ! modprobe $base "$@" 2>/dev/null; then
672 echo "gss/krb5 is not supported"
679 load_modules_local() {
680 if [ -n "$MODPROBE" ]; then
682 echo "Using modprobe to load modules"
686 # Create special udev test rules on every node
687 if [ -f $LUSTRE/lustre/conf/99-lustre.rules ]; then {
688 sed -e 's|/usr/sbin/lctl|$LCTL|g' $LUSTRE/lustre/conf/99-lustre.rules > /etc/udev/rules.d/99-lustre-test.rules
690 echo "SUBSYSTEM==\"lustre\", ACTION==\"change\", ENV{PARAM}==\"?*\", RUN+=\"$LCTL set_param '\$env{PARAM}=\$env{SETTING}'\"" > /etc/udev/rules.d/99-lustre-test.rules
692 udevadm control --reload-rules
695 # For kmemleak-enabled kernels we need clear all past state
696 # that obviously has nothing to do with this Lustre run
697 # Disable automatic memory scanning to avoid perf hit.
698 if [ -f /sys/kernel/debug/kmemleak ] ; then
699 echo scan=off > /sys/kernel/debug/kmemleak || true
700 echo scan > /sys/kernel/debug/kmemleak || true
701 echo clear > /sys/kernel/debug/kmemleak || true
704 echo Loading modules from $LUSTRE
708 if [ -f /sys/devices/system/cpu/online ]; then
709 ncpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/online) + 1))
710 echo "detected $ncpus online CPUs by sysfs"
712 ncpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
714 if [ $rc -eq 0 ]; then
715 echo "detected $ncpus online CPUs by getconf"
717 echo "Can't detect number of CPUs"
722 # if there is only one CPU core, libcfs can only create one partition
723 # if there is more than 4 CPU cores, libcfs should create multiple CPU
724 # partitions. So we just force libcfs to create 2 partitions for
725 # system with 2 or 4 cores
726 local saved_opts="$MODOPTS_LIBCFS"
727 if [ $ncpus -le 4 ] && [ $ncpus -gt 1 ]; then
728 # force to enable multiple CPU partitions
729 echo "Force libcfs to create 2 CPU partitions"
730 MODOPTS_LIBCFS="cpu_npartitions=2 $MODOPTS_LIBCFS"
732 echo "libcfs will create CPU partition based on online CPUs"
735 load_module ../libcfs/libcfs/libcfs
736 # Prevent local MODOPTS_LIBCFS being passed as part of environment
737 # variable to remote nodes
738 MODOPTS_LIBCFS=$saved_opts
741 load_module ../lnet/lnet/lnet
743 LNDPATH=${LNDPATH:-"../lnet/klnds"}
744 if [ -z "$LNETLND" ]; then
746 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
747 tcp*) LNETLND="socklnd/ksocklnd" ;;
748 *) local lnd="${NETTYPE%%[0-9]}lnd"
749 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
750 LNETLND="$lnd/k$lnd" ||
751 LNETLND="socklnd/ksocklnd"
754 load_module ../lnet/klnds/$LNETLND
755 load_module obdclass/obdclass
756 MODOPTS_PTLRPC=${MODOPTS_PTLRPC:-"lbug_on_grant_miscount=1"}
757 load_module ptlrpc/ptlrpc
758 load_module ptlrpc/gss/ptlrpc_gss
766 load_module obdecho/obdecho
767 if ! client_only; then
768 load_module lfsck/lfsck
769 [ "$LQUOTA" != "no" ] &&
770 load_module quota/lquota $LQUOTAOPTS
771 if [[ $(node_fstypes $HOSTNAME) == *zfs* ]]; then
772 load_module osd-zfs/osd_zfs
773 elif [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
774 load_module ../ldiskfs/ldiskfs
775 load_module osd-ldiskfs/osd_ldiskfs
787 load_module llite/lustre
788 [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
790 rm -f $OGDB/ogdb-$HOSTNAME
791 $LCTL modules > $OGDB/ogdb-$HOSTNAME
793 # 'mount' doesn't look in $PATH, just sbin
794 local mount_lustre=$LUSTRE/utils/mount.lustre
795 if [ -f $mount_lustre ]; then
796 local sbin_mount=$(readlink -f /sbin)/mount.lustre
797 if grep -qw "$sbin_mount" /proc/mounts; then
798 cmp -s $mount_lustre $sbin_mount || umount $sbin_mount
800 if ! grep -qw "$sbin_mount" /proc/mounts; then
801 [ ! -f "$sbin_mount" ] && touch "$sbin_mount"
802 if [ ! -s "$sbin_mount" -a -w "$sbin_mount" ]; then
803 cat <<- EOF > "$sbin_mount"
806 echo "This $sbin_mount just a mountpoint." 1>&2
807 echo "It is never supposed to be run." 1>&2
808 logger -p emerg -- "using stub $sbin_mount $@"
811 chmod a+x $sbin_mount
813 mount --bind $mount_lustre $sbin_mount ||
814 error "can't bind $mount_lustre to $sbin_mount"
822 # load modules on remote nodes optionally
823 # lustre-tests have to be installed on these nodes
824 if $LOAD_MODULES_REMOTE; then
825 local list=$(comma_list $(remote_nodes_list))
826 if [ -n "$list" ]; then
827 echo "loading modules on: '$list'"
828 do_rpc_nodes "$list" load_modules_local
834 LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
835 LEAK_PORTALS=$(dmesg | tail -n 20 | egrep -i "libcfs.*memory leaked" || true)
836 if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
837 echo "$LEAK_LUSTRE" 1>&2
838 echo "$LEAK_PORTALS" 1>&2
839 mv $TMP/debug $TMP/debug-leak.`date +%s` || true
840 echo "Memory leaks detected"
841 [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
846 unload_modules_local() {
847 $LUSTRE_RMMOD ldiskfs || return 2
849 [ -f /etc/udev/rules.d/99-lustre-test.rules ] &&
850 rm /etc/udev/rules.d/99-lustre-test.rules
851 udevadm control --reload-rules
854 check_mem_leak || return 254
862 wait_exit_ST client # bug 12845
864 unload_modules_local || rc=$?
866 if $LOAD_MODULES_REMOTE; then
867 local list=$(comma_list $(remote_nodes_list))
868 if [ -n "$list" ]; then
869 echo "unloading modules on: '$list'"
870 do_rpc_nodes "$list" unload_modules_local
874 local sbin_mount=$(readlink -f /sbin)/mount.lustre
875 if grep -qe "$sbin_mount " /proc/mounts; then
876 umount $sbin_mount || true
877 [ -s $sbin_mount ] && ! grep -q "STUB MARK" $sbin_mount ||
881 [[ $rc -eq 0 ]] && echo "modules unloaded."
887 local facet=${1:-$SINGLEMDS}
890 case $(facet_fstype $facet) in
891 ldiskfs) size=72;; # largest seen is 64, leave some headroom
892 # grant_block_size is in bytes, allow at least 2x max blocksize
893 zfs) size=$(lctl get_param osc.$FSNAME*.import |
894 awk '/grant_block_size:/ {print $2/512; exit;}')
898 echo -n $((size * MDSCOUNT))
902 local facet=${1:-$SINGLEMDS}
903 local fstype=$(facet_fstype $facet)
906 ldiskfs) size=4;; # ~4KB per inode
907 zfs) size=11;; # 10 to 11KB per inode
913 check_gss_daemon_nodes() {
917 do_nodesv $list "num=\\\$(ps -o cmd -C $dname | grep $dname | wc -l);
918 if [ \\\"\\\$num\\\" -ne 1 ]; then
919 echo \\\$num instance of $dname;
924 check_gss_daemon_facet() {
928 num=`do_facet $facet ps -o cmd -C $dname | grep $dname | wc -l`
929 if [ $num -ne 1 ]; then
930 echo "$num instance of $dname on $facet"
939 echo Stopping $@ on $list
940 do_nodes $list "killall -2 $@ 2>/dev/null || true"
943 # start gss daemons on all nodes, or "daemon" on "nodes" if set
944 start_gss_daemons() {
948 if [ "$nodes" ] && [ "$daemon" ] ; then
949 echo "Starting gss daemon on nodes: $nodes"
950 do_nodes $nodes "$daemon" || return 8
954 nodes=$(comma_list $(mdts_nodes))
955 echo "Starting gss daemon on mds: $nodes"
957 # Start all versions, in case of switching
958 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 1
960 do_nodes $nodes "$LSVCGSSD -v" || return 1
963 do_nodes $nodes "$LGSSD -v" || return 2
966 nodes=$(comma_list $(osts_nodes))
967 echo "Starting gss daemon on ost: $nodes"
969 # Start all versions, in case of switching
970 do_nodes $nodes "$LSVCGSSD -vvv -s -m -o -z" || return 3
972 do_nodes $nodes "$LSVCGSSD -v" || return 3
974 # starting on clients
976 local clients=${CLIENTS:-$HOSTNAME}
978 echo "Starting $LGSSD on clients $clients "
979 do_nodes $clients "$LGSSD -v" || return 4
982 # wait daemons entering "stable" status
986 # check daemons are running
988 nodes=$(comma_list $(mdts_nodes) $(osts_nodes))
989 check_gss_daemon_nodes $nodes lsvcgssd || return 5
991 nodes=$(comma_list $(mdts_nodes))
992 check_gss_daemon_nodes $nodes lgssd || return 6
995 check_gss_daemon_nodes $clients lgssd || return 7
1000 local nodes=$(comma_list $(mdts_nodes))
1002 send_sigint $nodes lsvcgssd lgssd
1004 nodes=$(comma_list $(osts_nodes))
1005 send_sigint $nodes lsvcgssd
1007 nodes=${CLIENTS:-$HOSTNAME}
1008 send_sigint $nodes lgssd
1012 # Add mount flags for shared key
1014 if grep -q skpath <<< "$mt_opts" ; then
1015 mt_opts=$(echo $mt_opts |
1016 sed -e "s#skpath=[^ ,]*#skpath=$SK_PATH#")
1018 if [ -z "$mt_opts" ]; then
1019 mt_opts="-o skpath=$SK_PATH"
1021 mt_opts="$mt_opts,skpath=$SK_PATH"
1031 /usr/lib/lustre/* | /usr/lib64/lustre/* | /usr/lib/lustre | \
1040 [ $from_tree = true ]
1044 if $SHARED_KEY; then
1053 if ! module_loaded ptlrpc_gss; then
1054 load_module ptlrpc/gss/ptlrpc_gss
1055 module_loaded ptlrpc_gss ||
1056 error_exit "init_gss: GSS=$GSS, but gss/krb5 missing"
1059 if $GSS_KRB5 || $GSS_SK; then
1060 start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
1063 if $GSS_SK && ! $SK_NO_KEY; then
1064 echo "Loading basic SSK keys on all servers"
1065 do_nodes $(comma_list $(all_server_nodes)) \
1066 "lgss_sk -t server -l $SK_PATH/$FSNAME.key || true"
1067 do_nodes $(comma_list $(all_server_nodes)) \
1068 "keyctl show | grep lustre | cut -c1-11 |
1070 xargs -IX keyctl setperm X 0x3f3f3f3f"
1073 if $GSS_SK && $SK_NO_KEY; then
1074 local numclients=${1:-$CLIENTCOUNT}
1075 local clients=${CLIENTS:-$HOSTNAME}
1077 # security ctx config for keyring
1079 local lgssc_conf_file="/etc/request-key.d/lgssc.conf"
1081 if from_build_tree; then
1082 mkdir -p $SK_OM_PATH
1083 if grep -q request-key /proc/mounts > /dev/null; then
1084 echo "SSK: Request key already mounted."
1086 mount -o bind $SK_OM_PATH /etc/request-key.d/
1088 local lgssc_conf_line='create lgssc * * '
1089 lgssc_conf_line+=$(which lgss_keyring)
1090 lgssc_conf_line+=' %o %k %t %d %c %u %g %T %P %S'
1091 echo "$lgssc_conf_line" > $lgssc_conf_file
1094 [ -e $lgssc_conf_file ] ||
1095 error_exit "Could not find key options in $lgssc_conf_file"
1096 echo "$lgssc_conf_file content is:"
1097 cat $lgssc_conf_file
1099 if ! local_mode; then
1100 if from_build_tree; then
1101 do_nodes $(comma_list $(all_nodes)) "mkdir -p \
1103 do_nodes $(comma_list $(all_nodes)) "mount \
1104 -o bind $SK_OM_PATH \
1105 /etc/request-key.d/"
1106 do_nodes $(comma_list $(all_nodes)) "rsync \
1107 -aqv $HOSTNAME:$lgssc_conf_file \
1108 $lgssc_conf_file >/dev/null 2>&1"
1110 do_nodes $(comma_list $(all_nodes)) \
1111 "echo $lgssc_conf_file: ; \
1112 cat $lgssc_conf_file"
1116 # create shared key on all nodes
1117 mkdir -p $SK_PATH/nodemap
1118 rm -f $SK_PATH/$FSNAME.key $SK_PATH/nodemap/c*.key \
1119 $SK_PATH/$FSNAME-*.key
1120 # for nodemap testing each client may need own key,
1121 # and S2S now requires keys as well, both for "client"
1124 lgss_sk -t server -f$FSNAME -n $SK_S2SNMCLI \
1125 -w $SK_PATH/$FSNAME-nmclient.key \
1126 -d /dev/urandom >/dev/null 2>&1
1127 lgss_sk -t mgs,server -f$FSNAME -n $SK_S2SNM \
1128 -w $SK_PATH/$FSNAME-s2s-server.key \
1129 -d /dev/urandom >/dev/null 2>&1
1132 lgss_sk -t server -f$FSNAME -w $SK_PATH/$FSNAME.key \
1133 -d /dev/urandom >/dev/null 2>&1
1135 for i in $(seq 0 $((numclients - 1))); do
1136 lgss_sk -t server -f$FSNAME -n c$i \
1137 -w $SK_PATH/nodemap/c$i.key -d /dev/urandom \
1141 if ! local_mode; then
1142 for lnode in $(all_nodes); do
1143 scp -r $SK_PATH ${lnode}:$(dirname $SK_PATH)/
1146 # Set client keys to client type to generate prime P
1148 do_nodes $(all_nodes) "lgss_sk -t client,server -m \
1149 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1151 do_nodes $clients "lgss_sk -t client -m \
1152 $SK_PATH/$FSNAME.key >/dev/null 2>&1"
1153 do_nodes $clients "find $SK_PATH/nodemap -name \*.key | \
1154 xargs -IX lgss_sk -t client -m X >/dev/null 2>&1"
1156 # This is required for servers as well, if S2S in use
1158 do_nodes $(comma_list $(mdts_nodes)) \
1159 "cp $SK_PATH/$FSNAME-s2s-server.key \
1160 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
1161 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1163 do_nodes $(comma_list $(osts_nodes)) \
1164 "cp $SK_PATH/$FSNAME-s2s-server.key \
1165 $SK_PATH/$FSNAME-s2s-client.key; lgss_sk \
1166 -t client -m $SK_PATH/$FSNAME-s2s-client.key \
1168 do_nodes $clients "lgss_sk -t client \
1169 -m $SK_PATH/$FSNAME-nmclient.key \
1174 # mount options for servers and clients
1175 MGS_MOUNT_OPTS=$(add_sk_mntflag $MGS_MOUNT_OPTS)
1176 MDS_MOUNT_OPTS=$(add_sk_mntflag $MDS_MOUNT_OPTS)
1177 OST_MOUNT_OPTS=$(add_sk_mntflag $OST_MOUNT_OPTS)
1178 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
1180 if [ -z "$LGSS_KEYRING_DEBUG" ]; then
1181 LGSS_KEYRING_DEBUG=4
1185 if [ -n "$LGSS_KEYRING_DEBUG" ] && \
1186 ( local_mode || from_build_tree ); then
1188 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG
1189 elif [ -n "$LGSS_KEYRING_DEBUG" ]; then
1190 do_nodes $(comma_list $(all_nodes)) "modprobe ptlrpc_gss && \
1192 sptlrpc.gss.lgss_keyring.debug_level=$LGSS_KEYRING_DEBUG"
1199 # maybe cleanup credential cache?
1206 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNM"
1207 do_node $(mgs_node) "$LCTL nodemap_del $SK_S2SNMCLI"
1208 $RPC_MODE || echo "Sleeping for 10 sec for Nodemap.."
1212 $RPC_MODE || echo "Cleaning up Shared Key.."
1213 do_nodes $(comma_list $(all_nodes)) "rm -f \
1214 $SK_PATH/$FSNAME*.key $SK_PATH/nodemap/$FSNAME*.key"
1215 do_nodes $(comma_list $(all_nodes)) "keyctl show | \
1216 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
1217 if from_build_tree; then
1218 # Remove the mount and clean up the files we added to
1220 do_nodes $(comma_list $(all_nodes)) "while grep -q \
1221 request-key.d /proc/mounts; do umount \
1222 /etc/request-key.d/; done"
1223 do_nodes $(comma_list $(all_nodes)) "rm -f \
1224 $SK_OM_PATH/lgssc.conf"
1225 do_nodes $(comma_list $(all_nodes)) "rmdir $SK_OM_PATH"
1233 local var=${facet}_svc
1241 echo -n $facet | sed -e 's/^fs[0-9]\+//' -e 's/[0-9_]\+//' |
1242 tr '[:lower:]' '[:upper:]'
1248 if [ $facet == mgs ] || [ $facet == client ]; then
1252 echo -n $facet | sed -e 's/^fs[0-9]\+//' | sed -e 's/^[a-z]\+//'
1260 if [ -n "${!var}" ]; then
1265 var=$(facet_type $facet)FSTYPE
1266 if [ -n "${!var}" ]; then
1271 if [ -n "$FSTYPE" ]; then
1276 if [[ $facet == mgs ]] && combined_mgs_mds; then
1288 local facets=$(get_facets)
1291 for facet in ${facets//,/ }; do
1292 if [ $node == $(facet_host $facet) ] ||
1293 [ $node == "$(facet_failover_host $facet)" ]; then
1294 fstype=$(facet_fstype $facet)
1295 if [[ $fstypes != *$fstype* ]]; then
1296 fstypes+="${fstypes:+,}$fstype"
1305 local num=$(facet_number $facet)
1308 if [[ $(facet_type $facet) = OST ]]; then
1309 index=OSTINDEX${num}
1310 if [[ -n "${!index}" ]]; then
1315 index=${OST_INDICES[num - 1]}
1318 [[ -n "$index" ]] || index=$((num - 1))
1326 local fstype=$(facet_fstype $facet)
1330 label=$(do_facet ${facet} "$E2LABEL ${dev} 2>/dev/null");;
1332 label=$(do_facet ${facet} "$ZFS get -H -o value lustre:svname \
1333 ${dev} 2>/dev/null");;
1335 error "unknown fstype!";;
1342 # Get the device of a facet.
1349 mgs) device=$(mgsdevname) ;;
1350 mds*) device=$(mdsdevname $(facet_number $facet)) ;;
1351 ost*) device=$(ostdevname $(facet_number $facet)) ;;
1352 fs2mds) device=$(mdsdevname 1_2) ;;
1353 fs2ost) device=$(ostdevname 1_2) ;;
1354 fs3ost) device=$(ostdevname 2_2) ;;
1362 # Get the virtual device of a facet.
1369 mgs) device=$(mgsvdevname) ;;
1370 mds*) device=$(mdsvdevname $(facet_number $facet)) ;;
1371 ost*) device=$(ostvdevname $(facet_number $facet)) ;;
1372 fs2mds) device=$(mdsvdevname 1_2) ;;
1373 fs2ost) device=$(ostvdevname 1_2) ;;
1374 fs3ost) device=$(ostvdevname 2_2) ;;
1382 local virt=$(virt-what 2> /dev/null)
1384 [ $? -eq 0 ] && [ -n "$virt" ] && { echo $virt; return; }
1386 virt=$(dmidecode -s system-product-name | awk '{print $1}')
1389 VMware|KVM|VirtualBox|Parallels|Bochs)
1390 echo $virt | tr '[A-Z]' '[a-z]' ;;
1396 # Re-read the partition table on failover partner host.
1397 # After a ZFS storage pool is created on a shared device, the partition table
1398 # on the device may change. However, the operating system on the failover
1399 # host may not notice the change automatically. Without the up-to-date partition
1400 # block devices, 'zpool import ..' cannot find the labels, whose positions are
1401 # relative to partition rather than disk beginnings.
1403 # This function performs partprobe on the failover host to make it re-read the
1406 refresh_partition_table() {
1411 host=$(facet_passive_host $facet)
1412 if [[ -n "$host" ]]; then
1413 do_node $host "$PARTPROBE $device"
1418 # Get ZFS storage pool name.
1425 device=$(facet_device $facet)
1426 # poolname is string before "/"
1427 poolname="${device%%/*}"
1434 # Get ZFS local fsname.
1436 zfs_local_fsname() {
1438 local lfsname=$(basename $(facet_device $facet))
1444 # Create ZFS storage pool.
1451 local opts=${@:-"-o cachefile=none"}
1453 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1454 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1455 $ZPOOL create -f $opts $poolname $vdev"
1459 # Create ZFS file system.
1465 local opts=${@:-"-o mountpoint=legacy"}
1467 do_facet $facet "$ZFS list -H $dataset >/dev/null 2>&1 ||
1468 $ZFS create $opts $dataset"
1472 # Export ZFS storage pool.
1473 # Before exporting the pool, all datasets within the pool should be unmounted.
1481 poolname=$(zpool_name $facet)
1483 if [[ -n "$poolname" ]]; then
1484 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1485 grep -q ^$poolname/ /proc/mounts ||
1486 $ZPOOL export $opts $poolname"
1491 # Destroy ZFS storage pool.
1492 # Destroy the given pool and free up any devices for other use. This command
1493 # tries to unmount any active datasets before destroying the pool.
1494 # -f Force any active datasets contained within the pool to be unmounted.
1498 local poolname=${2:-$(zpool_name $facet)}
1500 if [[ -n "$poolname" ]]; then
1501 do_facet $facet "! $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1502 $ZPOOL destroy -f $poolname"
1507 # Import ZFS storage pool.
1508 # Force importing, even if the pool appears to be potentially active.
1513 local opts=${@:-"-o cachefile=none -o failmode=panic"}
1516 poolname=$(zpool_name $facet)
1518 if [[ -n "$poolname" ]]; then
1519 opts+=" -d $(dirname $(facet_vdevice $facet))"
1520 do_facet $facet "lsmod | grep zfs >&/dev/null || modprobe zfs;
1521 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1522 $ZPOOL import -f $opts $poolname"
1527 # Reimport ZFS storage pool with new name
1532 local opts="-o cachefile=none"
1533 local poolname=$(zpool_name $facet)
1535 opts+=" -d $(dirname $(facet_vdevice $facet))"
1536 do_facet $facet "$ZPOOL export $poolname;
1537 $ZPOOL import $opts $poolname $newpool"
1541 # Set the "cachefile=none" property on ZFS storage pool so that the pool
1542 # is not automatically imported on system startup.
1544 # In a failover environment, this will provide resource level fencing which
1545 # will ensure that the same ZFS storage pool will not be imported concurrently
1546 # on different nodes.
1548 disable_zpool_cache() {
1552 poolname=$(zpool_name $facet)
1554 if [[ -n "$poolname" ]]; then
1555 do_facet $facet "$ZPOOL set cachefile=none $poolname"
1560 # This and set_osd_param() shall be used to access OSD parameters
1561 # once existed under "obdfilter":
1566 # writethrough_cache_enable
1570 local device=${2:-$FSNAME-OST*}
1573 do_nodes $nodes "$LCTL get_param -n osd-*.$device.$name"
1578 local device=${2:-$FSNAME-OST*}
1582 do_nodes $nodes "$LCTL set_param -n osd-*.$device.$name=$value"
1586 local dz=${1:-$DEBUG_SIZE}
1588 if [ -f /sys/devices/system/cpu/possible ]; then
1589 local cpus=$(($(cut -d "-" -f 2 /sys/devices/system/cpu/possible)+1))
1591 local cpus=$(getconf _NPROCESSORS_CONF 2>/dev/null)
1594 # bug 19944, adjust size to be -gt num_possible_cpus()
1595 # promise 2MB for every cpu at least
1596 if [ -n "$cpus" ] && [ $((cpus * 2)) -gt $dz ]; then
1599 lctl set_param debug_mb=$dz
1602 set_default_debug () {
1603 local debug=${1:-"$PTLDEBUG"}
1604 local subsys=${2:-"$SUBSYSTEM"}
1605 local debug_size=${3:-$DEBUG_SIZE}
1607 [ -n "$debug" ] && lctl set_param debug="$debug" >/dev/null
1608 [ -n "$subsys" ] && lctl set_param subsystem_debug="${subsys# }" >/dev/null
1610 [ -n "$debug_size" ] && set_debug_size $debug_size > /dev/null
1613 set_default_debug_nodes () {
1615 local debug="${2:-"$PTLDEBUG"}"
1616 local subsys="${3:-"$SUBSYSTEM"}"
1617 local debug_size="${4:-$DEBUG_SIZE}"
1619 if [[ ,$nodes, = *,$HOSTNAME,* ]]; then
1620 nodes=$(exclude_items_from_list "$nodes" "$HOSTNAME")
1624 [[ -z "$nodes" ]] ||
1625 do_rpc_nodes "$nodes" set_default_debug \
1626 \\\"$debug\\\" \\\"$subsys\\\" $debug_size || true
1629 set_default_debug_facet () {
1631 local debug="${2:-"$PTLDEBUG"}"
1632 local subsys="${3:-"$SUBSYSTEM"}"
1633 local debug_size="${4:-$DEBUG_SIZE}"
1634 local node=$(facet_active_host $facet)
1636 [ -n "$node" ] || error "No host defined for facet $facet"
1638 set_default_debug_nodes $node "$debug" "$subsys" $debug_size
1641 set_params_nodes () {
1642 [[ $# -ge 2 ]] || return 0
1646 do_nodes $nodes $LCTL set_param $@
1649 set_params_clients () {
1650 local clients=${1:-$CLIENTS}
1651 local params=${2:-$CLIENT_LCTL_SETPARAM_PARAM}
1653 [[ -n $params ]] || return 0
1654 set_params_nodes $clients $params
1658 local hostid=${1:-$(hostid)}
1660 if [ ! -s /etc/hostid ]; then
1661 printf $(echo -n $hostid |
1662 sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid
1668 local facets=${1:-$(get_facets)}
1671 for facet in ${facets//,/ }; do
1674 [ $RC -eq 0 ] && continue
1676 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1677 skip_noexit "Restart of $facet failed!." &&
1680 error "Restart of $facet failed!"
1687 # Add argument "arg" (e.g., "loop") to the comma-separated list
1688 # of arguments for option "opt" (e.g., "-o") on command
1689 # line "opts" (e.g., "-o flock").
1695 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1697 if echo "$opts" | grep -q $opt_pattern; then
1698 opts=$(echo "$opts" | sed -e \
1699 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1701 opts+="${opts:+ }$opt $arg"
1707 # Associate loop device with a given regular file.
1708 # Return the loop device.
1710 setup_loop_device() {
1714 do_facet $facet "loop_dev=\\\$($LOSETUP -j $file | cut -d : -f 1);
1715 if [[ -z \\\$loop_dev ]]; then
1716 loop_dev=\\\$($LOSETUP -f);
1717 $LOSETUP \\\$loop_dev $file || loop_dev=;
1719 echo -n \\\$loop_dev"
1723 # Detach a loop device.
1725 cleanup_loop_device() {
1729 do_facet $facet "! $LOSETUP $loop_dev >/dev/null 2>&1 ||
1730 $LOSETUP -d $loop_dev"
1734 # Check if a given device is a block device.
1741 [[ -n "$dev" ]] || return 1
1742 do_facet $facet "test -b $dev" || return 1
1743 if [[ -n "$size" ]]; then
1744 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k \
1745 count=1 skip=$size 2>&1" |
1746 awk '($3 == "in") { print $1 }')
1747 [[ "$in" = "1+0" ]] || return 1
1752 # Check if a given device is a device-mapper device.
1758 [[ -n "$dev" ]] || return 1
1759 do_facet $facet "$DMSETUP status $dev >/dev/null 2>&1"
1763 # Check if a given device is a device-mapper flakey device.
1765 is_dm_flakey_dev() {
1770 [[ -n "$dev" ]] || return 1
1772 type=$(do_facet $facet "$DMSETUP status $dev 2>&1" |
1774 [[ $type = flakey ]] && return 0 || return 1
1778 # Check if device-mapper flakey device is supported by the kernel
1779 # of $facet node or not.
1781 dm_flakey_supported() {
1785 do_facet $facet "modprobe dm-flakey;
1786 $DMSETUP targets | grep -q flakey" &> /dev/null
1790 # Get the device-mapper flakey device name of a given facet.
1792 dm_facet_devname() {
1794 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
1796 echo -n ${facet}_flakey
1800 # Get the device-mapper flakey device of a given facet.
1801 # A device created by dmsetup will appear as /dev/mapper/<device-name>.
1803 dm_facet_devpath() {
1806 echo -n $DM_DEV_PATH/$(dm_facet_devname $facet)
1810 # Set a device-mapper device with a new table.
1812 # The table has the following format:
1813 # <logical_start_sector> <num_sectors> <target_type> <target_args>
1815 # flakey <target_args> includes:
1816 # <destination_device> <offset> <up_interval> <down_interval> \
1817 # [<num_features> [<feature_arguments>]]
1819 # linear <target_args> includes:
1820 # <destination_device> <start_sector>
1822 dm_set_dev_table() {
1825 local target_type=$3
1831 read tmp num_sectors tmp real_dev tmp \
1832 <<< $(do_facet $facet "$DMSETUP table $dm_dev")
1834 case $target_type in
1836 table="0 $num_sectors flakey $real_dev 0 0 1800 1 drop_writes"
1839 table="0 $num_sectors linear $real_dev 0"
1841 *) error "invalid target type $target_type" ;;
1844 do_facet $facet "$DMSETUP suspend --nolockfs --noflush $dm_dev" ||
1845 error "failed to suspend $dm_dev"
1846 do_facet $facet "$DMSETUP load $dm_dev --table \\\"$table\\\"" ||
1847 error "failed to load $target_type table into $dm_dev"
1848 do_facet $facet "$DMSETUP resume $dm_dev" ||
1849 error "failed to resume $dm_dev"
1853 # Set a device-mapper flakey device as "read-only" by using the "drop_writes"
1854 # feature parameter.
1857 # All write I/O is silently ignored.
1858 # Read I/O is handled correctly.
1860 dm_set_dev_readonly() {
1862 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1864 dm_set_dev_table $facet $dm_dev flakey
1868 # Set a device-mapper device to traditional linear mapping mode.
1870 dm_clear_dev_readonly() {
1872 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1874 dm_set_dev_table $facet $dm_dev linear
1878 # Set the device of a given facet as "read-only".
1880 set_dev_readonly() {
1882 local svc=${facet}_svc
1884 if [[ $(facet_fstype $facet) = zfs ]] ||
1885 ! dm_flakey_supported $facet; then
1886 do_facet $facet $LCTL --device ${!svc} readonly
1888 dm_set_dev_readonly $facet
1893 # Get size in 512-byte sectors (BLKGETSIZE64 / 512) of a given device.
1900 num_sectors=$(do_facet $facet "blockdev --getsz $dev 2>/dev/null")
1901 [[ ${PIPESTATUS[0]} = 0 && -n "$num_sectors" ]] || num_sectors=0
1902 echo -n $num_sectors
1906 # Create a device-mapper device with a given block device or regular file (will
1907 # be associated with loop device).
1908 # Return the full path of the device-mapper device.
1912 local real_dev=$2 # destination device
1913 local dm_dev_name=${3:-$(dm_facet_devname $facet)} # device name
1914 local dm_dev=$DM_DEV_PATH/$dm_dev_name # device-mapper device
1916 # check if the device-mapper device to be created already exists
1917 if is_dm_dev $facet $dm_dev; then
1918 # if the existing device was set to "read-only", then clear it
1919 ! is_dm_flakey_dev $facet $dm_dev ||
1920 dm_clear_dev_readonly $facet $dm_dev
1926 # check if the destination device is a block device, and if not,
1927 # associate it with a loop device
1928 is_blkdev $facet $real_dev ||
1929 real_dev=$(setup_loop_device $facet $real_dev)
1930 [[ -n "$real_dev" ]] || { echo -n $real_dev; return 2; }
1932 # now create the device-mapper device
1933 local num_sectors=$(get_num_sectors $facet $real_dev)
1934 local table="0 $num_sectors linear $real_dev 0"
1937 do_facet $facet "$DMSETUP create $dm_dev_name --table \\\"$table\\\"" ||
1938 { rc=${PIPESTATUS[0]}; dm_dev=; }
1939 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
1946 # Map the facet name to its device variable name.
1948 facet_device_alias() {
1950 local dev_alias=$facet
1953 fs2mds) dev_alias=mds1_2 ;;
1954 fs2ost) dev_alias=ost1_2 ;;
1955 fs3ost) dev_alias=ost2_2 ;;
1963 # Save the original value of the facet device and export the new value.
1969 local active_facet=$(facet_active $facet)
1970 local dev_alias=$(facet_device_alias $active_facet)
1971 local dev_name=${dev_alias}_dev
1972 local dev=${!dev_name}
1974 if [[ $active_facet = $facet ]]; then
1975 local failover_dev=${dev_alias}failover_dev
1976 if [[ ${!failover_dev} = $dev ]]; then
1977 eval export ${failover_dev}_saved=$dev
1978 eval export ${failover_dev}=$dm_dev
1981 dev_alias=$(facet_device_alias $facet)
1982 local facet_dev=${dev_alias}_dev
1983 if [[ ${!facet_dev} = $dev ]]; then
1984 eval export ${facet_dev}_saved=$dev
1985 eval export ${facet_dev}=$dm_dev
1989 eval export ${dev_name}_saved=$dev
1990 eval export ${dev_name}=$dm_dev
1994 # Restore the saved value of the facet device.
1999 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
2000 local dev_alias=$(facet_device_alias $facet)
2002 local saved_dev=${dev_alias}_dev_saved
2003 [[ -z ${!saved_dev} ]] ||
2004 eval export ${dev_alias}_dev=${!saved_dev}
2006 saved_dev=${dev_alias}failover_dev_saved
2007 [[ -z ${!saved_dev} ]] ||
2008 eval export ${dev_alias}failover_dev=${!saved_dev}
2012 # Remove a device-mapper device.
2013 # If the destination device is a loop device, then also detach it.
2017 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2021 is_dm_dev $facet $dm_dev || return 0
2023 read major minor <<< $(do_facet $facet "$DMSETUP table $dm_dev" |
2024 awk '{ print $4 }' | awk -F: '{ print $1" "$2 }')
2026 do_facet $facet "$DMSETUP remove $dm_dev"
2027 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
2029 unexport_dm_dev $facet
2031 # detach a loop device
2032 [[ $major -ne 7 ]] || cleanup_loop_device $facet /dev/loop$minor
2034 # unload dm-flakey module
2035 do_facet $facet "modprobe -r dm-flakey" || true
2041 local active_facet=$(facet_active $facet)
2042 local dev_alias=$(facet_device_alias $active_facet)
2043 local dev=${dev_alias}_dev
2044 local opt=${facet}_opt
2045 local mntpt=$(facet_mntpt $facet)
2046 local opts="${!opt} $@"
2047 local fstype=$(facet_fstype $facet)
2049 local dm_dev=${!dev}
2051 module_loaded lustre || load_modules
2055 if dm_flakey_supported $facet; then
2056 dm_dev=$(dm_create_dev $facet ${!dev})
2057 [[ -n "$dm_dev" ]] || dm_dev=${!dev}
2060 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
2062 devicelabel=$(do_facet ${facet} "$E2LABEL $dm_dev");;
2064 # import ZFS storage pool
2065 import_zpool $facet || return ${PIPESTATUS[0]}
2067 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
2068 lustre:svname $dm_dev");;
2070 error "unknown fstype!";;
2073 echo "Starting ${facet}: $opts $dm_dev $mntpt"
2074 # for testing LU-482 error handling in mount_facets() and test_0a()
2075 if [ -f $TMP/test-lu482-trigger ]; then
2079 "mkdir -p $mntpt; $MOUNT_CMD $opts $dm_dev $mntpt"
2083 if [ $RC -ne 0 ]; then
2084 echo "Start of $dm_dev on ${facet} failed ${RC}"
2088 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
2089 if [[ "$health" != "healthy" ]]; then
2090 error "$facet is in a unhealthy state"
2093 set_default_debug_facet $facet
2095 if [[ $opts =~ .*nosvc.* ]]; then
2096 echo "Start $dm_dev without service"
2101 wait_update_facet ${facet} "$E2LABEL $dm_dev \
2102 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
2103 "" || error "$dm_dev failed to initialize!";;
2105 wait_update_facet ${facet} "$ZFS get -H -o value \
2106 lustre:svname $dm_dev 2>/dev/null | \
2107 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
2108 error "$dm_dev failed to initialize!";;
2111 error "unknown fstype!";;
2115 # commit the device label change to disk
2116 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
2117 echo "Commit the device label on ${!dev}"
2118 do_facet $facet "sync; sleep 1; sync"
2122 label=$(devicelabel ${facet} $dm_dev)
2123 [ -z "$label" ] && echo no label for $dm_dev && exit 1
2124 eval export ${facet}_svc=${label}
2125 echo Started ${label}
2127 export_dm_dev $facet $dm_dev
2132 # start facet device options
2138 local dev_alias=$(facet_device_alias $facet)
2140 eval export ${dev_alias}_dev=${device}
2141 eval export ${facet}_opt=\"$@\"
2143 local varname=${dev_alias}failover_dev
2144 if [ -n "${!varname}" ] ; then
2145 eval export ${dev_alias}failover_dev=${!varname}
2147 eval export ${dev_alias}failover_dev=$device
2150 local mntpt=$(facet_mntpt $facet)
2151 do_facet ${facet} mkdir -p $mntpt
2152 eval export ${facet}_MOUNT=$mntpt
2153 mount_facet ${facet}
2163 local HOST=$(facet_active_host $facet)
2164 [[ -z $HOST ]] && echo stop: no host for $facet && return 0
2166 local mntpt=$(facet_mntpt $facet)
2167 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts || true")
2168 if [ ${running} -ne 0 ]; then
2169 echo "Stopping $mntpt (opts:$@) on $HOST"
2170 do_facet ${facet} $UMOUNT $@ $mntpt
2173 # umount should block, but we should wait for unrelated obd's
2174 # like the MGS or MGC to also stop.
2175 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
2177 if [[ $(facet_fstype $facet) == zfs ]]; then
2178 # export ZFS storage pool
2179 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
2180 elif dm_flakey_supported $facet; then
2181 local host=${facet}_HOST
2182 local failover_host=${facet}failover_HOST
2183 if [[ -n ${!failover_host} && ${!failover_host} != ${!host} ]]||
2184 $CLEANUP_DM_DEV || [[ $facet = fs* ]]; then
2185 dm_cleanup_dev $facet
2190 # get mdt quota type
2192 local varsvc=${SINGLEMDS}_svc
2193 do_facet $SINGLEMDS $LCTL get_param -n \
2194 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
2197 # get ost quota type
2199 # All OSTs should have same quota type
2200 local varsvc=ost1_svc
2201 do_facet ost1 $LCTL get_param -n \
2202 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
2205 # restore old quota type settings
2207 if [ "$old_MDT_QUOTA_TYPE" ]; then
2208 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2209 do_facet mgs $PERM_CMD \
2210 osd-*.$FSNAME-MDT*.quota_slave.enabled = \
2213 do_facet mgs $PERM_CMD \
2214 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
2217 if [ "$old_OST_QUOTA_TYPE" ]; then
2218 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2219 do_facet mgs $PERM_CMD \
2220 osd-*.$FSNAME-OST*.quota_slave.enabled = \
2223 do_facet mgs $LCTL conf_param \
2224 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
2229 # Handle the case when there is a space in the lfs df
2230 # "filesystem summary" line the same as when there is no space.
2231 # This will allow fixing the "lfs df" summary line in the future.
2233 $LFS df $* | sed -e 's/filesystem /filesystem_/'
2234 check_lfs_df_ret_val $?
2237 # Get free inodes on the MDT specified by mdt index, free indoes on
2238 # the whole filesystem will be returned when index == -1.
2244 if [ $index -eq -1 ]; then
2247 mdt_uuid=$(mdtuuid_from_index $index)
2250 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
2255 # Get the OST device status from 'lfs df' with a given OST index.
2259 local mnt_pnt=${2:-$MOUNT}
2263 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
2264 lfs_df $opts $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
2270 # save old quota type & set new quota type
2271 local mdt_qtype=$(mdt_quota_type)
2272 local ost_qtype=$(ost_quota_type)
2274 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
2275 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
2277 export old_MDT_QUOTA_TYPE=$mdt_qtype
2278 export old_OST_QUOTA_TYPE=$ost_qtype
2280 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2281 do_facet mgs $PERM_CMD \
2282 osd-*.$FSNAME-MDT*.quota_slave.enabled=$QUOTA_TYPE
2283 do_facet mgs $PERM_CMD \
2284 osd-*.$FSNAME-OST*.quota_slave.enabled=$QUOTA_TYPE
2286 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$QUOTA_TYPE ||
2287 error "set mdt quota type failed"
2288 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$QUOTA_TYPE ||
2289 error "set ost quota type failed"
2292 local quota_usrs=$QUOTA_USERS
2294 # get_filesystem_size
2295 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
2296 local blk_soft=$((disksz + 1024))
2297 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
2299 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
2300 local i_soft=$inodes
2301 local i_hard=$((i_soft + i_soft / 20))
2303 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
2304 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
2305 "inode-hardlimit: $i_hard"
2308 for usr in $quota_usrs; do
2309 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
2311 cmd="$LFS setquota -$type $usr -b $blk_soft"
2312 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
2314 eval $cmd || error "$cmd FAILED!"
2316 # display the quota status
2317 echo "Quota settings for $usr : "
2318 $LFS quota -v -u $usr $mntpt || true
2325 local opts=${3:-$MOUNT_OPTS}
2326 opts=${opts:+-o $opts}
2327 local flags=${4:-$MOUNT_FLAGS}
2329 local device=$MGSNID:/$FSNAME$FILESET
2330 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2331 echo "Bad mount command: opt=$flags $opts dev=$device " \
2337 # update mount option with skpath
2338 opts=$(add_sk_mntflag $opts)
2341 echo "Starting client: $client: $flags $opts $device $mnt"
2342 do_node $client mkdir -p $mnt
2343 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
2344 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
2346 #disable FILESET if not supported
2347 do_nodes $client lctl get_param -n \
2348 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2349 device=$MGSNID:/$FSNAME
2350 do_node $client mkdir -p $mnt/$FILESET
2351 do_node $client "! grep -q $mnt' ' /proc/mounts ||
2354 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2355 # Mount using nodemap key
2356 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2357 if $SK_UNIQUE_NM; then
2358 mountkey=$SK_PATH/nodemap/c0.key
2360 local prunedopts=$(echo $opts |
2361 sed -e "s#skpath=[^,^ ]*#skpath=$mountkey#g")
2362 do_node $client $MOUNT_CMD $flags $prunedopts $device $mnt ||
2365 do_node $client $MOUNT_CMD $flags $opts $device $mnt ||
2369 set_default_debug_nodes $client
2370 set_params_clients $client
2381 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
2383 [ "$3" ] && force=-f
2384 [ $running -eq 0 ] && return 0
2386 echo "Stopping client $client $mnt (opts:$force)"
2387 do_node $client lsof -t $mnt || need_kill=no
2388 if [ "x$force" != "x" ] && [ "x$need_kill" != "xno" ]; then
2389 pids=$(do_node $client lsof -t $mnt | sort -u);
2390 if [ -n "$pids" ]; then
2391 do_node $client kill -9 $pids || true
2395 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") ||
2397 if [ $busy -ne 0 ] ; then
2398 echo "$mnt is still busy, wait one second" && sleep 1
2399 do_node $client umount $force $mnt
2403 # Mount the file system on the MDS
2404 mount_mds_client() {
2405 local mds_HOST=${SINGLEMDS}_HOST
2407 zconf_mount $mds1_HOST $MOUNT2 $MOUNT_OPTS ||
2408 error "unable to mount $MOUNT2 on MDS"
2411 # Unmount the file system on the MDS
2412 umount_mds_client() {
2413 local mds_HOST=${SINGLEMDS}_HOST
2414 zconf_umount $mds1_HOST $MOUNT2
2415 do_facet $SINGLEMDS "rmdir $MOUNT2"
2418 # nodes is comma list
2419 sanity_mount_check_nodes () {
2425 # FIXME: assume that all cluster nodes run the same os
2426 [ "$(uname)" = Linux ] || return 0
2429 for mnt in $mnts ; do
2430 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
2431 mpts=\\\$(mount | grep -c $mnt' ');
2432 if [ \\\$running -ne \\\$mpts ]; then
2433 echo \\\$(hostname) env are INSANE!;
2436 [ $? -eq 0 ] || rc=1
2441 sanity_mount_check_servers () {
2442 [ -n "$CLIENTONLY" ] &&
2443 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
2444 echo Checking servers environments
2446 # FIXME: modify get_facets to display all facets wo params
2447 local facets="$(get_facets OST),$(get_facets MDS),mgs"
2451 for facet in ${facets//,/ }; do
2452 node=$(facet_host ${facet})
2453 mntpt=$(facet_mntpt $facet)
2454 sanity_mount_check_nodes $node $mntpt ||
2455 { error "server $node environments are insane!"; return 1; }
2459 sanity_mount_check_clients () {
2460 local clients=${1:-$CLIENTS}
2461 local mntpt=${2:-$MOUNT}
2462 local mntpt2=${3:-$MOUNT2}
2464 [ -z $clients ] && clients=$(hostname)
2465 echo Checking clients $clients environments
2467 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
2468 error "clients environments are insane!"
2471 sanity_mount_check () {
2472 sanity_mount_check_servers || return 1
2473 sanity_mount_check_clients || return 2
2476 # mount clients if not mouted
2477 zconf_mount_clients() {
2480 local opts=${3:-$MOUNT_OPTS}
2481 opts=${opts:+-o $opts}
2482 local flags=${4:-$MOUNT_FLAGS}
2483 local device=$MGSNID:/$FSNAME$FILESET
2484 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2485 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
2490 echo "Starting client $clients: $flags $opts $device $mnt"
2491 do_nodes $clients mkdir -p $mnt
2492 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ]; then
2493 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2494 # Mount with own nodemap key
2496 # Mount all server nodes first with per-NM keys
2497 for nmclient in ${clients//,/ }; do
2498 # do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key -n c$i"
2499 do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key"
2502 # set perms for per-nodemap keys else permission denied
2503 do_nodes $(comma_list $(all_nodes)) \
2504 "keyctl show | grep lustre | cut -c1-11 |
2506 xargs -IX keyctl setperm X 0x3f3f3f3f"
2507 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2509 for nmclient in ${clients//,/ }; do
2510 if $SK_UNIQUE_NM; then
2511 mountkey=$SK_PATH/nodemap/c$i.key
2513 do_node $nmclient "! grep -q $mnt' ' \
2514 /proc/mounts || umount $mnt"
2515 local prunedopts=$(add_sk_mntflag $prunedopts);
2516 prunedopts=$(echo $prunedopts | sed -e \
2517 "s#skpath=[^ ^,]*#skpath=$mountkey#g")
2519 do_nodes $(comma_list $(all_server_nodes)) \
2522 do_node $nmclient $MOUNT_CMD $flags \
2523 $prunedopts $MGSNID:/$FSNAME $mnt ||
2528 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2530 do_nodes $clients $MOUNT_CMD $flags $opts \
2531 $MGSNID:/$FSNAME $mnt || return 1
2533 #disable FILESET if not supported
2534 do_nodes $clients lctl get_param -n \
2535 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2536 device=$MGSNID:/$FSNAME
2537 do_nodes $clients mkdir -p $mnt/$FILESET
2538 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2542 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2543 # Mount with nodemap key
2545 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2546 for nmclient in ${clients//,/ }; do
2547 if $SK_UNIQUE_NM; then
2548 mountkey=$SK_PATH/nodemap/c$i.key
2550 local prunedopts=$(echo $opts | sed -e \
2551 "s#skpath=[^ ^,]*#skpath=$mountkey#g");
2552 do_node $nmclient "! grep -q $mnt' ' /proc/mounts ||
2555 running=\\\$(mount | grep -c $mnt' ');
2557 if [ \\\$running -eq 0 ] ; then
2559 $MOUNT_CMD $flags $prunedopts $device $mnt;
2562 lustre_mnt_count=\\\$(mount | grep $mnt' ' | \
2563 grep 'type lustre' | wc -l);
2564 if [ \\\$running -ne \\\$lustre_mnt_count ] ; then
2565 echo zconf_mount_clients FAILED: \
2566 mount count \\\$running, not matching \
2567 with mount count of 'type lustre' \
2568 \\\$lustre_mnt_count;
2572 exit \\\$rc" || return ${PIPESTATUS[0]}
2579 if $SHARED_KEY; then
2580 tmpopts=$(add_sk_mntflag $opts)
2583 running=\\\$(mount | grep -c $mnt' ');
2585 if [ \\\$running -eq 0 ] ; then
2587 $MOUNT_CMD $flags $tmpopts $device $mnt;
2590 exit \\\$rc" || return ${PIPESTATUS[0]}
2593 echo "Started clients $clients: "
2594 do_nodes $clients "mount | grep $mnt' '"
2596 set_default_debug_nodes $clients
2597 set_params_clients $clients
2602 zconf_umount_clients() {
2607 [ "$3" ] && force=-f
2609 echo "Stopping clients: $clients $mnt (opts:$force)"
2610 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
2611 if [ \\\$running -ne 0 ] ; then
2612 echo Stopping client \\\$(hostname) $mnt opts:$force;
2613 lsof $mnt || need_kill=no;
2614 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
2615 pids=\\\$(lsof -t $mnt | sort -u);
2616 if [ -n \\\"\\\$pids\\\" ]; then
2620 while umount $force $mnt 2>&1 | grep -q "busy"; do
2621 echo "$mnt is still busy, wait one second" && sleep 1;
2628 echo + $POWER_DOWN $node
2632 shutdown_node_hard () {
2634 local attempts=$SHUTDOWN_ATTEMPTS
2636 for i in $(seq $attempts) ; do
2639 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
2640 echo "waiting for $host to fail attempts=$attempts"
2641 [ $i -lt $attempts ] || \
2642 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
2648 local mnt=${2:-$MOUNT}
2651 if [ "$FAILURE_MODE" = HARD ]; then
2652 shutdown_node_hard $client
2654 zconf_umount_clients $client $mnt -f
2660 local facets="$(get_facets OST),$(get_facets MDS)"
2663 combined_mgs_mds || facets="$facets,mgs"
2665 for facet in ${facets//,/ }; do
2666 if [ $(facet_active_host $facet) == $host ]; then
2667 affected="$affected $facet"
2671 echo $(comma_list $affected)
2676 local host=${2:-$(facet_host $facet)}
2678 local label=$(convert_facet2label $facet)
2679 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
2682 facets_up_on_host () {
2684 local facets=$(facets_on_host $host)
2687 for facet in ${facets//,/ }; do
2688 if $(facet_up $facet $host); then
2689 affected_up="$affected_up $facet"
2693 echo $(comma_list $affected_up)
2698 local affected_facet
2699 local affected_facets
2701 if [[ "$FAILURE_MODE" = HARD ]]; then
2702 if [[ $(facet_fstype $facet) = ldiskfs ]] &&
2703 dm_flakey_supported $facet; then
2704 affected_facets=$(affected_facets $facet)
2705 for affected_facet in ${affected_facets//,/ }; do
2706 unexport_dm_dev $affected_facet
2710 shutdown_node_hard $(facet_active_host $facet)
2718 echo + $POWER_UP $node
2731 local node=$(facet_active_host $facet)
2732 local sleep_time=${2:-10}
2734 if [ "$FAILURE_MODE" = HARD ]; then
2744 if [ "$FAILURE_MODE" = HARD ]; then
2747 if $LOAD_MODULES_REMOTE; then
2748 echo "loading modules on $node: $facet"
2749 do_rpc_nodes $node load_modules_local
2758 for facet in ${facets//,/ }; do
2759 hosts=$(expand_list $hosts $(facet_host $facet) )
2765 _check_progs_installed () {
2769 for prog in $progs; do
2770 if ! [ "$(which $prog)" -o "${!prog}" ]; then
2771 echo $prog missing on $(hostname)
2778 check_progs_installed () {
2782 do_rpc_nodes "$nodes" _check_progs_installed $@
2785 # recovery-scale functions
2787 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
2790 start_client_load() {
2793 local var=$(node_var_name $client)_load
2794 eval export ${var}=$load
2796 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
2797 BREAK_ON_ERROR=$BREAK_ON_ERROR \
2798 END_RUN_FILE=$END_RUN_FILE \
2799 LOAD_PID_FILE=$LOAD_PID_FILE \
2800 TESTLOG_PREFIX=$TESTLOG_PREFIX \
2801 TESTNAME=$TESTNAME \
2802 DBENCH_LIB=$DBENCH_LIB \
2803 DBENCH_SRC=$DBENCH_SRC \
2804 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
2809 MPIRUN_OPTIONS=\\\"$MPIRUN_OPTIONS\\\" \
2810 MACHINEFILE_OPTION=\\\"$MACHINEFILE_OPTION\\\" \
2811 num_clients=$(get_node_count ${CLIENTS//,/ }) \
2812 ior_THREADS=$ior_THREADS ior_iteration=$ior_iteration \
2813 ior_blockSize=$ior_blockSize \
2814 ior_blockUnit=$ior_blockUnit \
2815 ior_xferSize=$ior_xferSize ior_type=$ior_type \
2816 ior_DURATION=$ior_DURATION \
2817 ior_stripe_params=\\\"$ior_stripe_params\\\" \
2818 ior_custom_params=\\\"$ior_custom_param\\\" \
2819 mpi_ior_custom_threads=$mpi_ior_custom_threads \
2822 log "Started client load: ${load} on $client"
2824 # get the children process IDs
2825 local pids=$(ps --ppid $ppid -o pid= | xargs)
2826 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
2830 start_client_loads () {
2831 local -a clients=(${1//,/ })
2832 local numloads=${#CLIENT_LOADS[@]}
2834 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
2835 local load=$((nodenum % numloads))
2836 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[load]}
2838 # bug 22169: wait the background threads to start
2842 # only for remote client
2843 check_client_load () {
2845 local var=$(node_var_name $client)_load
2846 local testload=run_${!var}.sh
2848 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
2850 # bug 18914: try to connect several times not only when
2851 # check ps, but while check_node_health also
2855 while [ $RC = 254 -a $tries -gt 0 ]; do
2859 if ! check_node_health $client; then
2861 if [ $RC -eq 254 ]; then
2862 # FIXME: not sure how long we shuold sleep here
2866 echo "check node health failed: RC=$RC "
2870 # We can continue try to connect if RC=254
2871 # Just print the warning about this
2872 if [ $RC = 254 ]; then
2873 echo "got a return status of $RC from do_node while checking " \
2874 "node health on $client"
2877 # see if the load is still on the client
2880 while [ $RC = 254 -a $tries -gt 0 ]; do
2884 if ! do_node $client \
2885 "ps auxwww | grep -v grep | grep -q $testload"; then
2890 if [ $RC = 254 ]; then
2891 echo "got a return status of $RC from do_node while checking " \
2892 "(node health and 'ps') the client load on $client"
2893 # see if we can diagnose a bit why this is
2898 check_client_loads () {
2899 local clients=${1//,/ }
2903 for client in $clients; do
2904 check_client_load $client
2906 if [ "$rc" != 0 ]; then
2907 log "Client load failed on node $client, rc=$rc"
2913 restart_client_loads () {
2914 local clients=${1//,/ }
2915 local expectedfail=${2:-""}
2919 for client in $clients; do
2920 check_client_load $client
2922 if [ "$rc" != 0 -a "$expectedfail" ]; then
2923 local var=$(node_var_name $client)_load
2924 start_client_load $client ${!var}
2925 echo "Restarted client load ${!var}: on $client. Checking ..."
2926 check_client_load $client
2928 if [ "$rc" != 0 ]; then
2929 log "Client load failed to restart on node $client, rc=$rc"
2930 # failure one client load means test fail
2931 # we do not need to check other
2940 # Start vmstat and save its process ID in a file.
2945 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2948 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
2949 2>/dev/null </dev/null & echo \\\$! > $pid_file"
2952 # Display the nodes on which client loads failed.
2953 print_end_run_file() {
2957 [ -s $file ] || return 0
2959 echo "Found the END_RUN_FILE file: $file"
2962 # A client load will stop if it finds the END_RUN_FILE file.
2963 # That does not mean the client load actually failed though.
2964 # The first node in END_RUN_FILE is the one we are interested in.
2967 if [ -n "$node" ]; then
2968 local var=$(node_var_name $node)_load
2970 local prefix=$TESTLOG_PREFIX
2971 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
2972 local stdout_log=$prefix.run_${!var}_stdout.$node.log
2973 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
2975 echo "Client load ${!var} failed on node $node:"
2981 # Stop the process which had its PID saved in a file.
2986 [ -z "$nodes" -o -z "$pid_file" ] && return 0
2988 do_nodes $nodes "test -f $pid_file &&
2989 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
2992 # Stop all client loads.
2993 stop_client_loads() {
2994 local nodes=${1:-$CLIENTS}
2997 # stop the client loads
2998 stop_process $nodes $pid_file
3000 # clean up the processes that started them
3001 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
3003 # End recovery-scale functions
3006 # wait for a command to return the expected result
3008 # This will run @check on @node repeatedly until the output matches @expect
3009 # based on the supplied condition, or until @max_wait seconds have elapsed,
3010 # whichever comes first. @cond may be one of the normal bash operators,
3011 # "-gt", "-ge", "-eq", "-le", "-lt", "==", "!=", or "=~", and must be quoted
3012 # in the caller to avoid unintentional evaluation by the shell in the caller.
3014 # If @max_wait is not specified, the condition will be checked for up to 90s.
3016 # If --verbose is passed as the first argument, the result is printed on each
3017 # value change, otherwise it is only printed after every 10s interval.
3019 # If --quiet is passed as the first/second argument, the do_node() command
3020 # will not print the remote command before executing it each time.
3022 # Using wait_update_cond() or related helper function is preferable to adding
3023 # a "long enough" wait for some state to change in the background, since
3024 # "long enough" may be too short due to tunables, system config, or running in
3025 # a VM, and must by necessity wait too long for most cases or risk failure.
3027 # usage: wait_update_cond [--verbose] [--quiet] node check cond expect [max_wait]
3028 wait_update_cond() {
3032 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3033 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3039 local max_wait=${5:-90}
3043 local begin=$SECONDS
3047 while (( $waited <= $max_wait )); do
3048 result=$(do_node $quiet $node "$check")
3050 eval [[ "'$result'" $cond "'$expect'" ]]
3051 if [[ $? == 0 ]]; then
3052 [[ -z "$result" || $waited -le $sleep ]] ||
3053 echo "Updated after ${waited}s: want '$expect' got '$result'"
3056 if [[ -n "$verbose" && "$result" != "$prev_result" ]]; then
3057 [[ -n "$prev_result" ]] &&
3058 echo "Changed after ${waited}s: from '$prev_result' to '$result'"
3059 prev_result="$result"
3061 (( $waited % $print == 0 )) &&
3062 echo "Waiting $((max_wait - waited))s for '$expect'"
3064 waited=$((SECONDS - begin))
3066 echo "Update not seen after ${max_wait}s: want '$expect' got '$result'"
3070 # usage: wait_update [--verbose] [--quiet] node check expect [max_wait]
3075 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3076 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3083 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3086 # usage: wait_update_facet_cond [--verbose] facet check cond expect [max_wait]
3087 wait_update_facet_cond() {
3091 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3092 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3094 local node=$(facet_active_host $1)
3100 wait_update_cond $verbose $quiet $node "$check" "$cond" "$expect" $max_wait
3103 # usage: wait_update_facet [--verbose] facet check expect [max_wait]
3104 wait_update_facet() {
3108 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3109 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3111 local node=$(facet_active_host $1)
3116 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3120 do_nodes $(comma_list $(mdts_nodes)) \
3121 "lctl set_param -n os[cd]*.*MDT*.force_sync=1"
3122 do_nodes $(comma_list $(osts_nodes)) \
3123 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
3124 grep -v 'Found no match'
3128 local zfs_wait=${2:-5}
3130 # the occupied disk space will be released
3131 # only after TXGs are committed
3132 if [[ $(facet_fstype $1) == zfs ]]; then
3133 echo "sleep $zfs_wait for ZFS $(facet_fstype $1)"
3141 local lwm=$3 #low watermark
3142 local size_mb #how many MB should we write to pass watermark
3143 local ost_name=$(ostname_from_index $ost_idx)
3145 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3147 if (( $free_kb / 1024 > lwm )); then
3148 size_mb=$((free_kb / 1024 - lwm))
3150 #If 10% of free space cross low watermark use it
3151 if (( $free_kb / 10240 > size_mb )); then
3152 size_mb=$((free_kb / 10240))
3154 #At least we need to store 1.1 of difference between
3155 #free space and low watermark
3156 size_mb=$((size_mb + size_mb / 10))
3158 if (( lwm <= $free_kb / 1024 )) ||
3159 [ ! -f $DIR/${filename}.fill_ost$ost_idx ]; then
3160 $LFS setstripe -i $ost_idx -c1 $DIR/${filename}.fill_ost$ost_idx
3161 dd if=/dev/zero of=$DIR/${filename}.fill_ost$ost_idx bs=1M \
3162 count=$size_mb oflag=append conv=notrunc
3167 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3168 echo "OST still has $((free_kb / 1024)) MB free"
3171 # This checks only the primary MDS
3172 ost_watermarks_get() {
3174 local ost_name=$(ostname_from_index $ost_idx)
3175 local mdtosc_proc=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
3177 local hwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3178 osp.$mdtosc_proc.reserved_mb_high)
3179 local lwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3180 osp.$mdtosc_proc.reserved_mb_low)
3185 # Note that we set watermarks on all MDSes (necessary for striped dirs)
3186 ost_watermarks_set() {
3190 local ost_name=$(ostname_from_index $ost_idx)
3191 local facets=$(get_facets MDS)
3193 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param -n \
3194 osp.*$ost_name*.reserved_mb_low=$lwm \
3195 osp.*$ost_name*.reserved_mb_high=$hwm > /dev/null
3197 # sleep to ensure we see the change
3201 ost_watermarks_set_low_space() {
3203 local wms=$(ost_watermarks_get $ost_idx)
3204 local ost_name=$(ostname_from_index $ost_idx)
3206 local old_lwm=$(echo $wms | awk '{ print $1 }')
3207 local old_hwm=$(echo $wms | awk '{ print $2 }')
3209 local blocks=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3210 # minimal extension size is 64M
3212 if (( $blocks / 1024 > 50 )); then
3213 new_lwm=$((blocks / 1024 - 50))
3215 local new_hwm=$((new_lwm + 5))
3217 ost_watermarks_set $ost_idx $new_lwm $new_hwm
3218 echo "watermarks: $old_lwm $old_hwm $new_lwm $new_hwm"
3221 # Set watermarks to ~current available space & then write data to fill it
3222 # Note OST is not *actually* full after this, it just reports ENOSPC in the
3223 # internal statfs used by the stripe allocator
3225 # first parameter is the filename-prefix, which must get under t-f cleanup
3226 # requirements (rm -rf $DIR/[Rdfs][0-9]*), i.e. $tfile work fine
3227 ost_watermarks_set_enospc() {
3231 local ost_name=$(ostname_from_index $ost_idx)
3232 local facets=$(get_facets MDS)
3236 for MDS in ${facets//,/ }; do
3237 local mdtosc_proc=$(get_mdtosc_proc_path $MDS $ost_name)
3239 do_facet $MDS $LCTL get_param -n \
3240 osp.$mdtosc_proc.reserved_mb_high ||
3241 skip "remote MDS does not support reserved_mb_high"
3244 wms=$(ost_watermarks_set_low_space $ost_idx)
3245 local new_lwm=$(echo $wms | awk '{ print $4 }')
3246 fill_ost $filename $ost_idx $new_lwm
3247 #First enospc could execute orphan deletion so repeat
3248 fill_ost $filename $ost_idx $new_lwm
3252 ost_watermarks_enospc_delete_files() {
3256 rm -f $DIR/${filename}.fill_ost$ost_idx
3258 wait_delete_completed
3262 # clean up from "ost_watermarks_set_enospc"
3263 ost_watermarks_clear_enospc() {
3269 ost_watermarks_enospc_delete_files $filename $ost_idx
3270 ost_watermarks_set $ost_idx $old_lwm $old_hwm
3271 echo "set OST$ost_idx lwm back to $old_lwm, hwm back to $old_hwm"
3274 wait_delete_completed_mds() {
3275 local max_wait=${1:-20}
3277 local stime=$(date +%s)