Whamcloud - gitweb
o=Adilger
[fs/lustre-release.git] / lustre / tests / sanity.sh
index 4db4a3c..c50519f 100644 (file)
@@ -7,8 +7,8 @@
 set -e
 
 ONLY=${ONLY:-"$*"}
-# bug number for skipped test: 2108 9789 3637 9789 3561 12622 12653 12653 5188 10764 16260
-ALWAYS_EXCEPT="                42a  42b  42c  42d  45   51d   65a   65e   68   75    119d  $SANITY_EXCEPT"
+# bug number for skipped test: 13297 2108 9789 3637 9789 3561 12622 12653 12653 5188 10764 16260
+ALWAYS_EXCEPT="                27u   42a  42b  42c  42d  45   51d   65a   65e   68b   75    119d  $SANITY_EXCEPT"
 # bug number for skipped test: 2108 9789 3637 9789 3561 5188/5749 1443
 #ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"27m 42a 42b 42c 42d 45 68 76"}
 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
@@ -46,7 +46,6 @@ MCREATE=${MCREATE:-mcreate}
 OPENFILE=${OPENFILE:-openfile}
 OPENUNLINK=${OPENUNLINK:-openunlink}
 READS=${READS:-"reads"}
-TOEXCL=${TOEXCL:-toexcl}
 TRUNCATE=${TRUNCATE:-truncate}
 MUNLINK=${MUNLINK:-munlink}
 SOCKETSERVER=${SOCKETSERVER:-socketserver}
@@ -73,7 +72,7 @@ LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
 init_test_env $@
 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
 
-[ "$SLOW" = "no" ] && EXCEPT_SLOW="24o 27m 36f 36g 51b 51c 60c 63 64b 68 71 73 77f 78 101 103 115 120g 124b"
+[ "$SLOW" = "no" ] && EXCEPT_SLOW="24o 24v 27m 36f 36g 51b 51c 60c 63 64b 68 71 73 77f 78 101 103 115 120g 124b"
 
 SANITYLOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
 FAIL_ON_ERROR=false
@@ -91,11 +90,12 @@ setup() {
 }
 
 check_kernel_version() {
-       VERSION_FILE=version
        WANT_VER=$1
-       GOT_VER=$(lctl get_param -n $VERSION_FILE | awk '/kernel:/ {print $2}')
-       [ $GOT_VER == "patchless" ] && return 0
-       [ $GOT_VER -ge $WANT_VER ] && return 0
+       GOT_VER=$(lctl get_param -n version | awk '/kernel:/ {print $2}')
+       case $GOT_VER in
+       patchless|patchless_client) return 0;;
+       *) [ $GOT_VER -ge $WANT_VER ] && return 0 ;;
+       esac
        log "test needs at least kernel version $WANT_VER, running $GOT_VER"
        return 1
 }
@@ -112,11 +112,13 @@ check_and_setup_lustre
 DIR=${DIR:-$MOUNT}
 assert_DIR
 
-LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
-OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
-STRIPECOUNT=`lctl get_param -n lov.$LOVNAME.stripecount`
-STRIPESIZE=`lctl get_param -n lov.$LOVNAME.stripesize`
-ORIGFREE=`lctl get_param -n lov.$LOVNAME.kbytesavail`
+MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid | \
+    awk '{gsub(/_UUID/,""); print $1}' | head -1)
+LOVNAME=$($LCTL get_param -n llite.*.lov.common_name | tail -n 1)
+OSTCOUNT=$($LCTL get_param -n lov.$LOVNAME.numobd)
+STRIPECOUNT=$($LCTL get_param -n lov.$LOVNAME.stripecount)
+STRIPESIZE=$($LCTL get_param -n lov.$LOVNAME.stripesize)
+ORIGFREE=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
 
 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
@@ -126,7 +128,7 @@ rm -rf $DIR/[Rdfs][0-9]*
 # $RUNAS_ID may get set incorrectly somewhere else
 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
 
-check_runas_id $RUNAS_ID $RUNAS
+check_runas_id $RUNAS_ID $RUNAS_ID $RUNAS
 
 build_test_filter
 
@@ -159,6 +161,12 @@ test_0b() {
 }
 run_test 0b "chmod 0755 $DIR ============================="
 
+test_0c() {
+    $LCTL get_param mdc.*.import | grep  "state: FULL" || error "import not FULL"
+    $LCTL get_param mdc.*.import | grep  "target: $FSNAME-MDT" || error "bad target"
+}
+run_test 0c "check import proc ============================="
+
 test_1a() {
        mkdir $DIR/d1
        mkdir $DIR/d1/d2
@@ -458,6 +466,23 @@ test_17f() {
 }
 run_test 17f "symlinks: long and very long symlink name ========================"
 
+test_17g() {
+        mkdir -p $DIR/$tdir
+        LONGSYMLINK="$(dd if=/dev/zero bs=4095 count=1 | tr '\0' 'x')"
+        ln -s $LONGSYMLINK $DIR/$tdir/$tfile
+        ls -l $DIR/$tdir
+}
+run_test 17g "symlinks: really long symlink name ==============================="
+
+test_17h() { #bug 17378
+        mkdir -p $DIR/$tdir
+        $SETSTRIPE $DIR/$tdir -c -1
+#define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
+        do_facet mds lctl set_param fail_loc=0x80000141
+        touch $DIR/$tdir/$tfile || true
+}
+run_test 17h "create objects: lov_free_memmd() doesn't lbug"
+
 test_18() {
        touch $DIR/f
        ls $DIR || error
@@ -526,12 +551,28 @@ test_22() {
 }
 run_test 22 "unpack tar archive as non-root user ==============="
 
-test_23() {
-       mkdir $DIR/d23
-       $TOEXCL $DIR/d23/f23
-       $TOEXCL -e $DIR/d23/f23 || error
+# was test_23
+test_23a() {
+       mkdir -p $DIR/$tdir
+       local file=$DIR/$tdir/$tfile
+
+       openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
+       openfile -f O_CREAT:O_EXCL $file &&
+               error "$file recreate succeeded" || true
 }
-run_test 23 "O_CREAT|O_EXCL in subdir =========================="
+run_test 23a "O_CREAT|O_EXCL in subdir =========================="
+
+test_23b() { # bug 18988
+       mkdir -p $DIR/$tdir
+       local file=$DIR/$tdir/$tfile
+
+        rm -f $file
+        echo foo > $file || error "write filed"
+        echo bar >> $file || error "append filed"
+        $CHECKSTAT -s 8 $file || error "wrong size"
+        rm $file
+}
+run_test 23b "O_APPEND check =========================="
 
 test_24a() {
        echo '== rename sanity =============================================='
@@ -615,7 +656,7 @@ test_24i() {
        mrename $DIR/R9/f $DIR/R9/a
        $CHECKSTAT -t file $DIR/R9/f || error
        $CHECKSTAT -t dir  $DIR/R9/a || error
-       $CHECKSTAT -a file $DIR/R9/a/f || error
+       $CHECKSTAT -a $DIR/R9/a/f || error
 }
 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
 
@@ -728,6 +769,21 @@ test_24u() { # bug12192
 }
 run_test 24u "create stripe file"
 
+test_24v() {
+       local NRFILES=100000
+       local FREE_INODES=`lfs df -i|grep "filesystem summary" | awk '{print $5}'`
+       [ $FREE_INODES -lt $NRFILES ] && \
+               skip "not enough free inodes $FREE_INODES required $NRFILES" && \
+               return
+
+       mkdir -p $DIR/d24v
+       createmany -m $DIR/d24v/$tfile $NRFILES
+       ls $DIR/d24v >/dev/null || error "error in listing large dir"
+
+       rm $DIR/d24v -rf
+}
+run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
+
 test_25a() {
        echo '== symlink sanity ============================================='
 
@@ -801,6 +857,7 @@ run_test 26f "rm -r of a directory which has recursive symlink ="
 test_27a() {
        echo '== stripe sanity =============================================='
        mkdir -p $DIR/d27 || error "mkdir failed"
+       $GETSTRIPE $DIR/d27
        $SETSTRIPE $DIR/d27/f0 -c 1 || error "lstripe failed"
        $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
        pass
@@ -835,7 +892,7 @@ test_27e() {
        $SETSTRIPE $DIR/d27/f12 -c 2 && error "lstripe succeeded twice"
        $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
 }
-run_test 27e "lstripe existing file (should return error) ======"
+run_test 27e "setstripe existing file (should return error) ======"
 
 test_27f() {
        mkdir -p $DIR/d27
@@ -843,7 +900,7 @@ test_27f() {
        dd if=/dev/zero of=$DIR/d27/f12 bs=4k count=4 || error "dd failed"
        $GETSTRIPE $DIR/d27/fbad || error "lfs getstripe failed"
 }
-run_test 27f "lstripe with bad stripe size (should return error)"
+run_test 27f "setstripe with bad stripe size (should return error)"
 
 test_27g() {
        mkdir -p $DIR/d27
@@ -862,7 +919,7 @@ test_27j() {
        mkdir -p $DIR/d27
        $SETSTRIPE $DIR/d27/f27j -i $OSTCOUNT && error "lstripe failed"||true
 }
-run_test 27j "lstripe with bad stripe offset (should return error)"
+run_test 27j "setstripe with bad stripe offset (should return error)"
 
 test_27k() { # bug 2844
        mkdir -p $DIR/d27
@@ -916,29 +973,42 @@ run_test 27m "create file while OST0 was full =================="
 
 # osc's keep a NOSPC stick flag that gets unset with rmdir
 reset_enospc() {
-       [ "$1" ] && FAIL_LOC=$1 || FAIL_LOC=0
+       local FAIL_LOC=${1:-0}
+       local OSTIDX=${2:-""}
+
        mkdir -p $DIR/d27/nospc
        rmdir $DIR/d27/nospc
-       lctl set_param fail_loc=$FAIL_LOC
+       local list=$(comma_list $(osts_nodes))
+       [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
+
+       do_nodes $list lctl set_param fail_loc=$FAIL_LOC
 }
 
 exhaust_precreations() {
-       OSTIDX=$1
-       OST=$(lctl get_param -n lov.${LOVNAME}.target_obd |
-              grep ${OSTIDX}": " | \
-              awk '{print $2}' | sed -e 's/_UUID$//')
+       local OSTIDX=$1
+       local MDSIDX=$(get_mds_dir "$DIR/d27")
+       echo OSTIDX=$OSTIDX MDSIDX=$MDSIDX
+
+       local OST=$(lfs osts | grep ${OSTIDX}": " | \
+               awk '{print $2}' | sed -e 's/_UUID$//')
+       local MDT_INDEX=$(lfs df | grep "\[MDT:$((MDSIDX - 1))\]" | awk '{print $1}' | \
+                         sed -e 's/_UUID$//;s/^.*-//')
+
        # on the mdt's osc
-        last_id=$(lctl get_param -n osc.*${OST}-osc-MDT0000.prealloc_last_id)
-       next_id=$(lctl get_param -n osc.*${OST}-osc-MDT0000.prealloc_next_id)
+       local last_id=$(do_facet mds${MDSIDX} lctl get_param -n osc.*${OST}-osc-${MDT_INDEX}.prealloc_last_id)
+       local next_id=$(do_facet mds${MDSIDX} lctl get_param -n osc.*${OST}-osc-${MDT_INDEX}.prealloc_next_id)
+
+       echo ${OST}-osc-${MDT_INDEX}.prealloc_last_id=$last_id
+       echo ${OST}-osc-${MDT_INDEX}.prealloc_next_id=$next_id
 
-        mkdir -p $DIR/d27/${OST}
-       $SETSTRIPE $DIR/d27/${OST} -i $OSTIDX -c 1
+       mkdir -p $DIR/d27
+       $SETSTRIPE $DIR/d27 -i $OSTIDX -c 1
 #define OBD_FAIL_OST_ENOSPC              0x215
-       lctl set_param fail_loc=0x215
+       do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
        echo "Creating to objid $last_id on ost $OST..."
-       createmany -o $DIR/d27/${OST}/f $next_id $((last_id - next_id + 2))
-       lctl get_param -n osc.*${OST}-osc-MDT0000.prealloc* | grep '[0-9]'
-       reset_enospc $2
+       createmany -o $DIR/d27/${OST}-f $next_id $((last_id - next_id + 2))
+       do_facet mds${MDSIDX} lctl get_param osc.*${OST}-osc-${MDT_INDEX}.prealloc* | grep '[0-9]'
+       reset_enospc $2 $OSTIDX
 }
 
 exhaust_all_precreations() {
@@ -951,21 +1021,23 @@ exhaust_all_precreations() {
 
 test_27n() {
        [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
-       remote_mds && skip "remote MDS" && return
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
 
        reset_enospc
        rm -f $DIR/d27/f27n
        exhaust_precreations 0 0x80000215
-
+       $SETSTRIPE -c -1 $DIR/d27
        touch $DIR/d27/f27n || error
-
+       $GETSTRIPE $DIR/d27/f27n
        reset_enospc
 }
 run_test 27n "create file with some full OSTs =================="
 
 test_27o() {
        [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
-       remote_mds && skip "remote MDS" && return
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
 
        reset_enospc
        rm -f $DIR/d27/f27o
@@ -981,18 +1053,19 @@ run_test 27o "create file with all full OSTs (should error) ===="
 
 test_27p() {
        [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
-       remote_mds && skip "remote MDS" && return
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
 
        reset_enospc
        rm -f $DIR/d27/f27p
 
-       $MCREATE $DIR/d27/f27p || error
-       $TRUNCATE $DIR/d27/f27p 80000000 || error
-       $CHECKSTAT -s 80000000 $DIR/d27/f27p || error
+       $MCREATE $DIR/d27/f27p || error "mcreate failed"
+       $TRUNCATE $DIR/d27/f27p 80000000 || error "truncate failed"
+       $CHECKSTAT -s 80000000 $DIR/d27/f27p || error "checkstat failed"
 
        exhaust_precreations 0 0x80000215
-       echo foo >> $DIR/d27/f27p || error
-       $CHECKSTAT -s 80000004 $DIR/d27/f27p || error
+       echo foo >> $DIR/d27/f27p || error "append failed"
+       $CHECKSTAT -s 80000004 $DIR/d27/f27p || error "checkstat failed"
 
        reset_enospc
 }
@@ -1000,7 +1073,8 @@ run_test 27p "append to a truncated file with some full OSTs ==="
 
 test_27q() {
        [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
-       remote_mds && skip "remote MDS" && return
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
 
        reset_enospc
        rm -f $DIR/d27/f27q
@@ -1020,7 +1094,8 @@ run_test 27q "append to truncated file with all OSTs full (should error) ==="
 
 test_27r() {
        [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
-       remote_mds && skip "remote MDS" && return
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
 
        reset_enospc
        rm -f $DIR/d27/f27r
@@ -1033,9 +1108,13 @@ test_27r() {
 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
 
 test_27s() { # bug 10725
-       mkdir -p $DIR/$tdir
-       $LSTRIPE $DIR/$tdir $((2048 * 1024 * 1024)) -1 2 && \
-               error "stripe width >= 2^32 succeeded" || true
+       mkdir -p $DIR/$tdir
+       local stripe_size=$((4096 * 1024 * 1024))       # 2^32
+       local stripe_count=0
+       [ $OSTCOUNT -eq 1 ] || stripe_count=2
+       $SETSTRIPE $DIR/$tdir -s $stripe_size -c $stripe_count && \
+               error "stripe width >= 2^32 succeeded" || true
+
 }
 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
 
@@ -1050,15 +1129,14 @@ test_27t() { # bug 10864
 run_test 27t "check that utils parse path correctly"
 
 test_27u() { # bug 4900
-       [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
-       remote_mds && skip "remote MDS" && return
+        [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
+        remote_mds_nodsh && skip "remote MDS with nodsh" && return
 
-        #define OBD_FAIL_MDS_OSC_PRECREATE      0x13d
-
-        lctl set_param fail_loc=0x13d
+#define OBD_FAIL_MDS_OSC_PRECREATE      0x139
+        do_facet $SINGLEMDS lctl set_param fail_loc=0x139
         mkdir -p $DIR/d27u
         createmany -o $DIR/d27u/t- 1000
-        lctl set_param fail_loc=0
+        do_facet $SINGLEMDS lctl set_param fail_loc=0
 
         TLOG=$DIR/$tfile.getstripe
         $GETSTRIPE $DIR/d27u > $TLOG
@@ -1071,7 +1149,8 @@ run_test 27u "skip object creation on OSC w/o objects =========="
 
 test_27v() { # bug 4900
        [ "$OSTCOUNT" -lt "2" ] && skip "too few OSTs" && return
-       remote_mds && skip "remote MDS" && return
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
 
         exhaust_all_precreations
 
@@ -1080,15 +1159,17 @@ test_27v() { # bug 4900
 
         touch $DIR/$tdir/$tfile
         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
-        lctl set_param fail_loc=0x705
-        START=`date +%s`
-        for F in `seq 1 32`; do
-                touch $DIR/$tdir/$tfile.$F
+        # all except ost1
+        for (( i=0; i < OSTCOUNT; i++ )) ; do
+                do_facet ost$i lctl set_param fail_loc=0x705
         done
-        lctl set_param fail_loc=0
+        local START=`date +%s`
+        createmany -o $DIR/$tdir/$tfile 32
 
-        FINISH=`date +%s`
-        TIMEOUT=`lctl get_param -n timeout`
+        reset_enospc
+
+        local FINISH=`date +%s`
+        local TIMEOUT=`lctl get_param -n timeout`
         [ $((FINISH - START)) -ge $((TIMEOUT / 2)) ] && \
                error "$FINISH - $START >= $TIMEOUT / 2"
 
@@ -1114,7 +1195,9 @@ test_27w() { # bug 10997
 }
 run_test 27w "check lfs setstripe -c -s -i options ============="
 
-test_28() {
+# createtest also checks that device nodes are created and
+# then visible correctly (#2091)
+test_28() { # bug 2091
        mkdir $DIR/d28
        $CREATETEST $DIR/d28/ct || error
 }
@@ -1688,10 +1771,12 @@ test_36f() {
 run_test 36f "utime on file racing with OST BRW write =========="
 
 test_36g() {
-       remote_ost && skip "remote OST" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
+
+       mkdir -p $DIR/$tdir
        export FMD_MAX_AGE=`do_facet ost1 lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | head -n 1`
        FMD_BEFORE="`awk '/ll_fmd_cache/ { print $2 }' /proc/slabinfo`"
-       touch $DIR/d36/$tfile
+       touch $DIR/$tdir/$tfile
        sleep $((FMD_MAX_AGE + 12))
        FMD_AFTER="`awk '/ll_fmd_cache/ { print $2 }' /proc/slabinfo`"
        [ "$FMD_AFTER" -gt "$FMD_BEFORE" ] && \
@@ -1711,9 +1796,15 @@ test_37() {
 run_test 37 "ls a mounted file system to check old content ====="
 
 test_38() {
-       o_directory $DIR/$tfile
+       local file=$DIR/$tfile
+       touch $file
+       openfile -f O_DIRECTORY $file
+       local RC=$?
+       local ENOTDIR=20
+       [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
+       [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
 }
-run_test 38 "open a regular file with O_DIRECTORY =============="
+run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
 
 test_39() {
        touch $DIR/$tfile
@@ -2040,11 +2131,7 @@ test_46() {
 }
 run_test 46 "dirtying a previously written page ================"
 
-# Check that device nodes are created and then visible correctly (#2091)
-test_47() {
-       cmknod $DIR/test_47_node || error
-}
-run_test 47 "Device nodes check ================================"
+# test_47 is removed "Device nodes check" is moved to test_28
 
 test_48a() { # bug 2399
        check_kernel_version 34 || return 0
@@ -2199,7 +2286,7 @@ test_51b() {
 run_test 51b "mkdir .../t-0 --- .../t-$NUMTEST ===================="
 
 test_51bb() {
-       [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 
+       [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
 
        local ndirs=${TEST51BB_NDIRS:-10}
        local nfiles=${TEST51BB_NFILES:-100}
@@ -2221,7 +2308,7 @@ test_51bb() {
        declare -a dirs
        for ((i=0; i < $ndirs; i++)); do
                dirs[i]=$dir/$RANDOM
-               echo Creating directory ${dirs[i]} 
+               echo Creating directory ${dirs[i]}
                mkdir -p ${dirs[i]}
                ls $dir
                echo Creating $nfiles in dir ${dirs[i]} ...
@@ -2240,7 +2327,7 @@ test_51bb() {
                echo "mds $i: inodes count OLD ${OLDUSED[$i]} NEW ${NEWUSED[$i]}"
                [ ${OLDUSED[$i]} -lt ${NEWUSED[$i]} ] || rc=$((rc + 1))
        done
-       
+
        lctl set_param -n lmv.*.placement=$savePOLICY
 
        [ $rc -ne $MDSCOUNT ] || \
@@ -2324,14 +2411,22 @@ test_52b() {
 run_test 52b "immutable flag test (should return errors) ======="
 
 test_53() {
-       remote_mds && skip "remote MDS" && return
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
+
+       local param
+       local ostname
+       local mds_last
+       local ost_last
+       local ostnum
 
        # only test MDT0000
-        for value in `lctl get_param osc.*-osc-MDT0000.prealloc_last_id` ; do
+        for value in $(do_facet $SINGLEMDS lctl get_param osc.*-osc-MDT0000.prealloc_last_id) ; do
                 param=`echo ${value[0]} | cut -d "=" -f1`
                 ostname=`echo $param | cut -d "." -f2 | cut -d - -f 1-2`
-                ost_last=`lctl get_param -n obdfilter.$ostname.last_id | head -n 1`
-                mds_last=`lctl get_param -n $param`
+                mds_last=$(do_facet $SINGLEMDS lctl get_param -n $param)
+                ostnum=$(echo $ostname | sed "s/${FSNAME}-OST//g" | awk '{print ($1+1)}' )
+                ost_last=$(do_facet ost$ostnum lctl get_param -n obdfilter.$ostname.last_id | head -n 1)
                 echo "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
                 if [ $ost_last != $mds_last ]; then
                     error "$ostname.last_id=$ost_last ; MDS.last_id=$mds_last"
@@ -2620,11 +2715,11 @@ test_56o() {
        setup_56 $NUMFILES $NUMDIRS
        TDIR=$DIR/${tdir}g
 
-       utime $TDIR/file1 > /dev/null || error
-       utime $TDIR/file2 > /dev/null || error
-       utime $TDIR/dir1 > /dev/null || error
-       utime $TDIR/dir2 > /dev/null || error
-       utime $TDIR/dir1/file1 > /dev/null || error
+       utime $TDIR/file1 > /dev/null || error "utime (1)"
+       utime $TDIR/file2 > /dev/null || error "utime (2)"
+       utime $TDIR/dir1 > /dev/null || error "utime (3)"
+       utime $TDIR/dir2 > /dev/null || error "utime (4)"
+       utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
 
        EXPECTED=5
        NUMS=`$LFIND -mtime +1 $TDIR | wc -l`
@@ -2681,12 +2776,13 @@ run_test 56q "check lfs find -gid and ! -gid ==============================="
 
 test_57a() {
        # note test will not do anything if MDS is not local
-       remote_mds && skip "remote MDS" && return
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+
        local MNTDEV="osd.*MDT*.mntdev"
-       DEV=$(lctl get_param -n $MNTDEV)
+       DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
        [ -z "$DEV" ] && error "can't access $MNTDEV"
-       for DEV in `lctl get_param -n $MNTDEV`; do
-               dumpe2fs -h $DEV > $TMP/t57a.dump || error "can't access $DEV"
+       for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
+               do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump || error "can't access $DEV"
                DEVISIZE=`awk '/Inode size:/ { print $3 }' $TMP/t57a.dump`
                [ "$DEVISIZE" -gt 128 ] || error "inode size $DEVISIZE"
                rm $TMP/t57a.dump
@@ -2695,42 +2791,53 @@ test_57a() {
 run_test 57a "verify MDS filesystem created with large inodes =="
 
 test_57b() {
-       FILECOUNT=100
-       FILE1=$DIR/d57b/f1
-       FILEN=$DIR/d57b/f$FILECOUNT
-       rm -rf $DIR/d57b || error "removing $DIR/d57b"
-       mkdir -p $DIR/d57b || error "creating $DIR/d57b"
+       local dir=$DIR/d57b
+
+       local FILECOUNT=100
+       local FILE1=$dir/f1
+       local FILEN=$dir/f$FILECOUNT
+
+       rm -rf $dir || error "removing $dir"
+       mkdir -p $dir || error "creating $dir"
+       local num=$(get_mds_dir $dir)
+       local mymds=mds$num
+
        echo "mcreating $FILECOUNT files"
-       createmany -m $DIR/d57b/f 1 $FILECOUNT || \
-               error "creating files in $DIR/d57b"
+       createmany -m $dir/f 1 $FILECOUNT || \
+               error "creating files in $dir"
 
        # verify that files do not have EAs yet
        $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
        $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
 
-       MDSFREE="`lctl get_param -n osd.*MDT0000.kbytesfree 2> /dev/null`"
-       MDCFREE="`lctl get_param -n mdc.*.kbytesfree | head -n 1`"
+       sync
+       sleep 1
+       df $dir  #make sure we get new statfs data
+       local MDSFREE=$(do_facet $mymds lctl get_param -n osd.*MDT000$((num -1)).kbytesfree)
+       local MDCFREE=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
        echo "opening files to create objects/EAs"
-       for FILE in `seq -f $DIR/d57b/f%g 1 $FILECOUNT`; do
-               $OPENFILE -f O_RDWR $FILE > /dev/null || error "opening $FILE"
+       local FILE
+       for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
+               $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
        done
 
        # verify that files have EAs now
        $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
        $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
 
-       sleep 1 # make sure we get new statfs data
-#      MDSFREE2="`lctl get_param -n mds.*.kbytesfree`"
-#      MDCFREE2="`lctl get_param -n mdc.*.kbytesfree`"
-#      if [ "$MDCFREE2" -lt "$((MDCFREE - 8))" ]; then
-#              if [ "$MDSFREE" != "$MDSFREE2" ]; then
-#                      error "MDC before $MDCFREE != after $MDCFREE2"
-#              else
-#                      echo "MDC before $MDCFREE != after $MDCFREE2"
-#                      echo "unable to confirm if MDS has large inodes"
-#              fi
-#      fi
-       rm -rf $DIR/d57b
+       sleep 1  #make sure we get new statfs data
+       df $dir
+       local MDSFREE2=$(do_facet $mymds lctl get_param -n osd.*MDT000$((num -1)).kbytesfree)
+       local MDCFREE2=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
+       if [ "$MDCFREE2" -lt "$((MDCFREE - 8))" ]; then
+               if [ "$MDSFREE" != "$MDSFREE2" ]; then
+                       error "MDC before $MDCFREE != after $MDCFREE2"
+               else
+                       echo "MDC before $MDCFREE != after $MDCFREE2"
+                       echo "unable to confirm if MDS has large inodes"
+               fi
+       fi
+       rm -rf $dir
 }
 run_test 57b "default LOV EAs are stored inside large inodes ==="
 
@@ -2780,8 +2887,8 @@ run_test 60b "limit repeated messages from CERROR/CWARN ========"
 test_60c() {
        echo "create 5000 files"
        createmany -o $DIR/f60c- 5000
-#define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x13c
-       lctl set_param fail_loc=0x8000013c
+#define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
+       lctl set_param fail_loc=0x80000137
        unlinkmany $DIR/f60c- 5000
        lctl set_param fail_loc=0
 }
@@ -2959,6 +3066,21 @@ test_65i() { # bug6367
 }
 run_test 65i "set non-default striping on root directory (bug 6367)="
 
+test_65ia() { # bug12836
+       $LFS getstripe $MOUNT || error "getstripe $MOUNT failed"
+}
+run_test 65ia "getstripe on -1 default directory striping"
+
+test_65ib() { # bug12836
+       $LFS getstripe -v $MOUNT || error "getstripe -v $MOUNT failed"
+}
+run_test 65ib "getstripe -v on -1 default directory striping"
+
+test_65ic() { # bug12836
+       $LFS find -mtime -1 $MOUNT || error "find $MOUNT failed"
+}
+run_test 65ic "new find on -1 default directory striping"
+
 test_65j() { # bug6367
        sync; sleep 1
        # if we aren't already remounting for each test, do so for this test
@@ -2972,7 +3094,7 @@ run_test 65j "set default striping on root directory (bug 6367)="
 
 test_65k() { # bug11679
         [ "$OSTCOUNT" -lt 2 ] && skip "too few OSTs" && return
-        remote_mds_nodsh && skip "remote MDS" && return
+        remote_mds_nodsh && skip "remote MDS with nodsh" && return
 
         echo "Check OST status: "
         MDS_OSCS=`do_facet $SINGLEMDS lctl dl | awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
@@ -3023,12 +3145,15 @@ LLOOP=
 cleanup_68() {
        trap 0
        if [ ! -z "$LLOOP" ]; then
-               swapoff $LLOOP || error "swapoff failed"
+               if swapon -s | grep -q $LLOOP; then
+                       swapoff $LLOOP || error "swapoff failed"
+               fi
+
                $LCTL blockdev_detach $LLOOP || error "detach failed"
                rm -f $LLOOP
                unset LLOOP
        fi
-       rm -f $DIR/f68
+       rm -f $DIR/f68*
 }
 
 meminfo() {
@@ -3039,10 +3164,29 @@ swap_used() {
        swapon -s | awk '($1 == "'$1'") { print $4 }'
 }
 
+# test case for lloop driver, basic function
+test_68a() {
+       [ "$UID" != 0 ] && skip "must run as root" && return
+
+       grep -q llite_lloop /proc/modules
+       [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
+
+       LLOOP=$TMP/lloop.`date +%s`.`date +%N`
+       dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
+       $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
+
+       trap cleanup_68 EXIT
+
+       directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
+       directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
+
+       cleanup_68
+}
+run_test 68a "lloop driver - basic test ========================"
 
 # excercise swapping to lustre by adding a high priority swapfile entry
 # and then consuming memory until it is used.
-test_68() {
+test_68b() {  # was test_68
        [ "$UID" != 0 ] && skip "must run as root" && return
        lctl get_param -n devices | grep -q obdfilter && \
                skip "local OST" && return
@@ -3058,10 +3202,10 @@ test_68() {
        [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
 
        LLOOP=$TMP/lloop.`date +%s`.`date +%N`
-       dd if=/dev/zero of=$DIR/f68 bs=64k seek=$NR_BLOCKS count=1
-       mkswap $DIR/f68
+       dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
+       mkswap $DIR/f68b
 
-       $LCTL blockdev_attach $DIR/f68 $LLOOP || error "attach failed"
+       $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
 
        trap cleanup_68 EXIT
 
@@ -3076,39 +3220,39 @@ test_68() {
 
        [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
 }
-run_test 68 "support swapping to Lustre ========================"
+run_test 68b "support swapping to Lustre ========================"
 
 # bug5265, obdfilter oa2dentry return -ENOENT
 # #define OBD_FAIL_OST_ENOENT 0x217
 test_69() {
-       [ $(lctl get_param -n devices | grep -c obdfilter) -eq 0 ] && \
-               skip "skipping test for remote OST" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
 
        f="$DIR/$tfile"
-       touch $f
+       $SETSTRIPE $f -c 1 -i 0
 
        $DIRECTIO write ${f}.2 0 1 || error "directio write error"
 
-       lctl set_param fail_loc=0x217
+       do_facet ost1 lctl set_param fail_loc=0x217
        truncate $f 1 # vmtruncate() will ignore truncate() error.
        $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
 
-       lctl set_param fail_loc=0
+       do_facet ost1 lctl set_param fail_loc=0
        $DIRECTIO write $f 0 2 || error "write error"
 
        cancel_lru_locks osc
        $DIRECTIO read $f 0 1 || error "read error"
 
-       lctl set_param fail_loc=0x217
+       do_facet ost1 lctl set_param fail_loc=0x217
        $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
 
-       lctl set_param fail_loc=0
+       do_facet ost1 lctl set_param fail_loc=0
        rm -f $f
 }
 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
 
 test_71() {
-    sh rundbench -C -D $DIR 2 || error "dbench failed!"
+    mkdir -p $DIR/$tdir
+    sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
 }
 run_test 71 "Running dbench on lustre (don't segment fault) ===="
 
@@ -3117,7 +3261,7 @@ test_72() { # bug 5695 - Test that on 2.6 remove_suid works properly
        [ "$RUNAS_ID" = "$UID" ] && skip "RUNAS_ID = UID = $UID -- skipping" && return
 
         # Check that testing environment is properly set up. Skip if not
-        FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS || {
+        FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
                 skip "User $RUNAS_ID does not exist - skipping"
                 return 0
         }
@@ -3133,6 +3277,7 @@ test_72() { # bug 5695 - Test that on 2.6 remove_suid works properly
        cancel_lru_locks mdc
        test -u $DIR/f72 -o -g $DIR/f72 && error "S/gid is not dropped on MDS"
        true
+       rm -f $DIR/f72
 }
 run_test 72 "Test that remove suid works properly (bug5695) ===="
 
@@ -3175,6 +3320,7 @@ test_74a() { # bug 6149, 6184
        ls $DIR/f74a
        lctl set_param fail_loc=0
        true
+       rm -f $DIR/f74a
 }
 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
 
@@ -3188,6 +3334,7 @@ test_74b() { # bug 13310
        touch $DIR/f74b
        lctl set_param fail_loc=0
        true
+       rm -f $DIR/f74b
 }
 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
 
@@ -3208,9 +3355,6 @@ test75_prep() {
 }
 
 test_75a() {
-#      skipped temporarily: we do not have join file currently
-#      please remove this when ready - huanghua
-       return
         test75_prep
 
         cp -p ${F128k} ${FHEAD}
@@ -3228,9 +3372,6 @@ test_75a() {
 run_test 75a "TEST join file ===================================="
 
 test_75b() {
-#      skipped temporarily: we do not have join file currently
-#      please remove this when ready - huanghua
-       return
         test75_prep
 
         cp -p ${F128k} ${FTAIL}
@@ -3244,9 +3385,6 @@ test_75b() {
 run_test 75b "TEST join file 2 =================================="
 
 test_75c() {
-#      skipped temporarily: we do not have join file currently
-#      please remove this when ready - huanghua
-       return
         test75_prep
 
         cp -p ${F128k} ${FTAIL}
@@ -3260,9 +3398,6 @@ test_75c() {
 run_test 75c "TEST join file 3 =================================="
 
 test_75d() {
-#      skipped temporarily: we do not have join file currently
-#      please remove this when ready - huanghua
-       return
         test75_prep
 
         cp -p ${F128k} ${FHEAD}
@@ -3277,9 +3412,6 @@ test_75d() {
 run_test 75d "TEST join file 4 =================================="
 
 test_75e() {
-#      skipped temporarily: we do not have join file currently
-#      please remove this when ready - huanghua
-       return
         test75_prep
 
         rm -rf ${FHEAD} || "delete join file error"
@@ -3287,9 +3419,6 @@ test_75e() {
 run_test 75e "TEST join file 5 (remove joined file) ============="
 
 test_75f() {
-#      skipped temporarily: we do not have join file currently
-#      please remove this when ready - huanghua
-       return
         test75_prep
 
         cp -p ${F128k} ${F75}_join_10_compare
@@ -3307,9 +3436,6 @@ test_75f() {
 run_test 75f "TEST join file 6 (join 10 files) =================="
 
 test_75g() {
-#      skipped temporarily: we do not have join file currently
-#      please remove this when ready - huanghua
-       return
         [ ! -f ${F75}_join_10 ] && echo "${F75}_join_10 missing" && return
         $LFS getstripe ${F75}_join_10
 
@@ -3376,14 +3502,17 @@ setup_f77() {
 }
 
 test_77a() { # bug 10889
+       $GSS && skip "could not run with gss" && return
        [ ! -f $F77_TMP ] && setup_f77
        set_checksums 1
        dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
        set_checksums 0
+       rm -f $DIR/$tfile
 }
 run_test 77a "normal checksum read/write operation ============="
 
 test_77b() { # bug 10889
+       $GSS && skip "could not run with gss" && return
        [ ! -f $F77_TMP ] && setup_f77
        #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
        lctl set_param fail_loc=0x80000409
@@ -3396,6 +3525,7 @@ test_77b() { # bug 10889
 run_test 77b "checksum error on client write ===================="
 
 test_77c() { # bug 10889
+       $GSS && skip "could not run with gss" && return
        [ ! -f $DIR/f77b ] && skip "requires 77b - skipping" && return
        set_checksums 1
        for algo in $CKSUM_TYPES; do
@@ -3408,10 +3538,12 @@ test_77c() { # bug 10889
        done
        set_checksums 0
        set_checksum_type $ORIG_CSUM_TYPE
+       rm -f $DIR/f77b
 }
 run_test 77c "checksum error on client read ==================="
 
 test_77d() { # bug 10889
+       $GSS && skip "could not run with gss" && return
        #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
        lctl set_param fail_loc=0x80000409
        set_checksums 1
@@ -3423,6 +3555,7 @@ test_77d() { # bug 10889
 run_test 77d "checksum error on OST direct write ==============="
 
 test_77e() { # bug 10889
+       $GSS && skip "could not run with gss" && return
        [ ! -f $DIR/f77 ] && skip "requires 77d - skipping" && return
        #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
        lctl set_param fail_loc=0x80000408
@@ -3436,6 +3569,7 @@ test_77e() { # bug 10889
 run_test 77e "checksum error on OST direct read ================"
 
 test_77f() { # bug 10889
+       $GSS && skip "could not run with gss" && return
        set_checksums 1
        for algo in $CKSUM_TYPES; do
                cancel_lru_locks osc
@@ -3452,34 +3586,39 @@ test_77f() { # bug 10889
 run_test 77f "repeat checksum error on write (expect error) ===="
 
 test_77g() { # bug 10889
-       [ $(lctl get_param -n devices | grep -c obdfilter) -eq 0 ] && \
-               skip "remote OST" && return
+       $GSS && skip "could not run with gss" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
+
        [ ! -f $F77_TMP ] && setup_f77
+
+       $SETSTRIPE $DIR/f77g -c 1 -i 0
        #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
-       lctl set_param fail_loc=0x8000021a
+       do_facet ost1 lctl set_param fail_loc=0x8000021a
        set_checksums 1
-       dd if=$F77_TMP of=$DIR/f77 bs=1M count=$F77SZ || \
+       dd if=$F77_TMP of=$DIR/f77g bs=1M count=$F77SZ || \
                error "write error: rc=$?"
-       lctl set_param fail_loc=0
+       do_facet ost1 lctl set_param fail_loc=0
        set_checksums 0
 }
 run_test 77g "checksum error on OST write ======================"
 
 test_77h() { # bug 10889
-       [ $(lctl get_param -n devices | grep -c obdfilter) -eq 0 ] && \
-               skip "remote OST" && return
-       [ ! -f $DIR/f77 ] && skip "requires 77g - skipping" && return
+       $GSS && skip "could not run with gss" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
+
+       [ ! -f $DIR/f77g ] && skip "requires 77g - skipping" && return
        cancel_lru_locks osc
        #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
-       lctl set_param fail_loc=0x8000021b
+       do_facet ost1 lctl set_param fail_loc=0x8000021b
        set_checksums 1
-       cmp $F77_TMP $DIR/f77 || error "file compare failed"
-       lctl set_param fail_loc=0
+       cmp $F77_TMP $DIR/f77g || error "file compare failed"
+       do_facet ost1 lctl set_param fail_loc=0
        set_checksums 0
 }
 run_test 77h "checksum error on OST read ======================="
 
 test_77i() { # bug 13805
+       $GSS && skip "could not run with gss" && return
        #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
        lctl set_param fail_loc=0x40b
        remount_client $MOUNT
@@ -3494,6 +3633,7 @@ test_77i() { # bug 13805
 run_test 77i "client not supporting OSD_CONNECT_CKSUM =========="
 
 test_77j() { # bug 13805
+       $GSS && skip "could not run with gss" && return
        #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
        lctl set_param fail_loc=0x40c
        remount_client $MOUNT
@@ -3520,7 +3660,12 @@ test_78() { # bug 10901
        echo "MemTotal: $MEMTOTAL"
 # reserve 256MB of memory for the kernel and other running processes,
 # and then take 1/2 of the remaining memory for the read/write buffers.
-       MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
+    if [ $MEMTOTAL -gt 512 ] ;then
+        MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
+    else
+        # for those poor memory-starved high-end clusters...
+        MEMTOTAL=$((MEMTOTAL / 2))
+    fi
        echo "Mem to use for directio: $MEMTOTAL"
        [ $F78SIZE -gt $MEMTOTAL ] && F78SIZE=$MEMTOTAL
        [ $F78SIZE -gt 512 ] && F78SIZE=512
@@ -3530,11 +3675,12 @@ test_78() { # bug 10901
        [ $SMALLESTOST -lt 10240 ] && \
                skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
 
-       [ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 5)) ] && \
-               F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 5))
+       [ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ] && \
+               F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
+
        [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
        echo "File size: $F78SIZE"
-       $SETSTRIPE $DIR/$tfile -c -1 || error "setstripe failed"
+       $SETSTRIPE $DIR/$tfile -c $OSTCOUNT || error "setstripe failed"
        for i in `seq 1 $NSEQ`
        do
                FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
@@ -3547,14 +3693,12 @@ test_78() { # bug 10901
 run_test 78 "handle large O_DIRECT writes correctly ============"
 
 test_79() { # bug 12743
-       [ $(lctl get_param -n devices | grep -c obdfilter) -eq 0 ] &&
-               skip "skipping test for remote OST" && return
-
        wait_delete_completed
 
-        BKTOTAL=`lctl get_param -n obdfilter.*.kbytestotal | awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
-        BKFREE=`lctl get_param -n obdfilter.*.kbytesfree | awk 'BEGIN{free=0}; {free+=$1}; END{print free}'`
-        BKAVAIL=`lctl get_param -n obdfilter.*.kbytesavail | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}'`
+        BKTOTAL=$(calc_osc_kbytes kbytestotal)
+        BKFREE=$(calc_osc_kbytes kbytesfree)
+        BKAVAIL=$(calc_osc_kbytes kbytesavail)
+
         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
         DFTOTAL=`echo $STRING | cut -d, -f1`
         DFUSED=`echo $STRING  | cut -d, -f2`
@@ -3581,32 +3725,28 @@ run_test 79 "df report consistency check ======================="
 test_80() { # bug 10718
         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
         sync; sleep 1; sync
-        BEFORE=`date +%s`
-        cancel_lru_locks OSC
-        AFTER=`date +%s`
-        DIFF=$((AFTER-BEFORE))
+        local BEFORE=`date +%s`
+        cancel_lru_locks osc
+        local AFTER=`date +%s`
+        local DIFF=$((AFTER-BEFORE))
         if [ $DIFF -gt 1 ] ; then
                 error "elapsed for 1M@1T = $DIFF"
         fi
         true
+       rm -f $DIR/$tfile
 }
 run_test 80 "Page eviction is equally fast at high offsets too  ===="
 
-# on the LLNL clusters, runas will still pick up root's $TMP settings,
-# which will not be writable for the runas user, and then you get a CVS
-# error message with a corrupt path string (CVS bug) and panic.
-# We're not using much space, so just stick it in /tmp, which is safe.
-OLDTMPDIR=$TMPDIR
-OLDTMP=$TMP
-TMPDIR=/tmp
-TMP=/tmp
-OLDHOME=$HOME
-[ $RUNAS_ID -ne $UID ] && HOME=/tmp
-
 test_99a() {
+        [ -z "$(which cvs 2>/dev/null)" ] && skip "could not find cvs" && \
+           return
        mkdir -p $DIR/d99cvsroot
        chown $RUNAS_ID $DIR/d99cvsroot
+       local oldPWD=$PWD       # bug 13584, use $TMP as working dir
+       cd $TMP
+
        $RUNAS cvs -d $DIR/d99cvsroot init || error
+       cd $oldPWD
 }
 run_test 99a "cvs init ========================================="
 
@@ -3655,22 +3795,34 @@ test_99f() {
        [ ! -d $DIR/d99cvsroot ] && test_99d
        cd $DIR/d99reposname
        $RUNAS cvs commit -m 'nomsg' foo99
+    rm -fr $DIR/d99cvsroot
 }
 run_test 99f "cvs commit ======================================="
 
 test_100() {
-       netstat -tna | while read PROT SND RCV LOCAL REMOTE STAT; do
+       [ "$NETTYPE" = tcp ] || \
+               { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
+                       return ; }
+
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       remote_servers || \
+               { skip "useless for local single node setup" && return; }
+
+       netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
                [ "$PROT" != "tcp" ] && continue
-               RPORT=`echo $REMOTE | cut -d: -f2`
+               RPORT=$(echo $REMOTE | cut -d: -f2)
                [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
+
+               rc=0
                LPORT=`echo $LOCAL | cut -d: -f2`
                if [ $LPORT -ge 1024 ]; then
                        echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
                        netstat -tna
-                       error "local: $LPORT > 1024, remote: $RPORT"
+                       error_exit "local: $LPORT > 1024, remote: $RPORT"
                fi
        done
-       true
+       [ "$rc" = 0 ] || error_exit "privileged port not found" )
 }
 run_test 100 "check local port using privileged port ==========="
 
@@ -3750,6 +3902,7 @@ cleanup_test101() {
        [ "$SETUP_TEST101" = "yes" ] || return
        trap 0
        rm -rf $DIR/$tdir
+        rm -f $DIR/$tfile
        SETUP_TEST101=no
 }
 
@@ -3803,41 +3956,87 @@ test_101b() {
 }
 run_test 101b "check stride-io mode read-ahead ================="
 
+set_read_ahead() {
+   lctl get_param -n llite.*.max_read_ahead_mb | head -n 1
+   lctl set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
+}
+
+test_101d() {
+    local file=$DIR/$tfile
+    local size=${FILESIZE_101c:-500}
+    local ra_MB=${READAHEAD_MB:-40}
+
+    local space=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
+    [ $space -gt $((size / 1024)) ] ||
+        { skip "Need free space ${size}M, have $space" && return; }
+
+    echo Creating ${size}M test file $file
+    dd if=/dev/zero of=$file bs=1M count=$size
+    echo Cancel LRU locks on lustre client to flush the client cache
+    cancel_lru_locks osc
+
+    echo Disable read-ahead
+    local old_READAHEAD=$(set_read_ahead 0)
+
+    echo Reading the test file $file with read-ahead disabled
+    time_ra_OFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
+
+    echo Cancel LRU locks on lustre client to flush the client cache
+    cancel_lru_locks osc
+    echo Enable read-ahead with ${ra_MB}MB
+    set_read_ahead $ra_MB
+
+    echo Reading the test file $file with read-ahead enabled
+    time_ra_ON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$size")
+
+    echo read-ahead disabled time read $time_ra_OFF
+    echo read-ahead enabled  time read $time_ra_ON
+
+    set_read_ahead $old_READAHEAD
+    rm -f $file
+
+    [ $time_ra_ON -lt $time_ra_OFF ] ||
+        error "read-ahead enabled  time read (${time_ra_ON}s) is more than
+               read-ahead disabled time read (${time_ra_OFF}s) filesize ${size}M"
+}
+run_test 101d "file read with and without read-ahead enabled  ================="
+
 export SETUP_TEST102=no
 setup_test102() {
        [ "$SETUP_TEST102" = "yes" ] && return
        mkdir -p $DIR/$tdir
+       chown $RUNAS_ID $DIR/$tdir
        STRIPE_SIZE=65536
-       STRIPE_COUNT=4
-       STRIPE_OFFSET=2
+       STRIPE_OFFSET=1
+       STRIPE_COUNT=$OSTCOUNT
+       [ $OSTCOUNT -gt 4 ] && STRIPE_COUNT=4
 
        trap cleanup_test102 EXIT
        cd $DIR
-       $SETSTRIPE $tdir -s $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT
+       $1 $SETSTRIPE $tdir -s $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT
        cd $DIR/$tdir
        for num in 1 2 3 4
        do
-               for count in 1 2 3 4
+               for count in `seq 1 $STRIPE_COUNT`
                do
-                       for offset in 0 1 2 3
+                       for offset in `seq 0 $[$STRIPE_COUNT - 1]`
                        do
                                local stripe_size=`expr $STRIPE_SIZE \* $num`
                                local file=file"$num-$offset-$count"
-                               $SETSTRIPE $file -s $stripe_size -i $offset -c $count
+                               $1 $SETSTRIPE $file -s $stripe_size -i $offset -c $count
                        done
                done
        done
 
        cd $DIR
-       star -c  f=$TMP/f102.tar $tdir
+       $1 $TAR cf $TMP/f102.tar $tdir --xattrs
        SETUP_TEST102=yes
 }
 
 cleanup_test102() {
-       [ "$SETUP_TEST102" = "yes" ] || return
        trap 0
+       [ "$SETUP_TEST102" = "yes" ] || return 0
        rm -f $TMP/f102.tar
-       rm -rf $DIR/$tdir
        SETUP_TEST102=no
 }
 
@@ -3895,22 +4094,23 @@ test_102b() {
        echo "get/set/list trusted.lov xattr ..."
        [ "$OSTCOUNT" -lt "2" ] && skip "skipping 2-stripe test" && return
        local testfile=$DIR/$tfile
-       $SETSTRIPE $testfile -s 65536 -i 1 -c 2
+       $SETSTRIPE -s 65536 -i 1 -c 2 $testfile || error "setstripe failed"
        getfattr -d -m "^trusted" $testfile 2> /dev/null | \
        grep "trusted.lov" || error "can't get trusted.lov from $testfile"
 
        local testfile2=${testfile}2
        local value=`getfattr -n trusted.lov $testfile 2> /dev/null | \
                     grep "trusted.lov" |sed -e 's/[^=]\+=//'`
-       
+
        $MCREATE $testfile2
-       setfattr -n trusted.lov -v $value $testfile2    
+       setfattr -n trusted.lov -v $value $testfile2
        local tmp_file=${testfile}3
        $GETSTRIPE -v $testfile2 > $tmp_file
        local stripe_size=`grep "size"  $tmp_file| awk '{print $2}'`
        local stripe_count=`grep "count"  $tmp_file| awk '{print $2}'`
        [ "$stripe_size" -eq 65536 ] || error "stripe size $stripe_size != 65536"
        [ "$stripe_count" -eq 2 ] || error "stripe count $stripe_count != 2"
+       rm -f $DIR/$tfile
 }
 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
 
@@ -3921,16 +4121,16 @@ test_102c() {
        mkdir -p $DIR/$tdir
        chown $RUNAS_ID $DIR/$tdir
        local testfile=$DIR/$tdir/$tfile
-       $RUNAS $SETSTRIPE $testfile -s 65536 -i 1 -c 2
+       $RUNAS $SETSTRIPE -s 65536 -i 1 -c 2 $testfile||error "setstripe failed"
        $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
        grep "lustre.lov" || error "can't get lustre.lov from $testfile"
 
        local testfile2=${testfile}2
        local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
                     grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
-       
+
        $RUNAS $MCREATE $testfile2
-       $RUNAS setfattr -n lustre.lov -v $value $testfile2      
+       $RUNAS setfattr -n lustre.lov -v $value $testfile2
        local tmp_file=${testfile}3
        $RUNAS $GETSTRIPE -v $testfile2 > $tmp_file
        local stripe_size=`grep "size"  $tmp_file| awk '{print $2}'`
@@ -3940,135 +4140,88 @@ test_102c() {
 }
 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
 
-get_stripe_info() {
-       stripe_size=0
-       stripe_count=0
-       stripe_offset=0
-       local lines=`sed -n '/obdidx/=' $1`
-       stripe_size=`awk '{if($1~/size/) print $2}' $1`
-       stripe_count=`awk '{if($1~/count/) print $2}' $1`
-       lines=`expr $lines + 1`
-       stripe_offset=`sed -n ${lines}p $1 |awk '{print $1}'`
-}
-
 compare_stripe_info1() {
+       local stripe_index_all_zero=1
+
        for num in 1 2 3 4
        do
-               for count in 1 2 3 4
+               for count in `seq 1 $STRIPE_COUNT`
                do
-                       for offset in 0 1 2 3
+                       for offset in `seq 0 $[$STRIPE_COUNT - 1]`
                        do
                                local size=`expr $STRIPE_SIZE \* $num`
                                local file=file"$num-$offset-$count"
-                               local tmp_file=out
-                               $GETSTRIPE -v $file > $tmp_file
-                               get_stripe_info  $tmp_file
-                               if test $stripe_size -ne $size
-                               then
-                                       error "$file: different stripe size" && return
+                               get_stripe_info client $PWD/$file "$1"
+                               if [ $stripe_size -ne $size ]; then
+                                       error "$file: different stripe size $stripe_size, expected $size" && return
                                fi
-                               if test $stripe_count -ne $count
-                               then
-                                       error "$file: different stripe count" && return
+                               if [ $stripe_count -ne $count ]; then
+                                       error "$file: different stripe count $stripe_count, expected $count" && return
                                fi
-                               if test $stripe_offset -ne 0
-                               then
-                                       error "$file: different stripe offset" && return
+                               if [ $stripe_index -ne 0 ]; then
+                                      stripe_index_all_zero=0
                                fi
-                               rm -f $tmp_file
                        done
                done
        done
+       [ $stripe_index_all_zero -eq 1 ] && error "all files are being extracted starting from OST index 0"
+       return 0
 }
 
 compare_stripe_info2() {
        for num in 1 2 3 4
        do
-               for count in 1 2 3 4
+               for count in `seq 1 $STRIPE_COUNT`
                do
-                       for offset in 0 1 2 3
+                       for offset in `seq 0 $[$STRIPE_COUNT - 1]`
                        do
                                local size=`expr $STRIPE_SIZE \* $num`
                                local file=file"$num-$offset-$count"
-                               local tmp_file=out
-                               $GETSTRIPE -v $file > $tmp_file
-                               get_stripe_info  $tmp_file
-                               if test $stripe_size -ne $size
-                               then
-                                       error "$file: different stripe size" && return  
+                               get_stripe_info client $PWD/$file
+                               if [ $stripe_size -ne $size ]; then
+                                       error "$file: different stripe size $stripe_size, expected $size" && return
                                fi
-                               if test $stripe_count -ne $count
-                               then
-                                       error "$file: different stripe count" && return
+                               if [ $stripe_count -ne $count ]; then
+                                       error "$file: different stripe count $stripe_count, expected $count" && return
                                fi
-                               if test $stripe_offset -ne $offset
-                               then
-                                       error "$file: different stripe offset" && return
+                               if [ $stripe_index -ne $offset ]; then
+                                       error "$file: different stripe offset $stripe_index, expected $offset" && return
                                fi
-                               rm -f $tmp_file
                        done
                done
        done
 }
 
+find_lustre_tar() {
+       [ -n "$(which tar 2>/dev/null)" ] && strings $(which tar) | grep -q lustre && echo tar
+}
+
 test_102d() {
-       # b10930: star test for trusted.lov xattr
-       star --xhelp 2>&1 | grep -q nolustre
-       if [ $? -ne 0 ]
-       then
-               skip "being skipped because a lustre-aware star is not installed." && return
-       fi
-       [ "$OSTCOUNT" -lt "4" ] && skip "skipping 4-stripe test" && return
+       # b10930: tar test for trusted.lov xattr
+       TAR=$(find_lustre_tar)
+       [ -z "$TAR" ] && skip "lustre-aware tar is not installed" && return
+       [ "$OSTCOUNT" -lt "2" ] && skip "skipping N-stripe test" && return
        setup_test102
        mkdir -p $DIR/d102d
-       star -x  f=$TMP/f102.tar -C $DIR/d102d
+       $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
        cd $DIR/d102d/$tdir
        compare_stripe_info1
-
 }
-run_test 102d "star restore stripe info from tarfile,not keep osts ==========="
-
-test_102e() {
-       # b10930: star test for trusted.lov xattr
-       star --xhelp 2>&1 | grep -q nolustre
-       [ $? -ne 0 ] && skip "lustre-aware star is not installed" && return
-       [ "$OSTCOUNT" -lt "4" ] && skip "skipping 4-stripe test" && return
-       setup_test102
-       mkdir -p $DIR/d102e
-       star -x  -preserve-osts f=$TMP/f102.tar -C $DIR/d102e
-       cd $DIR/d102e/$tdir
-       compare_stripe_info2
-}
-run_test 102e "star restore stripe info from tarfile, keep osts ==========="
+run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
 
 test_102f() {
-       # b10930: star test for trusted.lov xattr
-       star --xhelp 2>&1 | grep -q nolustre
-       [ $? -ne 0 ] && skip "lustre-aware star is not installed" && return
-       [ "$OSTCOUNT" -lt "4" ] && skip "skipping 4-stripe test" && return
+       # b10930: tar test for trusted.lov xattr
+       TAR=$(find_lustre_tar)
+       [ -z "$TAR" ] && skip "lustre-aware tar is not installed" && return
+       [ "$OSTCOUNT" -lt "2" ] && skip "skipping N-stripe test" && return
        setup_test102
        mkdir -p $DIR/d102f
        cd $DIR
-       star -copy  $tdir $DIR/d102f
+       $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
        cd $DIR/d102f/$tdir
        compare_stripe_info1
 }
-run_test 102f "star copy files, not keep osts ==========="
-
-test_102g() {
-       # b10930: star test for trusted.lov xattr
-       star --xhelp 2>&1 | grep -q nolustre
-       [ $? -ne 0 ] && skip "lustre-aware star is not installed" && return
-       [ "$OSTCOUNT" -lt "4" ] && skip "skipping 4-stripe test" && return
-       setup_test102
-       mkdir -p $DIR/d102g
-       cd $DIR
-       star -copy -preserve-osts $tdir $DIR/d102g
-       cd $DIR/d102g/$tdir
-       compare_stripe_info2
-       cleanup_test102
-}
-run_test 102g "star copy files, keep osts ==========="
+run_test 102f "tar copy files, not keep osts ==========="
 
 test_102h() { # bug 15777
        [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
@@ -4111,9 +4264,34 @@ test_102h() { # bug 15777
                error "$XBIG different after growing $XSML"
        fi
        log "$XBIG still valid after growing $XSML"
+       rm -f $file
 }
 run_test 102h "grow xattr from inside inode to external block"
 
+test_102i() { # bug 17038
+        touch $DIR/$tfile
+        ln -s $DIR/$tfile $DIR/${tfile}link
+        getfattr -n trusted.lov $DIR/$tfile || error "lgetxattr on $DIR/$tfile failed"
+        getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 | grep -i "no such attr" || error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
+        rm -f $DIR/$tfile $DIR/${tfile}link
+}
+run_test 102i "lgetxattr test on symbolic link ============"
+
+test_102j() {
+       TAR=$(find_lustre_tar)
+       [ -z "$TAR" ] && skip "lustre-aware tar is not installed" && return
+       [ "$OSTCOUNT" -lt "2" ] && skip "skipping N-stripe test" && return
+       setup_test102 "$RUNAS"
+       mkdir -p $DIR/d102j
+       chown $RUNAS_ID $DIR/d102j
+       $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
+       cd $DIR/d102j/$tdir
+       compare_stripe_info1 "$RUNAS"
+}
+run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
+
+cleanup_test102
+
 run_acl_subtest()
 {
     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
@@ -4173,12 +4351,13 @@ test_104() {
        lfs df -i $DIR || error "lfs df -i $DIR failed"
        lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
        lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
-       
+
        OSC=`lctl get_param -n devices | awk '/-osc-/ {print $4}' | head -n 1`
        lctl --device %$OSC deactivate
        lfs df || error "lfs df with deactivated OSC failed"
        lctl --device %$OSC recover
        lfs df || error "lfs df with reactivated OSC failed"
+       rm -f $DIR/$tfile
 }
 run_test 104 "lfs df [-ih] [path] test ========================="
 
@@ -4191,6 +4370,7 @@ test_105a() {
         else
                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
         fi
+       rm -f $DIR/$tfile
 }
 run_test 105a "flock when mounted without -o flock test ========"
 
@@ -4202,6 +4382,7 @@ test_105b() {
         else
                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
         fi
+       rm -f $DIR/$tfile
 }
 run_test 105b "fcntl when mounted without -o flock test ========"
 
@@ -4213,6 +4394,7 @@ test_105c() {
         else
                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
         fi
+       rm -f $DIR/$tfile
 }
 run_test 105c "lockf when mounted without -o flock test ========"
 
@@ -4274,6 +4456,7 @@ test_110() {
        touch $DIR/d110/yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy && error ""create with 256 char should fail, but not
 
        ls -l $DIR/d110
+    rm -fr $DIR/d110
 }
 run_test 110 "filename length checking"
 
@@ -4326,7 +4509,6 @@ free_min_max () {
 
 test_116() {
        [ "$OSTCOUNT" -lt "2" ] && skip "$OSTCOUNT < 2 OSTs" && return
-       remote_mds && skip "remote MDS" && return
 
        echo -n "Free space priority "
        lctl get_param -n lov.*-clilov-*.qos_prio_free
@@ -4341,7 +4523,7 @@ test_116() {
        declare -i FILL
        FILL=$(($MINV / 4))
        echo "Filling 25% remaining space in OST${MINI} with ${FILL}Kb"
-       $SETSTRIPE $DIR/$tdir/OST${MINI} -i $MINI -c 1
+       $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI}||error "setstripe failed"
        i=0
        while [ $FILL -gt 0 ]; do
            i=$(($i + 1))
@@ -4406,6 +4588,8 @@ test_116() {
        echo "$MAXC files created on larger OST $MAXI1"
        [ $MINC -gt 0 ] && echo "Wrote $(($MAXC * 100 / $MINC - 100))% more files to larger OST $MAXI1"
        [ $MAXC -gt $MINC ] || error_ignore "stripe QOS didn't balance free space"
+
+       rm -rf $DIR/$tdir/OST${MINI}
 }
 run_test 116 "stripe QOS: free space balance ==================="
 
@@ -4417,6 +4601,7 @@ test_117() # bug 10891
         > $DIR/$tfile || error "truncate failed"
         lctl set_param fail_loc=0
         echo "Truncate succeeded."
+       rm -f $DIR/$tfile
 }
 run_test 117 "verify fsfilt_extend =========="
 
@@ -4435,7 +4620,7 @@ reset_async() {
        FILE=$DIR/reset_async
 
        # Ensure all OSCs are cleared
-       $LSTRIPE $FILE 0 -1 -1
+       $LSTRIPE -c -1 $FILE
         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
        sync
         rm $FILE
@@ -4444,7 +4629,7 @@ reset_async() {
 test_118a() #bug 11710
 {
        reset_async
-       
+
        multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
        DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
@@ -4453,12 +4638,13 @@ test_118a() #bug 11710
                error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
                return 1;
         fi
+       rm -f $DIR/$tfile
 }
 run_test 118a "verify O_SYNC works =========="
 
 test_118b()
 {
-       remote_ost_nodsh && skip "remote OST" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
 
        reset_async
 
@@ -4487,14 +4673,14 @@ test_118b()
        # until a subsequent RPC completes successfully without error.
        multiop $DIR/$tfile Ow4096yc
        rm -f $DIR/$tfile
-       
+
        return 0
 }
 run_test 118b "Reclaim dirty pages on fatal error =========="
 
 test_118c()
 {
-       remote_ost_nodsh && skip "remote OST" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
 
        reset_async
 
@@ -4529,7 +4715,7 @@ test_118c()
        if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
                error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
        fi
-       
+
        rm -f $DIR/$tfile
        echo "Dirty pages flushed via fsync on EROFS"
        return 0
@@ -4538,14 +4724,14 @@ run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
 
 test_118d()
 {
-       remote_ost_nodsh && skip "remote OST" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
 
        reset_async
 
        #define OBD_FAIL_OST_BRW_PAUSE_BULK
        set_nodes_failloc "$(osts_nodes)" 0x214
        # multiop should block due to fsync until pages are written
-       multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &     
+       multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
        MULTIPID=$!
        sleep 1
 
@@ -4587,7 +4773,7 @@ test_118f() {
        if [[ $RC -eq 0 ]]; then
                error "Must return error due to dropped pages, rc=$RC"
        fi
-       
+
         lctl set_param fail_loc=0x0
 
         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
@@ -4619,7 +4805,7 @@ test_118g() {
        # simulate local -ENOMEM
        multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
        RC=$?
-       
+
        lctl set_param fail_loc=0
        if [[ $RC -eq 0 ]]; then
                error "Must return error due to dropped pages, rc=$RC"
@@ -4632,7 +4818,7 @@ test_118g() {
        if [[ $LOCKED -ne 0 ]]; then
                error "Locked pages remain in cache, locked=$LOCKED"
        fi
-       
+
        if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
                error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
        fi
@@ -4646,7 +4832,7 @@ test_118g() {
 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
 
 test_118h() {
-       remote_ost_nodsh && skip "remote OST" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
 
         reset_async
 
@@ -4655,7 +4841,7 @@ test_118h() {
        # Should simulate ENOMEM error which is recoverable and should be handled by timeout
         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
         RC=$?
-       
+
         set_nodes_failloc "$(osts_nodes)" 0
        if [[ $RC -eq 0 ]]; then
                error "Must return error due to dropped pages, rc=$RC"
@@ -4668,7 +4854,7 @@ test_118h() {
        if [[ $LOCKED -ne 0 ]]; then
                error "Locked pages remain in cache, locked=$LOCKED"
        fi
-       
+
        if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
                error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
        fi
@@ -4681,19 +4867,19 @@ test_118h() {
 run_test 118h "Verify timeout in handling recoverables errors  =========="
 
 test_118i() {
-       remote_ost_nodsh && skip "remote OST" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
 
         reset_async
 
        #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
         set_nodes_failloc "$(osts_nodes)" 0x20e
-       
+
        # Should simulate ENOMEM error which is recoverable and should be handled by timeout
         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
        PID=$!
        sleep 5
        set_nodes_failloc "$(osts_nodes)" 0
-       
+
        wait $PID
         RC=$?
        if [[ $RC -ne 0 ]]; then
@@ -4706,7 +4892,7 @@ test_118i() {
        if [[ $LOCKED -ne 0 ]]; then
                error "Locked pages remain in cache, locked=$LOCKED"
        fi
-       
+
        if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
                error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
        fi
@@ -4719,7 +4905,7 @@ test_118i() {
 run_test 118i "Fix error before timeout in recoverable error  =========="
 
 test_118j() {
-       remote_ost_nodsh && skip "remote OST" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
 
         reset_async
 
@@ -4740,7 +4926,7 @@ test_118j() {
        if [[ $LOCKED -ne 0 ]]; then
                error "Locked pages remain in cache, locked=$LOCKED"
        fi
-       
+
        # in recoverable error on OST we want resend and stay until it finished
        if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
                error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
@@ -4755,6 +4941,8 @@ run_test 118j "Simulate unrecoverable OST side error =========="
 
 test_118k()
 {
+       remote_ost_nodsh && skip "remote OSTs with nodsh" && return
+
        #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
        set_nodes_failloc "$(osts_nodes)" 0x20e
        mkdir -p $DIR/$tdir
@@ -4794,7 +4982,7 @@ test_119b() # bug 11737
 {
         [ "$OSTCOUNT" -lt "2" ] && skip "skipping 2-stripe test" && return
 
-        $SETSTRIPE $DIR/$tfile -c 2
+        $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
         sync
         multiop $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
@@ -5037,45 +5225,83 @@ test_123a() { # was test 123, statahead(bug 11401)
                SLOWOK=1
         fi
 
-        remount_client $MOUNT
+        rm -rf $DIR/$tdir
         mkdir -p $DIR/$tdir
-        error=0
         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
         [ $NUMFREE -gt 100000 ] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
         MULT=10
-        for ((i=1, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
+        for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
 
-                lctl get_param -n llite.*.statahead_max | grep '[0-9]'
-                cancel_lru_locks mdc
-                cancel_lru_locks osc
-                stime=`date +%s`
-                ls -l $DIR/$tdir > /dev/null
-                etime=`date +%s`
-                delta_sa=$((etime - stime))
-                log "ls $i files with statahead:    $delta_sa sec"
-               lctl get_param -n llite.*.statahead_stats
-
                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
                 lctl set_param -n llite.*.statahead_max 0
                 lctl get_param llite.*.statahead_max
                 cancel_lru_locks mdc
                 cancel_lru_locks osc
                 stime=`date +%s`
-                ls -l $DIR/$tdir > /dev/null
+                time ls -l $DIR/$tdir | wc -l
                 etime=`date +%s`
                 delta=$((etime - stime))
                 log "ls $i files without statahead: $delta sec"
-
                 lctl set_param llite.*.statahead_max=$max
-                if [ $delta_sa -gt $(($delta + 2)) ]; then
-                        log "ls $i files is slower with statahead!"
-                        error=1
+
+                swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
+                lctl get_param -n llite.*.statahead_max | grep '[0-9]'
+                cancel_lru_locks mdc
+                cancel_lru_locks osc
+                stime=`date +%s`
+                time ls -l $DIR/$tdir | wc -l
+                etime=`date +%s`
+                delta_sa=$((etime - stime))
+                log "ls $i files with statahead: $delta_sa sec"
+               lctl get_param -n llite.*.statahead_stats
+                ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
+
+                if [ $swrong -lt $ewrong ]; then
+                        log "statahead was stopped, maybe too many locks held!"
+                fi
+
+                [ $delta -eq 0 -o $delta_sa -eq 0 ] && continue
+
+                if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
+                        if [  $SLOWOK -eq 0 ]; then
+                                error "ls $i files is slower with statahead!"
+                                debugsave
+
+                                lctl set_param debug=-1
+                                max=`lctl get_param -n llite.*.statahead_max | head -n 1`
+                                lctl set_param -n llite.*.statahead_max 0
+                                lctl get_param llite.*.statahead_max
+                                cancel_lru_locks mdc
+                                cancel_lru_locks osc
+                                $LCTL clear
+                                stime=`date +%s`
+                                time ls -l $DIR/$tdir | wc -l
+                                etime=`date +%s`
+                                error "ls $i files (again) without statahead: $((etime - stime)) sec"
+
+                                lctl set_param debug=-1
+                                lctl set_param llite.*.statahead_max=$max
+                                lctl get_param -n llite.*.statahead_max | grep '[0-9]'
+                                cancel_lru_locks mdc
+                                cancel_lru_locks osc
+                                $LCTL clear
+                                stime=`date +%s`
+                                time ls -l $DIR/$tdir | wc -l
+                                etime=`date +%s`
+                                error "ls $i files (again) with statahead: $((etime - stime)) sec"
+                               lctl get_param -n llite.*.statahead_stats
+
+                                debugrestore
+                        else
+                                log "ls $i files is slower with statahead!"
+                        fi
+                        break
                 fi
 
                 [ $delta -gt 20 ] && break
                 [ $delta -gt 8 ] && MULT=$((50 / delta))
-                [ "$SLOW" = "no" -a $delta -gt 3 ] && break
+                [ "$SLOW" = "no" -a $delta -gt 5 ] && break
         done
         log "ls done"
 
@@ -5087,17 +5313,13 @@ test_123a() { # was test 123, statahead(bug 11401)
         log "rm -r $DIR/$tdir/: $delta seconds"
         log "rm done"
         lctl get_param -n llite.*.statahead_stats
-        # wait for commitment of removal
-        sleep 2
-        [ $error -ne 0 -a $SLOWOK -eq 0 ] && error "statahead is slow!"
-        return 0
 }
 run_test 123a "verify statahead work"
 
 test_123b () { # statahead(bug 15027)
        mkdir -p $DIR/$tdir
        createmany -o $DIR/$tdir/$tfile-%d 1000
-       
+
         cancel_lru_locks mdc
         cancel_lru_locks osc
 
@@ -5116,10 +5338,9 @@ run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
 test_124a() {
        [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
                skip "no lru resize on server" && return 0
-        NR=2000
+        local NR=2000
         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
 
-        # use touch to produce $NR new locks
         log "create $NR files at $DIR/$tdir"
         createmany -o $DIR/$tdir/f $NR ||
                 error "failed to create $NR files in $DIR/$tdir"
@@ -5127,14 +5348,14 @@ test_124a() {
         cancel_lru_locks mdc
         ls -l $DIR/$tdir > /dev/null
 
-        NSDIR=""
-        LRU_SIZE=0
+        local NSDIR=""
+        local LRU_SIZE=0
         for VALUE in `lctl get_param ldlm.namespaces.*mdc-*.lru_size`; do
-               PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
+                local PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
                 LRU_SIZE=$(lctl get_param -n $PARAM)
                 if [ $LRU_SIZE -gt $(default_lru_size) ]; then
                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
-                        log "using $(basename $NSDIR) namespace"
+                        log "NS=$(basename $NSDIR)"
                         break
                 fi
         done
@@ -5143,40 +5364,53 @@ test_124a() {
                 skip "Not enough cached locks created!"
                 return 0
         fi
-        log "created $LRU_SIZE lock(s)"
-
-        # we want to sleep 30s to not make test too long
-        SLEEP=30
-        SLEEP_ADD=2
-
-        # we know that lru resize allows one client to hold $LIMIT locks for 10h
-        MAX_HRS=10
-
-        # get the pool limit
-        LIMIT=`lctl get_param -n $NSDIR.pool.limit`
-
-        # calculate lock volume factor taking into account data set size and the
-        # rule that number of locks will be getting smaller durring sleep interval
-        # and we need to additionally enforce LVF to take this into account.
-        # Use $LRU_SIZE_B here to take into account real number of locks created
-        # in the case of CMD, LRU_SIZE_B != $NR in most of cases
-        LVF=$(($MAX_HRS * 60 * 60 * $LIMIT / $SLEEP))
-        LRU_SIZE_B=$LRU_SIZE
-        log "make client drop locks $LVF times faster so that ${SLEEP}s is enough to cancel $LRU_SIZE lock(s)"
-        OLD_LVF=`lctl get_param -n $NSDIR.pool.lock_volume_factor`
+        log "LRU=$LRU_SIZE"
+
+        local SLEEP=30
+
+        # We know that lru resize allows one client to hold $LIMIT locks
+        # for 10h. After that locks begin to be killed by client.
+        local MAX_HRS=10
+        local LIMIT=`lctl get_param -n $NSDIR.pool.limit`
+
+        # Make LVF so higher that sleeping for $SLEEP is enough to _start_
+        # killing locks. Some time was spent for creating locks. This means
+        # that up to the moment of sleep finish we must have killed some of
+        # them (10-100 locks). This depends on how fast ther were created.
+        # Many of them were touched in almost the same moment and thus will
+        # be killed in groups.
+        local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
+
+        # Use $LRU_SIZE_B here to take into account real number of locks
+        # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
+        local LRU_SIZE_B=$LRU_SIZE
+        log "LVF=$LVF"
+        local OLD_LVF=`lctl get_param -n $NSDIR.pool.lock_volume_factor`
         lctl set_param -n $NSDIR.pool.lock_volume_factor $LVF
-        log "sleep for $((SLEEP+SLEEP_ADD))s"
-        sleep $((SLEEP+SLEEP_ADD))
+
+        # Let's make sure that we really have some margin. Client checks
+        # cached locks every 10 sec.
+        SLEEP=$((SLEEP+20))
+        log "Sleep ${SLEEP} sec"
+        local SEC=0
+        while ((SEC<$SLEEP)); do
+                echo -n "..."
+                sleep 5
+                SEC=$((SEC+5))
+                LRU_SIZE=`lctl get_param -n $NSDIR/lru_size`
+                echo -n "$LRU_SIZE"
+        done
+        echo ""
         lctl set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
-        LRU_SIZE_A=`lctl get_param -n $NSDIR.lru_size`
+        local LRU_SIZE_A=`lctl get_param -n $NSDIR/lru_size`
 
         [ $LRU_SIZE_B -gt $LRU_SIZE_A ] || {
-                error "No locks dropped in "$((SLEEP+SLEEP_ADD))"s. LRU size: $LRU_SIZE_A"
+                error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
                 unlinkmany $DIR/$tdir/f $NR
                 return
         }
 
-        log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in "$((SLEEP+SLEEP_ADD))"s"
+        log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
         log "unlink $NR files at $DIR/$tdir"
         unlinkmany $DIR/$tdir/f $NR
 }
@@ -5276,6 +5510,8 @@ run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs
 test_126() { # bug 12829/13455
        [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
        [ "$UID" != 0 ] && echo "skipping $TESTNAME (must run as root)" && return
+       $GSS && skip "must run as gss disabled" && return
+
        $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
        gid=`ls -n $DIR/$tfile | awk '{print $4}'`
        rm -f $DIR/$tfile
@@ -5284,7 +5520,7 @@ test_126() { # bug 12829/13455
 run_test 126 "check that the fsgid provided by the client is taken into account"
 
 test_127() { # bug 15521
-        $LSTRIPE -i 0 -c 1 $DIR/$tfile
+        $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
         $LCTL set_param osc.*.stats=0
         FSIZE=$((2048 * 1024))
         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
@@ -5296,7 +5532,7 @@ test_127() { # bug 15521
                 echo "got $COUNT $NAME"
                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
                 eval $NAME=$COUNT || error "Wrong proc format"
-               
+
                 case $NAME in
                         read_bytes|write_bytes)
                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
@@ -5350,6 +5586,7 @@ set_dir_limits () {
 }
 test_129() {
         [ "$FSTYPE" != "ldiskfs" ] && skip "not needed for FSTYPE=$FSTYPE" && return 0
+        remote_mds_nodsh && skip "remote MDS with nodsh" && return
 
         EFBIG=27
         MAX=16384
@@ -5380,10 +5617,18 @@ test_129() {
 }
 run_test 129 "test directory size limit ========================"
 
+OLDIFS="$IFS"
+cleanup_130() {
+       trap 0
+       IFS="$OLDIFS"
+}
+
 test_130a() {
        filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
        [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
 
+       trap cleanup_130 EXIT RETURN
+
        local fm_file=$DIR/$tfile
        lfs setstripe -s 65536 -c 1 $fm_file || error "setstripe failed on $fm_file"
        dd if=/dev/zero of=$fm_file bs=65536 count=1 || error "dd failed for $fm_file"
@@ -5401,6 +5646,7 @@ test_130a() {
                frag_lun=`echo $line | cut -d: -f5`
                ext_len=`echo $line | cut -d: -f4`
                if (( $frag_lun != $lun )); then
+                       cleanup_130
                        error "FIEMAP on 1-stripe file($fm_file) failed"
                        return
                fi
@@ -5408,9 +5654,13 @@ test_130a() {
        done
 
        if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
+               cleanup_130
                error "FIEMAP on 1-stripe file($fm_file) failed;"
                return
        fi
+
+       cleanup_130
+
        echo "FIEMAP on single striped file succeeded"
 }
 run_test 130a "FIEMAP (1-stripe file)"
@@ -5421,6 +5671,8 @@ test_130b() {
        filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
        [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
 
+       trap cleanup_130 EXIT RETURN
+
        local fm_file=$DIR/$tfile
        lfs setstripe -s 65536 -c 2 $fm_file || error "setstripe failed on $fm_file"
        dd if=/dev/zero of=$fm_file bs=1M count=2 || error "dd failed on $fm_file"
@@ -5439,6 +5691,7 @@ test_130b() {
                ext_len=`echo $line | cut -d: -f4`
                if (( $frag_lun != $last_lun )); then
                        if (( tot_len != 1024 )); then
+                               cleanup_130
                                error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
                                return
                        else
@@ -5450,10 +5703,13 @@ test_130b() {
                last_lun=$frag_lun
        done
        if (( num_luns != 2 || tot_len != 1024 )); then
+               cleanup_130
                error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
                return
        fi
 
+       cleanup_130
+
        echo "FIEMAP on 2-stripe file succeeded"
 }
 run_test 130b "FIEMAP (2-stripe file)"
@@ -5464,6 +5720,8 @@ test_130c() {
        filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
        [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
 
+       trap cleanup_130 EXIT RETURN
+
        local fm_file=$DIR/$tfile
        lfs setstripe -s 65536 -c 2 $fm_file || error "setstripe failed on $fm_file"
        dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
@@ -5483,10 +5741,12 @@ test_130c() {
                if (( $frag_lun != $last_lun )); then
                        logical=`echo $line | cut -d: -f2 | cut -d. -f1`
                        if (( logical != 512 )); then
+                               cleanup_130
                                error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
                                return
                        fi
                        if (( tot_len != 512 )); then
+                               cleanup_130
                                error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
                                return
                        else
@@ -5498,10 +5758,13 @@ test_130c() {
                last_lun=$frag_lun
        done
        if (( num_luns != 2 || tot_len != 512 )); then
+               cleanup_130
                error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
                return
        fi
 
+       cleanup_130
+
        echo "FIEMAP on 2-stripe file with hole succeeded"
 }
 run_test 130c "FIEMAP (2-stripe file with hole)"
@@ -5512,6 +5775,8 @@ test_130d() {
        filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
        [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
 
+       trap cleanup_130 EXIT RETURN
+
        local fm_file=$DIR/$tfile
        lfs setstripe -s 65536 -c $OSTCOUNT $fm_file || error "setstripe failed on $fm_file"
        dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT || error "dd failed on $fm_file"
@@ -5530,6 +5795,7 @@ test_130d() {
                ext_len=`echo $line | cut -d: -f4`
                if (( $frag_lun != $last_lun )); then
                        if (( tot_len != 1024 )); then
+                               cleanup_130
                                error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
                                return
                        else
@@ -5541,10 +5807,13 @@ test_130d() {
                last_lun=$frag_lun
        done
        if (( num_luns != OSTCOUNT || tot_len != 1024 )); then
+               cleanup_130
                error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
                return
        fi
 
+       cleanup_130
+
        echo "FIEMAP on N-stripe file succeeded"
 }
 run_test 130d "FIEMAP (N-stripe file)"
@@ -5555,6 +5824,8 @@ test_130e() {
        filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
        [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
 
+       trap cleanup_130 EXIT RETURN
+
        local fm_file=$DIR/$tfile
        lfs setstripe -s 65536 -c 2 $fm_file || error "setstripe failed on $fm_file"
        NUM_BLKS=512
@@ -5578,6 +5849,7 @@ test_130e() {
                ext_len=`echo $line | cut -d: -f4`
                if (( $frag_lun != $last_lun )); then
                        if (( tot_len != $EXPECTED_LEN )); then
+                               cleanup_130
                                error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
                                return
                        else
@@ -5589,15 +5861,148 @@ test_130e() {
                last_lun=$frag_lun
        done
        if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
-               echo "$num_luns $tot_len"
+               cleanup_130
                error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
                return
        fi
 
+       cleanup_130
+
        echo "FIEMAP with continuation calls succeeded"
 }
 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
 
+# Test for writev/readv
+test_131a() {
+       rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
+       error "writev test failed"
+       rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
+       error "readv failed"
+       rm -f $DIR/$tfile
+}
+run_test 131a "test iov's crossing stripe boundary for writev/readv"
+
+test_131b() {
+       rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
+       error "append writev test failed"
+       rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
+       error "append writev test failed"
+       rm -f $DIR/$tfile
+}
+run_test 131b "test append writev"
+
+test_131c() {
+       rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
+       error "NOT PASS"
+}
+run_test 131c "test read/write on file w/o objects"
+
+test_131d() {
+       rwv -f $DIR/$tfile -w -n 1 1572864
+       NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
+       if [ "$NOB" != 1572864 ]; then
+               error "Short read filed: read $NOB bytes instead of 1572864"
+       fi
+       rm -f $DIR/$tfile
+}
+run_test 131d "test short read"
+
+test_131e() {
+       rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
+       rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
+       error "read hitting hole failed"
+       rm -f $DIR/$tfile
+}
+run_test 131e "test read hitting hole"
+
+get_ost_param() {
+        local token=$1
+        local gl_sum=0
+        for node in $(osts_nodes); do
+                gl=$(do_node $node "$LCTL get_param -n ost.OSS.ost.stats" | awk '/'$token'/ {print $2}' | head -n 1)
+                [ x$gl = x"" ] && gl=0
+                gl_sum=$((gl_sum + gl))
+        done
+        echo $gl
+}
+
+som_mode_switch() {
+        local som=$1
+        local gl1=$2
+        local gl2=$3
+
+        if [ x$som = x"enabled" ]; then
+                [ $((gl2 - gl1)) -gt 0 ] && error "no glimpse RPC is expected"
+                do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=disabled"
+        else
+                [ $((gl2 - gl1)) -gt 0 ] || error "some glimpse RPC is expected"
+                do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=enabled"
+        fi
+
+        # do remount to make new mount-conf parameters actual
+        echo remounting...
+        sync
+        stopall
+        setupall
+}
+
+test_132() { #1028, SOM
+       local num=$(get_mds_dir $DIR)
+       local mymds=mds${num}
+
+        dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
+        cancel_lru_locks osc
+
+        som1=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
+
+        gl1=$(get_ost_param "ldlm_glimpse_enqueue")
+        stat $DIR/$tfile >/dev/null
+        gl2=$(get_ost_param "ldlm_glimpse_enqueue")
+        echo "====> SOM is "$som1", "$((gl2 - gl1))" glimpse RPC occured"
+        cancel_lru_locks osc
+        som_mode_switch $som1 $gl1 $gl2
+
+        som2=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
+        [ $som1 != $som2 ] || error "som is still "$som2
+
+        gl1=$(get_ost_param "ldlm_glimpse_enqueue")
+        stat $DIR/$tfile >/dev/null
+        gl2=$(get_ost_param "ldlm_glimpse_enqueue")
+        echo "SOM is "$som2", "$((gl2 - gl1))" glimpse RPC occured"
+        som_mode_switch $som2 $gl1 $gl2
+}
+run_test 132 "som avoids glimpse rpc"
+
+test_140() { #bug-17379
+        mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
+        cd $DIR/$tdir || error "Changing to $DIR/$tdir"
+        cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
+
+        # VFS limits max symlink depth to 5(4KSTACK) or 8
+        local i=0
+        while i=`expr $i + 1`; do
+                mkdir -p $i || error "Creating dir $i"
+                cd $i || error "Changing to $i"
+                ln -s ../stat stat || error "Creating stat symlink"
+                # Read the symlink until ELOOP present,
+                # not LBUGing the system is considered success,
+                # we didn't overrun the stack.
+                $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
+                [ $ret -ne 0 ] && {
+                        if [ $ret -eq 40 ]; then
+                                break  # -ELOOP
+                        else
+                                error "Open stat symlink"
+                                return
+                        fi
+                }
+        done
+        i=`expr $i - 1`
+        echo "The symlink depth = $i"
+        [ $i -eq 4 -o $i -eq 8 ] || error "Invalid symlink depth"
+}
+run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
+
 test_150() {
        local TF="$TMP/$tfile"
 
@@ -5629,61 +6034,66 @@ test_150() {
 run_test 150 "truncate/append tests"
 
 function roc_access() {
-       ACCNUM=`$LCTL get_param -n obdfilter.*.stats | \
-               grep 'cache_access'| awk '{print $2}' | \
-               awk '{sum=sum+$3} END{print sum}'`
-       echo $ACCNUM
+        local list=$(comma_list $(osts_nodes))
+        ACCNUM=`do_nodes $list $LCTL get_param -n obdfilter.*.stats | \
+                grep 'cache_access'| awk '{print $2}' | \
+                awk '{sum=sum+$3} END{print sum}'`
+        echo $ACCNUM
 }
 
 function roc_hit() {
-       ACCNUM=`$LCTL get_param -n obdfilter.*.stats | \
-               grep 'cache_hit'|awk '{print $2}' | \
-               awk '{sum=sum+$1} END{print sum}'`
-       echo $ACCNUM
+        local list=$(comma_list $(osts_nodes))
+        ACCNUM=`do_nodes $list $LCTL get_param -n obdfilter.*.stats | \
+                grep 'cache_hit'|awk '{print $2}' | \
+                awk '{sum=sum+$1} END{print sum}'`
+        echo $ACCNUM
 }
 
 test_151() {
-       local CPAGES=3
+        remote_ost_nodsh && skip "remote OST with nodsh" && return
 
-       # check whether obdfilter is cache capable at all
-       if ! $LCTL get_param -n obdfilter.*.read_cache_enable; then
-               echo "not cache-capable obdfilter"
-               return 0
-       fi
+        local CPAGES=3
+        local list=$(comma_list $(osts_nodes))
 
-       # check cache is enabled on all obdfilters
-       if $LCTL get_param -n obdfilter.*.read_cache_enable | grep 0 >&/dev/null; then
-               echo "oss cache is disabled"
-               return 0
-       fi
+        # check whether obdfilter is cache capable at all
+        if ! do_nodes $list $LCTL get_param -n obdfilter.*.read_cache_enable > /dev/null; then
+                echo "not cache-capable obdfilter"
+                return 0
+        fi
 
-       $LCTL set_param -n obdfilter.*.writethrough_cache_enable 1
+        # check cache is enabled on all obdfilters
+        if do_nodes $list $LCTL get_param -n obdfilter.*.read_cache_enable | grep 0 >&/dev/null; then
+                echo "oss cache is disabled"
+                return 0
+        fi
 
-       # pages should be in the case right after write 
+        do_nodes $list $LCTL set_param -n obdfilter.*.writethrough_cache_enable 1
+
+        # pages should be in the case right after write
         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES || error "dd failed"
-       BEFORE=`roc_hit`
+        local BEFORE=`roc_hit`
         cancel_lru_locks osc
-       cat $DIR/$tfile >/dev/null
-       AFTER=`roc_hit`
-       if ! let "AFTER - BEFORE == CPAGES"; then
-               error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
-       fi
+        cat $DIR/$tfile >/dev/null
+        local AFTER=`roc_hit`
+        if ! let "AFTER - BEFORE == CPAGES"; then
+                error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
+        fi
 
-       # the following read invalidates the cache
+        # the following read invalidates the cache
         cancel_lru_locks osc
-       $LCTL set_param -n obdfilter.*.read_cache_enable 0
-       cat $DIR/$tfile >/dev/null
+        do_nodes $list $LCTL set_param -n obdfilter.*.read_cache_enable 0
+        cat $DIR/$tfile >/dev/null
 
-       # now data shouldn't be found in the cache
-       BEFORE=`roc_hit`
+        # now data shouldn't be found in the cache
+        BEFORE=`roc_hit`
         cancel_lru_locks osc
-       cat $DIR/$tfile >/dev/null
-       AFTER=`roc_hit`
-       if ! let "AFTER - BEFORE == CPAGES"; then
-               error "IN CACHE: before: $BEFORE, after: $AFTER"
-       fi
+        cat $DIR/$tfile >/dev/null
+        AFTER=`roc_hit`
+        if let "AFTER - BEFORE != 0"; then
+                error "IN CACHE: before: $BEFORE, after: $AFTER"
+        fi
 
-       $LCTL set_param -n obdfilter.*.read_cache_enable 1
+        do_nodes $list $LCTL set_param -n obdfilter.*.read_cache_enable 1
         rm -f $DIR/$tfile
 }
 run_test 151 "test cache on oss and controls ==============================="
@@ -5691,14 +6101,14 @@ run_test 151 "test cache on oss and controls ==============================="
 test_152() {
         local TF="$TMP/$tfile"
 
-       # simulate ENOMEM during write
-#define OBD_FAIL_OST_NOMEM             0x226
+        # simulate ENOMEM during write
+#define OBD_FAIL_OST_NOMEM      0x226
         lctl set_param fail_loc=0x80000226
         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
         cp $TF $DIR/$tfile
         sync || error "sync failed"
         lctl set_param fail_loc=0
-       
+
         # discard client's cache
         cancel_lru_locks osc
 
@@ -5707,10 +6117,268 @@ test_152() {
         cmp $TF $DIR/$tfile || error "cmp failed"
         lctl set_param fail_loc=0
 
-       rm -f $TF
+        rm -f $TF
 }
 run_test 152 "test read/write with enomem ============================"
 
+test_153() {
+        multiop $DIR/$tfile Ow4096Ycu || error "multiop failed"
+}
+run_test 153 "test if fdatasync does not crash ======================="
+
+test_154() {
+       cp /etc/hosts $DIR/$tfile
+
+       fid=$($LFS path2fid $DIR/$tfile)
+       rc=$?
+       [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
+
+       echo "open fid $fid"
+       diff /etc/hosts $DIR/.lustre/fid/$fid || error "open by fid failed: did not find expected data in file."
+
+       echo "Opening a file by FID succeeded"
+}
+run_test 154 "Opening a file by FID"
+
+#Changelogs
+err17935 () {
+    if [ $MDSCOUNT -gt 1 ]; then
+       error_ignore 17935 $*
+    else
+       error $*
+    fi
+}
+test_160() {
+    USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
+    echo "Registered as changelog user $USER"
+    do_facet $SINGLEMDS lctl get_param -n mdd.$MDT0.changelog_users | \
+       grep -q $USER || error "User $USER not found in changelog_users"
+
+    # change something
+    mkdir -p $DIR/$tdir/pics/2008/zachy
+    touch $DIR/$tdir/pics/2008/zachy/timestamp
+    cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
+    mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
+    ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
+    ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
+    rm $DIR/$tdir/pics/desktop.jpg
+
+    $LFS changelog $MDT0 | tail -5
+
+    echo "verifying changelog mask"
+    do_facet $SINGLEMDS lctl set_param mdd.$MDT0.changelog_mask="-mkdir"
+    mkdir -p $DIR/$tdir/pics/2009/sofia
+    do_facet $SINGLEMDS lctl set_param mdd.$MDT0.changelog_mask="+mkdir"
+    mkdir $DIR/$tdir/pics/2009/zachary
+    DIRS=$($LFS changelog $MDT0 | tail -5 | grep -c MKDIR)
+    [ $DIRS -eq 1 ] || err17935 "changelog mask count $DIRS != 1"
+
+    # verify contents
+    echo "verifying target fid"
+    fidc=$($LFS changelog $MDT0 | grep timestamp | grep "CREAT" | \
+       tail -1 | awk '{print $5}')
+    fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
+    [ "$fidc" == "t=$fidf" ] || \
+       err17935 "fid in changelog $fidc != file fid $fidf"
+    echo "verifying parent fid"
+    fidc=$($LFS changelog $MDT0 | grep timestamp | grep "CREAT" | \
+       tail -1 | awk '{print $6}')
+    fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
+    [ "$fidc" == "p=$fidf" ] || \
+       err17935 "pfid in changelog $fidc != dir fid $fidf"
+
+    USER_REC1=$(do_facet $SINGLEMDS lctl get_param -n \
+       mdd.$MDT0.changelog_users | grep $USER | awk '{print $2}')
+    $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
+    USER_REC2=$(do_facet $SINGLEMDS lctl get_param -n \
+       mdd.$MDT0.changelog_users | grep $USER | awk '{print $2}')
+    echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
+    [ $USER_REC2 == $(($USER_REC1 + 5)) ] || \
+       err17935 "user index should be $(($USER_REC1 + 5)); is $USER_REC2"
+
+    MIN_REC=$(do_facet $SINGLEMDS lctl get_param mdd.$MDT0.changelog_users | \
+       awk 'min == "" || $2 < min {min = $2}; END {print min}')
+    FIRST_REC=$($LFS changelog $MDT0 | head -1 | awk '{print $1}')
+    echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
+    [ $FIRST_REC == $(($MIN_REC + 1)) ] || \
+       err17935 "first index should be $(($MIN_REC + 1)); is $FIRST_REC"
+
+    echo "verifying user deregister"
+    do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $USER
+    do_facet $SINGLEMDS lctl get_param -n mdd.$MDT0.changelog_users | \
+       grep -q $USER && error "User $USER still found in changelog_users"
+
+    USERS=$(( $(do_facet $SINGLEMDS lctl get_param -n \
+       mdd.$MDT0.changelog_users | wc -l) - 2 ))
+    if [ $USERS -eq 0 ]; then
+       LAST_REC1=$(do_facet $SINGLEMDS lctl get_param -n \
+           mdd.$MDT0.changelog_users | head -1 | awk '{print $3}')
+       touch $DIR/$tdir/chloe
+       LAST_REC2=$(do_facet $SINGLEMDS lctl get_param -n \
+           mdd.$MDT0.changelog_users | head -1 | awk '{print $3}')
+       echo "verify changelogs are off if we were the only user: $LAST_REC1 == $LAST_REC2"
+       [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
+    else
+       echo "$USERS other changelog users; can't verify off"
+    fi
+}
+run_test 160 "changelog sanity"
+
+test_161() {
+    mkdir -p $DIR/$tdir
+    cp /etc/hosts $DIR/$tdir/$tfile
+    mkdir $DIR/$tdir/foo1
+    mkdir $DIR/$tdir/foo2
+    ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
+    ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
+    ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
+    ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
+    local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[')
+    if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
+       $LFS fid2path $DIR $FID
+       err17935 "bad link ea"
+    fi
+    # middle
+    rm $DIR/$tdir/foo2/zachary
+    # last
+    rm $DIR/$tdir/foo2/thor
+    # first
+    rm $DIR/$tdir/$tfile
+    # rename
+    mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
+    if [ "$($LFS fid2path $DIR --link 1 $FID)" != "/$tdir/foo2/maggie" ]
+       then
+       $LFS fid2path $DIR $FID
+       err17935 "bad link rename"
+    fi
+    rm $DIR/$tdir/foo2/maggie
+
+    # overflow the EA
+    local longname=filename_avg_len_is_thirty_two_
+    createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 || \
+       error "failed to hardlink many files"
+    links=$($LFS fid2path $DIR $FID | wc -l)
+    echo -n "${links}/1000 links in link EA"
+    [ ${links} -gt 60 ] || err17935 "expected at least 60 links in link EA"
+    unlinkmany $DIR/$tdir/foo2/$longname 1000 || \
+       error "failed to unlink many hardlinks"
+}
+run_test 161 "link ea sanity"
+
+check_path() {
+    local expected=$1
+    shift
+    local fid=$2
+
+    local path=$(${LFS} fid2path $*)
+    RC=$?
+
+    if [ $RC -ne 0 ]; then
+       err17935 "path looked up of $expected failed. Error $RC"
+       return $RC
+    elif [ "${path}" != "${expected}" ]; then
+       err17935 "path looked up \"${path}\" instead of \"${expected}\""
+       return 2
+    fi
+    echo "fid $fid resolves to path $path"
+}
+
+test_162() {
+    # Make changes to filesystem
+    mkdir -p $DIR/$tdir/d2
+    touch $DIR/$tdir/d2/$tfile
+    touch $DIR/$tdir/d2/x1
+    touch $DIR/$tdir/d2/x2
+    mkdir -p $DIR/$tdir/d2/a/b/c
+    mkdir -p $DIR/$tdir/d2/p/q/r
+    FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[')
+    check_path "/$tdir/d2/$tfile" $DIR $FID --link 0
+    ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
+    mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
+    FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[')
+    # fid2path dir/fsname should both work
+    check_path "/$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1
+    check_path "/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0
+    # check that there are 2 links
+    ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
+       err17935 "expected 2 links"
+
+    rm $DIR/$tdir/d2/p/q/r/hlink
+    check_path "/$tdir/d2/a/b/c/new_file" $DIR $FID --link 0
+    # Doesnt work with CMD yet: 17935
+    return 0
+}
+run_test 162 "path lookup sanity"
+
+test_169() {
+       # do directio so as not to populate the page cache
+       log "creating a 10 Mb file"
+       multiop $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
+       log "starting reads"
+       dd if=$DIR/$tfile of=/dev/null bs=4096 &
+       log "truncating the file"
+       multiop $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
+       log "killing dd"
+       kill %+ || true # reads might have finished
+       echo "wait until dd is finished"
+       wait
+       log "removing the temporary file"
+       rm -rf $DIR/$tfile || error "tmp file removal failed"
+}
+run_test 169 "parallel read and truncate should not deadlock ==="
+
+test_170() {
+        $LCTL clear    # bug 18514
+        $LCTL debug_daemon start $TMP/${tfile}_log_good
+        touch $DIR/$tfile
+        $LCTL debug_daemon stop
+        sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
+               error "sed failed to read log_good"
+
+        $LCTL debug_daemon start $TMP/${tfile}_log_good
+        rm -rf $DIR/$tfile
+        $LCTL debug_daemon stop
+
+        $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
+               error "lctl df log_bad failed"
+
+        local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
+        local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
+
+        $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
+        local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
+
+       [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
+               error "bad_line good_line1 good_line2 are empty"
+
+        cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
+        cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
+        cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
+
+        $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
+        local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
+        local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
+
+       [ "$bad_line_new" ] && [ "$good_line_new" ] ||
+               error "bad_line_new good_line_new are empty"
+
+        local expected_good=$((good_line1 + good_line2*2))
+
+        rm -f $TMP/${tfile}*
+        if [ $bad_line -ne $bad_line_new ]; then
+                error "expected $bad_line bad lines, but got $bad_line_new"
+                return 1
+        fi
+
+        if [ $expected_good -ne $good_line_new ]; then
+                error "expected $expected_good good lines, but got $good_line_new"
+                return 2
+        fi
+        true
+}
+run_test 170 "test lctl df to handle corrupted log ====================="
+
+# OST pools tests
 POOL=${POOL:-cea1}
 TGT_COUNT=$OSTCOUNT
 TGTPOOL_FIRST=1
@@ -5740,24 +6408,24 @@ check_file_in_pool()
 }
 
 test_200a() {
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && return
        do_facet mgs $LCTL pool_new $FSNAME.$POOL
-       do_facet mgs $LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL
-       [ $? == 0 ] || error "Pool creation of $POOL failed"
+        # get param should return err until pool is created
+        wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null || echo foo" "" || error "Pool creation of $POOL failed"
 }
 run_test 200a "Create new pool =========================================="
 
 test_200b() {
-       TGT=$(seq -f $FSNAME-OST%04g_UUID $TGTPOOL_FIRST $TGTPOOL_STEP \
-               $TGTPOOL_MAX | tr '\n' ' ')
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && return
+       TGT=$(for i in `seq $TGTPOOL_FIRST $TGTPOOL_STEP $TGTPOOL_MAX`; do printf "$FSNAME-OST%04x_UUID " $i; done)
        do_facet mgs $LCTL pool_add $FSNAME.$POOL \
-               $FSNAME-OST[$TGTPOOL_FIRST-$TGTPOOL_MAX/$TGTPOOL_STEP]_UUID
-       res=$(do_facet mgs $LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL | sort \
-                       | tr '\n' ' ')
-       [ "$res" = "$TGT" ] || error "Pool content ($res) do not match requested ($TGT)"
+               $FSNAME-OST[$TGTPOOL_FIRST-$TGTPOOL_MAX/$TGTPOOL_STEP]
+       wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL | sort -u | tr '\n' ' ' " "$TGT" || error "Add to pool failed"
 }
 run_test 200b "Add targets to a pool ===================================="
 
 test_200c() {
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && return
        mkdir -p $POOL_DIR
        $SETSTRIPE -c 2 -p $POOL $POOL_DIR
        [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR"
@@ -5765,12 +6433,14 @@ test_200c() {
 run_test 200c "Set pool on a directory ================================="
 
 test_200d() {
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && return
        res=$($GETSTRIPE $POOL_DIR | grep pool: | cut -f8 -d " ")
        [ "$res" = $POOL ] || error "Pool on $POOL_DIR is not $POOL"
 }
 run_test 200d "Check pool on a directory ==============================="
 
 test_200e() {
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && return
        failed=0
        for i in $(seq -w 1 $(($TGT_COUNT * 3)))
        do
@@ -5787,6 +6457,7 @@ test_200e() {
 run_test 200e "Check files allocation from directory pool =============="
 
 test_200f() {
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && return
        mkdir -p $POOL_FILE
        failed=0
        for i in $(seq -w 1 $(($TGT_COUNT * 3)))
@@ -5804,33 +6475,71 @@ test_200f() {
 run_test 200f "Create files in a pool ==================================="
 
 test_200g() {
-       TGT=$(do_facet mgs $LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL | head -1)
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && return
+       TGT=$($LCTL get_param -n lov.$FSNAME-*.pools.$POOL | head -1)
        do_facet mgs $LCTL pool_remove $FSNAME.$POOL $TGT
-       res=$(do_facet mgs $LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL | grep $TGT)
-       [ "$res" = "" ] || error "$TGT not removed from $FSNAME.$POOL"
+       wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL | grep $TGT" "" || error "$TGT not removed from $FSNAME.$POOL"
 }
 run_test 200g "Remove a target from a pool ============================="
 
 test_200h() {
-       for TGT in $(do_facet mgs $LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL)
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && return
+       for TGT in $($LCTL get_param -n lov.$FSNAME-*.pools.$POOL | sort -u)
        do
                do_facet mgs $LCTL pool_remove $FSNAME.$POOL $TGT
        done
-       res=$(do_facet mgs $LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL)
-       [ "$res" = "" ] || error "Pool $FSNAME.$POOL cannot be drained"
+       wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL" ""\
+           || error "Pool $FSNAME.$POOL cannot be drained"
+       # striping on an empty pool should fall back to "pool of everything"
+       $SETSTRIPE -p $POOL ${POOL_FILE}/$tfile || error "failed to create file with empty pool"
 }
 run_test 200h "Remove all targets from a pool =========================="
 
 test_200i() {
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && return
        do_facet mgs $LCTL pool_destroy $FSNAME.$POOL
-       res=$(do_facet mgs "$LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL 2>/dev/null")
-       [ "$res" = "" ] || error "Pool $FSNAME.$POOL is not destroyed"
+       # get param should return err once pool is gone
+       wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null || echo foo" "foo" && return 0
+       error "Pool $FSNAME.$POOL is not destroyed"
 }
 run_test 200i "Remove a pool ============================================"
 
-TMPDIR=$OLDTMPDIR
-TMP=$OLDTMP
-HOME=$OLDHOME
+test_212() {
+       size=`date +%s`
+       size=$((size % 8192 + 1))
+       dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
+       sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
+       rm -f $DIR/f212 $DIR/f212.xyz
+}
+run_test 212 "Sendfile test ============================================"
+
+test_213() {
+       dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
+       cancel_lru_locks osc
+       lctl set_param fail_loc=0x8000040f
+       # generate a read lock
+       cat $DIR/$tfile > /dev/null
+       # write to the file, it will try to cancel the above read lock.
+       cat /etc/hosts >> $DIR/$tfile
+}
+run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
+
+#
+# tests that do cleanup/setup should be run at the end
+#
+
+test_900() {
+        local ls
+        #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
+        $LCTL set_param fail_loc=0x903
+        # cancel_lru_locks mgc - does not work due to lctl set_param syntax
+        for ls in /proc/fs/lustre/ldlm/namespaces/MGC*/lru_size; do
+                echo "clear" > $ls
+        done
+        FAIL_ON_ERROR=true cleanup
+        FAIL_ON_ERROR=true setup
+}
+run_test 900 "umount should not race with any mgc requeue thread"
 
 log "cleanup: ======================================================"
 check_and_cleanup_lustre