Whamcloud - gitweb
LU-2903 tests: calculation of available space
[fs/lustre-release.git] / lustre / tests / test-framework.sh
index 7384e12..25c6669 100644 (file)
@@ -118,10 +118,11 @@ print_summary () {
 }
 
 init_test_env() {
-    export LUSTRE=`absolute_path $LUSTRE`
-    export TESTSUITE=`basename $0 .sh`
-    export TEST_FAILED=false
-    export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
+       export LUSTRE=$(absolute_path $LUSTRE)
+       export TESTSUITE=$(basename $0 .sh)
+       export TEST_FAILED=false
+       export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
+       export RPC_MODE=${RPC_MODE:-false}
 
     export MKE2FS=$MKE2FS
     if [ -z "$MKE2FS" ]; then
@@ -312,10 +313,12 @@ init_test_env() {
     shift $((OPTIND - 1))
     ONLY=${ONLY:-$*}
 
-    # print the durations of each test if "true"
-    DDETAILS=${DDETAILS:-false}
-    [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
-    rm -f $TMP/*active
+       # print the durations of each test if "true"
+       DDETAILS=${DDETAILS:-false}
+       [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
+       if ! $RPC_MODE; then
+               rm -f $TMP/*active
+       fi
 }
 
 check_cpt_number() {
@@ -336,7 +339,7 @@ version_code() {
     # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
     eval set -- $(tr "[:punct:]" " " <<< $*)
 
-    echo -n $((($1 << 16) | ($2 << 8) | $3))
+    echo -n "$((($1 << 16) | ($2 << 8) | $3))"
 }
 
 export LINUX_VERSION=$(uname -r | sed -e "s/[-.]/ /3" -e "s/ .*//")
@@ -582,6 +585,18 @@ unload_modules() {
     return 0
 }
 
+fs_log_size() {
+       local facet=${1:-$SINGLEMDS}
+       local fstype=$(facet_fstype $facet)
+       local size=0
+       case $fstype in
+               ldiskfs) size=50;; # largest seen is 44, leave some headroom
+               zfs)     size=256;;
+       esac
+
+       echo -n $size
+}
+
 check_gss_daemon_nodes() {
     local list=$1
     dname=$2
@@ -732,6 +747,11 @@ facet_fstype() {
                return
        fi
 
+       if [[ $facet == mgs ]] && combined_mgs_mds; then
+               facet_fstype mds1
+               return
+       fi
+
        return 1
 }
 
@@ -788,7 +808,7 @@ ostdevlabel() {
 }
 
 #
-# This and set_obdfilter_param() shall be used to access OSD parameters
+# This and set_osd_param() shall be used to access OSD parameters
 # once existed under "obdfilter":
 #
 #   mntdev
@@ -796,7 +816,7 @@ ostdevlabel() {
 #   read_cache_enable
 #   writethrough_cache_enable
 #
-get_obdfilter_param() {
+get_osd_param() {
        local nodes=$1
        local device=${2:-$FSNAME-OST*}
        local name=$3
@@ -805,7 +825,7 @@ get_obdfilter_param() {
                osd-*.$device.$name 2>&1" | grep -v 'Found no match'
 }
 
-set_obdfilter_param() {
+set_osd_param() {
        local nodes=$1
        local device=${2:-$FSNAME-OST*}
        local name=$3
@@ -1531,6 +1551,7 @@ TESTLOG_PREFIX=$TESTLOG_PREFIX \
 TESTNAME=$TESTNAME \
 DBENCH_LIB=$DBENCH_LIB \
 DBENCH_SRC=$DBENCH_SRC \
+LFS=$LFS \
 run_${load}.sh" &
     local ppid=$!
     log "Started client load: ${load} on $client"
@@ -1888,30 +1909,44 @@ wait_recovery_complete () {
 }
 
 wait_mds_ost_sync () {
-    # just because recovery is done doesn't mean we've finished
-    # orphan cleanup. Wait for llogs to get synchronized.
-    echo "Waiting for orphan cleanup..."
-    # MAX value includes time needed for MDS-OST reconnection
-    local MAX=$(( TIMEOUT * 2 ))
-    local WAIT=0
-    while [ $WAIT -lt $MAX ]; do
-        local -a sync=($(do_nodes $(comma_list $(osts_nodes)) \
-            "$LCTL get_param -n obdfilter.*.mds_sync"))
-        local con=1
-        local i
-        for ((i=0; i<${#sync[@]}; i++)); do
-            [ ${sync[$i]} -eq 0 ] && continue
-            # there is a not finished MDS-OST synchronization
-            con=0
-            break;
-        done
-        sleep 2 # increase waiting time and cover statfs cache
-        [ ${con} -eq 1 ] && return 0
-        echo "Waiting $WAIT secs for $facet mds-ost sync done."
-        WAIT=$((WAIT + 2))
-    done
-    echo "$facet recovery not done in $MAX sec. $STATUS"
-    return 1
+       # just because recovery is done doesn't mean we've finished
+       # orphan cleanup. Wait for llogs to get synchronized.
+       echo "Waiting for orphan cleanup..."
+       # MAX value includes time needed for MDS-OST reconnection
+       local MAX=$(( TIMEOUT * 2 ))
+       local WAIT=0
+       local new_wait=true
+       local list=$(comma_list $(mdts_nodes))
+       local cmd="$LCTL get_param -n osp.*osc*.old_sync_processed"
+       if ! do_facet $SINGLEMDS \
+               "$LCTL list_param osp.*osc*.old_sync_processed 2> /dev/null"
+       then
+               # old way, use mds_sync
+               new_wait=false
+               list=$(comma_list $(osts_nodes))
+               cmd="$LCTL get_param -n obdfilter.*.mds_sync"
+       fi
+       while [ $WAIT -lt $MAX ]; do
+               local -a sync=($(do_nodes $list "$cmd"))
+               local con=1
+               local i
+               for ((i=0; i<${#sync[@]}; i++)); do
+                       if $new_wait; then
+                               [ ${sync[$i]} -eq 1 ] && continue
+                       else
+                               [ ${sync[$i]} -eq 0 ] && continue
+                       fi
+                       # there is a not finished MDS-OST synchronization
+                       con=0
+                       break;
+               done
+               sleep 2 # increase waiting time and cover statfs cache
+               [ ${con} -eq 1 ] && return 0
+               echo "Waiting $WAIT secs for $facet mds-ost sync done."
+               WAIT=$((WAIT + 2))
+       done
+       echo "$facet recovery not done in $MAX sec. $STATUS"
+       return 1
 }
 
 wait_destroy_complete () {
@@ -2109,42 +2144,42 @@ obd_name() {
 }
 
 replay_barrier() {
-    local facet=$1
-    do_facet $facet "sync; sync; sync"
-    df $MOUNT
+       local facet=$1
+       do_facet $facet "sync; sync; sync"
+       df $MOUNT
 
-    # make sure there will be no seq change
-    local clients=${CLIENTS:-$HOSTNAME}
-    local f=fsa-\\\$\(hostname\)
-    do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
-    do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
+        # make sure there will be no seq change
+       local clients=${CLIENTS:-$HOSTNAME}
+       local f=fsa-\\\$\(hostname\)
+       do_nodes $clients "mcreate $MOUNT/$f; rm $MOUNT/$f"
+       do_nodes $clients "if [ -d $MOUNT2 ]; then mcreate $MOUNT2/$f; rm $MOUNT2/$f; fi"
 
-    local svc=${facet}_svc
-    do_facet $facet $LCTL --device %${!svc} notransno
-    do_facet $facet $LCTL --device %${!svc} readonly
-    do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
-    $LCTL mark "local REPLAY BARRIER on ${!svc}"
+       local svc=${facet}_svc
+       do_facet $facet $LCTL --device ${!svc} notransno
+       do_facet $facet $LCTL --device ${!svc} readonly
+       do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
+       $LCTL mark "local REPLAY BARRIER on ${!svc}"
 }
 
 replay_barrier_nodf() {
-    local facet=$1    echo running=${running}
-    do_facet $facet "sync; sync; sync"
-    local svc=${facet}_svc
-    echo Replay barrier on ${!svc}
-    do_facet $facet $LCTL --device %${!svc} notransno
-    do_facet $facet $LCTL --device %${!svc} readonly
-    do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
-    $LCTL mark "local REPLAY BARRIER on ${!svc}"
+       local facet=$1    echo running=${running}
+       do_facet $facet "sync; sync; sync"
+       local svc=${facet}_svc
+       echo Replay barrier on ${!svc}
+       do_facet $facet $LCTL --device ${!svc} notransno
+       do_facet $facet $LCTL --device ${!svc} readonly
+       do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
+       $LCTL mark "local REPLAY BARRIER on ${!svc}"
 }
 
 replay_barrier_nosync() {
-    local facet=$1    echo running=${running}
-    local svc=${facet}_svc
-    echo Replay barrier on ${!svc}
-    do_facet $facet $LCTL --device %${!svc} notransno
-    do_facet $facet $LCTL --device %${!svc} readonly
-    do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
-    $LCTL mark "local REPLAY BARRIER on ${!svc}"
+       local facet=$1    echo running=${running}
+       local svc=${facet}_svc
+       echo Replay barrier on ${!svc}
+       do_facet $facet $LCTL --device ${!svc} notransno
+       do_facet $facet $LCTL --device ${!svc} readonly
+       do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
+       $LCTL mark "local REPLAY BARRIER on ${!svc}"
 }
 
 mds_evict_client() {
@@ -2158,8 +2193,12 @@ ost_evict_client() {
 }
 
 fail() {
-    facet_failover $* || error "failover: $?"
-    clients_up || error "post-failover df: $?"
+       local facets=$1
+       local clients=${CLIENTS:-$HOSTNAME}
+
+       facet_failover $* || error "failover: $?"
+       wait_clients_import_state "$clients" "$facets" FULL
+       clients_up || error "post-failover df: $?"
 }
 
 fail_nodf() {
@@ -2668,37 +2707,50 @@ mdsvdevname() {
 }
 
 mgsdevname() {
-       local DEVNAME=MGSDEV
-       local MDSDEV1=$(mdsdevname 1)
-
-       local fstype=$(facet_fstype mds1)
+       local DEVPTR
+       local fstype=$(facet_fstype mgs)
 
        case $fstype in
-               ldiskfs|zfs )
-                       #if $MGSDEV isn't defined, default is $MDSDEV1
-                       #ZFS independent mgsdev should be ${FSNAME}-mgs/mgs
-                       eval DEVPTR=${!DEVNAME:=${MDSDEV1}};;
-               * )
-                       error "unknown fstype!";;
+       ldiskfs )
+               if [ $(facet_host mgs) = $(facet_host mds1) ] &&
+                  ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsdevname 1) ] ); then
+                       DEVPTR=$(mdsdevname 1)
+               else
+                       DEVPTR=$MGSDEV
+               fi;;
+       zfs )
+               if [ $(facet_host mgs) = $(facet_host mds1) ] &&
+                  ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsvdevname 1) ] ); then
+                       DEVPTR=$(mdsdevname 1)
+               else
+                       DEVPTR=${FSNAME}-mgs/mgs
+               fi;;
+       * )
+               error "unknown fstype!";;
        esac
 
-    echo -n $DEVPTR
+       echo -n $DEVPTR
 }
 
 mgsvdevname() {
+       local VDEVPTR
        DEVNAME=MGSDEV
 
-       local fstype=$(facet_fstype mds1)
+       local fstype=$(facet_fstype mgs)
 
        case $fstype in
-               ldiskfs )
-                       # vdevs are not supported by ldiskfs
-                       eval VDEVPTR="";;
-               zfs )
-                       #if $MGSDEV isn't defined, default is $MGSDEV1
-                       eval VDEVPTR=${!DEVNAME:=${MDSDEV1}};;
-               * )
-                       error "unknown fstype!";;
+       ldiskfs )
+               # vdevs are not supported by ldiskfs
+               ;;
+       zfs )
+               if [ $(facet_host mgs) = $(facet_host mds1) ] &&
+                  ( [ -z "$MGSDEV" ] || [ $MGSDEV = $(mdsvdevname 1) ] ); then
+                       VDEVPTR=$(mdsvdevname 1)
+               else
+                       VDEVPTR=$MGSDEV
+               fi;;
+       * )
+               error "unknown fstype!";;
        esac
 
        echo -n $VDEVPTR
@@ -3133,18 +3185,15 @@ init_facets_vars () {
        if ! remote_mds_nodsh; then
                for num in $(seq $MDSCOUNT); do
                        DEVNAME=`mdsdevname $num`
-                       eval export MDSDEV${num}=$DEVNAME
                        init_facet_vars mds$num $DEVNAME $MDS_MOUNT_OPTS
                done
        fi
 
-       eval export MGSDEV=$(mgsdevname)
        combined_mgs_mds || init_facet_vars mgs $(mgsdevname) $MGS_MOUNT_OPTS
 
        if ! remote_ost_nodsh; then
                for num in $(seq $OSTCOUNT); do
                        DEVNAME=$(ostdevname $num)
-                       eval export OSTDEV${num}=$DEVNAME
                        init_facet_vars ost$num $DEVNAME $OST_MOUNT_OPTS
                done
        fi
@@ -3320,17 +3369,17 @@ is_mounted () {
 }
 
 is_empty_dir() {
-    [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
-    return 1
+       [ $(find $1 -maxdepth 1 -print | wc -l) = 1 ] && return 0
+       return 1
 }
 
 # empty lustre filesystem may have empty directories lost+found and .lustre
 is_empty_fs() {
-    [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
-       -print | wc -l) = 1 ] || return 1
-    [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found && return 0
-    [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre && return 0
-    return 1
+       [ $(find $1 -maxdepth 1 -name lost+found -o -name .lustre -prune -o \
+               -print | wc -l) = 1 ] || return 1
+       [ ! -d $1/lost+found ] || is_empty_dir $1/lost+found || return 1
+       [ ! -d $1/.lustre ] || is_empty_dir $1/.lustre || return 1
+       return 0
 }
 
 check_and_setup_lustre() {
@@ -3434,7 +3483,7 @@ get_mnt_devs() {
        local dev
 
        if [ "$type" == ost ]; then
-               devs=$(get_obdfilter_param $node "" mntdev)
+               devs=$(get_osd_param $node "" mntdev)
        else
                devs=$(do_node $node \
                       "lctl get_param -n osd-*.$FSNAME-M*.mntdev")
@@ -3521,17 +3570,55 @@ generate_db() {
     done
 }
 
+# Run lfsck on server node if lfsck can't be found on client (LU-2571)
+run_lfsck_remote() {
+       local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
+       local client=$1
+       local mounted=true
+       local rc=0
+
+       #Check if lustre is already mounted
+       do_rpc_nodes $client is_mounted $MOUNT || mounted=false
+       if ! $mounted; then
+               zconf_mount $client $MOUNT ||
+                       error "failed to mount Lustre on $client"
+       fi
+       #Run lfsck
+       echo $cmd
+       do_node $node $cmd || rc=$?
+       #Umount if necessary
+       if ! $mounted; then
+               zconf_umount $client $MOUNT ||
+                       error "failed to unmount Lustre on $client"
+       fi
+
+       [ $rc -le $FSCK_MAX_ERR ] ||
+               error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
+       echo "lfsck finished with rc=$rc"
+
+       return $rc
+}
+
 run_lfsck() {
-    local cmd="$LFSCK_BIN -c -l --mdsdb $MDSDB --ostdb $OSTDB_LIST $MOUNT"
-    echo $cmd
-    local rc=0
-    eval $cmd || rc=$?
-    [ $rc -le $FSCK_MAX_ERR ] || \
-        error "$cmd returned $rc, should be <= $FSCK_MAX_ERR"
-    echo "lfsck finished with rc=$rc"
+       local facets="client $SINGLEMDS"
+       local found=false
+       local facet
+       local node
+       local rc=0
 
-    rm -rvf $MDSDB* $OSTDB* || true
-    return 0
+       for facet in $facets; do
+               node=$(facet_active_host $facet)
+               if check_progs_installed $node $LFSCK_BIN; then
+                       found=true
+                       break
+               fi
+       done
+       ! $found && error "None of \"$facets\" supports lfsck"
+
+       run_lfsck_remote $node || rc=$?
+
+       rm -rvf $MDSDB* $OSTDB* || true
+       return $rc
 }
 
 check_and_cleanup_lustre() {
@@ -3773,11 +3860,11 @@ drop_reint_reply() {
 }
 
 drop_update_reply() {
-# OBD_FAIL_MDS_OBJ_UPDATE_NET
+# OBD_FAIL_UPDATE_OBJ_NET_REP
        local index=$1
        shift 1
        RC=0
-       do_facet mds${index} lctl set_param fail_loc=0x188
+       do_facet mds${index} lctl set_param fail_loc=0x1701
        do_facet client "$@" || RC=$?
        do_facet mds${index} lctl set_param fail_loc=0
        return $RC
@@ -4203,7 +4290,10 @@ run_one() {
     reset_fail_loc
     check_grant ${testnum} || error "check_grant $testnum failed with $?"
     check_catastrophe || error "LBUG/LASSERT detected"
-    ps auxww | grep -v grep | grep -q multiop && error "multiop still running"
+       if [ "$PARALLEL" != "yes" ]; then
+               ps auxww | grep -v grep | grep -q multiop &&
+                                       error "multiop still running"
+       fi
     unset TESTNAME
     unset tdir
     umask $SAVE_UMASK
@@ -4338,9 +4428,45 @@ mdtuuid_from_index()
     $LFS mdts $2 | sed -ne "/^$1: /s/.* \(.*\) .*$/\1/p"
 }
 
+# Description:
+#   Return unique identifier for given hostname
+host_id() {
+       local host_name=$1
+       echo $host_name | md5sum | cut -d' ' -f1
+}
+
+# Description:
+#   Returns list of ip addresses for each interface
+local_addr_list() {
+       ip addr | awk '/inet\ / {print $2}' | awk -F\/ '{print $1}'
+}
+
+is_local_addr() {
+       local addr=$1
+       # Cache address list to avoid mutiple execution of local_addr_list
+       LOCAL_ADDR_LIST=${LOCAL_ADDR_LIST:-$(local_addr_list)}
+       local i
+       for i in $LOCAL_ADDR_LIST ; do
+               [[ "$i" == "$addr" ]] && return 0
+       done
+       return 1
+}
+
+local_node() {
+       local host_name=$1
+       local is_local="IS_LOCAL_$(host_id $host_name)"
+       if [ -z "${!is_local-}" ] ; then
+               eval $is_local=0
+               local host_ip=$($LUSTRE/tests/resolveip $host_name)
+               is_local_addr "$host_ip" && eval $is_local=1
+       fi
+       [[ "${!is_local}" == "1" ]]
+}
+
 remote_node () {
-    local node=$1
-    [ "$node" != "$(hostname)" ]
+       local node=$1
+       local_node $node && return 1
+       return 0
 }
 
 remote_mds ()
@@ -4782,9 +4908,17 @@ check_catastrophe() {
 
        [ -z "$rnodes" ] && return 0
 
-       do_nodes "$rnodes" "rc=\\\$([ -f $C ] && echo \\\$(< $C) || echo 0);
+       local data
+       data=$(do_nodes "$rnodes" "rc=\\\$([ -f $C ] &&
+               echo \\\$(< $C) || echo 0);
                if [ \\\$rc -ne 0 ]; then echo \\\$(hostname): \\\$rc; fi
-               exit \\\$rc;"
+               exit \\\$rc")
+       local rc=$?
+       if [ -n "$data" ]; then
+           echo $data
+           return $rc
+       fi
+       return 0
 }
 
 # CMD: determine mds index where directory inode presents
@@ -4815,10 +4949,11 @@ get_mds_dir () {
 }
 
 mdsrate_cleanup () {
-    if [ -d $4 ]; then
-        mpi_run -np $1 -machinefile $2 ${MDSRATE} --unlink --nfiles $3 --dir $4 --filefmt $5 $6
-        rmdir $4
-    fi
+       if [ -d $4 ]; then
+               mpi_run -np $1 ${MACHINEFILE_OPTION} $2 ${MDSRATE} --unlink \
+                       --nfiles $3 --dir $4 --filefmt $5 $6
+               rmdir $4
+       fi
 }
 
 delayed_recovery_enabled () {
@@ -4845,7 +4980,7 @@ convert_facet2label() {
 }
 
 get_clientosc_proc_path() {
-    echo "${1}-osc-[^M]*"
+    echo "${1}-osc-*"
 }
 
 get_lustre_version () {
@@ -4909,7 +5044,7 @@ _wait_import_state () {
     local CONN_STATE
     local i=0
 
-    CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
+       CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
     while [ "${CONN_STATE}" != "${expected}" ]; do
         if [ "${expected}" == "DISCONN" ]; then
             # for disconn we can check after proc entry is removed
@@ -4922,7 +5057,8 @@ _wait_import_state () {
             error "can't put import for $CONN_PROC into ${expected} state after $i sec, have ${CONN_STATE}" && \
             return 1
         sleep 1
-        CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
+       # Add uniq for multi-mount case
+       CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2 | uniq)
         i=$(($i + 1))
     done
 
@@ -4941,6 +5077,14 @@ wait_import_state() {
     done
 }
 
+wait_import_state_mount() {
+       if ! is_mounted $MOUNT && ! is_mounted $MOUNT2; then
+               return 0
+       fi
+
+       wait_import_state $*
+}
+
 # One client request could be timed out because server was not ready
 # when request was sent by client.
 # The request timeout calculation details :
@@ -4987,14 +5131,36 @@ wait_osc_import_state() {
     local expected=$3
     local ost=$(get_osc_import_name $facet $ost_facet)
 
-    local param="osc.${ost}.ost_server_uuid"
+       local param="osc.${ost}.ost_server_uuid"
+       local i=0
 
     # 1. wait the deadline of client 1st request (it could be skipped)
     # 2. wait the deadline of client 2nd request
     local maxtime=$(( 2 * $(request_timeout $facet)))
 
+       #During setup time, the osc might not be setup, it need wait
+       #until list_param can return valid value. And also if there
+       #are mulitple osc entries we should list all of them before
+       #go to wait.
+       local params=$($LCTL list_param $param || true)
+       while [ -z "$params" ]; do
+               if [ $i -ge $maxtime ]; then
+                       echo "can't get $param by list_param in $maxtime secs"
+                       if [[ $facet != client* ]]; then
+                               echo "Go with $param directly"
+                               params=$param
+                               break
+                       else
+                               return 1
+                       fi
+               fi
+               sleep 1
+               i=$((i + 1))
+               params=$($LCTL list_param $param || true)
+       done
+
        if ! do_rpc_nodes "$(facet_host $facet)" \
-                       _wait_import_state $expected $param $maxtime; then
+                       wait_import_state $expected "$params" $maxtime; then
                error "import is not in ${expected} state"
                return 1
        fi
@@ -5039,7 +5205,7 @@ wait_clients_import_state () {
     local params=$(expand_list $params $proc_path)
     done
 
-       if ! do_rpc_nodes "$list" wait_import_state $expected $params; then
+       if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params; then
                error "import is not in ${expected} state"
                return 1
        fi
@@ -5652,7 +5818,7 @@ remove_mdt_files() {
 
        echo "removing files from $mdtdev on $facet: $files"
        if [ $(facet_fstype $facet) == ldiskfs ] &&
-          ! do_facet $facet test -b ${!dev}; then
+          ! do_facet $facet test -b $mdtdev; then
                opts=$(csa_add "$opts" -o loop)
        fi
        mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
@@ -5676,7 +5842,7 @@ duplicate_mdt_files() {
        echo "duplicating files on $mdtdev on $facet: $files"
        mkdir -p $mntpt || return $?
        if [ $(facet_fstype $facet) == ldiskfs ] &&
-          ! do_facet $facet test -b ${!dev}; then
+          ! do_facet $facet test -b $mdtdev; then
                opts=$(csa_add "$opts" -o loop)
        fi
        mount -t $(facet_fstype $facet) $opts $mdtdev $mntpt ||
@@ -5818,6 +5984,7 @@ mds_backup_restore() {
        local metadata=${TMP}/backup_restore.tgz
        local opts=${MDS_MOUNT_OPTS}
        local svc=${SINGLEMDS}_svc
+       local igif=$1
 
        if ! ${rcmd} test -b ${devname}; then
                opts=$(csa_add "$opts" -o loop)
@@ -5831,6 +5998,10 @@ mds_backup_restore() {
        ${rcmd} rm -f $metaea $metadata
        # step 3: mount dev
        ${rcmd} mount -t ldiskfs $opts $devname $mntpt || return 1
+       if [ ! -z $igif ]; then
+               # step 3.5: rm .lustre
+               ${rcmd} rm -rf $mntpt/ROOT/.lustre || return 1
+       fi
        # step 4: backup metaea
        echo "backup EA"
        ${rcmd} "cd $mntpt && getfattr -R -d -m '.*' -P . > $metaea && cd -" ||
@@ -5908,3 +6079,64 @@ generate_logname() {
 
        echo "$TESTLOG_PREFIX.$TESTNAME.$logname.$(hostname -s).log"
 }
+
+# mkdir directory on different MDTs
+test_mkdir() {
+       local option
+       local parent
+       local child
+       local path
+       local dir
+       local rc=0
+
+       if [ $# -eq 2 ]; then
+               option=$1
+               path=$2
+       else
+               path=$1
+       fi
+
+       child=${path##*/}
+       parent=${path%/*}
+
+       if [ "$parent" == "$child" ]; then
+               parent=$(pwd)
+       fi
+
+       if [ "$option" == "-p" -a -d ${parent}/${child} ]; then
+               return $rc
+       fi
+
+       # it needs to check whether there is further / in child
+       dir=$(echo $child | awk -F '/' '{print $2}')
+       if [ ! -z "$dir" ]; then
+               local subparent=$(echo $child | awk -F '/' '{ print $1 }')
+               parent=${parent}"/"${subparent}
+               child=$dir
+       fi
+
+       if [ ! -d ${parent} ]; then
+               if [ "$option" == "-p" ]; then
+                       mkdir -p ${parent}
+               else
+                       return 1
+               fi
+       fi
+
+       if [ $MDSCOUNT -le 1 ]; then
+               mkdir $option ${parent}/${child} || rc=$?
+       else
+               local mdt_idx=$($LFS getstripe -M $parent)
+
+               if [ "$mdt_idx" -ne 0 ]; then
+                       mkdir $option ${parent}/${child} || rc=$?
+                       return $rc
+               fi
+
+               local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
+               local mdt_idx=$((test_num % MDSCOUNT))
+               echo "mkdir $mdt_idx for ${parent}/${child}"
+               $LFS setdirstripe -i $mdt_idx ${parent}/${child} || rc=$?
+       fi
+       return $rc
+}