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)}
1709 for facet in ${facets//,/ }; do
1710 mount_facet $facet &
1714 for ((index=0; index<$total; index++)); do
1715 wait ${mountpids[index]}
1717 [ $RC -eq 0 ] && continue
1719 if [ "$TESTSUITE.$TESTNAME" = "replay-dual.test_0a" ]; then
1720 skip_noexit "Restart of $facet failed!." &&
1723 error "Restart of $facet failed!"
1731 # Add argument "arg" (e.g., "loop") to the comma-separated list
1732 # of arguments for option "opt" (e.g., "-o") on command
1733 # line "opts" (e.g., "-o flock").
1739 local opt_pattern="\([[:space:]]\+\|^\)$opt"
1741 if echo "$opts" | grep -q $opt_pattern; then
1742 opts=$(echo "$opts" | sed -e \
1743 "s/$opt_pattern[[:space:]]*[^[:space:]]\+/&,$arg/")
1745 opts+="${opts:+ }$opt $arg"
1751 # Associate loop device with a given regular file.
1752 # Return the loop device.
1754 setup_loop_device() {
1758 do_facet $facet "loop_dev=\\\$($LOSETUP -j $file | cut -d : -f 1);
1759 if [[ -z \\\$loop_dev ]]; then
1760 loop_dev=\\\$($LOSETUP -f);
1761 $LOSETUP \\\$loop_dev $file || loop_dev=;
1763 echo -n \\\$loop_dev"
1767 # Detach a loop device.
1769 cleanup_loop_device() {
1773 do_facet $facet "! $LOSETUP $loop_dev >/dev/null 2>&1 ||
1774 $LOSETUP -d $loop_dev"
1778 # Check if a given device is a block device.
1785 [[ -n "$dev" ]] || return 1
1786 do_facet $facet "test -b $dev" || return 1
1787 if [[ -n "$size" ]]; then
1788 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k \
1789 count=1 skip=$size 2>&1" |
1790 awk '($3 == "in") { print $1 }')
1791 [[ "$in" = "1+0" ]] || return 1
1796 # Check if a given device is a device-mapper device.
1802 [[ -n "$dev" ]] || return 1
1803 do_facet $facet "$DMSETUP status $dev >/dev/null 2>&1"
1807 # Check if a given device is a device-mapper flakey device.
1809 is_dm_flakey_dev() {
1814 [[ -n "$dev" ]] || return 1
1816 type=$(do_facet $facet "$DMSETUP status $dev 2>&1" |
1818 [[ $type = flakey ]] && return 0 || return 1
1822 # Check if device-mapper flakey device is supported by the kernel
1823 # of $facet node or not.
1825 dm_flakey_supported() {
1829 do_facet $facet "modprobe dm-flakey;
1830 $DMSETUP targets | grep -q flakey" &> /dev/null
1834 # Get the device-mapper flakey device name of a given facet.
1836 dm_facet_devname() {
1838 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
1840 echo -n ${facet}_flakey
1844 # Get the device-mapper flakey device of a given facet.
1845 # A device created by dmsetup will appear as /dev/mapper/<device-name>.
1847 dm_facet_devpath() {
1850 echo -n $DM_DEV_PATH/$(dm_facet_devname $facet)
1854 # Set a device-mapper device with a new table.
1856 # The table has the following format:
1857 # <logical_start_sector> <num_sectors> <target_type> <target_args>
1859 # flakey <target_args> includes:
1860 # <destination_device> <offset> <up_interval> <down_interval> \
1861 # [<num_features> [<feature_arguments>]]
1863 # linear <target_args> includes:
1864 # <destination_device> <start_sector>
1866 dm_set_dev_table() {
1869 local target_type=$3
1875 read tmp num_sectors tmp real_dev tmp \
1876 <<< $(do_facet $facet "$DMSETUP table $dm_dev")
1878 case $target_type in
1880 table="0 $num_sectors flakey $real_dev 0 0 1800 1 drop_writes"
1883 table="0 $num_sectors linear $real_dev 0"
1885 *) error "invalid target type $target_type" ;;
1888 do_facet $facet "$DMSETUP suspend --nolockfs --noflush $dm_dev" ||
1889 error "failed to suspend $dm_dev"
1890 do_facet $facet "$DMSETUP load $dm_dev --table \\\"$table\\\"" ||
1891 error "failed to load $target_type table into $dm_dev"
1892 do_facet $facet "$DMSETUP resume $dm_dev" ||
1893 error "failed to resume $dm_dev"
1897 # Set a device-mapper flakey device as "read-only" by using the "drop_writes"
1898 # feature parameter.
1901 # All write I/O is silently ignored.
1902 # Read I/O is handled correctly.
1904 dm_set_dev_readonly() {
1906 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1908 dm_set_dev_table $facet $dm_dev flakey
1912 # Set a device-mapper device to traditional linear mapping mode.
1914 dm_clear_dev_readonly() {
1916 local dm_dev=${2:-$(dm_facet_devpath $facet)}
1918 dm_set_dev_table $facet $dm_dev linear
1922 # Set the device of a given facet as "read-only".
1924 set_dev_readonly() {
1926 local svc=${facet}_svc
1928 if [[ $(facet_fstype $facet) = zfs ]] ||
1929 ! dm_flakey_supported $facet; then
1930 do_facet $facet $LCTL --device ${!svc} readonly
1932 dm_set_dev_readonly $facet
1937 # Get size in 512-byte sectors (BLKGETSIZE64 / 512) of a given device.
1944 num_sectors=$(do_facet $facet "blockdev --getsz $dev 2>/dev/null")
1945 [[ ${PIPESTATUS[0]} = 0 && -n "$num_sectors" ]] || num_sectors=0
1946 echo -n $num_sectors
1950 # Create a device-mapper device with a given block device or regular file (will
1951 # be associated with loop device).
1952 # Return the full path of the device-mapper device.
1956 local real_dev=$2 # destination device
1957 local dm_dev_name=${3:-$(dm_facet_devname $facet)} # device name
1958 local dm_dev=$DM_DEV_PATH/$dm_dev_name # device-mapper device
1960 # check if the device-mapper device to be created already exists
1961 if is_dm_dev $facet $dm_dev; then
1962 # if the existing device was set to "read-only", then clear it
1963 ! is_dm_flakey_dev $facet $dm_dev ||
1964 dm_clear_dev_readonly $facet $dm_dev
1970 # check if the destination device is a block device, and if not,
1971 # associate it with a loop device
1972 is_blkdev $facet $real_dev ||
1973 real_dev=$(setup_loop_device $facet $real_dev)
1974 [[ -n "$real_dev" ]] || { echo -n $real_dev; return 2; }
1976 # now create the device-mapper device
1977 local num_sectors=$(get_num_sectors $facet $real_dev)
1978 local table="0 $num_sectors linear $real_dev 0"
1981 do_facet $facet "$DMSETUP create $dm_dev_name --table \\\"$table\\\"" ||
1982 { rc=${PIPESTATUS[0]}; dm_dev=; }
1983 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
1990 # Map the facet name to its device variable name.
1992 facet_device_alias() {
1994 local dev_alias=$facet
1997 fs2mds) dev_alias=mds1_2 ;;
1998 fs2ost) dev_alias=ost1_2 ;;
1999 fs3ost) dev_alias=ost2_2 ;;
2007 # Save the original value of the facet device and export the new value.
2013 local active_facet=$(facet_active $facet)
2014 local dev_alias=$(facet_device_alias $active_facet)
2015 local dev_name=${dev_alias}_dev
2016 local dev=${!dev_name}
2018 if [[ $active_facet = $facet ]]; then
2019 local failover_dev=${dev_alias}failover_dev
2020 if [[ ${!failover_dev} = $dev ]]; then
2021 eval export ${failover_dev}_saved=$dev
2022 eval export ${failover_dev}=$dm_dev
2025 dev_alias=$(facet_device_alias $facet)
2026 local facet_dev=${dev_alias}_dev
2027 if [[ ${!facet_dev} = $dev ]]; then
2028 eval export ${facet_dev}_saved=$dev
2029 eval export ${facet_dev}=$dm_dev
2033 eval export ${dev_name}_saved=$dev
2034 eval export ${dev_name}=$dm_dev
2038 # Restore the saved value of the facet device.
2043 [[ $facet = mgs ]] && combined_mgs_mds && facet=mds1
2044 local dev_alias=$(facet_device_alias $facet)
2046 local saved_dev=${dev_alias}_dev_saved
2047 [[ -z ${!saved_dev} ]] ||
2048 eval export ${dev_alias}_dev=${!saved_dev}
2050 saved_dev=${dev_alias}failover_dev_saved
2051 [[ -z ${!saved_dev} ]] ||
2052 eval export ${dev_alias}failover_dev=${!saved_dev}
2056 # Remove a device-mapper device.
2057 # If the destination device is a loop device, then also detach it.
2061 local dm_dev=${2:-$(dm_facet_devpath $facet)}
2065 is_dm_dev $facet $dm_dev || return 0
2067 read major minor <<< $(do_facet $facet "$DMSETUP table $dm_dev" |
2068 awk '{ print $4 }' | awk -F: '{ print $1" "$2 }')
2070 do_facet $facet "$DMSETUP remove $dm_dev"
2071 do_facet $facet "$DMSETUP mknodes >/dev/null 2>&1"
2073 unexport_dm_dev $facet
2075 # detach a loop device
2076 [[ $major -ne 7 ]] || cleanup_loop_device $facet /dev/loop$minor
2078 # unload dm-flakey module
2079 do_facet $facet "modprobe -r dm-flakey" || true
2085 local active_facet=$(facet_active $facet)
2086 local dev_alias=$(facet_device_alias $active_facet)
2087 local dev=${dev_alias}_dev
2088 local opt=${facet}_opt
2089 local mntpt=$(facet_mntpt $facet)
2090 local opts="${!opt} $@"
2091 local fstype=$(facet_fstype $facet)
2093 local dm_dev=${!dev}
2095 [[ $dev == "mgsfailover_dev" ]] && combined_mgs_mds &&
2096 dev=mds1failover_dev
2098 module_loaded lustre || load_modules
2102 if dm_flakey_supported $facet; then
2103 dm_dev=$(dm_create_dev $facet ${!dev})
2104 [[ -n "$dm_dev" ]] || dm_dev=${!dev}
2107 is_blkdev $facet $dm_dev || opts=$(csa_add "$opts" -o loop)
2109 devicelabel=$(do_facet ${facet} "$E2LABEL $dm_dev");;
2111 # import ZFS storage pool
2112 import_zpool $facet || return ${PIPESTATUS[0]}
2114 devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
2115 lustre:svname $dm_dev");;
2117 error "unknown fstype!";;
2120 echo "Starting ${facet}: $opts $dm_dev $mntpt"
2121 # for testing LU-482 error handling in mount_facets() and test_0a()
2122 if [ -f $TMP/test-lu482-trigger ]; then
2126 "mkdir -p $mntpt; $MOUNT_CMD $opts $dm_dev $mntpt"
2130 if [ $RC -ne 0 ]; then
2131 echo "Start of $dm_dev on ${facet} failed ${RC}"
2135 health=$(do_facet ${facet} "$LCTL get_param -n health_check")
2136 if [[ "$health" != "healthy" ]]; then
2137 error "$facet is in a unhealthy state"
2140 set_default_debug_facet $facet
2142 if [[ $opts =~ .*nosvc.* ]]; then
2143 echo "Start $dm_dev without service"
2148 wait_update_facet ${facet} "$E2LABEL $dm_dev \
2149 2>/dev/null | grep -E ':[a-zA-Z]{3}[0-9]{4}'" \
2150 "" || error "$dm_dev failed to initialize!";;
2152 wait_update_facet ${facet} "$ZFS get -H -o value \
2153 lustre:svname $dm_dev 2>/dev/null | \
2154 grep -E ':[a-zA-Z]{3}[0-9]{4}'" "" ||
2155 error "$dm_dev failed to initialize!";;
2158 error "unknown fstype!";;
2162 # commit the device label change to disk
2163 if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
2164 echo "Commit the device label on ${!dev}"
2165 do_facet $facet "sync; sleep 1; sync"
2169 label=$(devicelabel ${facet} $dm_dev)
2170 [ -z "$label" ] && echo no label for $dm_dev && exit 1
2171 eval export ${facet}_svc=${label}
2172 echo Started ${label}
2174 export_dm_dev $facet $dm_dev
2179 # start facet device options
2185 local dev_alias=$(facet_device_alias $facet)
2187 eval export ${dev_alias}_dev=${device}
2188 eval export ${facet}_opt=\"$@\"
2190 combined_mgs_mds && [[ ${dev_alias} == mds1 ]] &&
2191 eval export mgs_dev=${device}
2193 local varname=${dev_alias}failover_dev
2194 if [ -n "${!varname}" ] ; then
2195 eval export ${dev_alias}failover_dev=${!varname}
2197 eval export ${dev_alias}failover_dev=$device
2198 combined_mgs_mds && [[ ${dev_alias} == mds1 ]] &&
2199 eval export mgsfailover_dev=${device}
2203 local mntpt=$(facet_mntpt $facet)
2204 do_facet ${facet} mkdir -p $mntpt
2205 eval export ${facet}_MOUNT=$mntpt
2206 mount_facet ${facet}
2216 local HOST=$(facet_active_host $facet)
2217 [[ -z $HOST ]] && echo stop: no host for $facet && return 0
2219 local mntpt=$(facet_mntpt $facet)
2220 running=$(do_facet ${facet} "grep -c $mntpt' ' /proc/mounts || true")
2221 if [ ${running} -ne 0 ]; then
2222 echo "Stopping $mntpt (opts:$@) on $HOST"
2223 do_facet ${facet} $UMOUNT $@ $mntpt
2226 # umount should block, but we should wait for unrelated obd's
2227 # like the MGS or MGC to also stop.
2228 wait_exit_ST ${facet} || return ${PIPESTATUS[0]}
2230 if [[ $(facet_fstype $facet) == zfs ]]; then
2231 # export ZFS storage pool
2232 [ "$KEEP_ZPOOL" = "true" ] || export_zpool $facet
2233 elif dm_flakey_supported $facet; then
2234 local host=${facet}_HOST
2235 local failover_host=${facet}failover_HOST
2236 if [[ -n ${!failover_host} && ${!failover_host} != ${!host} ]]||
2237 $CLEANUP_DM_DEV || [[ $facet = fs* ]]; then
2238 dm_cleanup_dev $facet
2243 # get mdt quota type
2245 local varsvc=${SINGLEMDS}_svc
2246 do_facet $SINGLEMDS $LCTL get_param -n \
2247 osd-$(facet_fstype $SINGLEMDS).${!varsvc}.quota_slave.enabled
2250 # get ost quota type
2252 # All OSTs should have same quota type
2253 local varsvc=ost1_svc
2254 do_facet ost1 $LCTL get_param -n \
2255 osd-$(facet_fstype ost1).${!varsvc}.quota_slave.enabled
2258 # restore old quota type settings
2260 if [ "$old_MDT_QUOTA_TYPE" ]; then
2261 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2262 do_facet mgs $PERM_CMD \
2263 osd-*.$FSNAME-MDT*.quota_slave.enabled = \
2266 do_facet mgs $PERM_CMD \
2267 $FSNAME.quota.mdt=$old_MDT_QUOTA_TYPE
2270 if [ "$old_OST_QUOTA_TYPE" ]; then
2271 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2272 do_facet mgs $PERM_CMD \
2273 osd-*.$FSNAME-OST*.quota_slave.enabled = \
2276 do_facet mgs $LCTL conf_param \
2277 $FSNAME.quota.ost=$old_OST_QUOTA_TYPE
2282 # Handle the case when there is a space in the lfs df
2283 # "filesystem summary" line the same as when there is no space.
2284 # This will allow fixing the "lfs df" summary line in the future.
2286 $LFS df $* | sed -e 's/filesystem /filesystem_/'
2287 check_lfs_df_ret_val $?
2290 # Get free inodes on the MDT specified by mdt index, free indoes on
2291 # the whole filesystem will be returned when index == -1.
2297 if [ $index -eq -1 ]; then
2300 mdt_uuid=$(mdtuuid_from_index $index)
2303 free_inodes=$(lfs_df -i $MOUNT | grep $mdt_uuid | awk '{print $4}')
2308 # Get the OST device status from 'lfs df' with a given OST index.
2312 local mnt_pnt=${2:-$MOUNT}
2316 ost_uuid=$(ostuuid_from_index $ost_idx $mnt_pnt)
2317 lfs_df $opts $mnt_pnt | awk '/'$ost_uuid'/ { print $7 }'
2323 # save old quota type & set new quota type
2324 local mdt_qtype=$(mdt_quota_type)
2325 local ost_qtype=$(ost_quota_type)
2327 echo "[HOST:$HOSTNAME] [old_mdt_qtype:$mdt_qtype]" \
2328 "[old_ost_qtype:$ost_qtype] [new_qtype:$QUOTA_TYPE]"
2330 export old_MDT_QUOTA_TYPE=$mdt_qtype
2331 export old_OST_QUOTA_TYPE=$ost_qtype
2333 if [[ $PERM_CMD == *"set_param -P"* ]]; then
2334 do_facet mgs $PERM_CMD \
2335 osd-*.$FSNAME-MDT*.quota_slave.enabled=$QUOTA_TYPE
2336 do_facet mgs $PERM_CMD \
2337 osd-*.$FSNAME-OST*.quota_slave.enabled=$QUOTA_TYPE
2339 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$QUOTA_TYPE ||
2340 error "set mdt quota type failed"
2341 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$QUOTA_TYPE ||
2342 error "set ost quota type failed"
2345 local quota_usrs=$QUOTA_USERS
2347 # get_filesystem_size
2348 local disksz=$(lfs_df $mntpt | grep "summary" | awk '{print $2}')
2349 local blk_soft=$((disksz + 1024))
2350 local blk_hard=$((blk_soft + blk_soft / 20)) # Go 5% over
2352 local inodes=$(lfs_df -i $mntpt | grep "summary" | awk '{print $2}')
2353 local i_soft=$inodes
2354 local i_hard=$((i_soft + i_soft / 20))
2356 echo "Total disk size: $disksz block-softlimit: $blk_soft" \
2357 "block-hardlimit: $blk_hard inode-softlimit: $i_soft" \
2358 "inode-hardlimit: $i_hard"
2361 for usr in $quota_usrs; do
2362 echo "Setting up quota on $HOSTNAME:$mntpt for $usr..."
2364 cmd="$LFS setquota -$type $usr -b $blk_soft"
2365 cmd="$cmd -B $blk_hard -i $i_soft -I $i_hard $mntpt"
2367 eval $cmd || error "$cmd FAILED!"
2369 # display the quota status
2370 echo "Quota settings for $usr : "
2371 $LFS quota -v -u $usr $mntpt || true
2378 local opts=${3:-$MOUNT_OPTS}
2379 opts=${opts:+-o $opts}
2380 local flags=${4:-$MOUNT_FLAGS}
2382 local device=$MGSNID:/$FSNAME$FILESET
2383 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2384 echo "Bad mount command: opt=$flags $opts dev=$device " \
2390 # update mount option with skpath
2391 opts=$(add_sk_mntflag $opts)
2394 echo "Starting client: $client: $flags $opts $device $mnt"
2395 do_node $client mkdir -p $mnt
2396 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
2397 do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
2399 #disable FILESET if not supported
2400 do_nodes $client lctl get_param -n \
2401 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2402 device=$MGSNID:/$FSNAME
2403 do_node $client mkdir -p $mnt/$FILESET
2404 do_node $client "! grep -q $mnt' ' /proc/mounts ||
2407 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2408 # Mount using nodemap key
2409 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2410 if $SK_UNIQUE_NM; then
2411 mountkey=$SK_PATH/nodemap/c0.key
2413 local prunedopts=$(echo $opts |
2414 sed -e "s#skpath=[^,^ ]*#skpath=$mountkey#g")
2415 do_node $client $MOUNT_CMD $flags $prunedopts $device $mnt ||
2418 do_node $client $MOUNT_CMD $flags $opts $device $mnt ||
2422 set_default_debug_nodes $client
2423 set_params_clients $client
2434 local running=$(do_node $client "grep -c $mnt' ' /proc/mounts") || true
2436 [ "$3" ] && force=-f
2437 [ $running -eq 0 ] && return 0
2439 echo "Stopping client $client $mnt (opts:$force)"
2440 do_node $client lsof -t $mnt || need_kill=no
2441 if [ "x$force" != "x" ] && [ "x$need_kill" != "xno" ]; then
2442 pids=$(do_node $client lsof -t $mnt | sort -u);
2443 if [ -n "$pids" ]; then
2444 do_node $client kill -9 $pids || true
2448 busy=$(do_node $client "umount $force $mnt 2>&1" | grep -c "busy") ||
2450 if [ $busy -ne 0 ] ; then
2451 echo "$mnt is still busy, wait one second" && sleep 1
2452 do_node $client umount $force $mnt
2456 # Mount the file system on the MDS
2457 mount_mds_client() {
2458 local host=$(facet_active_host $SINGLEMDS)
2460 zconf_mount $host $MOUNT2 $MOUNT_OPTS ||
2461 error "unable to mount $MOUNT2 on $host"
2464 # Unmount the file system on the MDS
2465 umount_mds_client() {
2466 local host=$(facet_active_host $SINGLEMDS)
2467 zconf_umount $host $MOUNT2
2468 do_facet $SINGLEMDS "rmdir $MOUNT2"
2471 # nodes is comma list
2472 sanity_mount_check_nodes () {
2478 # FIXME: assume that all cluster nodes run the same os
2479 [ "$(uname)" = Linux ] || return 0
2482 for mnt in $mnts ; do
2483 do_nodes $nodes "running=\\\$(grep -c $mnt' ' /proc/mounts);
2484 mpts=\\\$(mount | grep -c $mnt' ');
2485 if [ \\\$running -ne \\\$mpts ]; then
2486 echo \\\$(hostname) env are INSANE!;
2489 [ $? -eq 0 ] || rc=1
2494 sanity_mount_check_servers () {
2495 [ -n "$CLIENTONLY" ] &&
2496 { echo "CLIENTONLY mode, skip mount_check_servers"; return 0; } || true
2497 echo Checking servers environments
2499 # FIXME: modify get_facets to display all facets wo params
2500 local facets="$(get_facets OST),$(get_facets MDS),mgs"
2504 for facet in ${facets//,/ }; do
2505 node=$(facet_host ${facet})
2506 mntpt=$(facet_mntpt $facet)
2507 sanity_mount_check_nodes $node $mntpt ||
2508 { error "server $node environments are insane!"; return 1; }
2512 sanity_mount_check_clients () {
2513 local clients=${1:-$CLIENTS}
2514 local mntpt=${2:-$MOUNT}
2515 local mntpt2=${3:-$MOUNT2}
2517 [ -z $clients ] && clients=$(hostname)
2518 echo Checking clients $clients environments
2520 sanity_mount_check_nodes $clients $mntpt $mntpt2 ||
2521 error "clients environments are insane!"
2524 sanity_mount_check () {
2525 sanity_mount_check_servers || return 1
2526 sanity_mount_check_clients || return 2
2529 # mount clients if not mouted
2530 zconf_mount_clients() {
2533 local opts=${3:-$MOUNT_OPTS}
2534 opts=${opts:+-o $opts}
2535 local flags=${4:-$MOUNT_FLAGS}
2536 local device=$MGSNID:/$FSNAME$FILESET
2537 if [ -z "$mnt" -o -z "$FSNAME" ]; then
2538 echo "Bad conf mount command: opt=$flags $opts dev=$device " \
2543 echo "Starting client $clients: $flags $opts $device $mnt"
2544 do_nodes $clients mkdir -p $mnt
2545 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ]; then
2546 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2547 # Mount with own nodemap key
2549 # Mount all server nodes first with per-NM keys
2550 for nmclient in ${clients//,/ }; do
2551 # do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key -n c$i"
2552 do_nodes $(comma_list $(all_server_nodes)) "lgss_sk -t server -l $SK_PATH/nodemap/c$i.key"
2555 # set perms for per-nodemap keys else permission denied
2556 do_nodes $(comma_list $(all_nodes)) \
2557 "keyctl show | grep lustre | cut -c1-11 |
2559 xargs -IX keyctl setperm X 0x3f3f3f3f"
2560 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2562 for nmclient in ${clients//,/ }; do
2563 if $SK_UNIQUE_NM; then
2564 mountkey=$SK_PATH/nodemap/c$i.key
2566 do_node $nmclient "! grep -q $mnt' ' \
2567 /proc/mounts || umount $mnt"
2568 local prunedopts=$(add_sk_mntflag $prunedopts);
2569 prunedopts=$(echo $prunedopts | sed -e \
2570 "s#skpath=[^ ^,]*#skpath=$mountkey#g")
2572 do_nodes $(comma_list $(all_server_nodes)) \
2575 do_node $nmclient $MOUNT_CMD $flags \
2576 $prunedopts $MGSNID:/$FSNAME $mnt ||
2581 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2583 do_nodes $clients $MOUNT_CMD $flags $opts \
2584 $MGSNID:/$FSNAME $mnt || return 1
2586 #disable FILESET if not supported
2587 do_nodes $clients lctl get_param -n \
2588 mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
2589 device=$MGSNID:/$FSNAME
2590 do_nodes $clients mkdir -p $mnt/$FILESET
2591 do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
2595 if $GSS_SK && ($SK_UNIQUE_NM || $SK_S2S); then
2596 # Mount with nodemap key
2598 local mountkey=$SK_PATH/$FSNAME-nmclient.key
2599 for nmclient in ${clients//,/ }; do
2600 if $SK_UNIQUE_NM; then
2601 mountkey=$SK_PATH/nodemap/c$i.key
2603 local prunedopts=$(echo $opts | sed -e \
2604 "s#skpath=[^ ^,]*#skpath=$mountkey#g");
2605 do_node $nmclient "! grep -q $mnt' ' /proc/mounts ||
2608 running=\\\$(mount | grep -c $mnt' ');
2610 if [ \\\$running -eq 0 ] ; then
2612 $MOUNT_CMD $flags $prunedopts $device $mnt;
2615 lustre_mnt_count=\\\$(mount | grep $mnt' ' | \
2616 grep 'type lustre' | wc -l);
2617 if [ \\\$running -ne \\\$lustre_mnt_count ] ; then
2618 echo zconf_mount_clients FAILED: \
2619 mount count \\\$running, not matching \
2620 with mount count of 'type lustre' \
2621 \\\$lustre_mnt_count;
2625 exit \\\$rc" || return ${PIPESTATUS[0]}
2632 if $SHARED_KEY; then
2633 tmpopts=$(add_sk_mntflag $opts)
2636 running=\\\$(mount | grep -c $mnt' ');
2638 if [ \\\$running -eq 0 ] ; then
2640 $MOUNT_CMD $flags $tmpopts $device $mnt;
2643 exit \\\$rc" || return ${PIPESTATUS[0]}
2646 echo "Started clients $clients: "
2647 do_nodes $clients "mount | grep $mnt' '"
2649 set_default_debug_nodes $clients
2650 set_params_clients $clients
2655 zconf_umount_clients() {
2660 [ "$3" ] && force=-f
2662 echo "Stopping clients: $clients $mnt (opts:$force)"
2663 do_nodes $clients "running=\\\$(grep -c $mnt' ' /proc/mounts);
2664 if [ \\\$running -ne 0 ] ; then
2665 echo Stopping client \\\$(hostname) $mnt opts:$force;
2666 lsof $mnt || need_kill=no;
2667 if [ "x$force" != "x" -a "x\\\$need_kill" != "xno" ]; then
2668 pids=\\\$(lsof -t $mnt | sort -u);
2669 if [ -n \\\"\\\$pids\\\" ]; then
2673 while umount $force $mnt 2>&1 | grep -q "busy"; do
2674 echo "$mnt is still busy, wait one second" && sleep 1;
2681 echo + $POWER_DOWN $node
2685 shutdown_node_hard () {
2687 local attempts=$SHUTDOWN_ATTEMPTS
2689 for i in $(seq $attempts) ; do
2692 wait_for_function --quiet "! ping -w 3 -c 1 $host" 5 1 && return 0
2693 echo "waiting for $host to fail attempts=$attempts"
2694 [ $i -lt $attempts ] || \
2695 { echo "$host still pingable after power down! attempts=$attempts" && return 1; }
2701 local mnt=${2:-$MOUNT}
2704 if [ "$FAILURE_MODE" = HARD ]; then
2705 shutdown_node_hard $client
2707 zconf_umount_clients $client $mnt -f
2713 local facets="$(get_facets OST),$(get_facets MDS)"
2716 combined_mgs_mds || facets="$facets,mgs"
2718 for facet in ${facets//,/ }; do
2719 if [ $(facet_active_host $facet) == $host ]; then
2720 affected="$affected $facet"
2724 echo $(comma_list $affected)
2729 local host=${2:-$(facet_host $facet)}
2731 local label=$(convert_facet2label $facet)
2732 do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
2735 facets_up_on_host () {
2737 local facets=$(facets_on_host $host)
2740 for facet in ${facets//,/ }; do
2741 if $(facet_up $facet $host); then
2742 affected_up="$affected_up $facet"
2746 echo $(comma_list $affected_up)
2751 local affected_facet
2752 local affected_facets
2754 if [[ "$FAILURE_MODE" = HARD ]]; then
2755 if [[ $(facet_fstype $facet) = ldiskfs ]] &&
2756 dm_flakey_supported $facet; then
2757 affected_facets=$(affected_facets $facet)
2758 for affected_facet in ${affected_facets//,/ }; do
2759 unexport_dm_dev $affected_facet
2763 shutdown_node_hard $(facet_active_host $facet)
2771 echo + $POWER_UP $node
2784 local node=$(facet_active_host $facet)
2785 local sleep_time=${2:-10}
2787 if [ "$FAILURE_MODE" = HARD ]; then
2797 if [ "$FAILURE_MODE" = HARD ]; then
2800 if $LOAD_MODULES_REMOTE; then
2801 echo "loading modules on $node: $facet"
2802 do_rpc_nodes $node load_modules_local
2811 for facet in ${facets//,/ }; do
2812 hosts=$(expand_list $hosts $(facet_host $facet) )
2818 _check_progs_installed () {
2822 for prog in $progs; do
2823 if ! [ "$(which $prog)" -o "${!prog}" ]; then
2824 echo $prog missing on $(hostname)
2831 check_progs_installed () {
2835 do_rpc_nodes "$nodes" _check_progs_installed $@
2838 # recovery-scale functions
2840 echo __$(echo $1 | tr '-' '_' | tr '.' '_')
2843 start_client_load() {
2846 local var=$(node_var_name $client)_load
2847 eval export ${var}=$load
2849 do_node $client "PATH=$PATH MOUNT=$MOUNT ERRORS_OK=$ERRORS_OK \
2850 BREAK_ON_ERROR=$BREAK_ON_ERROR \
2851 END_RUN_FILE=$END_RUN_FILE \
2852 LOAD_PID_FILE=$LOAD_PID_FILE \
2853 TESTLOG_PREFIX=$TESTLOG_PREFIX \
2854 TESTNAME=$TESTNAME \
2855 DBENCH_LIB=$DBENCH_LIB \
2856 DBENCH_SRC=$DBENCH_SRC \
2857 CLIENT_COUNT=$((CLIENTCOUNT - 1)) \
2862 MPIRUN_OPTIONS=\\\"$MPIRUN_OPTIONS\\\" \
2863 MACHINEFILE_OPTION=\\\"$MACHINEFILE_OPTION\\\" \
2864 num_clients=$(get_node_count ${CLIENTS//,/ }) \
2865 ior_THREADS=$ior_THREADS ior_iteration=$ior_iteration \
2866 ior_blockSize=$ior_blockSize \
2867 ior_blockUnit=$ior_blockUnit \
2868 ior_xferSize=$ior_xferSize ior_type=$ior_type \
2869 ior_DURATION=$ior_DURATION \
2870 ior_stripe_params=\\\"$ior_stripe_params\\\" \
2871 ior_custom_params=\\\"$ior_custom_param\\\" \
2872 mpi_ior_custom_threads=$mpi_ior_custom_threads \
2875 log "Started client load: ${load} on $client"
2877 # get the children process IDs
2878 local pids=$(ps --ppid $ppid -o pid= | xargs)
2879 CLIENT_LOAD_PIDS="$CLIENT_LOAD_PIDS $ppid $pids"
2883 start_client_loads () {
2884 local -a clients=(${1//,/ })
2885 local numloads=${#CLIENT_LOADS[@]}
2887 for ((nodenum=0; nodenum < ${#clients[@]}; nodenum++ )); do
2888 local load=$((nodenum % numloads))
2889 start_client_load ${clients[nodenum]} ${CLIENT_LOADS[load]}
2891 # bug 22169: wait the background threads to start
2895 # only for remote client
2896 check_client_load () {
2898 local var=$(node_var_name $client)_load
2899 local testload=run_${!var}.sh
2901 ps auxww | grep -v grep | grep $client | grep -q $testload || return 1
2903 # bug 18914: try to connect several times not only when
2904 # check ps, but while check_node_health also
2908 while [ $RC = 254 -a $tries -gt 0 ]; do
2912 if ! check_node_health $client; then
2914 if [ $RC -eq 254 ]; then
2915 # FIXME: not sure how long we shuold sleep here
2919 echo "check node health failed: RC=$RC "
2923 # We can continue try to connect if RC=254
2924 # Just print the warning about this
2925 if [ $RC = 254 ]; then
2926 echo "got a return status of $RC from do_node while checking " \
2927 "node health on $client"
2930 # see if the load is still on the client
2933 while [ $RC = 254 -a $tries -gt 0 ]; do
2937 if ! do_node $client \
2938 "ps auxwww | grep -v grep | grep -q $testload"; then
2943 if [ $RC = 254 ]; then
2944 echo "got a return status of $RC from do_node while checking " \
2945 "(node health and 'ps') the client load on $client"
2946 # see if we can diagnose a bit why this is
2951 check_client_loads () {
2952 local clients=${1//,/ }
2956 for client in $clients; do
2957 check_client_load $client
2959 if [ "$rc" != 0 ]; then
2960 log "Client load failed on node $client, rc=$rc"
2966 restart_client_loads () {
2967 local clients=${1//,/ }
2968 local expectedfail=${2:-""}
2972 for client in $clients; do
2973 check_client_load $client
2975 if [ "$rc" != 0 -a "$expectedfail" ]; then
2976 local var=$(node_var_name $client)_load
2977 start_client_load $client ${!var}
2978 echo "Restarted client load ${!var}: on $client. Checking ..."
2979 check_client_load $client
2981 if [ "$rc" != 0 ]; then
2982 log "Client load failed to restart on node $client, rc=$rc"
2983 # failure one client load means test fail
2984 # we do not need to check other
2993 # Start vmstat and save its process ID in a file.
2998 [ -z "$nodes" -o -z "$pid_file" ] && return 0
3001 "vmstat 1 > $TESTLOG_PREFIX.$TESTNAME.vmstat.\\\$(hostname -s).log \
3002 2>/dev/null </dev/null & echo \\\$! > $pid_file"
3005 # Display the nodes on which client loads failed.
3006 print_end_run_file() {
3010 [ -s $file ] || return 0
3012 echo "Found the END_RUN_FILE file: $file"
3015 # A client load will stop if it finds the END_RUN_FILE file.
3016 # That does not mean the client load actually failed though.
3017 # The first node in END_RUN_FILE is the one we are interested in.
3020 if [ -n "$node" ]; then
3021 local var=$(node_var_name $node)_load
3023 local prefix=$TESTLOG_PREFIX
3024 [ -n "$TESTNAME" ] && prefix=$prefix.$TESTNAME
3025 local stdout_log=$prefix.run_${!var}_stdout.$node.log
3026 local debug_log=$(echo $stdout_log | sed 's/\(.*\)stdout/\1debug/')
3028 echo "Client load ${!var} failed on node $node:"
3034 # Stop the process which had its PID saved in a file.
3039 [ -z "$nodes" -o -z "$pid_file" ] && return 0
3041 do_nodes $nodes "test -f $pid_file &&
3042 { kill -s TERM \\\$(cat $pid_file); rm -f $pid_file; }" || true
3045 # Stop all client loads.
3046 stop_client_loads() {
3047 local nodes=${1:-$CLIENTS}
3050 # stop the client loads
3051 stop_process $nodes $pid_file
3053 # clean up the processes that started them
3054 [ -n "$CLIENT_LOAD_PIDS" ] && kill -9 $CLIENT_LOAD_PIDS 2>/dev/null || true
3056 # End recovery-scale functions
3059 # wait for a command to return the expected result
3061 # This will run @check on @node repeatedly until the output matches @expect
3062 # based on the supplied condition, or until @max_wait seconds have elapsed,
3063 # whichever comes first. @cond may be one of the normal bash operators,
3064 # "-gt", "-ge", "-eq", "-le", "-lt", "==", "!=", or "=~", and must be quoted
3065 # in the caller to avoid unintentional evaluation by the shell in the caller.
3067 # If @max_wait is not specified, the condition will be checked for up to 90s.
3069 # If --verbose is passed as the first argument, the result is printed on each
3070 # value change, otherwise it is only printed after every 10s interval.
3072 # If --quiet is passed as the first/second argument, the do_node() command
3073 # will not print the remote command before executing it each time.
3075 # Using wait_update_cond() or related helper function is preferable to adding
3076 # a "long enough" wait for some state to change in the background, since
3077 # "long enough" may be too short due to tunables, system config, or running in
3078 # a VM, and must by necessity wait too long for most cases or risk failure.
3080 # usage: wait_update_cond [--verbose] [--quiet] node check cond expect [max_wait]
3081 wait_update_cond() {
3085 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3086 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3092 local max_wait=${5:-90}
3096 local begin=$SECONDS
3100 while (( $waited <= $max_wait )); do
3101 result=$(do_node $quiet $node "$check")
3103 eval [[ "'$result'" $cond "'$expect'" ]]
3104 if [[ $? == 0 ]]; then
3105 [[ -z "$result" || $waited -le $sleep ]] ||
3106 echo "Updated after ${waited}s: want '$expect' got '$result'"
3109 if [[ -n "$verbose" && "$result" != "$prev_result" ]]; then
3110 [[ -n "$prev_result" ]] &&
3111 echo "Changed after ${waited}s: from '$prev_result' to '$result'"
3112 prev_result="$result"
3114 (( $waited % $print == 0 )) &&
3115 echo "Waiting $((max_wait - waited))s for '$expect'"
3117 waited=$((SECONDS - begin))
3119 echo "Update not seen after ${max_wait}s: want '$expect' got '$result'"
3123 # usage: wait_update [--verbose] [--quiet] node check expect [max_wait]
3128 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3129 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3136 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3139 # usage: wait_update_facet_cond [--verbose] facet check cond expect [max_wait]
3140 wait_update_facet_cond() {
3144 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3145 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3147 local node=$(facet_active_host $1)
3153 wait_update_cond $verbose $quiet $node "$check" "$cond" "$expect" $max_wait
3156 # usage: wait_update_facet [--verbose] facet check expect [max_wait]
3157 wait_update_facet() {
3161 [[ "$1" == "--verbose" ]] && verbose="$1" && shift
3162 [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
3164 local node=$(facet_active_host $1)
3169 wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
3173 do_nodes $(comma_list $(mdts_nodes)) \
3174 "lctl set_param -n os[cd]*.*MDT*.force_sync=1"
3175 do_nodes $(comma_list $(osts_nodes)) \
3176 "lctl set_param -n osd*.*OS*.force_sync=1" 2>&1 |
3177 grep -v 'Found no match'
3181 local zfs_wait=${2:-5}
3183 # the occupied disk space will be released
3184 # only after TXGs are committed
3185 if [[ $(facet_fstype $1) == zfs ]]; then
3186 echo "sleep $zfs_wait for ZFS $(facet_fstype $1)"
3194 local lwm=$3 #low watermark
3195 local size_mb #how many MB should we write to pass watermark
3196 local ost_name=$(ostname_from_index $ost_idx)
3198 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3200 if (( $free_kb / 1024 > lwm )); then
3201 size_mb=$((free_kb / 1024 - lwm))
3203 #If 10% of free space cross low watermark use it
3204 if (( $free_kb / 10240 > size_mb )); then
3205 size_mb=$((free_kb / 10240))
3207 #At least we need to store 1.1 of difference between
3208 #free space and low watermark
3209 size_mb=$((size_mb + size_mb / 10))
3211 if (( lwm <= $free_kb / 1024 )) ||
3212 [ ! -f $DIR/${filename}.fill_ost$ost_idx ]; then
3213 $LFS setstripe -i $ost_idx -c1 $DIR/${filename}.fill_ost$ost_idx
3214 dd if=/dev/zero of=$DIR/${filename}.fill_ost$ost_idx bs=1M \
3215 count=$size_mb oflag=append conv=notrunc
3220 free_kb=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3221 echo "OST still has $((free_kb / 1024)) MB free"
3224 # This checks only the primary MDS
3225 ost_watermarks_get() {
3227 local ost_name=$(ostname_from_index $ost_idx)
3228 local mdtosc_proc=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
3230 local hwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3231 osp.$mdtosc_proc.reserved_mb_high)
3232 local lwm=$(do_facet $SINGLEMDS $LCTL get_param -n \
3233 osp.$mdtosc_proc.reserved_mb_low)
3238 # Note that we set watermarks on all MDSes (necessary for striped dirs)
3239 ost_watermarks_set() {
3243 local ost_name=$(ostname_from_index $ost_idx)
3244 local facets=$(get_facets MDS)
3246 do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param -n \
3247 osp.*$ost_name*.reserved_mb_low=$lwm \
3248 osp.*$ost_name*.reserved_mb_high=$hwm > /dev/null
3250 # sleep to ensure we see the change
3254 ost_watermarks_set_low_space() {
3256 local wms=$(ost_watermarks_get $ost_idx)
3257 local ost_name=$(ostname_from_index $ost_idx)
3259 local old_lwm=$(echo $wms | awk '{ print $1 }')
3260 local old_hwm=$(echo $wms | awk '{ print $2 }')
3262 local blocks=$($LFS df $MOUNT | awk "/$ost_name/ { print \$4 }")
3263 # minimal extension size is 64M
3265 if (( $blocks / 1024 > 50 )); then
3266 new_lwm=$((blocks / 1024 - 50))
3268 local new_hwm=$((new_lwm + 5))
3270 ost_watermarks_set $ost_idx $new_lwm $new_hwm
3271 echo "watermarks: $old_lwm $old_hwm $new_lwm $new_hwm"
3274 # Set watermarks to ~current available space & then write data to fill it