Whamcloud - gitweb
LU-14627 tests: Create unload_modules_local
[fs/lustre-release.git] / lustre / tests / test-framework.sh
index 41ac61e..5bb3702 100755 (executable)
@@ -293,6 +293,8 @@ init_test_env() {
        fi
        export RSYNC_RSH=${RSYNC_RSH:-rsh}
 
+       export LNETCTL=${LNETCTL:-"$LUSTRE/../lnet/utils/lnetctl"}
+       [ ! -f "$LNETCTL" ] && export LNETCTL=$(which lnetctl 2> /dev/null)
        export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
        [ ! -f "$LCTL" ] && export LCTL=$(which lctl)
        export LFS=${LFS:-"$LUSTRE/utils/lfs"}
@@ -455,10 +457,10 @@ check_cpt_number() {
 # Return a numeric version code based on a version string.  The version
 # code is useful for comparison two version strings to see which is newer.
 version_code() {
-       # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
-       eval set -- $(tr "[:punct:]" " " <<< $*)
+       # split arguments like "1.8.6-wc3" into "1", "8", "6", "3"
+       eval set -- $(tr "[:punct:][a-z]" " " <<< $*)
 
-       echo -n $(((${1:-0} << 16) | (${2:-0} << 8) | ${3:-0}))
+       echo -n $(((${1:-0}<<24) | (${2:-0}<<16) | (${3:-0}<<8) | (${4:-0})))
 }
 
 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
@@ -809,21 +811,19 @@ load_modules () {
 }
 
 check_mem_leak () {
-    LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
-    LEAK_PORTALS=$(dmesg | tail -n 20 | grep "Portals memory leaked" || true)
-    if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
-        echo "$LEAK_LUSTRE" 1>&2
-        echo "$LEAK_PORTALS" 1>&2
-        mv $TMP/debug $TMP/debug-leak.`date +%s` || true
-        echo "Memory leaks detected"
-        [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
-        return 1
-    fi
+       LEAK_LUSTRE=$(dmesg | tail -n 30 | grep "obd_memory.*leaked" || true)
+       LEAK_PORTALS=$(dmesg | tail -n 20 | egrep -i "libcfs.*memory leaked" || true)
+       if [ "$LEAK_LUSTRE" -o "$LEAK_PORTALS" ]; then
+               echo "$LEAK_LUSTRE" 1>&2
+               echo "$LEAK_PORTALS" 1>&2
+               mv $TMP/debug $TMP/debug-leak.`date +%s` || true
+               echo "Memory leaks detected"
+               [ -n "$IGNORE_LEAK" ] && { echo "ignoring leaks" && return 0; } || true
+               return 1
+       fi
 }
 
-unload_modules() {
-       wait_exit_ST client # bug 12845
-
+unload_modules_local() {
        $LUSTRE_RMMOD ldiskfs || return 2
 
        [ -f /etc/udev/rules.d/99-lustre-test.rules ] &&
@@ -831,15 +831,23 @@ unload_modules() {
        udevadm control --reload-rules
        udevadm trigger
 
+       check_mem_leak || return 254
+
+       return 0
+}
+
+unload_modules() {
+       local rc=0
+
+       wait_exit_ST client # bug 12845
+
+       unload_modules_local || rc=$?
+
        if $LOAD_MODULES_REMOTE; then
                local list=$(comma_list $(remote_nodes_list))
                if [ -n "$list" ]; then
                        echo "unloading modules on: '$list'"
-                       do_rpc_nodes "$list" $LUSTRE_RMMOD ldiskfs
-                       do_rpc_nodes "$list" check_mem_leak
-                       do_rpc_nodes "$list" "rm -f /etc/udev/rules.d/99-lustre-test.rules"
-                       do_rpc_nodes "$list" "udevadm control --reload-rules"
-                       do_rpc_nodes "$list" "udevadm trigger"
+                       do_rpc_nodes "$list" unload_modules_local
                fi
        fi
 
@@ -850,10 +858,9 @@ unload_modules() {
                        rm -f $sbin_mount
        fi
 
-       check_mem_leak || return 254
+       [[ $rc -eq 0 ]] && echo "modules unloaded."
 
-       echo "modules unloaded."
-       return 0
+       return $rc
 }
 
 fs_log_size() {
@@ -1033,6 +1040,16 @@ init_gss() {
                start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
        fi
 
+       if $GSS_SK && ! $SK_NO_KEY; then
+               echo "Loading basic SSK keys on all servers"
+               do_nodes $(comma_list $(all_server_nodes)) \
+                       "lgss_sk -t server -l $SK_PATH/$FSNAME.key || true"
+               do_nodes $(comma_list $(all_server_nodes)) \
+                               "keyctl show | grep lustre | cut -c1-11 |
+                               sed -e 's/ //g;' |
+                               xargs -IX keyctl setperm X 0x3f3f3f3f"
+       fi
+
        if $GSS_SK && $SK_NO_KEY; then
                local numclients=${1:-$CLIENTCOUNT}
                local clients=${CLIENTS:-$HOSTNAME}
@@ -1617,6 +1634,22 @@ set_default_debug_facet () {
        set_default_debug_nodes $node "$debug" "$subsys" $debug_size
 }
 
+set_params_nodes () {
+       [[ $# -ge 2 ]] || return 0
+
+       local nodes=$1
+       shift
+       do_nodes $nodes $LCTL set_param $@
+}
+
+set_params_clients () {
+       local clients=${1:-$CLIENTS}
+       local params=${2:-$CLIENT_LCTL_SETPARAM_PARAM}
+
+       [[ -n $params ]] || return 0
+       set_params_nodes $clients $params
+}
+
 set_hostid () {
     local hostid=${1:-$(hostid)}
 
@@ -2329,6 +2362,7 @@ zconf_mount() {
        fi
 
        set_default_debug_nodes $client
+       set_params_clients $client
 
        return 0
 }
@@ -2555,6 +2589,7 @@ exit \\\$rc" || return ${PIPESTATUS[0]}
        do_nodes $clients "mount | grep $mnt' '"
 
        set_default_debug_nodes $clients
+       set_params_clients $clients
 
        return 0
 }
@@ -2688,19 +2723,26 @@ remount_facet() {
 
 reboot_facet() {
        local facet=$1
+       local node=$(facet_active_host $facet)
+
        if [ "$FAILURE_MODE" = HARD ]; then
-               reboot_node $(facet_active_host $facet)
+               boot_node $node
        else
                sleep 10
        fi
 }
 
 boot_node() {
-    local node=$1
-    if [ "$FAILURE_MODE" = HARD ]; then
-       reboot_node $node
-       wait_for_host $node
-    fi
+       local node=$1
+
+       if [ "$FAILURE_MODE" = HARD ]; then
+               reboot_node $node
+               wait_for_host $node
+               if $LOAD_MODULES_REMOTE; then
+                       echo "loading modules on $node: $facet"
+                       do_rpc_nodes $node load_modules_local
+               fi
+       fi
 }
 
 facets_hosts () {
@@ -3738,16 +3780,19 @@ fail() {
 }
 
 fail_nodf() {
-        local facet=$1
-        facet_failover $facet
+       local facet=$1
+
+       facet_failover $facet
 }
 
 fail_abort() {
        local facet=$1
+       local abort_type=${2:-"abort_recovery"}
+
        stop $facet
        change_active $facet
        wait_for_facet $facet
-       mount_facet $facet -o abort_recovery
+       mount_facet $facet -o $abort_type
        clients_up || echo "first stat failed: $?"
        clients_up || error "post-failover stat: $?"
 }
@@ -4192,6 +4237,12 @@ add() {
        stop ${facet} -f
        rm -f $TMP/${facet}active
        [[ $facet = mds1 ]] && combined_mgs_mds && rm -f $TMP/mgsactive
+
+       # make sure in-tree ldiskfs is loaded before mkfs
+       if local_mode && [[ $(node_fstypes $HOSTNAME) == *ldiskfs* ]]; then
+               load_module ../ldiskfs/ldiskfs
+       fi
+
        do_facet ${facet} $MKFS $* || return ${PIPESTATUS[0]}
 
        if [[ $(facet_fstype $facet) == zfs ]]; then
@@ -5448,17 +5499,18 @@ check_and_setup_lustre() {
         export I_MOUNTED2=yes
     fi
 
-    if $do_check; then
-        # FIXME: what to do if check_config failed?
-        # i.e. if:
-        # 1) remote client has mounted other Lustre fs?
-        # 2) lustre is mounted on remote_clients atall ?
-        check_config_clients $MOUNT
-        init_facets_vars
-        init_param_vars
+       if $do_check; then
+               # FIXME: what to do if check_config failed?
+               # i.e. if:
+               # 1) remote client has mounted other Lustre fs?
+               # 2) lustre is mounted on remote_clients atall ?
+               check_config_clients $MOUNT
+               init_facets_vars
+               init_param_vars
 
-        set_default_debug_nodes $(comma_list $(nodes_list))
-    fi
+               set_default_debug_nodes $(comma_list $(nodes_list))
+               set_params_clients
+       fi
 
        if [ -z "$CLIENTONLY" -a $(lower $OSD_TRACK_DECLARES_LBUG) == 'yes' ]; then
                local facets=""
@@ -5568,6 +5620,8 @@ run_e2fsck() {
        local log=$TMP/e2fsck.log
        local rc=0
 
+       # turn on pfsck if it is supported
+       do_node $node $E2FSCK -h 2>&1 | grep -qw -- -m && cmd+=" -m8"
        echo $cmd
        do_node $node $cmd 2>&1 | tee $log
        rc=${PIPESTATUS[0]}
@@ -6041,9 +6095,9 @@ cancel_lru_locks() {
 
 default_lru_size()
 {
-        NR_CPU=$(grep -c "processor" /proc/cpuinfo)
-        DEFAULT_LRU_SIZE=$((100 * NR_CPU))
-        echo "$DEFAULT_LRU_SIZE"
+       local nr_cpu=$(grep -c "processor" /proc/cpuinfo)
+
+       echo $((100 * nr_cpu))
 }
 
 lru_resize_enable()
@@ -6053,7 +6107,10 @@ lru_resize_enable()
 
 lru_resize_disable()
 {
-    lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
+       local dev=${1}
+       local lru_size=${2:-$(default_lru_size)}
+
+       $LCTL set_param ldlm.namespaces.*$dev*.lru_size=$lru_size
 }
 
 flock_is_enabled()
@@ -6208,9 +6265,14 @@ error_noexit() {
 
 exit_status () {
        local status=0
-       local log=$TESTSUITELOG
+       local logs="$TESTSUITELOG $1"
+
+       for log in $logs; do
+               if [ -f "$log" ]; then
+                       grep -qw FAIL $log && status=1
+               fi
+       done
 
-       [ -f "$log" ] && grep -qw FAIL $log && status=1
        exit $status
 }
 
@@ -6563,7 +6625,7 @@ run_one_logged() {
 
                # remove temp files between repetitions to avoid test failures
                [ -n "$append" -a -n "$DIR" -a -n "$tdir" -a -n "$tfile" ] &&
-                       rm -rf $DIR/$tdir* $DIR/$tfile*
+                       rm -rvf $DIR/$tdir* $DIR/$tfile*
                # loop around subshell so stack_trap EXIT triggers each time
                (run_one $testnum "$testmsg") 2>&1 | tee -i $append $test_log
                rc=${PIPESTATUS[0]}
@@ -6741,7 +6803,7 @@ host_id() {
 # Description:
 #   Returns list of ip addresses for each interface
 local_addr_list() {
-       ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
+       ip addr | awk '/inet / {print $2}' | awk -F/ '{print $1}'
 }
 
 is_local_addr() {
@@ -7114,35 +7176,46 @@ add_user() {
 }
 
 check_runas_id_ret() {
-    local myRC=0
-    local myRUNAS_UID=$1
-    local myRUNAS_GID=$2
-    shift 2
-    local myRUNAS=$@
-    if [ -z "$myRUNAS" ]; then
-        error_exit "myRUNAS command must be specified for check_runas_id"
-    fi
-    if $GSS_KRB5; then
-        $myRUNAS krb5_login.sh || \
-            error "Failed to refresh Kerberos V5 TGT for UID $myRUNAS_ID."
-    fi
-    mkdir $DIR/d0_runas_test
-    chmod 0755 $DIR
-    chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
-    $myRUNAS touch $DIR/d0_runas_test/f$$ || myRC=$?
-    rm -rf $DIR/d0_runas_test
-    return $myRC
+       local myRC=0
+       local myRUNAS_UID=$1
+       local myRUNAS_GID=$2
+       shift 2
+       local myRUNAS=$@
+
+       if [ -z "$myRUNAS" ]; then
+               error_exit "check_runas_id_ret requires myRUNAS argument"
+       fi
+
+       $myRUNAS true ||
+               error "Unable to execute $myRUNAS"
+
+       id $myRUNAS_UID > /dev/null ||
+               error "Invalid RUNAS_ID $myRUNAS_UID. Please set RUNAS_ID to " \
+                     "some UID which exists on MDS and client or add user " \
+                     "$myRUNAS_UID:$myRUNAS_GID on these nodes."
+
+       if $GSS_KRB5; then
+               $myRUNAS krb5_login.sh ||
+                       error "Failed to refresh krb5 TGT for UID $myRUNAS_ID."
+       fi
+       mkdir $DIR/d0_runas_test
+       chmod 0755 $DIR
+       chown $myRUNAS_UID:$myRUNAS_GID $DIR/d0_runas_test
+       $myRUNAS -u $myRUNAS_UID -g $myRUNAS_GID touch $DIR/d0_runas_test/f$$ ||
+               myRC=$?
+       rm -rf $DIR/d0_runas_test
+       return $myRC
 }
 
 check_runas_id() {
-    local myRUNAS_UID=$1
-    local myRUNAS_GID=$2
-    shift 2
-    local myRUNAS=$@
-    check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
-        error "unable to write to $DIR/d0_runas_test as UID $myRUNAS_UID.
-        Please set RUNAS_ID to some UID which exists on MDS and client or
-        add user $myRUNAS_UID:$myRUNAS_GID on these nodes."
+       local myRUNAS_UID=$1
+       local myRUNAS_GID=$2
+       shift 2
+       local myRUNAS=$@
+
+       check_runas_id_ret $myRUNAS_UID $myRUNAS_GID $myRUNAS || \
+               error "unable to write to $DIR/d0_runas_test as " \
+                     "UID $myRUNAS_UID."
 }
 
 # obtain the UID/GID for MPI_USER
@@ -7503,8 +7576,9 @@ _wait_osc_import_state() {
                params=$param
        fi
 
+       local plist=$(comma_list $params)
        if ! do_rpc_nodes "$(facet_active_host $facet)" \
-                       wait_import_state $expected "$params" $maxtime; then
+                       wait_import_state $expected $plist $maxtime; then
                error "$facet: import is not in $expected state after $maxtime"
                return 1
        fi
@@ -7559,8 +7633,9 @@ _wait_mgc_import_state() {
                        params=$($LCTL list_param $param 2>/dev/null || true)
                done
        fi
+       local plist=$(comma_list $params)
        if ! do_rpc_nodes "$(facet_active_host $facet)" \
-                       wait_import_state $expected "$params" $maxtime \
+                       wait_import_state $expected $plist $maxtime \
                                          $error_on_failure; then
                if [ $error_on_failure -ne 0 ]; then
                    error "import is not in ${expected} state"
@@ -7892,8 +7967,11 @@ gather_logs () {
        fi
 
        if [ ! -f $LOGDIR/shared ]; then
-               do_nodes $list rsync -az "${prefix}.*.${suffix}" \
-                        $HOSTNAME:$LOGDIR
+               local remote_nodes=$(exclude_items_from_list $list $HOSTNAME)
+
+               for node in ${remote_nodes//,/ }; do
+                       rsync -az -e ssh $node:${prefix}.'*'.${suffix} $LOGDIR &
+               done
        fi
 }
 
@@ -8950,8 +9028,18 @@ pool_add_targets() {
        fi
 
        local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
+       local tg=$(for i in $list;
+               do printf -- "-e $FSNAME-OST%04x_UUID " $i; done)
+       local firstx=$(printf "%04x" $first)
+       local lastx=$(printf "%04x" $last)
+
        do_facet mgs $LCTL pool_add \
-                       $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
+               $FSNAME.$pool $FSNAME-OST[$firstx-$lastx/$step]
+       # ignore EEXIST(17)
+       if (( $? != 0 && $? != 17 )); then
+               error_noexit "pool_add $FSNAME-OST[$firstx-$lastx/$step] failed"
+               return 3
+       fi
 
        # wait for OSTs to be added to the pool
        for mds_id in $(seq $MDSCOUNT); do
@@ -8959,23 +9047,16 @@ pool_add_targets() {
                local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
                wait_update_facet mds$mds_id \
                        "lctl get_param -n lod.$lodname.pools.$pool |
-                               sort -u | tr '\n' ' ' " "$t" || {
+                               grep $tg | sort -u | tr '\n' ' '" "$t" || {
                        error_noexit "mds$mds_id: Add to pool failed"
-                       return 3
+                       return 2
                }
        done
-       wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
-                       | sort -u | tr '\n' ' ' " "$t" || {
+       wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool |
+                       grep $tg | sort -u | tr '\n' ' ' " "$t" || {
                error_noexit "Add to pool failed"
                return 1
        }
-       local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
-       local addcount=$(((last - first) / step + 1))
-       [ $lfscount -eq $addcount ] || {
-               error_noexit "lfs pool_list bad ost count" \
-                                               "$lfscount != $addcount"
-               return 2
-       }
 }
 
 pool_set_dir() {
@@ -9498,14 +9579,17 @@ check_clients_evicted() {
        local rc=0
 
        for osc in $oscs; do
-               ((rc++))
                echo "Check state for $osc"
                local evicted=$(do_facet client $LCTL get_param osc.$osc.state |
-                       tail -n 3 | awk -F"[ [,]" \
-                       '/EVICTED ]$/ { if (mx<$5) {mx=$5;} } END { print mx }')
+                       tail -n 5 | awk -F"[ ,]" \
+                       '/EVICTED/ { if (mx<$4) { mx=$4; } } END { print mx }')
                if (($? == 0)) && (($evicted > $before)); then
                        echo "$osc is evicted at $evicted"
-                       ((rc--))
+               else
+                       ((rc++))
+                       echo "$osc was not evicted after $before:"
+                       do_facet client $LCTL get_param osc.$osc.state |
+                               tail -n 8
                fi
        done
 
@@ -10027,10 +10111,16 @@ init_agt_vars() {
        export SINGLEAGT=${SINGLEAGT:-agt1}
 
        export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
+       export HSMTOOL_PID_FILE=${HSMTOOL_PID_FILE:-"/var/run/lhsmtool_posix.pid"}
        export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
        export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
        export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
        export HSMTOOL_TESTDIR
+       export HSMTOOL_ARCHIVE_FORMAT=${HSMTOOL_ARCHIVE_FORMAT:-v2}
+
+       if ! [[ $HSMTOOL =~ hsmtool ]]; then
+               echo "HSMTOOL = '$HSMTOOL' does not contain 'hsmtool', GLWT" >&2
+       fi
 
        HSM_ARCHIVE_NUMBER=2
 
@@ -10064,10 +10154,17 @@ get_mdt_devices() {
        done
 }
 
+pkill_copytools() {
+       local hosts="$1"
+       local signal="$2"
+
+       do_nodes "$hosts" "pkill --pidfile=$HSMTOOL_PID_FILE --signal=$signal hsmtool"
+}
+
 copytool_continue() {
        local agents=${1:-$(facet_active_host $SINGLEAGT)}
 
-       do_nodesv $agents "libtool execute pkill -CONT -x $HSMTOOL" || return 0
+       pkill_copytools "$agents" CONT || return 0
        echo "Copytool is continued on $agents"
 }
 
@@ -10075,7 +10172,7 @@ kill_copytools() {
        local hosts=${1:-$(facet_active_host $SINGLEAGT)}
 
        echo "Killing existing copytools on $hosts"
-       do_nodesv $hosts "libtool execute killall -q $HSMTOOL" || true
+       pkill_copytools "$hosts" TERM || return 0
        copytool_continue "$hosts"
 }
 
@@ -10111,28 +10208,29 @@ copytool_logfile()
 
 __lhsmtool_rebind()
 {
-       do_facet $facet $HSMTOOL -p "$hsm_root" --rebind "$@" "$mountpoint"
+       do_facet $facet $HSMTOOL "${hsmtool_options[@]}" --rebind "$@" "$mountpoint"
 }
 
 __lhsmtool_import()
 {
        mkdir -p "$(dirname "$2")" ||
                error "cannot create directory '$(dirname "$2")'"
-       do_facet $facet $HSMTOOL -p "$hsm_root" --import "$@" "$mountpoint"
+       do_facet $facet $HSMTOOL "${hsmtool_options[@]}" --import "$@" "$mountpoint"
 }
 
 __lhsmtool_setup()
 {
-       local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root \"$hsm_root\""
+       local host="$(facet_host "$facet")"
+       local cmd="$HSMTOOL ${hsmtool_options[@]} --daemon --pid-file=$HSMTOOL_PID_FILE"
        [ -n "$bandwidth" ] && cmd+=" --bandwidth $bandwidth"
        [ -n "$archive_id" ] && cmd+=" --archive $archive_id"
-       [ ${#misc_options[@]} -gt 0 ] &&
-               cmd+=" $(IFS=" " echo "$@")"
-       cmd+=" \"$mountpoint\""
+#      [ ${#misc_options[@]} -gt 0 ] &&
+#              cmd+=" $(IFS=" " echo "$@")"
+       cmd+=" $@ \"$mountpoint\""
 
-       echo "Starting copytool $facet on $(facet_host $facet)"
-       stack_trap "do_facet $facet libtool execute pkill -x '$HSMTOOL' || true" EXIT
-       do_facet $facet "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
+       echo "Starting copytool '$facet' on '$host' with cmdline '$cmd'"
+       stack_trap "pkill_copytools $host TERM || true" EXIT
+       do_node "$host" "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
 }
 
 hsm_root() {
@@ -10165,7 +10263,17 @@ copytool()
 
        # Parse arguments
        local fail_on_error=true
-       local -a misc_options
+       local -a hsmtool_options=("--hsm-root=$hsm_root")
+       local -a action_options=()
+
+       if [[ -n "$HSMTOOL_ARCHIVE_FORMAT" ]]; then
+               hsmtool_options+=("--archive-format=$HSMTOOL_ARCHIVE_FORMAT")
+       fi
+
+       if [[ -n "$HSMTOOL_VERBOSE" ]]; then
+               hsmtool_options+=("$HSMTOOL_VERBOSE")
+       fi
+
        while [ $# -gt 0 ]; do
                case "$1" in
                -f|--facet)
@@ -10193,7 +10301,7 @@ copytool()
                        ;;
                *)
                        # Uncommon(/copytool dependent) option
-                       misc_options+=("$1")
+                       action_options+=("$1")
                        ;;
                esac
                shift
@@ -10209,7 +10317,7 @@ copytool()
                ;;
        esac
 
-       __${copytool}_${action} "${misc_options[@]}"
+       __${copytool}_${action} "${action_options[@]}"
        if [ $? -ne 0 ]; then
                local error_msg
 
@@ -10219,8 +10327,8 @@ copytool()
                        error_msg="Failed to start copytool $facet on '$host'"
                        ;;
                import)
-                       local src="${misc_options[0]}"
-                       local dest="${misc_options[1]}"
+                       local src="${action_options[0]}"
+                       local dest="${action_options[1]}"
                        error_msg="Failed to import '$src' to '$dest'"
                        ;;
                rebind)
@@ -10491,3 +10599,32 @@ function unlinkmany() {
                do_nodes $list "$LCTL set_param debug=\\\"$saved_debug\\\""
        return $rc
 }
+
+# Check if fallocate supported on OSTs, enable if unset, default mode=0
+# Optionally pass the OST fallocate mode (0=unwritten extents, 1=zero extents)
+function check_set_fallocate()
+{
+       local new_mode="$1"
+       local osts=$(comma_list $(osts_nodes))
+       local fa_mode="osd-ldiskfs.*.fallocate_zero_blocks"
+       local old_mode=$(do_facet ost1 $LCTL get_param -n $fa_mode 2>/dev/null|
+                        head -n 1)
+
+       [[ -n "$old_mode" ]] || { echo "fallocate not supported"; return 1; }
+       [[ -z "$new_mode" && "$old_mode" != "-1" ]] &&
+               { echo "keep default fallocate mode: $old_mode"; return 0; }
+       [[ "$new_mode" && "$old_mode" == "$new_mode" ]] &&
+               { echo "keep current fallocate mode: $old_mode"; return 0; }
+
+       stack_trap "do_nodes $osts $LCTL set_param $fa_mode=$old_mode"
+       do_nodes $osts $LCTL set_param $fa_mode=${new_mode:-0} ||
+               error "set $fa_mode=$new_mode"
+}
+
+# Check if fallocate supported on OSTs, enable if unset, skip if unavailable
+function check_set_fallocate_or_skip()
+{
+       [ "$ost1_FSTYPE" != ldiskfs ] && skip "non-ldiskfs backend"
+       check_set_fallocate || skip "need at least 2.13.57 for fallocate"
+}
+