Whamcloud - gitweb
LU-4843 mdt: disallow old clients access striped dir
[fs/lustre-release.git] / lustre / tests / test-framework.sh
old mode 100644 (file)
new mode 100755 (executable)
index b4a5ade..d26cb56
@@ -24,6 +24,7 @@ export JOBID_VAR=${JOBID_VAR:-"procname_uid"}  # or "existing" or "disable"
 export LOAD_LLOOP=${LOAD_LLOOP:-false}
 
 #export PDSH="pdsh -S -Rssh -w"
+export MOUNT_CMD=${MOUNT_CMD:-"mount -t lustre"}
 
 # function used by scripts run on remote nodes
 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
@@ -90,16 +91,21 @@ print_summary () {
         local total=
         local status=Unfinished
         if [ -f $log ]; then
-            skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' | sed 's/test_//g')
-            slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g | sort -nr -k 3  | head -5 |  awk '{ print $2":"$3"s" }')
-            total=$(grep duration $log | awk '{ print $2}')
-            if [ "${!O}" = "done" ]; then
-                status=Done
-            fi
-            if $DDETAILS; then
-                local durations=$(egrep "^PASS|^FAIL" $log |  tr -d "("| sed s/s\)$//g | awk '{ print $2":"$3"|" }')
-                details=$(printf "%s\n%s %s %s\n" "$details" "DDETAILS" "$O" "$(echo $durations)")
-            fi
+               skipped=$(grep excluded $log | awk '{ printf " %s", $3 }' |
+                       sed 's/test_//g')
+               slow=$(egrep "^PASS|^FAIL" $log | tr -d "("| sed s/s\)$//g |
+                       sort -nr -k 3  | head -n5 |  awk '{ print $2":"$3"s" }')
+               total=$(grep duration $log | awk '{ print $2 }')
+               if [ "${!O}" = "done" ]; then
+                       status=Done
+               fi
+               if $DDETAILS; then
+                       local durations=$(egrep "^PASS|^FAIL" $log |
+                               tr -d "("| sed s/s\)$//g |
+                               awk '{ print $2":"$3"|" }')
+                       details=$(printf "%s\n%s %s %s\n" "$details" \
+                               "DDETAILS" "$O" "$(echo $durations)")
+               fi
         fi
         printf "$form" $status "$O" "${total}" "E=$skipped"
         printf "$form" "-" "-" "-" "S=$(echo $slow)"
@@ -355,7 +361,7 @@ version_code() {
     echo -n "$((($1 << 16) | ($2 << 8) | $3))"
 }
 
-export LINUX_VERSION=$(uname -r | sed -e "s/[-.]/ /3" -e "s/ .*//")
+export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
 
 module_loaded () {
@@ -525,20 +531,25 @@ load_modules_local() {
                load_module osp/osp
     fi
 
-
-    load_module llite/lustre
-    llite_lloop_enabled && load_module llite/llite_lloop
-    [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
-    OGDB=${OGDB:-$TMP}
-    rm -f $OGDB/ogdb-$HOSTNAME
-    $LCTL modules > $OGDB/ogdb-$HOSTNAME
-
-    # 'mount' doesn't look in $PATH, just sbin
-    if [ -f $LUSTRE/utils/mount.lustre ] && \
-       ! grep -qe "/sbin/mount\.lustre " /proc/mounts; then
-        [ ! -f /sbin/mount.lustre ] && touch /sbin/mount.lustre
-        mount --bind $LUSTRE/utils/mount.lustre /sbin/mount.lustre || true
-    fi
+       load_module llite/lustre
+       llite_lloop_enabled && load_module llite/llite_lloop
+       [ -d /r ] && OGDB=${OGDB:-"/r/tmp"}
+       OGDB=${OGDB:-$TMP}
+       rm -f $OGDB/ogdb-$HOSTNAME
+       $LCTL modules > $OGDB/ogdb-$HOSTNAME
+
+       # 'mount' doesn't look in $PATH, just sbin
+       local MOUNT_LUSTRE=$LUSTRE/utils/mount.lustre
+       if [ -f $MOUNT_LUSTRE ]; then
+               if grep -qe "/sbin/mount\.lustre " /proc/mounts; then
+                       cmp $MOUNT_LUSTRE /sbin/mount.lustre ||
+                               umount /sbin/mount.lustre
+               fi
+               if ! grep -qe "/sbin/mount\.lustre " /proc/mounts; then
+                       [ ! -f /sbin/mount.lustre ] && touch /sbin/mount.lustre
+                       mount --bind $MOUNT_LUSTRE /sbin/mount.lustre
+               fi
+       fi
 }
 
 load_modules () {
@@ -649,7 +660,6 @@ start_gss_daemons() {
     fi
 
     local list=$(comma_list $(mdts_nodes))
-
     echo "Starting gss daemon on mds: $list"
     do_nodes $list "$LSVCGSSD -v" || return 1
     if $GSS_PIPEFS; then
@@ -686,7 +696,7 @@ start_gss_daemons() {
 
 stop_gss_daemons() {
     local list=$(comma_list $(mdts_nodes))
-    
+
     send_sigint $list lsvcgssd lgssd
 
     list=$(comma_list $(osts_nodes))
@@ -703,7 +713,9 @@ init_gss() {
             module_loaded ptlrpc_gss ||
                 error_exit "init_gss : GSS=$GSS, but gss/krb5 is not supported!"
         fi
-        start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
+        if $GSS_KRB5; then
+                start_gss_daemons || error_exit "start gss daemon failed! rc=$?"
+        fi
 
         if [ -n "$LGSS_KEYRING_DEBUG" ]; then
             echo $LGSS_KEYRING_DEBUG > /proc/fs/lustre/sptlrpc/gss/lgss_keyring/debug_level
@@ -1138,7 +1150,7 @@ mount_facet() {
        if [ -f $TMP/test-lu482-trigger ]; then
                RC=2
        else
-               do_facet ${facet} "mkdir -p $mntpt; mount -t lustre $opts \
+               do_facet ${facet} "mkdir -p $mntpt; $MOUNT_CMD $opts \
                                   ${!dev} $mntpt"
                RC=${PIPESTATUS[0]}
        fi
@@ -1171,12 +1183,19 @@ start() {
         eval export ${facet}failover_dev=$device
     fi
 
-    local mntpt=$(facet_mntpt $facet)
-    do_facet ${facet} mkdir -p $mntpt
-    eval export ${facet}_MOUNT=$mntpt
-    mount_facet ${facet}
-    RC=$?
-    return $RC
+       local mntpt=$(facet_mntpt $facet)
+       do_facet ${facet} mkdir -p $mntpt
+       eval export ${facet}_MOUNT=$mntpt
+       mount_facet ${facet}
+       RC=$?
+
+       if [[ $facet == mds* ]]; then
+               do_facet $facet \
+                       lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
+                               2>/dev/null
+       fi
+
+       return $RC
 }
 
 stop() {
@@ -1240,7 +1259,7 @@ quota_type() {
                rc=$?
        do_nodes $(comma_list $(osts_nodes)) \
                lctl get_param obdfilter.${fsname}-OST*.quota_type || rc=$?
-       return $rc 
+       return $rc
 }
 
 # XXX This function is kept for interoperability with old server (< 2.3.50),
@@ -1429,7 +1448,7 @@ zconf_mount() {
 
     echo "Starting client: $client: $OPTIONS $device $mnt"
     do_node $client mkdir -p $mnt
-    do_node $client mount -t lustre $OPTIONS $device $mnt || return 1
+    do_node $client $MOUNT_CMD $OPTIONS $device $mnt || return 1
 
     set_default_debug_nodes $client
 
@@ -1540,7 +1559,7 @@ running=\\\$(mount | grep -c $mnt' ');
 rc=0;
 if [ \\\$running -eq 0 ] ; then
     mkdir -p $mnt;
-    mount -t lustre $OPTIONS $device $mnt;
+    $MOUNT_CMD $OPTIONS $device $mnt;
     rc=\\\$?;
 fi;
 exit \\\$rc" || return ${PIPESTATUS[0]}
@@ -1630,7 +1649,7 @@ facet_up() {
        local host=${2:-$(facet_host $facet)}
 
        local label=$(convert_facet2label $facet)
-       do_node $host $LCTL dl | awk '{print $4}' | grep -q -x $label
+       do_node $host $LCTL dl | awk '{ print $4 }' | grep -q "^$label\$"
 }
 
 facets_up_on_host () {
@@ -1923,18 +1942,18 @@ stop_client_loads() {
 
 # verify that lustre actually cleaned up properly
 cleanup_check() {
-    [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
-        error "LBUG/LASSERT detected"
-    BUSY=`dmesg | grep -i destruct || true`
-    if [ "$BUSY" ]; then
-        echo "$BUSY" 1>&2
-        [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.`date +%s`
-        exit 205
-    fi
+       [ -f "$CATASTROPHE" ] && [[ $(< $CATASTROPHE) -ne 0 ]] &&
+               error "LBUG/LASSERT detected"
+       BUSY=$(dmesg | grep -i destruct || true)
+       if [ -n "$BUSY" ]; then
+               echo "$BUSY" 1>&2
+               [ -e $TMP/debug ] && mv $TMP/debug $TMP/debug-busy.$(date +%s)
+               exit 205
+       fi
 
-    check_mem_leak || exit 204
+       check_mem_leak || exit 204
 
-       [ "`lctl dl 2> /dev/null | wc -l`" -gt 0 ] && lctl dl &&
+       [[ $($LCTL dl 2>/dev/null | wc -l) -gt 0 ]] && $LCTL dl &&
                echo "$TESTSUITE: lustre didn't clean up..." 1>&2 &&
                return 202 || true
 
@@ -2004,39 +2023,39 @@ sync_all_data() {
 wait_delete_completed_mds() {
        local MAX_WAIT=${1:-20}
        local mds2sync=""
-       local stime=`date +%s`
+       local stime=$(date +%s)
        local etime
        local node
        local changes
 
        # find MDS with pending deletions
        for node in $(mdts_nodes); do
-               changes=$(do_node $node "lctl get_param -n osc.*MDT*.sync_*" \
+               changes=$(do_node $node "$LCTL get_param -n osc.*MDT*.sync_*" \
                        2>/dev/null | calc_sum)
-               if [ -z "$changes" ] || [ $changes -eq 0 ]; then
+               if [[ $changes -eq 0 ]]; then
                        continue
                fi
                mds2sync="$mds2sync $node"
        done
-       if [ "$mds2sync" == "" ]; then
+       if [ -z "$mds2sync" ]; then
                return
        fi
        mds2sync=$(comma_list $mds2sync)
 
        # sync MDS transactions
-       do_nodes $mds2sync "lctl set_param -n osd*.*MD*.force_sync 1"
+       do_nodes $mds2sync "$LCTL set_param -n osd*.*MD*.force_sync 1"
 
        # wait till all changes are sent and commmitted by OSTs
        # for ldiskfs space is released upon execution, but DMU
        # do this upon commit
 
        local WAIT=0
-       while [ "$WAIT" -ne "$MAX_WAIT" ]; do
-               changes=$(do_nodes $mds2sync "lctl get_param -n osc.*MDT*.sync_*" \
-                       | calc_sum)
+       while [[ $WAIT -ne $MAX_WAIT ]]; do
+               changes=$(do_nodes $mds2sync \
+                       "$LCTL get_param -n osc.*MDT*.sync_*" | calc_sum)
                #echo "$node: $changes changes on all"
-               if [ "$changes" -eq "0" ]; then
-                       etime=`date +%s`
+               if [[ $changes -eq 0 ]]; then
+                       etime=$(date +%s)
                        #echo "delete took $((etime - stime)) seconds"
                        return
                fi
@@ -2044,9 +2063,9 @@ wait_delete_completed_mds() {
                WAIT=$(( WAIT + 1))
        done
 
-       etime=`date +%s`
+       etime=$(date +%s)
        echo "Delete is not completed in $((etime - stime)) seconds"
-       do_nodes $mds2sync "lctl get_param osc.*MDT*.sync_*"
+       do_nodes $mds2sync "$LCTL get_param osc.*MDT*.sync_*"
 }
 
 wait_for_host() {
@@ -2269,7 +2288,7 @@ client_evicted() {
     ! client_up $1
 }
 
-client_reconnect() {
+client_reconnect_try() {
     uname -n >> $MOUNT/recon
     if [ -z "$CLIENTS" ]; then
         df $MOUNT; uname -n >> $MOUNT/recon
@@ -2282,6 +2301,14 @@ client_reconnect() {
     rm $MOUNT/recon
 }
 
+client_reconnect() {
+       # one client_reconnect_try call does not always do the job...
+       while true ; do
+               client_reconnect_try && break
+               sleep 1
+       done
+}
+
 affected_facets () {
     local facet=$1
 
@@ -3249,6 +3276,12 @@ mkfs_opts() {
                opts+=${L_GETIDENTITY:+" --param=mdt.identity_upcall=$L_GETIDENTITY"}
 
                if [ $fstype == ldiskfs ]; then
+                       # Check for wide striping
+                       if [ $OSTCOUNT -gt 160 ]; then
+                               MDSJOURNALSIZE=${MDSJOURNALSIZE:-4096}
+                               fs_mkfs_opts+="-O large_xattr"
+                       fi
+
                        fs_mkfs_opts+=${MDSJOURNALSIZE:+" -J size=$MDSJOURNALSIZE"}
                        if [ ! -z $EJOURNAL ]; then
                                fs_mkfs_opts+=${MDSJOURNALSIZE:+" device=$EJOURNAL"}
@@ -3831,6 +3864,13 @@ check_and_setup_lustre() {
                set_flavor_all $SEC
        fi
 
+       #Enable remote MDT create for testing
+       for num in $(seq $MDSCOUNT); do
+               do_facet mds$num \
+                       lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
+                               2>/dev/null
+       done
+
        if [ "$ONLY" == "setup" ]; then
                exit 0
        fi
@@ -4057,18 +4097,22 @@ check_and_cleanup_lustre() {
                [ "$ENABLE_QUOTA" ] && restore_quota || true
        fi
 
-    if [ "$I_UMOUNTED2" = "yes" ]; then
-        restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
-    fi
+       if [ "$I_UMOUNTED2" = "yes" ]; then
+               restore_mount $MOUNT2 || error "restore $MOUNT2 failed"
+       fi
 
-    if [ "$I_MOUNTED2" = "yes" ]; then
-        cleanup_mount $MOUNT2
-    fi
+       if [ "$I_MOUNTED2" = "yes" ]; then
+               cleanup_mount $MOUNT2
+       fi
 
-    if [ "$I_MOUNTED" = "yes" ]; then
-        cleanupall -f || error "cleanup failed"
-        unset I_MOUNTED
-    fi
+       if [ "$I_MOUNTED" = "yes" ]; then
+               cleanupall -f || error "cleanup failed"
+               unset I_MOUNTED
+       fi
+
+       if grep -qe "/sbin/mount\.lustre " /proc/mounts; then
+               umount /sbin/mount.lustre
+       fi
 }
 
 #######
@@ -4375,6 +4419,13 @@ lru_resize_disable()
     lctl set_param ldlm.namespaces.*$1*.lru_size $(default_lru_size)
 }
 
+flock_is_enabled()
+{
+       local RC=0
+       [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] && RC=1
+       return $RC
+}
+
 pgcache_empty() {
     local FILE
     for FILE in `lctl get_param -N "llite.*.dump_page_cache"`; do
@@ -4575,64 +4626,64 @@ export ALWAYS_SKIPPED=
 # run or not run.  These need to be documented...
 #
 run_test() {
-    assert_DIR
-
-    export base=`basetest $1`
-    if [ ! -z "$ONLY" ]; then
-        testname=ONLY_$1
-        if [ ${!testname}x != x ]; then
-            [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
-            run_one_logged $1 "$2"
-            return $?
-        fi
-        testname=ONLY_$base
-        if [ ${!testname}x != x ]; then
-            [ "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
-            run_one_logged $1 "$2"
-            return $?
-        fi
-        LAST_SKIPPED="y"
-        return 0
-    fi
+       assert_DIR
+
+       export base=$(basetest $1)
+       if [ -n "$ONLY" ]; then
+               testname=ONLY_$1
+               if [ ${!testname}x != x ]; then
+                       [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
+                       run_one_logged $1 "$2"
+                       return $?
+               fi
+               testname=ONLY_$base
+               if [ ${!testname}x != x ]; then
+                       [ -n "$LAST_SKIPPED" ] && echo "" && LAST_SKIPPED=
+                       run_one_logged $1 "$2"
+                       return $?
+               fi
+               LAST_SKIPPED="y"
+               return 0
+       fi
 
        LAST_SKIPPED="y"
        ALWAYS_SKIPPED="y"
-    testname=EXCEPT_$1
-    if [ ${!testname}x != x ]; then
-        TESTNAME=test_$1 skip "skipping excluded test $1"
-        return 0
-    fi
-    testname=EXCEPT_$base
-    if [ ${!testname}x != x ]; then
-        TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
-        return 0
-    fi
-    testname=EXCEPT_ALWAYS_$1
-    if [ ${!testname}x != x ]; then
-        TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
-        return 0
-    fi
-    testname=EXCEPT_ALWAYS_$base
-    if [ ${!testname}x != x ]; then
-        TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
-        return 0
-    fi
-    testname=EXCEPT_SLOW_$1
-    if [ ${!testname}x != x ]; then
-        TESTNAME=test_$1 skip "skipping SLOW test $1"
-        return 0
-    fi
-    testname=EXCEPT_SLOW_$base
-    if [ ${!testname}x != x ]; then
-        TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
-        return 0
-    fi
+       testname=EXCEPT_$1
+       if [ ${!testname}x != x ]; then
+               TESTNAME=test_$1 skip "skipping excluded test $1"
+               return 0
+       fi
+       testname=EXCEPT_$base
+       if [ ${!testname}x != x ]; then
+               TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
+               return 0
+       fi
+       testname=EXCEPT_ALWAYS_$1
+       if [ ${!testname}x != x ]; then
+               TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1"
+               return 0
+       fi
+       testname=EXCEPT_ALWAYS_$base
+       if [ ${!testname}x != x ]; then
+               TESTNAME=test_$1 skip "skipping ALWAYS excluded test $1 (base $base)"
+               return 0
+       fi
+       testname=EXCEPT_SLOW_$1
+       if [ ${!testname}x != x ]; then
+               TESTNAME=test_$1 skip "skipping SLOW test $1"
+               return 0
+       fi
+       testname=EXCEPT_SLOW_$base
+       if [ ${!testname}x != x ]; then
+               TESTNAME=test_$1 skip "skipping SLOW test $1 (base $base)"
+               return 0
+       fi
 
-    LAST_SKIPPED=
-    ALWAYS_SKIPPED=
-    run_one_logged $1 "$2"
+       LAST_SKIPPED=
+       ALWAYS_SKIPPED=
+       run_one_logged $1 "$2"
 
-    return $?
+       return $?
 }
 
 log() {
@@ -4750,14 +4801,14 @@ run_one() {
 #  - test result is saved to data file
 #
 run_one_logged() {
-       local BEFORE=`date +%s`
+       local BEFORE=$(date +%s)
        local TEST_ERROR
        local name=${TESTSUITE}.test_${1}.test_log.$(hostname -s).log
        local test_log=$LOGDIR/$name
        rm -rf $LOGDIR/err
        rm -rf $LOGDIR/ignore
        rm -rf $LOGDIR/skip
-       local SAVE_UMASK=`umask`
+       local SAVE_UMASK=$(umask)
        umask 0022
 
        echo
@@ -4768,7 +4819,7 @@ run_one_logged() {
        [ $RC -ne 0 ] && [ ! -f $LOGDIR/err ] &&
                echo "test_$1 returned $RC" | tee $LOGDIR/err
 
-       duration=$((`date +%s` - $BEFORE))
+       duration=$(($(date +%s) - $BEFORE))
        pass "$1" "(${duration}s)"
 
        if [[ -f $LOGDIR/err ]]; then
@@ -4803,46 +4854,45 @@ skip_logged(){
 }
 
 canonical_path() {
-    (cd `dirname $1`; echo $PWD/`basename $1`)
+       (cd $(dirname $1); echo $PWD/$(basename $1))
 }
 
 
 check_grant() {
-    export base=`basetest $1`
-    [ "$CHECK_GRANT" == "no" ] && return 0
+       export base=$(basetest $1)
+       [ "$CHECK_GRANT" == "no" ] && return 0
 
-        testname=GCHECK_ONLY_${base}
-        [ ${!testname}x == x ] && return 0
+       testname=GCHECK_ONLY_${base}
+       [ ${!testname}x == x ] && return 0
 
-    echo -n "checking grant......"
+       echo -n "checking grant......"
 
-        local clients=$CLIENTS
-        [ -z $clients ] && clients=$(hostname)
+       local clients=$CLIENTS
+       [ -z "$clients" ] && clients=$(hostname)
 
-    # sync all the data and make sure no pending data on server
-    do_nodes $clients sync
-
-    # get client grant
-    client_grant=`do_nodes $clients \
-                    "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" | \
-                    awk '{total += $1} END{print total}'`
-
-    # get server grant
-    server_grant=`do_nodes $(comma_list $(osts_nodes)) \
-                    "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
-                    awk '{total += $1} END{print total}'`
-
-    # check whether client grant == server grant
-    if [ $client_grant -ne $server_grant ]; then
-        echo "failed: client:${client_grant} server: ${server_grant}."
-        do_nodes $(comma_list $(osts_nodes)) \
-                   "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
-        do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
-        return 1
-    else
-        echo "pass: client:${client_grant} server: ${server_grant}"
-    fi
+       # sync all the data and make sure no pending data on server
+       do_nodes $clients sync
+
+       # get client grant
+       client_grant=$(do_nodes $clients \
+               "$LCTL get_param -n osc.${FSNAME}-*.cur_*grant_bytes" |
+               awk '{ total += $1 } END { printf("%0.0f", total) }')
+
+       # get server grant
+       server_grant=$(do_nodes $(comma_list $(osts_nodes)) \
+               "$LCTL get_param -n obdfilter.${FSNAME}-OST*.tot_granted" |
+               awk '{ total += $1 } END { printf("%0.0f", total) }')
 
+       # check whether client grant == server grant
+       if [[ $client_grant -ne $server_grant ]]; then
+               echo "failed: client:${client_grant} server: ${server_grant}."
+               do_nodes $(comma_list $(osts_nodes)) \
+                       "$LCTL get_param obdfilter.${FSNAME}-OST*.tot*"
+               do_nodes $clients "$LCTL get_param osc.${FSNAME}-*.cur_*_bytes"
+               return 1
+       else
+               echo "pass: client:${client_grant} server: ${server_grant}"
+       fi
 }
 
 ########################
@@ -5184,14 +5234,14 @@ get_stripe () {
 }
 
 setstripe_nfsserver () {
-    local dir=$1
+       local dir=$1
 
-    local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
-                { print $1 }' /proc/mounts | cut -f 1 -d : | head -1)
+       local nfsserver=$(awk '"'$dir'" ~ $2 && $3 ~ "nfs" && $2 != "/" \
+               { print $1 }' /proc/mounts | cut -f 1 -d : | head -n1)
 
-    [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
+       [ -z $nfsserver ] && echo "$dir is not nfs mounted" && return 1
 
-    do_nodev $nfsserver lfs setstripe "$@"
+       do_nodev $nfsserver lfs setstripe "$@"
 }
 
 # Check and add a test group.
@@ -5347,7 +5397,7 @@ do_and_time () {
 
     SECONDS=0
     eval '$cmd'
-    
+
     [ ${PIPESTATUS[0]} -eq 0 ] || rc=1
 
     echo $SECONDS
@@ -5355,8 +5405,9 @@ do_and_time () {
 }
 
 inodes_available () {
-    local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{print $4}' | sort -un | head -1) || return 1
-    echo $IFree
+       local IFree=$($LFS df -i $MOUNT | grep ^$FSNAME | awk '{ print $4 }' |
+               sort -un | head -n1) || return 1
+       echo $((IFree))
 }
 
 mdsrate_inodes_available () {
@@ -5371,25 +5422,25 @@ clear_llite_stats(){
 
 # sum llite stat items
 calc_llite_stats() {
-        local res=$(lctl get_param -n llite.*.stats |
-                    awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
-        echo $res
+       local res=$(lctl get_param -n llite.*.stats |
+               awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
+       echo $((res))
 }
 
 # reset osc stat counters
 clear_osc_stats(){
-        lctl set_param -n osc.*.osc_stats 0
+       lctl set_param -n osc.*.osc_stats 0
 }
 
 # sum osc stat items
 calc_osc_stats() {
-        local res=$(lctl get_param -n osc.*.osc_stats |
-                    awk 'BEGIN {s = 0} END {print s} /^'"$1"'/ {s += $2}')
-        echo $res
+       local res=$(lctl get_param -n osc.*.osc_stats |
+               awk '/^'"$1"'/ {sum += $2} END { printf("%0.0f", sum) }')
+       echo $((res))
 }
 
 calc_sum () {
-        awk 'BEGIN {s = 0}; {s += $1}; END {print s}'
+       awk '{sum += $1} END { printf("%0.0f", sum) }'
 }
 
 calc_osc_kbytes () {
@@ -6696,24 +6747,41 @@ test_mkdir() {
        local parent
        local child
        local path
+       local p_option
+       local option2
+       local stripe_count=2
        local rc=0
 
        case $# in
                1) path=$1;;
                2) option=$1
                   path=$2;;
+               3) option=$1
+                  option2=$2
+                  path=$3;;
                *) error "Only creating single directory is supported";;
        esac
 
        child=$(basename $path)
        parent=$(dirname $path)
 
-       if [ "$option" == "-p" -a -d $parent/$child ]; then
-               return $rc
+       if [ "$option" == "-p" -o "$option2" == "-p" ]; then
+               if [ -d $parent/$child ]; then
+                       return $rc
+               fi
+               p_option="-p"
+       fi
+
+       if [ "${option:0:2}" == "-c" ]; then
+               stripe_count=$(echo $option | sed 's/^-c//')
+       fi
+
+       if [ "${option2:0:2}" == "-c" ]; then
+               stripe_count=$(echo $option2 | sed 's/^-c//')
        fi
 
        if [ ! -d ${parent} ]; then
-               if [ "$option" == "-p" ]; then
+               if [ "$p_option" == "-p" ]; then
                        mkdir -p ${parent}
                else
                        return 1
@@ -6721,18 +6789,14 @@ test_mkdir() {
        fi
 
        if [ $MDSCOUNT -le 1 ]; then
-               mkdir $option $parent/$child || rc=$?
+               mkdir $p_option $parent/$child || rc=$?
        else
                local mdt_idx=$($LFS getstripe -M $parent)
                local test_num=$(echo $testnum | sed -e 's/[^0-9]*//g')
 
-               if [ "$mdt_idx" -ne 0 ]; then
-                       mkdir $option $parent/$child || rc=$?
-               else
-                       mdt_idx=$((test_num % MDSCOUNT))
-                       echo "mkdir $mdt_idx for $parent/$child"
-                       $LFS setdirstripe -i $mdt_idx $parent/$child || rc=$?
-               fi
+               mdt_idx=$((test_num % MDSCOUNT))
+               echo "striped dir -i$mdt_idx -c$stripe_count $path"
+               $LFS setdirstripe -i$mdt_idx -c$stripe_count $path || rc=$?
        fi
        return $rc
 }
@@ -6748,3 +6812,27 @@ free_fd()
         [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
         echo $fd
 }
+
+check_mount_and_prep()
+{
+       is_mounted $MOUNT || setupall
+
+       rm -rf $DIR/[df][0-9]* || error "Fail to cleanup the env!"
+       mkdir $DIR/$tdir || error "Fail to mkdir $DIR/$tdir."
+}
+
+# calcule how many ost-objects to be created.
+precreated_ost_obj_count()
+{
+       local mdt_idx=$1
+       local ost_idx=$2
+       local mdt_name="MDT$(printf '%04x' $mdt_idx)"
+       local ost_name="OST$(printf '%04x' $ost_idx)"
+       local proc_path="${FSNAME}-${ost_name}-osc-${mdt_name}"
+       local last_id=$(do_facet mds${mdt_idx} lctl get_param -n \
+                       osp.$proc_path.prealloc_last_id)
+       local next_id=$(do_facet mds${mdt_idx} lctl get_param -n \
+                       osp.$proc_path.prealloc_next_id)
+
+       echo $((last_id - next_id + 1))
+}