Whamcloud - gitweb
LU-9514 test: sanity 51f add to ALWAYS_EXCEPT
[fs/lustre-release.git] / lustre / tests / sanity.sh
index 50b3bfa..fb4539d 100755 (executable)
@@ -12,9 +12,8 @@ ONLY=${ONLY:-"$*"}
 ALWAYS_EXCEPT="                42a  42b  42c  42d  45   68b   $SANITY_EXCEPT"
 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
 
-# with LOD/OSP landing
-# bug number for skipped tests: LU-2036 LU-8139
-ALWAYS_EXCEPT="                 76     101g    $ALWAYS_EXCEPT"
+# bug number for skipped tests: LU-2036 LU-8411 LU-9096
+ALWAYS_EXCEPT="                 76     407     253 $ALWAYS_EXCEPT"
 
 is_sles11()                                            # LU-4341
 {
@@ -75,14 +74,14 @@ init_test_env $@
 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
 init_logging
 
-#                                  5              12          (min)"
-[ "$SLOW" = "no" ] && EXCEPT_SLOW="24D 27m 64b 68 71 115 300o"
+#                                  5          12          (min)"
+[ "$SLOW" = "no" ] && EXCEPT_SLOW="27m 64b 68 71 115 300o"
 
 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
-       # bug number for skipped test: LU-4536 LU-1957 LU-2805
-       ALWAYS_EXCEPT="$ALWAYS_EXCEPT  65ic    180     184c"
-       #                                               4   13    (min)"
-       [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b 51ba"
+       # bug number for skipped test: LU-9514 LU-4536 LU-1957
+       ALWAYS_EXCEPT="$ALWAYS_EXCEPT  51f     65ic    180"
+       #                                               13    (min)"
+       [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b"
 fi
 
 FAIL_ON_ERROR=false
@@ -264,6 +263,21 @@ test_6g() {
        test_mkdir $DIR/$tdir/d/subdir || error "mkdir $tdir/d/subdir failed"
        $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
                error "$tdir/d/subdir should be GID $RUNAS_GID"
+       if [[ $MDSCOUNT -gt 1 ]]; then
+               # check remote dir sgid inherite
+               $LFS mkdir -i 0 $DIR/$tdir.local ||
+                       error "mkdir $tdir.local failed"
+               chmod g+s $DIR/$tdir.local ||
+                       error "chmod $tdir.local failed"
+               chgrp $RUNAS_GID $DIR/$tdir.local ||
+                       error "chgrp $tdir.local failed"
+               $LFS mkdir -i 1 $DIR/$tdir.local/$tdir.remote ||
+                       error "mkdir $tdir.remote failed"
+               $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir.local/$tdir.remote ||
+                       error "$tdir.remote should be owned by $UID.$RUNAS_ID"
+               $CHECKSTAT -p 02755 $DIR/$tdir.local/$tdir.remote ||
+                       error "$tdir.remote should be mode 02755"
+       fi
 }
 run_test 6g "Is new dir in sgid dir inheriting group?"
 
@@ -690,11 +704,11 @@ test_17o() {
        local rc=0
 
        test_mkdir -p $WDIR
-       mdt_index=$($LFS getstripe -M $WDIR)
-       mdt_index=$((mdt_index+1))
-
        touch $WDIR/$tfile
+       mdt_index=$($LFS getstripe -M $WDIR/$tfile)
+       mdt_index=$((mdt_index+1))
 
+       cancel_lru_locks mdc
        #fail mds will wait the failover finish then set
        #following fail_loc to avoid interfer the recovery process.
        fail mds${mdt_index}
@@ -1023,53 +1037,73 @@ page_size() {
 }
 
 simple_cleanup_common() {
+       local rc=0
        trap 0
+       [ -z "$DIR" -o -z "$tdir" ] && return 0
+
+       local start=$SECONDS
        rm -rf $DIR/$tdir
+       rc=$?
        wait_delete_completed
+       echo "cleanup time $((SECONDS - start))"
+       return $rc
 }
 
 max_pages_per_rpc() {
-       $LCTL get_param -n mdc.*.max_pages_per_rpc | head -n1
+       local mdtname="$(printf "MDT%04x" ${1:-0})"
+       $LCTL get_param -n mdc.*$mdtname*.max_pages_per_rpc
 }
 
 test_24v() {
-       local NRFILES=100000
-       local FREE_INODES=$(mdt_free_inodes 0)
-       [[ $FREE_INODES -lt $NRFILES ]] &&
-               skip "not enough free inodes $FREE_INODES required $NRFILES" &&
-               return
-
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
-       trap simple_cleanup_common EXIT
-
+       local nrfiles=${COUNT:-100000}
        # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
-       [ $(facet_fstype $SINGLEMDS) = "zfs" ] && NRFILES=10000
+       [ $(facet_fstype $SINGLEMDS) = "zfs" ] && nrfiles=${COUNT:-10000}
 
-       test_mkdir -p $DIR/$tdir
-       createmany -m $DIR/$tdir/$tfile $NRFILES
+       local fname="$DIR/$tdir/$tfile"
+       test_mkdir "$(dirname $fname)"
+       # assume MDT0000 has the fewest inodes
+       local stripes=$($LFS getdirstripe -c $(dirname $fname))
+       local free_inodes=$(($(mdt_free_inodes 0) * stripes))
+       [[ $free_inodes -lt $nrfiles ]] && nrfiles=$free_inodes
+
+       trap simple_cleanup_common EXIT
+
+       createmany -m "$fname" $nrfiles
 
        cancel_lru_locks mdc
        lctl set_param mdc.*.stats clear
 
-       ls $DIR/$tdir >/dev/null || error "error in listing large dir"
-
+       # was previously test_24D: LU-6101
+       # readdir() returns correct number of entries after cursor reload
+       local num_ls=$(ls $DIR/$tdir | wc -l)
+       local num_uniq=$(ls $DIR/$tdir | sort -u | wc -l)
+       local num_all=$(ls -a $DIR/$tdir | wc -l)
+       if [ $num_ls -ne $nrfiles -o $num_uniq -ne $nrfiles -o \
+            $num_all -ne $((nrfiles + 2)) ]; then
+               error "Expected $nrfiles files, got $num_ls " \
+                       "($num_uniq unique $num_all .&..)"
+       fi
        # LU-5 large readdir
-       # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
-       #               8 bytes for name(filename is mostly 5 in this test) +
-       #               8 bytes for luda_type
+       # dirent_size = 32 bytes for sizeof(struct lu_dirent) +
+       #               N bytes for name (len($nrfiles) rounded to 8 bytes) +
+       #               8 bytes for luda_type (4 bytes rounded to 8 bytes)
        # take into account of overhead in lu_dirpage header and end mark in
-       # each page, plus one in RPC_NUM calculation.
-       DIRENT_SIZE=48
-       RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
-       RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
-       mds_readpage=$(lctl get_param mdc.*MDT0000*.stats |
-                               awk '/^mds_readpage/ {print $2}')
-       [[ $mds_readpage -gt $RPC_NUM ]] &&
-               error "large readdir doesn't take effect"
+       # each page, plus one in rpc_num calculation.
+       local dirent_size=$((32 + (${#tfile} | 7) + 1 + 8))
+       local page_entries=$((($(page_size) - 24) / dirent_size))
+       local mdt_idx=$($LFS getdirstripe -i $(dirname $fname))
+       local rpc_pages=$(max_pages_per_rpc $mdt_idx)
+       local rpc_max=$((nrfiles / (page_entries * rpc_pages) + stripes))
+       local mds_readpage=$(calc_stats mdc.*.stats mds_readpage)
+       echo "readpages: $mds_readpage rpc_max: $rpc_max"
+       (( $mds_readpage < $rpc_max - 2 || $mds_readpage > $rpc_max + 1)) &&
+               error "large readdir doesn't take effect: " \
+                     "$mds_readpage should be about $rpc_max"
 
        simple_cleanup_common
 }
-run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
+run_test 24v "list large directory (test hash collision, b=17560)"
 
 test_24w() { # bug21506
         SZ1=234852
@@ -1148,6 +1182,7 @@ test_24A() { # LU-3182
 
        rm -rf $DIR/$tdir
        test_mkdir -p $DIR/$tdir
+       trap simple_cleanup_common EXIT
        createmany -m $DIR/$tdir/$tfile $NFILES
        local t=$(ls $DIR/$tdir | wc -l)
        local u=$(ls $DIR/$tdir | sort -u | wc -l)
@@ -1156,7 +1191,7 @@ test_24A() { # LU-3182
                error "Expected $NFILES files, got $t ($u unique $v .&..)"
        fi
 
-       rm -rf $DIR/$tdir || error "Can not delete directories"
+       simple_cleanup_common || error "Can not delete directories"
 }
 run_test 24A "readdir() returns correct number of entries."
 
@@ -1214,23 +1249,6 @@ test_24C() {
 }
 run_test 24C "check .. in striped dir"
 
-test_24D() { # LU-6101
-       local NFILES=50000
-
-       rm -rf $DIR/$tdir
-       mkdir -p $DIR/$tdir
-       createmany -m $DIR/$tdir/$tfile $NFILES
-       local t=$(ls $DIR/$tdir | wc -l)
-       local u=$(ls $DIR/$tdir | sort -u | wc -l)
-       local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
-       if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
-               error "Expected $NFILES files, got $t ($u unique $v .&..)"
-       fi
-
-       rm -rf $DIR/$tdir || error "Can not delete directories"
-}
-run_test 24D "readdir() returns correct number of entries after cursor reload"
-
 test_24E() {
        [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
@@ -1646,14 +1664,15 @@ test_27u() { # bug 4900
 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
        do_nodes $list $LCTL set_param fail_loc=0x139
        test_mkdir -p $DIR/$tdir
-       rm -rf $DIR/$tdir/*
+       trap simple_cleanup_common EXIT
        createmany -o $DIR/$tdir/t- 1000
        do_nodes $list $LCTL set_param fail_loc=0
 
-       TLOG=$DIR/$tfile.getstripe
+       TLOG=$TMP/$tfile.getstripe
        $GETSTRIPE $DIR/$tdir > $TLOG
        OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
        unlinkmany $DIR/$tdir/t- 1000
+       trap 0
        [[ $OBJS -gt 0 ]] &&
                error "$OBJS objects created on OST-0. See $TLOG" || pass
 }
@@ -1869,10 +1888,11 @@ check_seq_oid()
                # update too, until that use mount/ll_decode_filter_fid/mount.
                # Re-enable when debugfs will understand new filter_fid.
                #
-               if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
+               if [ $(facet_fstype ost$ost) == ldiskfs ]; then
                        ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
                                $dev 2>/dev/null" | grep "parent=")
-               else
+               fi
+               if [ -z "$ff" ]; then
                        stop ost$ost
                        mount_fstype ost$ost
                        ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
@@ -1888,33 +1908,39 @@ check_seq_oid()
 
                # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
                # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
-               local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
-               local ff_pseq=$(echo $ff_parent | cut -d: -f1)
-               local ff_poid=$(echo $ff_parent | cut -d: -f2)
+               #
+               # fid: parent=[0x200000400:0x1e:0x0] stripe=1 stripe_count=2 \
+               #       stripe_size=1048576 component_id=1 component_start=0 \
+               #       component_end=33554432
+               local ff_parent=$(sed -e 's/.*parent=.//' <<<$ff)
+               local ff_pseq=$(cut -d: -f1 <<<$ff_parent)
+               local ff_poid=$(cut -d: -f2 <<<$ff_parent)
                local ff_pstripe
-               if echo $ff_parent | grep -q 'stripe='; then
-                       ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
+               if grep -q 'stripe=' <<<$ff; then
+                       ff_pstripe=$(sed -e 's/.*stripe=//' -e 's/ .*//' <<<$ff)
                else
-                       #
                        # $LL_DECODE_FILTER_FID does not print "stripe="; look
-                       # into f_ver in this case.  See the comment on
-                       # ff_parent.
-                       #
-                       ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
-                               sed -e 's/\]//')
+                       # into f_ver in this case.  See comment on ff_parent.
+                       ff_pstripe=$(cut -d: -f3 <<<$ff_parent | sed -e 's/]//')
                fi
 
-                # compare lmm_seq and filter_fid->ff_parent.f_seq
-                [ $ff_pseq = $lmm_seq ] ||
-                        error "FF parent SEQ $ff_pseq != $lmm_seq"
-                # compare lmm_object_id and filter_fid->ff_parent.f_oid
-                [ $ff_poid = $lmm_oid ] ||
-                        error "FF parent OID $ff_poid != $lmm_oid"
+               if grep -q 'stripe_count=' <<<$ff; then
+                       local ff_scnt=$(sed -e 's/.*stripe_count=//' \
+                                           -e 's/ .*//' <<<$ff)
+                       [ $lmm_count = $ff_scnt ] ||
+                               error "FF stripe count $lmm_count != $ff_scnt"
+               fi
+               # compare lmm_seq and filter_fid->ff_parent.f_seq
+               [ $ff_pseq = $lmm_seq ] ||
+                       error "FF parent SEQ $ff_pseq != $lmm_seq"
+               # compare lmm_object_id and filter_fid->ff_parent.f_oid
+               [ $ff_poid = $lmm_oid ] ||
+                       error "FF parent OID $ff_poid != $lmm_oid"
                (($ff_pstripe == $stripe_nr)) ||
-                        error "FF stripe $ff_pstripe != $stripe_nr"
+                       error "FF stripe $ff_pstripe != $stripe_nr"
 
-                stripe_nr=$((stripe_nr + 1))
-        done
+               stripe_nr=$((stripe_nr + 1))
+       done
 }
 
 test_27z() {
@@ -2037,12 +2063,14 @@ test_27D() {
        pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
 
        local skip27D
-       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
-               skip27D = "-s 29"
+       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ] &&
+               skip27D += "-s 29"
+       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.55) ] &&
+               skip27D += "-s 30,31"
        llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT $skip27D ||
                error "llapi_layout_test failed"
 
-       cleanup_pools || error "cleanup_pools failed"
+       destroy_test_pools || error "destroy test pools failed"
 }
 run_test 27D "validate llapi_layout API"
 
@@ -2078,11 +2106,10 @@ test_27E() {
 run_test 27E "check that default extended attribute size properly increases"
 
 test_27F() { # LU-5346/LU-7975
-
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
-
        [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.51) ]] &&
                skip "Need MDS version at least 2.8.51" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
 
        test_mkdir -p $DIR/$tdir
        rm -f $DIR/$tdir/f0
@@ -2411,10 +2438,10 @@ run_test 31p "remove of open striped directory"
 cleanup_test32_mount() {
        local rc=0
        trap 0
-       local loopdev=$(losetup -a | grep $EXT2_DEV | sed -ne 's/:.*$/p')
+       local loopdev=$(losetup -a | grep $EXT2_DEV | sed -ne 's/:.*$//p')
        $UMOUNT $DIR/$tdir/ext2-mountpoint || rc=$?
        losetup -d $loopdev || true
-       rm -rf $DIR/$tdir/ext2-mountpoint
+       rm -rf $DIR/$tdir
        return $rc
 }
 
@@ -2598,59 +2625,49 @@ test_32o() {
 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
 
 test_32p() {
-    log 32p_1
+       log 32p_1
        rm -fr $DIR/d32p
-    log 32p_2
+       log 32p_2
        rm -f $DIR/$tfile
-    log 32p_3
+       log 32p_3
        touch $DIR/$tfile
-    log 32p_4
+       log 32p_4
        test_mkdir -p $DIR/d32p/tmp
-    log 32p_5
+       log 32p_5
        TMP_DIR=$DIR/d32p/tmp
-    log 32p_6
+       log 32p_6
        ln -s $DIR/$tfile $TMP_DIR/symlink12
-    log 32p_7
+       log 32p_7
        ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
-    log 32p_8
+       log 32p_8
        cat $DIR/d32p/tmp/symlink12 || error
-    log 32p_9
+       log 32p_9
        cat $DIR/d32p/symlink02 || error
-    log 32p_10
+       log 32p_10
 }
 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
 
-cleanup_testdir_mount() {
-       local rc=0
-       trap 0
-       local loopdev=$(losetup -a | grep $EXT2_DEV | sed -ne 's/:.*$/p')
-       $UMOUNT $DIR/$tdir || rc=$?
-       losetup -d $loopdev || true
-       rm -rf $DIR/$tdir
-       return $rc
-}
-
 test_32q() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
-       trap cleanup_testdir_mount EXIT
-       test_mkdir -p $DIR/$tdir
-        touch $DIR/$tdir/under_the_mount
-       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
-       ls $DIR/$tdir | grep "\<under_the_mount\>" && error
-       cleanup_testdir_mount
+       trap cleanup_test32_mount EXIT
+       test_mkdir -p $DIR/$tdir/ext2-mountpoint
+       touch $DIR/$tdir/ext2-mountpoint/under_the_mount
+       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
+       ls $DIR/$tdir/ext2-mountpoint | grep "\<under_the_mount\>" && error
+       cleanup_test32_mount
 }
 run_test 32q "stat follows mountpoints in Lustre (should return error)"
 
 test_32r() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
-       trap cleanup_testdir_mount EXIT
-       test_mkdir -p $DIR/$tdir
-        touch $DIR/$tdir/under_the_mount
-       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
-       ls $DIR/$tdir | grep -q under_the_mount && error || true
-       cleanup_testdir_mount
+       trap cleanup_test32_mount EXIT
+       test_mkdir -p $DIR/$tdir/ext2-mountpoint
+       touch $DIR/$tdir/ext2-mountpoint/under_the_mount
+       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
+       ls $DIR/$tdir/ext2-mountpoint | grep -q under_the_mount && error || true
+       cleanup_test32_mount
 }
 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
 
@@ -2850,6 +2867,15 @@ test_33f() {
 }
 run_test 33f "nonroot user can create, access, and remove a striped directory"
 
+test_33g() {
+       mkdir -p $DIR/$tdir/dir2
+
+       local err=$($RUNAS mkdir $DIR/$tdir/dir2 2>&1)
+       echo $err
+       [[ $err =~ "exists" ]] || error "Not exists error"
+}
+run_test 33g "nonroot user create already existing root created file"
+
 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
 test_34a() {
        rm -f $DIR/f34
@@ -3103,7 +3129,7 @@ test_38() {
 }
 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
 
-test_39() {
+test_39a() { # was test_39
        touch $DIR/$tfile
        touch $DIR/${tfile}2
 #      ls -l  $DIR/$tfile $DIR/${tfile}2
@@ -3121,7 +3147,7 @@ test_39() {
                error "O_TRUNC didn't change timestamps"
        fi
 }
-run_test 39 "mtime changed on create ==========================="
+run_test 39a "mtime changed on create ==========================="
 
 test_39b() {
        test_mkdir -p -c1 $DIR/$tdir
@@ -3630,7 +3656,7 @@ test_42a() {
                error "$BEFOREWRITES < $AFTERWRITES"
        start_writeback
 }
-run_test 42a "ensure that we don't flush on close =============="
+run_test 42a "ensure that we don't flush on close"
 
 test_42b() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
@@ -3783,7 +3809,7 @@ test_42e() { # bug22074
 }
 run_test 42e "verify sub-RPC writes are not done synchronously"
 
-test_43() {
+test_43A() { # was test_43
        test_mkdir -p $DIR/$tdir
        cp -p /bin/ls $DIR/$tdir/$tfile
        $MULTIOP $DIR/$tdir/$tfile Ow_c &
@@ -3791,56 +3817,53 @@ test_43() {
        # give multiop a chance to open
        sleep 1
 
-       $DIR/$tdir/$tfile && error || true
+       $DIR/$tdir/$tfile && error "execute $DIR/$tdir/$tfile succeeded" || true
        kill -USR1 $pid
 }
-run_test 43 "execution of file opened for write should return -ETXTBSY"
+run_test 43A "execution of file opened for write should return -ETXTBSY"
 
 test_43a() {
-       [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
-       test_mkdir -p $DIR/$tdir
-       cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
-                       cp -p multiop $DIR/$tdir/multiop
+       test_mkdir $DIR/$tdir
+       cp -p $(which $MULTIOP) $DIR/$tdir/multiop ||
+               cp -p multiop $DIR/$tdir/multiop
        MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
-                       return 1
-        MULTIOP_PID=$!
-        $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
-        kill -USR1 $MULTIOP_PID || return 2
-        wait $MULTIOP_PID || return 3
-       rm $TMP/$tfile.junk $DIR/$tdir/multiop
+               error "multiop open $TMP/$tfile.junk failed"
+       MULTIOP_PID=$!
+       $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
+       kill -USR1 $MULTIOP_PID || error "kill -USR1 PID $MULTIOP_PID failed"
+       wait $MULTIOP_PID || error "wait PID $MULTIOP_PID failed"
 }
 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
 
 test_43b() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
-       test_mkdir -p $DIR/$tdir
-       cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
-                       cp -p multiop $DIR/$tdir/multiop
+       test_mkdir $DIR/$tdir
+       cp -p $(which $MULTIOP) $DIR/$tdir/multiop ||
+               cp -p multiop $DIR/$tdir/multiop
        MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
-                       return 1
-        MULTIOP_PID=$!
-        $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
-        kill -USR1 $MULTIOP_PID || return 2
-        wait $MULTIOP_PID || return 3
-       rm $TMP/$tfile.junk $DIR/$tdir/multiop
+               error "multiop open $TMP/$tfile.junk failed"
+       MULTIOP_PID=$!
+       $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
+       kill -USR1 $MULTIOP_PID || error "kill -USR1 PID $MULTIOP_PID failed"
+       wait $MULTIOP_PID || error "wait PID $MULTIOP_PID failed"
 }
 run_test 43b "truncate of file being executed should return -ETXTBSY"
 
 test_43c() {
        local testdir="$DIR/$tdir"
-       test_mkdir -p $DIR/$tdir
+       test_mkdir $testdir
        cp $SHELL $testdir/
-       ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
-               ( cd $testdir && md5sum -c)
+       ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) |
+               ( cd $testdir && md5sum -c )
 }
-run_test 43c "md5sum of copy into lustre========================"
+run_test 43c "md5sum of copy into lustre"
 
-test_44() {
+test_44A() { # was test_44
        [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
        dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
        dd if=$DIR/f1 bs=4k count=1 > /dev/null
 }
-run_test 44 "zero length read from a sparse stripe ============="
+run_test 44A "zero length read from a sparse stripe"
 
 test_44a() {
        local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
@@ -4097,6 +4120,12 @@ test_51a() {     # was test_51
 }
 run_test 51a "special situations: split htree with empty entry =="
 
+cleanup_print_lfs_df () {
+       trap 0
+       $LFS df
+       $LFS df -i
+}
+
 test_51b() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        local dir=$DIR/$tdir
@@ -4118,10 +4147,12 @@ test_51b() {
 
        # need to check free space for the directories as well
        local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
-       numfree=$((blkfree / 4))
+       numfree=$(( blkfree / $(fs_inode_ksize) ))
        [[ $numfree -lt $nrdirs ]] && skip "not enough blocks ($numfree)" &&
                return
 
+       trap cleanup_print_lfsdf EXIT
+
        # create files
        createmany -d $dir/d $nrdirs ||
                error "failed to create $nrdirs subdirs in MDT$mdtidx:$dir"
@@ -4133,6 +4164,9 @@ test_51b() {
        local left=100
        local delete=$((nrdirs - left))
 
+       $LFS df
+       $LFS df -i
+
        # for ldiskfs the nlink count should be 1, but this is OSD specific
        # and so this is listed for informational purposes only
        echo "nlink before: $(stat -c %h $dir), created before: $nrdirs"
@@ -4151,6 +4185,8 @@ test_51b() {
        local after=$(stat -c %h $dir)
        [[ $after -gt 2 ]] && error "nlink after: $after > 2" ||
                echo "nlink after: $after"
+
+       cleanup_print_lfs_df
 }
 run_test 51b "exceed 64k subdirectory nlink limit on create, verify unlink"
 
@@ -4209,6 +4245,35 @@ test_51e() {
 }
 run_test 51e "check file nlink limit"
 
+test_51f() {
+       test_mkdir $DIR/$tdir
+
+       local max=100000
+       local ulimit_old=$(ulimit -n)
+       local spare=20 # number of spare fd's for scripts/libraries, etc.
+       local mdt=$(lfs getstripe -M $DIR/$tdir)
+       local numfree=$(lfs df -i $DIR/$tdir | awk '/MDT:'$mdt'/ { print $4 }')
+
+       echo "MDT$mdt numfree=$numfree, max=$max"
+       [[ $numfree -gt $max ]] && numfree=$max || numfree=$((numfree * 7 / 8))
+       if [ $((numfree + spare)) -gt $ulimit_old ]; then
+               while ! ulimit -n $((numfree + spare)); do
+                       numfree=$((numfree * 3 / 4))
+               done
+               echo "changed ulimit from $ulimit_old to $((numfree + spare))"
+       else
+               echo "left ulimit at $ulimit_old"
+       fi
+
+       createmany -o -k -t 120 $DIR/$tdir/f $numfree ||
+               error "create+open $numfree files in $DIR/$tdir failed"
+       ulimit -n $ulimit_old
+
+       # if createmany exits at 120s there will be fewer than $numfree files
+       unlinkmany $DIR/$tdir/f $numfree || true
+}
+run_test 51f "check many open files limit"
+
 test_52a() {
        [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
        test_mkdir -p $DIR/$tdir
@@ -4318,6 +4383,8 @@ test_53() {
 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
 
 test_54a() {
+       perl -MSocket -e ';' || { skip "no Socket perl module installed" && return; }
+
        $SOCKETSERVER $DIR/socket ||
                error "$SOCKETSERVER $DIR/socket failed: $?"
        $SOCKETCLIENT $DIR/socket ||
@@ -4423,30 +4490,47 @@ test_56a() {    # was test_56
                error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
        echo "$GETSTRIPE --recursive passed."
 
-        # test lfs getstripe with file instead of dir
+       # test lfs getstripe with file instead of dir
        FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
        [[ $FILENUM -eq 1 ]] ||
                error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
        echo "$GETSTRIPE file1 passed."
 
-        #test lfs getstripe with --verbose
+       #test lfs getstripe with --verbose
        [[ $($GETSTRIPE --verbose $DIR/$tdir |
                grep -c lmm_magic) -eq $NUMFILES ]] ||
                error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
        [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
-               rror "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
+               error "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
+
+       #test lfs getstripe with -v prints lmm_fid
+       [[ $($GETSTRIPE -v $DIR/$tdir | grep -c lmm_fid) -eq $NUMFILES ]] ||
+               error "$GETSTRIPE -v $DIR/$tdir: want $NUMFILES lmm_fid: lines"
+       [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_fid) -eq 0 ]] ||
+               error "$GETSTRIPE $DIR/$tdir: showed lmm_fid"
        echo "$GETSTRIPE --verbose passed."
 
-        #test lfs getstripe with --obd
-        $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
+       #check for FID information
+       local fid1=$($GETSTRIPE --fid $DIR/$tdir/file1)
+       local fid2=$($GETSTRIPE --verbose $DIR/$tdir/file1 |
+                      awk '/lmm_fid: / { print $2 }')
+       local fid3=$($LFS path2fid $DIR/$tdir/file1)
+       [ "$fid1" != "$fid2" ] &&
+               error "getstripe --fid $fid1 != getstripe --verbose $fid2"
+       [ "$fid1" != "$fid3" ] &&
+               error "getstripe --fid $fid1 != lfs path2fid $fid3"
+       echo "$GETSTRIPE --fid passed."
+
+       #test lfs getstripe with --obd
+       $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
                grep -q "unknown obduuid" ||
                error "$GETSTRIPE --obd wrong_uuid should return error message"
 
        [[ $OSTCOUNT -lt 2 ]] &&
-                skip_env "skipping other $GETSTRIPE --obd test" && return
+               skip_env "skipping other $GETSTRIPE --obd test" && return
 
-        OSTIDX=1
-        OBDUUID=$(ostuuid_from_index $OSTIDX)
+       OSTIDX=1
+       OBDUUID=$(ostuuid_from_index $OSTIDX)
        FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
        FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
        [[ $FOUND -eq $FILENUM ]] ||
@@ -4459,6 +4543,50 @@ test_56a() {     # was test_56
 }
 run_test 56a "check $GETSTRIPE"
 
+test_56b() {
+       test_mkdir $DIR/$tdir
+       NUMDIRS=3
+       for i in $(seq 1 $NUMDIRS); do
+               test_mkdir $DIR/$tdir/dir$i
+       done
+
+       # test lfs getdirstripe default mode is non-recursion, which is
+       # different from lfs getstripe
+       dircnt=$($LFS getdirstripe $DIR/$tdir | grep -c lmv_stripe_count)
+       [[ $dircnt -eq 1 ]] ||
+               error "$LFS getdirstripe: found $dircnt, not 1"
+       dircnt=$($LFS getdirstripe --recursive $DIR/$tdir |
+               grep -c lmv_stripe_count)
+       [[ $dircnt -eq $((NUMDIRS + 1)) ]] ||
+               error "$LFS getdirstripe --recursive: found $dircnt, \
+                       not $((NUMDIRS + 1))"
+}
+run_test 56b "check $LFS getdirstripe"
+
+test_56c() {
+       local ost_idx=0
+       local ost_name=$(ostname_from_index $ost_idx)
+
+       local old_status=$(ost_dev_status $ost_idx)
+       [[ -z "$old_status" ]] ||
+               { skip_env "OST $ost_name is in $old_status status"; return 0; }
+
+       do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
+       sleep_maxage
+
+       local new_status=$(ost_dev_status $ost_idx)
+       [[ "$new_status" = "D" ]] ||
+               error "OST $ost_name is in status of '$new_status', not 'D'"
+
+       do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
+       sleep_maxage
+
+       new_status=$(ost_dev_status $ost_idx)
+       [[ -z "$new_status" ]] ||
+               error "OST $ost_name is in status of '$new_status', not ''"
+}
+run_test 56c "check 'lfs df' showing device status"
+
 NUMFILES=3
 NUMDIRS=3
 setup_56() {
@@ -4718,8 +4846,22 @@ run_test 56r "check lfs find -size works =========================="
 
 test_56s() { # LU-611
        TDIR=$DIR/${tdir}s
-       setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
 
+       #LU-9369
+       setup_56 0 $NUMDIRS
+       for i in $(seq 1 $NUMDIRS); do
+               $SETSTRIPE -c $((OSTCOUNT + 1)) $TDIR/dir$i/$tfile
+       done
+       EXPECTED=$NUMDIRS
+       CMD="$LFIND -c $OSTCOUNT $TDIR"
+       NUMS=$($CMD | wc -l)
+       [ $NUMS -eq $EXPECTED ] || {
+               $GETSTRIPE -R $TDIR
+               error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
+       }
+       rm -rf $TDIR
+
+       setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
        if [[ $OSTCOUNT -gt 1 ]]; then
                $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
                ONESTRIPE=4
@@ -4772,7 +4914,22 @@ run_test 56s "check lfs find -stripe-count works"
 
 test_56t() { # LU-611
        TDIR=$DIR/${tdir}t
-       setup_56 $NUMFILES $NUMDIRS "-s 512k"
+
+       #LU-9369
+       setup_56 0 $NUMDIRS
+       for i in $(seq 1 $NUMDIRS); do
+               $SETSTRIPE -S 4M $TDIR/dir$i/$tfile
+       done
+       EXPECTED=$NUMDIRS
+       CMD="$LFIND -S 4M $TDIR"
+       NUMS=$($CMD | wc -l)
+       [ $NUMS -eq $EXPECTED ] || {
+               $GETSTRIPE -R $TDIR
+               error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
+       }
+       rm -rf $TDIR
+
+       setup_56 $NUMFILES $NUMDIRS "--stripe-size 512k"
 
        $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
 
@@ -5288,7 +5445,23 @@ test_60a() {
        start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
        $pass || error "test failed, see FAILED test_60a messages for specifics"
 }
-run_test 60a "llog_test run from kernel module and test llog_reader =========="
+run_test 60a "llog_test run from kernel module and test llog_reader"
+
+test_60aa() {
+       # test old logid format
+       if [ $(lustre_version_code mgs) -le $(version_code 3.1.53) ]; then
+               do_facet mgs $LCTL dl | grep MGS
+               do_facet mgs "$LCTL --device %MGS llog_print \\\\\\\$$FSNAME-client" ||
+                       error "old llog_print failed"
+       fi
+
+       # test new logid format
+       if [ $(lustre_version_code mgs) -ge $(version_code 2.9.53) ]; then
+               do_facet mgs "$LCTL --device MGS llog_print $FSNAME-client" ||
+                       error "new llog_print failed"
+       fi
+}
+run_test 60aa "llog_print works with FIDs and simple names"
 
 test_60b() { # bug 6411
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
@@ -5640,6 +5813,12 @@ test_65l() { # bug 12836
 }
 run_test 65l "lfs find on -1 stripe dir ========================"
 
+test_65m() {
+       $RUNAS $SETSTRIPE -c 2 $MOUNT && error "setstripe should fail"
+       true
+}
+run_test 65m "normal user can't set filesystem default stripe"
+
 # bug 2543 - update blocks count on client
 test_66() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
@@ -5666,10 +5845,6 @@ cleanup_68() {
                rm -f $LLOOP
                unset LLOOP
        fi
-       if [ ! -z "$LLITELOOPLOAD" ]; then
-               rmmod llite_lloop
-               unset LLITELOOPLOAD
-       fi
        rm -f $DIR/f68*
 }
 
@@ -5681,74 +5856,6 @@ swap_used() {
        swapon -s | awk '($1 == "'$1'") { print $4 }'
 }
 
-# test case for lloop driver, basic function
-test_68a() {
-       [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
-       [ "$UID" != 0 ] && skip_env "must run as root" && return
-       llite_lloop_enabled || \
-               { skip_env "llite_lloop module disabled" && return; }
-
-       trap cleanup_68 EXIT
-
-       if ! module_loaded llite_lloop; then
-               if load_module llite/llite_lloop; then
-                       LLITELOOPLOAD=yes
-               else
-                       skip_env "can't find module llite_lloop"
-                       return
-               fi
-       fi
-
-       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"
-
-       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_68b() {  # was test_68
-       [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
-       [ "$UID" != 0 ] && skip_env "must run as root" && return
-       lctl get_param -n devices | grep -q obdfilter && \
-               skip "local OST" && return
-
-       grep -q llite_lloop /proc/modules
-       [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
-
-       [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
-               skip "can't reliably test swap with TCP" && return
-
-       MEMTOTAL=`meminfo MemTotal`
-       NR_BLOCKS=$((MEMTOTAL>>8))
-       [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
-
-       LLOOP=$TMP/lloop.`date +%s`.`date +%N`
-       dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
-       mkswap $DIR/f68b
-
-       $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
-
-       trap cleanup_68 EXIT
-
-       swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
-
-       echo "before: `swapon -s | grep $LLOOP`"
-       $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
-       echo "after: `swapon -s | grep $LLOOP`"
-       SWAPUSED=`swap_used $LLOOP`
-
-       cleanup_68
-
-       [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
-}
-run_test 68b "support swapping to Lustre ========================"
-
 # bug5265, obdfilter oa2dentry return -ENOENT
 # #define OBD_FAIL_SRV_ENOENT 0x217
 test_69() {
@@ -6026,6 +6133,96 @@ test_77b() { # bug 10889
 }
 run_test 77b "checksum error on client write, read"
 
+cleanup_77c() {
+       trap 0
+       set_checksums 0
+       $LCTL set_param osc.*osc-[^mM]*.checksum_dump=0
+       $check_ost &&
+               do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=0
+       [ -n $osc_file_prefix ] && rm -f ${osc_file_prefix}*
+       $check_ost && [ -n $ost_file_prefix ] &&
+               do_facet ost1 rm -f ${ost_file_prefix}\*
+}
+
+test_77c() {
+       [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+       $GSS && skip "could not run with gss" && return
+
+       local bad1
+       local osc_file_prefix
+       local osc_file
+       local check_ost=false
+       local ost_file_prefix
+       local ost_file
+       local orig_cksum
+       local dump_cksum
+       local fid
+
+       # ensure corruption will occur on first OSS/OST
+       $LFS setstripe -i 0 $DIR/$tfile
+
+       [ ! -f $F77_TMP ] && setup_f77
+       dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
+               error "dd write error: $?"
+       fid=$($LFS path2fid $DIR/$tfile)
+
+       if [ $(lustre_version_code ost1) -ge $(version_code 2.5.42.6) ]
+       then
+               check_ost=true
+               ost_file_prefix=$(do_facet ost1 $LCTL get_param -n debug_path)
+               ost_file_prefix=${ost_file_prefix}-checksum_dump-ost-\\${fid}
+       else
+               echo "OSS do not support bulk pages dump upon error"
+       fi
+
+       osc_file_prefix=$($LCTL get_param -n debug_path)
+       osc_file_prefix=${osc_file_prefix}-checksum_dump-osc-\\${fid}
+
+       trap cleanup_77c EXIT
+
+       set_checksums 1
+       # enable bulk pages dump upon error on Client
+       $LCTL set_param osc.*osc-[^mM]*.checksum_dump=1
+       # enable bulk pages dump upon error on OSS
+       $check_ost &&
+               do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=1
+
+       # flush Client cache to allow next read to reach OSS
+       cancel_lru_locks osc
+
+       #define OBD_FAIL_OSC_CHECKSUM_RECEIVE       0x408
+       $LCTL set_param fail_loc=0x80000408
+       dd if=$DIR/$tfile of=/dev/null bs=1M || error "dd read error: $?"
+       $LCTL set_param fail_loc=0
+
+       rm -f $DIR/$tfile
+
+       # check cksum dump on Client
+       osc_file=$(ls ${osc_file_prefix}*)
+       [ -n "$osc_file" ] || error "no checksum dump file on Client"
+       # OBD_FAIL_OSC_CHECKSUM_RECEIVE corrupts with "bad1" at start of file
+       bad1=$(dd if=$osc_file bs=1 count=4 2>/dev/null) || error "dd error: $?"
+       [ $bad1 == "bad1" ] || error "unexpected corrupt pattern"
+       orig_cksum=$(dd if=$F77_TMP bs=1 skip=4 count=1048572 2>/dev/null |
+                    cksum)
+       dump_cksum=$(dd if=$osc_file bs=1 skip=4 2>/dev/null | cksum)
+       [[ "$orig_cksum" == "$dump_cksum" ]] ||
+               error "dump content does not match on Client"
+
+       $check_ost || skip "No need to check cksum dump on OSS"
+
+       # check cksum dump on OSS
+       ost_file=$(do_facet ost1 ls ${ost_file_prefix}\*)
+       [ -n "$ost_file" ] || error "no checksum dump file on OSS"
+       orig_cksum=$(dd if=$F77_TMP bs=1048576 count=1 2>/dev/null | cksum)
+       dump_cksum=$(do_facet ost1 dd if=$ost_file 2>/dev/null \| cksum)
+       [[ "$orig_cksum" == "$dump_cksum" ]] ||
+               error "dump content does not match on OSS"
+
+       cleanup_77c
+}
+run_test 77c "checksum error on client read with debug"
+
 test_77d() { # bug 10889
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        $GSS && skip "could not run with gss" && return
@@ -6092,22 +6289,6 @@ test_77g() { # bug 10889
 }
 run_test 77g "checksum error on OST write, read"
 
-test_77i() { # bug 13805
-       [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
-       $GSS && skip "could not run with gss" && return
-       #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
-       lctl set_param fail_loc=0x40b
-       remount_client $MOUNT
-       lctl set_param fail_loc=0
-       for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
-               PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
-               algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
-               [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
-       done
-       remount_client $MOUNT
-}
-run_test 77i "client not supporting OSD_CONNECT_CKSUM"
-
 test_77j() { # bug 13805
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        $GSS && skip "could not run with gss" && return
@@ -6115,10 +6296,15 @@ test_77j() { # bug 13805
        lctl set_param fail_loc=0x40c
        remount_client $MOUNT
        lctl set_param fail_loc=0
-       sleep 2 # wait async osc connect to finish
-       for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
-                PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
-               algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
+       # wait async osc connect to finish and reflect updated state value
+       local i
+       for (( i=0; i < OSTCOUNT; i++ )) ; do
+               wait_osc_import_state client ost$((i+1)) FULL
+       done
+
+       for VALUE in $(lctl get_param osc.*osc-[^mM]*.checksum_type); do
+               PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
+               algo=$(lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g')
                [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
        done
        remount_client $MOUNT
@@ -6129,6 +6315,11 @@ run_test 77j "client only supporting ADLER32"
 rm -f $F77_TMP
 unset F77_TMP
 
+cleanup_test_78() {
+       trap 0
+       rm -f $DIR/$tfile
+}
+
 test_78() { # bug 10901
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        remote_ost || { skip_env "local OST" && return; }
@@ -6158,6 +6349,8 @@ test_78() { # bug 10901
        [[ $SMALLESTOST -lt 10240 ]] &&
                skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
 
+       trap cleanup_test_78 EXIT
+
        [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
                F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
 
@@ -6170,7 +6363,7 @@ test_78() { # bug 10901
                $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
        done
 
-       rm -f $DIR/$tfile
+       cleanup_test_78
 }
 run_test 78 "handle large O_DIRECT writes correctly ============"
 
@@ -6652,6 +6845,10 @@ run_test 101e "check read-ahead for small read(1k) for small files(500k)"
 test_101f() {
        which iozone || { skip "no iozone installed" && return; }
 
+       local old_debug=$($LCTL get_param debug)
+       old_debug=${old_debug#*=}
+       $LCTL set_param debug="reada mmap"
+
        # create a test file
        iozone -i 0 -+n -r 1m -s 128m -w -f $DIR/$tfile > /dev/null 2>&1
 
@@ -6662,71 +6859,87 @@ test_101f() {
        $LCTL set_param -n llite.*.read_ahead_stats 0
 
        echo mmap read the file with small block size
-       iozone -i 1 -+n -r 32k -s 128m -B -f $DIR/$tfile > /dev/null 2>&1
+       iozone -i 1 -u 1 -l 1 -+n -r 32k -s 128m -B -f $DIR/$tfile \
+               > /dev/null 2>&1
 
        echo checking missing pages
+       $LCTL get_param llite.*.read_ahead_stats
        local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
                        get_named_value 'misses' | cut -d" " -f1 | calc_total)
 
-       [ $miss -lt 3 ] || error "misses too much pages!"
+       $LCTL set_param debug="$old_debug"
+       [ $miss -lt 3 ] || error "misses too much pages ('$miss')!"
        rm -f $DIR/$tfile
 }
 run_test 101f "check mmap read performance"
 
+test_101g_brw_size_test() {
+       local mb=$1
+       local pages=$((mb * 1048576 / $(page_size)))
+
+       $LCTL set_param osc.*.max_pages_per_rpc=${mb}M ||
+               { error "unable to set max_pages_per_rpc=${mb}M"; return 1; }
+       for mp in $($LCTL get_param -n osc.*.max_pages_per_rpc); do
+               [ $mp -ne $pages ] && error "max_pages_per_rpc $mp != $pages" &&
+                       return 2
+       done
+
+       $LCTL set_param -n osc.*.rpc_stats=0
+
+       # 10 RPCs should be enough for the test
+       local count=10
+       dd if=/dev/zero of=$DIR/$tfile bs=${mb}M count=$count ||
+               { error "dd write ${mb} MB blocks failed"; return 3; }
+       cancel_lru_locks osc
+       dd of=/dev/null if=$DIR/$tfile bs=${mb}M count=$count ||
+               { error "dd write ${mb} MB blocks failed"; return 4; }
+
+       # calculate number of full-sized read and write RPCs
+       rpcs=($($LCTL get_param -n 'osc.*.rpc_stats' |
+               sed -n '/pages per rpc/,/^$/p' |
+               awk '/'$pages':/ { reads += $2; writes += $5 };' \
+               'END { print reads,writes }'))
+       [ ${rpcs[0]} -ne $count ] && error "${rpcs[0]} != $count read RPCs" &&
+               return 5
+       [ ${rpcs[1]} -ne $count ] && error "${rpcs[1]} != $count write RPCs" &&
+               return 6
+
+       return 0
+}
+
 test_101g() {
        local rpcs
        local osts=$(get_facets OST)
        local list=$(comma_list $(osts_nodes))
        local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
+       local brw_size="obdfilter.*.brw_size"
 
-       save_lustre_params $osts "obdfilter.*.brw_size" > $p
-
-       $LFS setstripe -c 1 $DIR/$tfile
+       $LFS setstripe -i 0 -c 1 $DIR/$tfile
 
+       local orig_mb=$(do_facet ost1 $LCTL get_param -n $brw_size | head -n 1)
        if [ $(lustre_version_code ost1) -ge $(version_code 2.8.52) ]; then
-               set_osd_param $list '' brw_size 16M
-
-               echo "remount client to enable large RPC size"
-               remount_client $MOUNT || error "remount_client failed"
-
-               for mp in $($LCTL get_param -n osc.*.max_pages_per_rpc); do
-                       [ "$mp" -eq 4096 ] ||
-                               error "max_pages_per_rpc not correctly set"
-               done
-
-               $LCTL set_param -n osc.*.rpc_stats=0
-
-               # 10*16 MiB should be enough for the test
-               dd if=/dev/zero of=$DIR/$tfile bs=16M count=10
-               cancel_lru_locks osc
-               dd of=/dev/null if=$DIR/$tfile bs=16M count=10
+               [ $(lustre_version_code ost1) -ge $(version_code 2.9.52) ] &&
+                       suffix="M"
+               if [[ $orig_mb < 16 ]]; then
+                       save_lustre_params $osts "$brw_size" > $p
+                       do_nodes $list $LCTL set_param -n $brw_size=16$suffix ||
+                               error "set 16MB RPC size failed"
+
+                       echo "remount client to enable new RPC size"
+                       remount_client $MOUNT || error "remount_client failed"
+               fi
 
-               # calculate 16 MiB RPCs
-               rpcs=$($LCTL get_param 'osc.*.rpc_stats' |
-                      sed -n '/pages per rpc/,/^$/p' |
-                      awk 'BEGIN { sum = 0 }; /4096:/ { sum += $2 };
-                           END { print sum }')
-               echo $rpcs RPCs
-               [ "$rpcs" -eq 10 ] || error "not all RPCs are 16 MiB BRW rpcs"
+               test_101g_brw_size_test 16 || error "16MB RPC test failed"
+               # should be able to set brw_size=12, but no rpc_stats for that
+               test_101g_brw_size_test 8 || error "8MB RPC test failed"
        fi
 
-       echo "set RPC size to 4MB"
+       test_101g_brw_size_test 4 || error "4MB RPC test failed"
 
-       $LCTL set_param -n osc.*.max_pages_per_rpc=4M osc.*.rpc_stats=0
-       dd if=/dev/zero of=$DIR/$tfile bs=4M count=25
-       cancel_lru_locks osc
-       dd of=/dev/null if=$DIR/$tfile bs=4M count=25
-
-       # calculate 4 MiB RPCs
-       rpcs=$($LCTL get_param 'osc.*.rpc_stats' |
-               sed -n '/pages per rpc/,/^$/p' |
-               awk 'BEGIN { sum = 0 }; /1024:/ { sum += $2 };
-                    END { print sum }')
-       echo $rpcs RPCs
-       [ "$rpcs" -eq 25 ] || error "not all RPCs are 4 MiB BRW rpcs"
-
-       restore_lustre_params < $p
-       remount_client $MOUNT || error "remount_client failed"
+       if [[ $orig_mb < 16 ]]; then
+               restore_lustre_params < $p
+               remount_client $MOUNT || error "remount_client restore failed"
+       fi
 
        rm -f $p $DIR/$tfile
 }
@@ -7101,29 +7314,31 @@ getxattr() { # getxattr path name
 }
 
 test_102n() { # LU-4101 mdt: protect internal xattrs
-       local file0=$DIR/$tfile.0
-       local file1=$DIR/$tfile.1
-       local xattr0=$TMP/$tfile.0
-       local xattr1=$TMP/$tfile.1
-       local name
-       local value
-
        [ -z "$(which setfattr 2>/dev/null)" ] &&
                skip "could not find setfattr" && return
-
        if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
        then
                skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
                return
        fi
 
-       rm -rf $file0 $file1 $xattr0 $xattr1
-       touch $file0 $file1
+       local file0=$DIR/$tfile.0
+       local file1=$DIR/$tfile.1
+       local xattr0=$TMP/$tfile.0
+       local xattr1=$TMP/$tfile.1
+       local namelist="lov lma lmv link fid version som hsm"
+       local name
+       local value
+
+       rm -rf $file0 $file1 $xattr0 $xattr1
+       touch $file0 $file1
 
        # Get 'before' xattrs of $file1.
        getfattr --absolute-names --dump --match=- $file1 > $xattr0
 
-       for name in lov lma lmv link fid version som hsm; do
+       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.53) ] &&
+               namelist+=" lfsck_namespace"
+       for name in $namelist; do
                # Try to copy xattr from $file0 to $file1.
                value=$(getxattr $file0 trusted.$name 2> /dev/null)
 
@@ -7260,7 +7475,8 @@ test_103a() {
 
        SAVE_UMASK=$(umask)
        umask 0022
-       cd $DIR
+       mkdir -p $DIR/$tdir
+       cd $DIR/$tdir
 
        echo "performing cp ..."
        run_acl_subtest cp || error "run_acl_subtest cp failed"
@@ -7270,6 +7486,15 @@ test_103a() {
        run_acl_subtest misc || error  "misc test failed"
        echo "performing permissions..."
        run_acl_subtest permissions || error "permissions failed"
+       # LU-1482 mdd: Setting xattr are properly checked with and without ACLs
+       if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.8.55) -o \
+            \( $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6) -a \
+            $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.29) \) ]
+       then
+               echo "performing permissions xattr..."
+               run_acl_subtest permissions_xattr ||
+                       error "permissions_xattr failed"
+       fi
        echo "performing setfacl..."
        run_acl_subtest setfacl || error  "setfacl test failed"
 
@@ -7499,51 +7724,137 @@ test_110() {
 }
 run_test 110 "filename length checking"
 
+#
+# Purpose: To verify dynamic thread (OSS) creation.
+#
 test_115() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
-       OSTIO_pre=$(ps -e | grep ll_ost_io | awk '{ print $4 }'| sort -n |
-               tail -1 | cut -c11-20)
-       [ -z "$OSTIO_pre" ] && skip "no OSS threads" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
+
+       # Lustre does not stop service threads once they are started.
+       # Reset number of running threads to default.
+       stopall
+       setupall
+
+       local OSTIO_pre
+       local save_params="$TMP/sanity-$TESTNAME.parameters"
+
+       # Get ll_ost_io count before I/O
+       OSTIO_pre=$(do_facet ost1 \
+               "$LCTL get_param ost.OSS.ost_io.threads_started | cut -d= -f2")
+       # Exit if lustre is not running (ll_ost_io not running).
+       [ -z "$OSTIO_pre" ] && error "no OSS threads"
+
        echo "Starting with $OSTIO_pre threads"
+       local thread_max=$((OSTIO_pre * 2))
+       local rpc_in_flight=$((thread_max * 2))
+       # Number of I/O Process proposed to be started.
+       local nfiles
+       local facets=$(get_facets OST)
 
-       NUMTEST=20000
-       NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
-       [[ $NUMFREE -lt $NUMTEST ]] && NUMTEST=$(($NUMFREE - 1000))
-       echo "$NUMTEST creates/unlinks"
-       test_mkdir -p $DIR/$tdir
-       createmany -o $DIR/$tdir/$tfile $NUMTEST
-       unlinkmany $DIR/$tdir/$tfile $NUMTEST
+       save_lustre_params client \
+               "osc.*OST*.max_rpcs_in_flight" > $save_params
+       save_lustre_params $facets \
+               "ost.OSS.ost_io.threads_max" >> $save_params
+
+       # Set in_flight to $rpc_in_flight
+       $LCTL set_param osc.*OST*.max_rpcs_in_flight=$rpc_in_flight ||
+               error "Failed to set max_rpcs_in_flight to $rpc_in_flight"
+       nfiles=${rpc_in_flight}
+       # Set ost thread_max to $thread_max
+       do_facet ost1 \
+               "$LCTL set_param ost.OSS.ost_io.threads_max=$thread_max"
+
+       # 5 Minutes should be sufficient for max number of OSS
+       # threads(thread_max) to be created.
+       local timeout=300
+
+       # Start I/O.
+       local WTL=${WTL:-"$LUSTRE/tests/write_time_limit"}
+       mkdir -p $DIR/$tdir
+       for i in $(seq $nfiles); do
+               local file=$DIR/$tdir/${tfile}-$i
+               $LFS setstripe -c -1 -i 0 $file
+               ($WTL $file $timeout)&
+       done
+
+       # I/O Started - Wait for thread_started to reach thread_max or report
+       # error if thread_started is more than thread_max.
+       echo "Waiting for thread_started to reach thread_max"
+       local thread_started=0
+       local end_time=$((SECONDS + timeout))
+
+       while [ $SECONDS -le $end_time ] ; do
+               echo -n "."
+               # Get ost i/o thread_started count.
+               thread_started=$(do_facet ost1 \
+                       "$LCTL get_param \
+                       ost.OSS.ost_io.threads_started | cut -d= -f2")
+               # Break out if thread_started is equal/greater than thread_max
+               if [[ $thread_started -ge $thread_max ]]; then
+                       echo ll_ost_io thread_started $thread_started, \
+                               equal/greater than thread_max $thread_max
+                       break
+               fi
+               sleep 1
+       done
 
-       OSTIO_post=$(ps -e | grep ll_ost_io | awk '{ print $4 }' | sort -n |
-               tail -1 | cut -c11-20)
+       # Cleanup - We have the numbers, Kill i/o jobs if running.
+       jobcount=($(jobs -p))
+       for i in $(seq 0 $((${#jobcount[@]}-1)))
+       do
+               kill -9 ${jobcount[$i]}
+               if [ $? -ne 0 ] ; then
+                       echo Warning: \
+                       Failed to Kill \'WTL\(I/O\)\' with pid ${jobcount[$i]}
+               fi
+       done
 
-       # don't return an error
-       [ $OSTIO_post == $OSTIO_pre ] && echo \
-           "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
-           echo "This may be fine, depending on what ran before this test" &&
-           echo "and how fast this system is." && return
+       # Cleanup files left by WTL binary.
+       for i in $(seq $nfiles); do
+               local file=$DIR/$tdir/${tfile}-$i
+               rm -rf $file
+               if [ $? -ne 0 ] ; then
+                       echo "Warning: Failed to delete file $file"
+               fi
+       done
 
-       echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
+       restore_lustre_params <$save_params
+       rm -f $save_params || echo "Warning: delete file '$save_params' failed"
+
+       # Error out if no new thread has started or Thread started is greater
+       # than thread max.
+       if [[ $thread_started -le $OSTIO_pre ||
+                       $thread_started -gt $thread_max ]]; then
+               error "ll_ost_io: thread_started $thread_started" \
+                     "OSTIO_pre $OSTIO_pre, thread_max $thread_max." \
+                     "No new thread started or thread started greater " \
+                     "than thread_max."
+       fi
 }
 run_test 115 "verify dynamic thread creation===================="
 
 free_min_max () {
        wait_delete_completed
        AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
-       echo OST kbytes available: ${AVAIL[@]}
-       MAXI=0; MAXV=${AVAIL[0]}
-       MINI=0; MINV=${AVAIL[0]}
+       echo "OST kbytes available: ${AVAIL[@]}"
+       MAXV=${AVAIL[0]}
+       MAXI=0
+       MINV=${AVAIL[0]}
+       MINI=0
        for ((i = 0; i < ${#AVAIL[@]}; i++)); do
                #echo OST $i: ${AVAIL[i]}kb
                if [[ ${AVAIL[i]} -gt $MAXV ]]; then
-                       MAXV=${AVAIL[i]}; MAXI=$i
+                       MAXV=${AVAIL[i]}
+                       MAXI=$i
                fi
                if [[ ${AVAIL[i]} -lt $MINV ]]; then
-                       MINV=${AVAIL[i]}; MINI=$i
+                       MINV=${AVAIL[i]}
+                       MINI=$i
                fi
        done
-       echo Min free space: OST $MINI: $MINV
-       echo Max free space: OST $MAXI: $MAXV
+       echo "Min free space: OST $MINI: $MINV"
+       echo "Max free space: OST $MAXI: $MAXV"
 }
 
 test_116a() { # was previously test_116()
@@ -7566,9 +7877,9 @@ test_116a() { # was previously test_116()
 
        # Check if we need to generate uneven OSTs
        test_mkdir -p $DIR/$tdir/OST${MINI}
-       local FILL=$(($MINV / 4))
-       local DIFF=$(($MAXV - $MINV))
-       local DIFF2=$(($DIFF * 100 / $MINV))
+       local FILL=$((MINV / 4))
+       local DIFF=$((MAXV - MINV))
+       local DIFF2=$((DIFF * 100 / MINV))
 
        local threshold=$(do_facet $SINGLEMDS \
                lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
@@ -7582,15 +7893,15 @@ test_116a() { # was previously test_116()
        else
                # generate uneven OSTs. Write 2% over the QOS threshold value
                echo "no"
-               DIFF=$(($threshold - $DIFF2 + 2))
-               DIFF2=$(( ($MINV * $DIFF)/100 ))
-               echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
+               DIFF=$((threshold - DIFF2 + 2))
+               DIFF2=$((MINV * DIFF / 100))
+               echo "Fill $DIFF% remaining space in OST$MINI with ${DIFF2}KB"
                $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
                        error "setstripe failed"
-               DIFF=$(($DIFF2 / 2048))
+               DIFF=$((DIFF2 / 2048))
                i=0
                while [ $i -lt $DIFF ]; do
-                       i=$(($i + 1))
+                       i=$((i + 1))
                        dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
                                bs=2M count=1 2>/dev/null
                        echo -n .
@@ -7601,10 +7912,10 @@ test_116a() { # was previously test_116()
                free_min_max
        fi
 
-       DIFF=$(($MAXV - $MINV))
-       DIFF2=$(($DIFF * 100 / $MINV))
-       echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
-       if [[ $DIFF2 -gt $threshold ]]; then
+       DIFF=$((MAXV - MINV))
+       DIFF2=$((DIFF * 100 / MINV))
+       echo -n "diff=$DIFF=$DIFF2% must be > $threshold% for QOS mode..."
+       if [ $DIFF2 -gt $threshold ]; then
                echo "ok"
        else
                echo "failed - QOS mode won't be used"
@@ -7613,12 +7924,14 @@ test_116a() { # was previously test_116()
                return
        fi
 
-       MINI1=$MINI; MINV1=$MINV
-       MAXI1=$MAXI; MAXV1=$MAXV
+       MINI1=$MINI
+       MINV1=$MINV
+       MAXI1=$MAXI
+       MAXV1=$MAXV
 
        # now fill using QOS
        $SETSTRIPE -c 1 $DIR/$tdir
-       FILL=$(($FILL / 200))
+       FILL=$((FILL / 200))
        if [ $FILL -gt 600 ]; then
                FILL=600
        fi
@@ -7636,31 +7949,31 @@ test_116a() { # was previously test_116()
 
        echo "Note: free space may not be updated, so measurements might be off"
        free_min_max
-       DIFF2=$(($MAXV - $MINV))
+       DIFF2=$((MAXV - MINV))
        echo "free space delta: orig $DIFF final $DIFF2"
        [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
-       DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
+       DIFF=$((MINV1 - ${AVAIL[$MINI1]}))
        echo "Wrote ${DIFF}KB to smaller OST $MINI1"
-       DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
+       DIFF2=$((MAXV1 - ${AVAIL[$MAXI1]}))
        echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
        if [[ $DIFF -gt 0 ]]; then
-               FILL=$(($DIFF2 * 100 / $DIFF - 100))
+               FILL=$((DIFF2 * 100 / DIFF - 100))
                echo "Wrote ${FILL}% more data to larger OST $MAXI1"
        fi
 
        # Figure out which files were written where
        UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
-                 awk '/'$MINI1': / {print $2; exit}')
+              awk '/'$MINI1': / {print $2; exit}')
        echo $UUID
        MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
        echo "$MINC files created on smaller OST $MINI1"
        UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
-                 awk '/'$MAXI1': / {print $2; exit}')
+              awk '/'$MAXI1': / {print $2; exit}')
        echo $UUID
        MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
        echo "$MAXC files created on larger OST $MAXI1"
        if [[ $MINC -gt 0 ]]; then
-               FILL=$(($MAXC * 100 / $MINC - 100))
+               FILL=$((MAXC * 100 / MINC - 100))
                echo "Wrote ${FILL}% more files to larger OST $MAXI1"
        fi
        [[ $MAXC -gt $MINC ]] ||
@@ -8305,6 +8618,7 @@ test_120e() {
        stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
        # XXX client can not do early lock cancel of OST lock
        # during unlink (LU-4206), so cancel osc lock now.
+       sleep 2
        cancel_lru_locks osc
        can1=$(do_facet $SINGLEMDS \
               "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
@@ -8347,6 +8661,7 @@ test_120f() {
        stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
        # XXX client can not do early lock cancel of OST lock
        # during rename (LU-4206), so cancel osc lock now.
+       sleep 2
        cancel_lru_locks osc
        can1=$(do_facet $SINGLEMDS \
               "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
@@ -8641,11 +8956,18 @@ test_124b() {
 
        NR=$(($(default_lru_size)*20))
        if [[ $NR -gt $LIMIT ]]; then
-                log "Limit lock number by $LIMIT locks"
-                NR=$LIMIT
-        fi
-        lru_resize_disable mdc
-        test_mkdir -p $DIR/$tdir/disable_lru_resize ||
+               log "Limit lock number by $LIMIT locks"
+               NR=$LIMIT
+       fi
+
+       IFree=$(mdsrate_inodes_available)
+       if [ $IFree -lt $NR ]; then
+               log "Limit lock number by $IFree inodes"
+               NR=$IFree
+       fi
+
+       lru_resize_disable mdc
+       test_mkdir -p $DIR/$tdir/disable_lru_resize ||
                error "failed to create $DIR/$tdir/disable_lru_resize"
 
         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
@@ -8858,18 +9180,16 @@ set_dir_limits () {
        local canondev
        local node
 
-       local LDPROC=/proc/fs/ldiskfs
+       local ldproc=/proc/fs/ldiskfs
        local facets=$(get_facets MDS)
 
        for facet in ${facets//,/ }; do
                canondev=$(ldiskfs_canon \
                           *.$(convert_facet2label $facet).mntdev $facet)
-               do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
-                                               LDPROC=/sys/fs/ldiskfs
-               do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
-               do_facet $facet "test -e $LDPROC/$canondev/warning_dir_size" ||
-                                               LDPROC=/sys/fs/ldiskfs
-               do_facet $facet "echo $2 >$LDPROC/$canondev/warning_dir_size"
+               do_facet $facet "test -e $ldproc/$canondev/max_dir_size" ||
+                       ldproc=/sys/fs/ldiskfs
+               do_facet $facet "echo $1 >$ldproc/$canondev/max_dir_size"
+               do_facet $facet "echo $2 >$ldproc/$canondev/warning_dir_size"
        done
 }
 
@@ -8882,6 +9202,9 @@ check_mds_dmesg() {
 }
 
 test_129() {
+       [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.56) ]] ||
+               { skip "Need MDS version with at least 2.5.56"; return 0; }
+
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
                skip "Only applicable to ldiskfs-based MDTs"
@@ -8890,62 +9213,54 @@ test_129() {
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
        local ENOSPC=28
        local EFBIG=27
-       local has_warning=0
+       local has_warning=false
 
        rm -rf $DIR/$tdir
        mkdir -p $DIR/$tdir
 
        # block size of mds1
-       local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
-       local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
-       local MAX=$((MDSBLOCKSIZE * 5))
-       set_dir_limits $MAX $MAX
-       local I=$(stat -c%s "$DIR/$tdir")
-       local J=0
-       while [[ $I -le $MAX ]]; do
-               $MULTIOP $DIR/$tdir/$J Oc
+       local maxsize=$(($($LCTL get_param -n mdc.*MDT0000*.blocksize) * 5))
+       set_dir_limits $maxsize $maxsize
+       local dirsize=$(stat -c%s "$DIR/$tdir")
+       local nfiles=0
+       while [[ $dirsize -le $maxsize ]]; do
+               $MULTIOP $DIR/$tdir/file_base_$nfiles Oc
                rc=$?
-               if [ $has_warning -eq 0 ]; then
-                       check_mds_dmesg '"is approaching"' &&
-                               has_warning=1
+               if ! $has_warning; then
+                       check_mds_dmesg '"is approaching"' && has_warning=true
                fi
-               #check two errors ENOSPC for new version of ext4 max_dir_size patch
-               #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
-               #and EFBIG for previous versions
+               # check two errors:
+               # ENOSPC for new ext4 max_dir_size (kernel commit df981d03ee)
+               # EFBIG for previous versions included in ldiskfs series
                if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
                        set_dir_limits 0 0
                        echo "return code $rc received as expected"
 
-                       createmany -o $DIR/$tdir/$J_file_ 1000 ||
+                       createmany -o $DIR/$tdir/file_extra_$nfiles. 5 ||
                                error_exit "create failed w/o dir size limit"
 
                        check_mds_dmesg '"has reached"' ||
-                               error_exit "has reached message should be output"
+                               error_exit "reached message should be output"
 
                        [ $has_warning -eq 0 ] &&
                                error_exit "warning message should be output"
 
-                       I=$(stat -c%s "$DIR/$tdir")
+                       dirsize=$(stat -c%s "$DIR/$tdir")
 
-                       if [ $(lustre_version_code $SINGLEMDS) -lt \
-                                       $(version_code 2.4.51) ]
-                       then
-                               [[ $I -eq $MAX ]] && return 0
-                       else
-                               [[ $I -gt $MAX ]] && return 0
-                       fi
-                       error_exit "current dir size $I, previous limit $MAX"
+                       [[ $dirsize -ge $maxsize ]] && return 0
+                       error_exit "current dir size $dirsize, " \
+                                  "previous limit $maxsize"
                elif [ $rc -ne 0 ]; then
                        set_dir_limits 0 0
-                       error_exit "return code $rc received instead of expected " \
-                                  "$EFBIG or $ENOSPC, files in dir $I"
+                       error_exit "return $rc received instead of expected " \
+                                  "$EFBIG or $ENOSPC, files in dir $dirsize"
                fi
-               J=$((J+1))
-               I=$(stat -c%s "$DIR/$tdir")
+               nfiles=$((nfiles + 1))
+               dirsize=$(stat -c%s "$DIR/$tdir")
        done
 
        set_dir_limits 0 0
-       error "exceeded dir size limit $MAX($MDSCOUNT) : $I bytes"
+       error "exceeded dir size limit $maxsize($MDSCOUNT) : $dirsize bytes"
 }
 run_test 129 "test directory size limit ========================"
 
@@ -9303,22 +9618,27 @@ test_131e() {
 run_test 131e "test read hitting hole"
 
 check_stats() {
+       local facet=$1
+       local op=$2
+       local want=${3:-0}
        local res
-       local count
-       case $1 in
-       $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
+
+       case $facet in
+       mds*) res=$(do_facet $facet \
+                  $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$op")
                 ;;
-       ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
+       ost*) res=$(do_facet $facet \
+                  $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$op")
                 ;;
-       *) error "Wrong argument $1" ;;
+       *) error "Wrong facet '$facet'" ;;
        esac
        echo $res
-       [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
+       [ "$res" ] || error "The counter for $op on $facet was not incremented"
        # if the argument $3 is zero, it means any stat increment is ok.
-       if [[ $3 -gt 0 ]]; then
-               count=$(echo $res | awk '{ print $2 }')
-               [[ $count -ne $3 ]] &&
-                       error "The $2 counter on $1 is wrong - expected $3"
+       if [[ $want -gt 0 ]]; then
+               local count=$(echo $res | awk '{ print $2 }')
+               [[ $count -ne $want ]] &&
+                       error "The $op counter on $facet is $count, not $want"
        fi
 }
 
@@ -9418,17 +9738,17 @@ test_133c() {
        dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
        sync
        cancel_lru_locks osc
-       check_stats ost "write" 1
+       check_stats ost1 "write" 1
 
        dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
-       check_stats ost "read" 1
+       check_stats ost1 "read" 1
 
        > ${testdir}/${tfile} || error "truncate failed"
-       check_stats ost "punch" 1
+       check_stats ost1 "punch" 1
 
        rm -f ${testdir}/${tfile} || error "file remove failed"
        wait_delete_completed
-       check_stats ost "destroy" 1
+       check_stats ost1 "destroy" 1
 
        rm -rf $DIR/${tdir}
 }
@@ -9605,17 +9925,15 @@ test_133e() {
 }
 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
 
-proc_dirs=""
-for dir in /proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
-          /sys/fs/lustre/ /sys/fs/lnet/ /sys/kernel/debug/lnet/ \
-          /sys/kernel/debug/lustre/; do
-       [[ -d $dir ]] && proc_dirs+=" $dir"
-done
+proc_regexp="/{proc,sys}/{fs,sys,kernel/debug}/{lustre,lnet}/"
 
 test_133f() {
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
        remote_ost_nodsh && skip "remote OST with nodsh" && return
        # First without trusting modes.
+       local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
+       echo "proc_dirs='$proc_dirs'"
+       [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
        find $proc_dirs -exec cat '{}' \; &> /dev/null
 
        # Second verifying readability.
@@ -9624,12 +9942,16 @@ test_133f() {
        # eventually, this can also be replaced with "lctl get_param -R",
        # but not until that option is always available on the server
        local facet
-       for facet in $SINGLEMDS ost1; do
-               do_facet $facet find $proc_dirs \
+       for facet in mds1 ost1; do
+               local facet_proc_dirs=$(do_facet $facet \
+                                       \\\ls -d $proc_regexp 2>/dev/null)
+               echo "${facet}_proc_dirs='$facet_proc_dirs'"
+               [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
+               do_facet $facet find $facet_proc_dirs \
                        ! -name req_history \
                        -exec cat '{}' \\\; &> /dev/null
 
-               do_facet $facet find $proc_dirs \
+               do_facet $facet find $facet_proc_dirs \
                        ! -name req_history \
                        -type f \
                        -exec cat '{}' \\\; &> /dev/null ||
@@ -9642,6 +9964,9 @@ test_133g() {
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
        remote_ost_nodsh && skip "remote OST with nodsh" && return
        # Second verifying writability.
+       local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
+       echo "proc_dirs='$proc_dirs'"
+       [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
        find $proc_dirs \
                -type f \
                -not -name force_lbug \
@@ -9649,21 +9974,20 @@ test_133g() {
                -exec badarea_io '{}' \; &> /dev/null ||
                error "find $proc_dirs failed"
 
-       [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.5.54) ] &&
-               skip "Too old lustre on MDS" && return
-
-       [ $(lustre_version_code ost1) -le $(version_code 2.5.54) ] &&
-               skip "Too old lustre on ost1" && return
-
        local facet
-       for facet in $SINGLEMDS ost1; do
-               do_facet $facet find $proc_dirs \
+       for facet in mds1 ost1; do
+               [ $(lustre_version_code $facet) -le $(version_code 2.5.54) ] &&
+                       skip "Too old lustre on $facet" && continue
+               local facet_proc_dirs=$(do_facet $facet \
+                                       \\\ls -d $proc_regexp 2> /dev/null)
+               echo "${facet}_proc_dirs='$facet_proc_dirs'"
+               [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
+               do_facet $facet find $facet_proc_dirs \
                        -type f \
                        -not -name force_lbug \
                        -not -name changelog_mask \
                        -exec badarea_io '{}' \\\; &> /dev/null ||
-               error "$facet find $proc_dirs failed"
-
+                               error "$facet find $facet_proc_dirs failed"
        done
 
        # remount the FS in case writes/reads /proc break the FS
@@ -9673,6 +9997,34 @@ test_133g() {
 }
 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
 
+test_133h() {
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
+       [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.54) ]] &&
+               skip "Need MDS version at least 2.9.54" && return
+
+       local facet
+       for facet in client mds1 ost1; do
+               local facet_proc_dirs=$(do_facet $facet \
+                                       \\\ls -d $proc_regexp 2> /dev/null)
+               [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
+               echo "${facet}_proc_dirs='$facet_proc_dirs'"
+               # Get the list of files that are missing the terminating newline
+               local missing=($(do_facet $facet \
+                       find ${facet_proc_dirs} -type f \|              \
+                               while read F\; do                       \
+                                       awk -v FS='\v' -v RS='\v\v'     \
+                                       "'END { if(NR>0 &&              \
+                                       \\\$NF !~ /.*\\\n\$/)           \
+                                               print FILENAME}'"       \
+                                       '\$F'\;                         \
+                               done 2>/dev/null))
+               [ ${#missing[*]} -eq 0 ] ||
+                       error "files do not end with newline: ${missing[*]}"
+       done
+}
+run_test 133h "Proc files should end with newlines"
+
 test_134a() {
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
        [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
@@ -10102,20 +10454,43 @@ test_154A() {
        [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
                skip "Need MDS version at least 2.4.1" && return
 
-       touch $DIR/$tfile
-       local FID=$($LFS path2fid $DIR/$tfile)
-       [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
+       local tf=$DIR/$tfile
+       touch $tf
 
-       # check that we get the same pathname back
-       local FOUND=$($LFS fid2path $MOUNT "$FID")
-       [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
-       [ "$FOUND" != "$DIR/$tfile" ] &&
-               error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
+       local fid=$($LFS path2fid $tf)
+       [ -z "$fid" ] && error "path2fid unable to get $tf FID"
 
-       rm -rf $DIR/$tfile
+       # check that we get the same pathname back
+       local found=$($LFS fid2path $MOUNT "$fid")
+       [ -z "$found" ] && error "fid2path unable to get '$fid' path"
+       [ "$found" == "$tf" ] ||
+               error "fid2path($fid=path2fid($tf)) = $found != $tf"
 }
 run_test 154A "lfs path2fid and fid2path basic checks"
 
+test_154B() {
+       [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
+               skip "Need MDS version at least 2.4.1" && return
+
+       mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
+       touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
+       local linkea=$($LL_DECODE_LINKEA $DIR/$tdir/$tfile | grep 'pfid')
+       [ -z "$linkea" ] && error "decode linkea $DIR/$tdir/$tfile failed"
+
+       local name=$(echo $linkea | awk '/pfid/ {print $5}' | sed -e "s/'//g")
+       local PFID=$(echo $linkea | awk '/pfid/ {print $3}' | sed -e "s/,//g")
+
+       # check that we get the same pathname
+       echo "PFID: $PFID, name: $name"
+       local FOUND=$($LFS fid2path $MOUNT "$PFID")
+       [ -z "$FOUND" ] && error "fid2path unable to get $PFID path"
+       [ "$FOUND/$name" != "$DIR/$tdir/$tfile" ] &&
+               error "ll_decode_linkea has $FOUND/$name != $DIR/$tdir/$tfile"
+
+       rm -rf $DIR/$tdir || error "Can not delete directory $DIR/$tdir"
+}
+run_test 154B "verify the ll_decode_linkea tool"
+
 test_154a() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
@@ -10390,67 +10765,114 @@ test_155_big_load() {
     true
 }
 
+save_writethrough() {
+       local facets=$(get_facets OST)
+
+       save_lustre_params $facets "obdfilter.*.writethrough_cache_enable" > $1
+       save_lustre_params $facets "osd-*.*.writethrough_cache_enable" >> $1
+}
+
 test_155a() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+       local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
+       save_writethrough $p
+
        set_cache read on
        set_cache writethrough on
        test_155_small_load
+       restore_lustre_params < $p
+       rm -f $p
 }
 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
 
 test_155b() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+       local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
+       save_writethrough $p
+
        set_cache read on
        set_cache writethrough off
        test_155_small_load
+       restore_lustre_params < $p
+       rm -f $p
 }
 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
 
 test_155c() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+       local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
+       save_writethrough $p
+
        set_cache read off
        set_cache writethrough on
        test_155_small_load
+       restore_lustre_params < $p
+       rm -f $p
 }
 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
 
 test_155d() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+       local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
+       save_writethrough $p
+
        set_cache read off
        set_cache writethrough off
        test_155_small_load
+       restore_lustre_params < $p
+       rm -f $p
 }
 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
 
 test_155e() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+       local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
+       save_writethrough $p
+
        set_cache read on
        set_cache writethrough on
        test_155_big_load
+       restore_lustre_params < $p
+       rm -f $p
 }
 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
 
 test_155f() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+       local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
+       save_writethrough $p
+
        set_cache read on
        set_cache writethrough off
        test_155_big_load
+       restore_lustre_params < $p
+       rm -f $p
 }
 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
 
 test_155g() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+       local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
+       save_writethrough $p
+
        set_cache read off
        set_cache writethrough on
        test_155_big_load
+       restore_lustre_params < $p
+       rm -f $p
 }
 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
 
 test_155h() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+       local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
+       save_writethrough $p
+
        set_cache read off
        set_cache writethrough off
        test_155_big_load
+       restore_lustre_params < $p
+       rm -f $p
 }
 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
 
@@ -10461,12 +10883,14 @@ test_156() {
        local BEFORE
        local AFTER
        local file="$DIR/$tfile"
+       local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
 
        [ "$(facet_fstype ost1)" = "zfs" -a \
           $(lustre_version_code ost1 -lt $(version_code 2.6.93)) ] &&
                skip "LU-1956/LU-2261: stats not implemented on OSD ZFS" &&
                return
 
+       save_writethrough $p
        roc_hit_init
 
        log "Turn on read and write cache"
@@ -10595,10 +11019,18 @@ test_156() {
        fi
 
        rm -f $file
+       restore_lustre_params < $p
+       rm -f $p
 }
 run_test 156 "Verification of tunables"
 
 #Changelogs
+cleanup_changelog () {
+       trap 0
+       echo "Deregistering changelog client $CL_USER"
+       do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
+}
+
 err17935 () {
        if [[ $MDSCOUNT -gt 1 ]]; then
                error_ignore bz17935 $*
@@ -10639,10 +11071,12 @@ test_160a() {
 
        local CL_USERS="mdd.$MDT0.changelog_users"
        local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
-       USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
-       echo "Registered as changelog user $USER"
-       $GET_CL_USERS | grep -q $USER ||
-               error "User $USER not found in changelog_users"
+       CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
+               changelog_register -n)
+       echo "Registered as changelog user $CL_USER"
+       trap cleanup_changelog EXIT
+       $GET_CL_USERS | grep -q $CL_USER ||
+               error "User $CL_USER not found in changelog_users"
 
        # change something
        test_mkdir -p $DIR/$tdir/pics/2008/zachy
@@ -10686,9 +11120,9 @@ test_160a() {
        [ "$fidc" == "$fidf" ] ||
                err17935 "pfid in changelog $fidc != dir fid $fidf"
 
-       USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
-       $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
-       USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
+       USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$CL_USER\" {print \$2}")
+       $LFS changelog_clear $MDT0 $CL_USER $(($USER_REC1 + 5))
+       USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$CL_USER\" {print \$2}")
        echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
        [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
                err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
@@ -10703,7 +11137,7 @@ test_160a() {
        # LU-3446 changelog index reset on MDT restart
        local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
        CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
-       $LFS changelog_clear $MDT0 $USER 0
+       $LFS changelog_clear $MDT0 $CL_USER 0
        stop $SINGLEMDS || error "Fail to stop MDT."
        start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
        CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
@@ -10712,19 +11146,19 @@ test_160a() {
                err17935 "current index should be $CUR_REC1 is $CUR_REC2"
 
        echo "verifying user deregister"
-       do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
-       $GET_CL_USERS | grep -q $USER &&
-               error "User $USER still in changelog_users"
+       cleanup_changelog
+       $GET_CL_USERS | grep -q $CL_USER &&
+               error "User $CL_USER still in changelog_users"
 
        USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
-       if [ $USERS -eq 0 ]; then
+       if [ $CL_USER -eq 0 ]; then
                LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
                touch $DIR/$tdir/chloe
                LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
                echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
                [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
        else
-               echo "$USERS other changelog users; can't verify off"
+               echo "$CL_USER other changelog users; can't verify off"
        fi
 }
 run_test 160a "changelog sanity"
@@ -10737,10 +11171,12 @@ test_160b() { # LU-3587
 
        local CL_USERS="mdd.$MDT0.changelog_users"
        local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
-       USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
-       echo "Registered as changelog user $USER"
-       $GET_CL_USERS | grep -q $USER ||
-               error "User $USER not found in changelog_users"
+       CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
+               changelog_register -n)
+       echo "Registered as changelog user $CL_USER"
+       trap cleanup_changelog EXIT
+       $GET_CL_USERS | grep -q $CL_USER ||
+               error "User $CL_USER not found in changelog_users"
 
        local LONGNAME1=$(str_repeat a 255)
        local LONGNAME2=$(str_repeat b 255)
@@ -10752,11 +11188,8 @@ test_160b() { # LU-3587
        mv $LONGNAME1 $LONGNAME2
 
        $LFS changelog $MDT0 | grep RENME
-
-       echo "deregistering $USER"
-       do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
-
        rm -f $LONGNAME2
+       cleanup_changelog
 }
 run_test 160b "Verify that very long rename doesn't crash in changelog"
 
@@ -10773,8 +11206,9 @@ test_160c() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
 
        # Registration step
-       local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
+       CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
                changelog_register -n)
+       trap cleanup_changelog EXIT
 
        rm -rf $DIR/$tdir
        mkdir -p $DIR/$tdir
@@ -10786,11 +11220,10 @@ test_160c() {
        $LFS changelog $MDT0
        TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
        [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
-       $LFS changelog_clear $MDT0 $USER 0
+       $LFS changelog_clear $MDT0 $CL_USER 0
 
        # Deregistration step
-       echo "deregistering $USER"
-       do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
+       cleanup_changelog
 }
 run_test 160c "verify that changelog log catch the truncate event"
 
@@ -10806,24 +11239,57 @@ test_160d() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
 
        # Registration step
-       local USER=$(do_facet mds1 $LCTL --device $MDT0 \
+       CL_USER=$(do_facet mds1 $LCTL --device $MDT0 \
                changelog_register -n)
 
+       trap cleanup_changelog EXIT
        mkdir -p $DIR/$tdir/migrate_dir
-       $LFS changelog_clear $MDT0 $USER 0
+       $LFS changelog_clear $MDT0 $CL_USER 0
 
        $LFS migrate -m 1 $DIR/$tdir/migrate_dir || error "migrate fails"
        $LFS changelog $MDT0
        MIGRATES=$($LFS changelog $MDT0 | tail -5 | grep -c "MIGRT")
-       $LFS changelog_clear $MDT0 $USER 0
+       $LFS changelog_clear $MDT0 $CL_USER 0
        [ $MIGRATES -eq 1 ] ||
                error "MIGRATE changelog mask count $MIGRATES != 1"
 
        # Deregistration step
-       do_facet mds1 $LCTL --device $MDT0 changelog_deregister $USER
+       cleanup_changelog
 }
 run_test 160d "verify that changelog log catch the migrate event"
 
+test_160e() {
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+
+       # Create a user
+       CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
+               changelog_register -n)
+       echo "Registered as changelog user $CL_USER"
+       trap cleanup_changelog EXIT
+
+       # Delete a future user (expect fail)
+       do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister cl77
+       local rc=$?
+
+       if [ $rc -eq 0 ]; then
+               error "Deleted non-existant user cl77"
+       elif [ $rc -ne 2 ]; then
+               error "changelog_deregister failed with $rc, " \
+                       "expected 2 (ENOENT)"
+       fi
+
+       # Clear to a bad index (1 billion should be safe)
+       $LFS changelog_clear $MDT0 $CL_USER 1000000000
+       rc=$?
+
+       if [ $rc -eq 0 ]; then
+               error "Successfully cleared to invalid CL index"
+       elif [ $rc -ne 22 ]; then
+               error "changelog_clear failed with $rc, expected 22 (EINVAL)"
+       fi
+}
+run_test 160e "changelog negative testing"
+
 test_161a() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        test_mkdir -p -c1 $DIR/$tdir
@@ -10927,8 +11393,10 @@ test_161c() {
 
        # define CLF_RENAME_LAST 0x0001
        # rename overwrite a target having nlink = 1 (changelog flag 0x1)
-       local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
+       CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
                changelog_register -n)
+
+       trap cleanup_changelog EXIT
        rm -rf $DIR/$tdir
        mkdir -p $DIR/$tdir
        touch $DIR/$tdir/foo_161c
@@ -10937,10 +11405,8 @@ test_161c() {
        $LFS changelog $MDT0 | grep RENME
        local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
                cut -f5 -d' ')
-       $LFS changelog_clear $MDT0 $USER 0
+       $LFS changelog_clear $MDT0 $CL_USER 0
        if [ x$flags != "x0x1" ]; then
-               do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
-                       $USER
                error "flag $flags is not 0x1"
        fi
        echo "rename overwrite a target having nlink = 1," \
@@ -10953,10 +11419,8 @@ test_161c() {
        mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
        $LFS changelog $MDT0 | grep RENME
        flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
-       $LFS changelog_clear $MDT0 $USER 0
+       $LFS changelog_clear $MDT0 $CL_USER 0
        if [ x$flags != "x0x0" ]; then
-               do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
-                       $USER
                error "flag $flags is not 0x0"
        fi
        echo "rename overwrite a target having nlink > 1," \
@@ -10967,10 +11431,8 @@ test_161c() {
        mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
        $LFS changelog $MDT0 | grep RENME
        flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
-       $LFS changelog_clear $MDT0 $USER 0
+       $LFS changelog_clear $MDT0 $CL_USER 0
        if [ x$flags != "x0x0" ]; then
-               do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
-                       $USER
                error "flag $flags is not 0x0"
        fi
        echo "rename doesn't overwrite a target," \
@@ -10981,10 +11443,8 @@ test_161c() {
        rm -f $DIR/$tdir/foo2_161c
        $LFS changelog $MDT0 | grep UNLNK
        flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
-       $LFS changelog_clear $MDT0 $USER 0
+       $LFS changelog_clear $MDT0 $CL_USER 0
        if [ x$flags != "x0x1" ]; then
-               do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
-                       $USER
                error "flag $flags is not 0x1"
        fi
        echo "unlink a file having nlink = 1," \
@@ -10995,18 +11455,65 @@ test_161c() {
        rm -f $DIR/$tdir/foobar_161c
        $LFS changelog $MDT0 | grep UNLNK
        flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
-       $LFS changelog_clear $MDT0 $USER 0
+       $LFS changelog_clear $MDT0 $CL_USER 0
        if [ x$flags != "x0x0" ]; then
-               do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
-                       $USER
                error "flag $flags is not 0x0"
        fi
        echo "unlink a file having nlink > 1," \
                "changelog record has flags of $flags"
-       do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
+       cleanup_changelog
 }
 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
 
+test_161d() {
+       local user
+       local pid
+       local fid
+
+       # cleanup previous run
+       rm -rf $DIR/$tdir/$tfile
+
+       user=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
+               changelog_register -n)
+       [[ $? -eq 0 ]] || error "changelog_register failed"
+
+       # work in a standalone dir to avoid locking on $DIR/$MOUNT to
+       # interfer with $MOUNT/.lustre/fid/ access
+       mkdir $DIR/$tdir
+       [[ $? -eq 0 ]] || error "mkdir failed"
+
+       #define OBD_FAIL_LLITE_CREATE_NODE_PAUSE 0x140c | OBD_FAIL_ONCE
+       $LCTL set_param fail_loc=0x8000140c
+       # 5s pause
+       $LCTL set_param fail_val=5
+
+       # create file
+       echo foofoo > $DIR/$tdir/$tfile &
+       pid=$!
+
+       # wait for create to be delayed
+       sleep 2
+
+       ps -p $pid
+       [[ $? -eq 0 ]] || error "create should be blocked"
+
+       local tempfile=$(mktemp)
+       fid=$(changelog_extract_field $MDT0 "CREAT" "$tfile" "t=")
+       cat $MOUNT/.lustre/fid/$fid 2>/dev/null >$tempfile || error "cat failed"
+       # some delay may occur during ChangeLog publishing and file read just
+       # above, that could allow file write to happen finally
+       [[ -s $tempfile ]] && echo "file should be empty"
+
+       $LCTL set_param fail_loc=0
+
+       wait $pid
+       [[ $? -eq 0 ]] || error "create failed"
+
+       $LFS changelog_clear $MDT0 $user 0
+       do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $user
+}
+run_test 161d "create with concurrent .lustre/fid access"
+
 check_path() {
     local expected=$1
     shift
@@ -11320,12 +11827,11 @@ test_180b() {
        local rc=0
        local rmmod_remote=0
 
-       do_facet ost1 "lsmod | grep -q obdecho || "                      \
-                     "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
-                     "modprobe obdecho; }" && rmmod_remote=1
+       do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
+               rmmod_remote=true || error "failed to load module obdecho"
        target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
        [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
-       [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
+       $rmmod_remote && do_facet ost1 "rmmod obdecho"
        return $rc
 }
 run_test 180b "test obdecho directly on obdfilter"
@@ -11556,14 +12062,16 @@ test_184d() {
                error "create $file2 failed"
        $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
                error "create $file3 failed"
-       lovea1=$($LFS getstripe $file1 | sed 1d)
+       lovea1=$(get_layout_param $file1)
 
        $LFS swap_layouts $file2 $file3 ||
                error "swap $file2 $file3 layouts failed"
        $LFS swap_layouts $file1 $file2 ||
                error "swap $file1 $file2 layouts failed"
 
-       lovea2=$($LFS getstripe $file2 | sed 1d)
+       lovea2=$(get_layout_param $file2)
+       echo "$lovea1"
+       echo "$lovea2"
        [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
 
        lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
@@ -11733,7 +12241,7 @@ test_200() {
                break
        done
 
-       cleanup_pools
+       destroy_test_pools
        return $rc
 }
 run_test 200 "OST pools"
@@ -11747,11 +12255,11 @@ default_attr() {
 check_default_stripe_attr() {
        ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
        case $1 in
-       --stripe-count|--count)
+       --stripe-count|-c)
                [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
-       --stripe-size|--size)
+       --stripe-size|-S)
                [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
-       --stripe-index|--index)
+       --stripe-index|-i)
                EXPECTED=-1;;
        *)
                error "unknown getstripe attr '$1'"
@@ -11925,13 +12433,17 @@ jobstats_set() {
 }
 
 cleanup_205() {
+       trap 0
        do_facet $SINGLEMDS \
                $LCTL set_param mdt.*.job_cleanup_interval=$OLD_INTERVAL
        [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
-       do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
+       cleanup_changelog
 }
 
 test_205() { # Job stats
+       [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.1) ]] ||
+               { skip "Need MDS version with at least 2.7.1"; return 0; }
+
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        remote_mgs_nodsh && skip "remote MGS with nodsh" && return
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
@@ -11996,8 +12508,10 @@ test_205() { # Job stats
        cmd="mv -f $DIR/$tfile $DIR/$tdir.rename"
        verify_jobstats "$cmd" "$SINGLEMDS"
        # jobstats expiry - sleep until old stats should be expired
-       local left=$((interval_new + 2 - (SECONDS - start)))
-       [ $left -ge 0 ] && echo "sleep $left for expiry" && sleep $((left + 1))
+       local left=$((interval_new + 5 - (SECONDS - start)))
+       [ $left -ge 0 ] && wait_update_facet $SINGLEMDS \
+               "lctl get_param *.*.job_stats | grep -c 'job_id.*mkdir'" \
+                       "0" $left
        cmd="mkdir $DIR/$tdir.expire"
        verify_jobstats "$cmd" "$SINGLEMDS"
        [ $(do_facet $SINGLEMDS lctl get_param *.*.job_stats |
@@ -12322,32 +12836,34 @@ test_216() { # bug 20317
                "ldlm.namespaces.filter-*.contended_locks" >> $p
        save_lustre_params $facets \
                "ldlm.namespaces.filter-*.contention_seconds" >> $p
-       clear_osc_stats
-
-        # agressive lockless i/o settings
-        for node in $(osts_nodes); do
-                do_node $node 'lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes 2000000; lctl set_param -n ldlm.namespaces.filter-*.contended_locks 0; lctl set_param -n ldlm.namespaces.filter-*.contention_seconds 60'
-        done
-        lctl set_param -n osc.*.contention_seconds 60
-
-        $DIRECTIO write $DIR/$tfile 0 10 4096
-        $CHECKSTAT -s 40960 $DIR/$tfile
-
-        # disable lockless i/o
-        for node in $(osts_nodes); do
-                do_node $node 'lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes 0; lctl set_param -n ldlm.namespaces.filter-*.contended_locks 32; lctl set_param -n ldlm.namespaces.filter-*.contention_seconds 0'
-        done
-        lctl set_param -n osc.*.contention_seconds 0
-        clear_osc_stats
-
-        dd if=/dev/zero of=$DIR/$tfile count=0
-        $CHECKSTAT -s 0 $DIR/$tfile
-
-        restore_lustre_params <$p
-        rm -f $p
-        rm $DIR/$tfile
+       clear_stats osc.*.osc_stats
+
+       # agressive lockless i/o settings
+       do_nodes $(comma_list $(osts_nodes)) \
+               "lctl set_param -n ldlm.namespaces.*.max_nolock_bytes=2000000 \
+                       ldlm.namespaces.filter-*.contended_locks=0 \
+                       ldlm.namespaces.filter-*.contention_seconds=60"
+       lctl set_param -n osc.*.contention_seconds=60
+
+       $DIRECTIO write $DIR/$tfile 0 10 4096
+       $CHECKSTAT -s 40960 $DIR/$tfile
+
+       # disable lockless i/o
+       do_nodes $(comma_list $(osts_nodes)) \
+               "lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes=0 \
+                       ldlm.namespaces.filter-*.contended_locks=32 \
+                       ldlm.namespaces.filter-*.contention_seconds=0"
+       lctl set_param -n osc.*.contention_seconds=0
+       clear_stats osc.*.osc_stats
+
+       dd if=/dev/zero of=$DIR/$tfile count=0
+       $CHECKSTAT -s 0 $DIR/$tfile
+
+       restore_lustre_params <$p
+       rm -f $p
+       rm $DIR/$tfile
 }
-run_test 216 "check lockless direct write works and updates file size and kms correctly"
+run_test 216 "check lockless direct write updates file size and kms correctly"
 
 test_217() { # bug 22430
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
@@ -12427,7 +12943,7 @@ test_220() { #LU-325
        do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
        #define OBD_FAIL_OST_ENOINO              0x229
        do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
-       do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
+       create_pool $FSNAME.$TESTNAME || return 1
        do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
 
        $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
@@ -12546,6 +13062,11 @@ run_test 224b "Don't panic on bulk IO failure"
 test_224c() { # LU-6441
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
+
+       local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
+       save_writethrough $p
+       set_cache writethrough on
+
        local pages_per_rpc=$($LCTL get_param \
                                osc.*.max_pages_per_rpc)
        local at_max=$($LCTL get_param -n at_max)
@@ -12563,10 +13084,11 @@ test_224c() { # LU-6441
                error "conf_param timeout=5 failed"
 
        #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3   0x520
-       $LCTL set_param fail_loc=0x520
+       do_facet ost1 $LCTL set_param fail_loc=0x520
+       $LFS setstripe -c 1 -i 0 $DIR/$tfile
        dd if=/dev/zero of=$DIR/$tfile bs=8MB count=1
        sync
-       $LCTL set_param fail_loc=0
+       do_facet ost1 $LCTL set_param fail_loc=0
 
        set_conf_param_and_check client "$test_at" "$param_at" $at_max ||
                error "conf_param at_max=$at_max failed"
@@ -12574,6 +13096,8 @@ test_224c() { # LU-6441
                $timeout || error "conf_param timeout=$timeout failed"
 
        $LCTL set_param -n $pages_per_rpc
+       restore_lustre_params < $p
+       rm -f $p
 }
 run_test 224c "Don't hang if one of md lost during large bulk RPC"
 
@@ -13591,7 +14115,7 @@ test_241_dio() {
        done
 }
 
-test_241() {
+test_241a() { # was test_241
        dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
        ls -la $DIR/$tfile
        cancel_lru_locks osc
@@ -13600,7 +14124,7 @@ test_241() {
        test_241_dio 1000
        wait $PID
 }
-run_test 241 "bio vs dio"
+run_test 241a "bio vs dio"
 
 test_241b() {
        dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
@@ -13767,18 +14291,9 @@ test_247e() {
 run_test 247e "mount .. as fileset"
 
 test_248() {
-       local my_error=error
-
        local fast_read_sav=$($LCTL get_param -n llite.*.fast_read 2>/dev/null)
        [ -z "$fast_read_sav" ] && skip "no fast read support" && return
 
-       # This test case is time sensitive and Maloo uses KVM to run autotest.
-       # Therefore the complete time of I/O task is unreliable and depends on
-       # the workload on the host machine when the task is running.
-       local virt=$(running_in_vm)
-       [ -n "$virt" ] && echo "running in VM '$virt', ignore error" &&
-                 my_error="error_ignore env=$virt"
-
        # create a large file for fast read verification
        dd if=/dev/zero of=$DIR/$tfile bs=1M count=128 > /dev/null 2>&1
 
@@ -13800,7 +14315,8 @@ test_248() {
 
        # verify that fast read is 4 times faster for cache read
        [ $(bc <<< "4 * $t_fast < $t_slow") -eq 1 ] ||
-               $my_error "fast read was not 4 times faster: $t_fast vs $t_slow"
+               error_not_in_vm "fast read was not 4 times faster: " \
+                          "$t_fast vs $t_slow"
 
        echo "Test 2: verify the performance between big and small read"
        $LCTL set_param -n llite.*.fast_read=1
@@ -13817,7 +14333,7 @@ test_248() {
 
        # verify that big IO is not 4 times faster than small IO
        [ $(bc <<< "4 * $t_1k >= $t_1m") -eq 1 ] ||
-               $my_error "bigger IO is way too fast: $t_1k vs $t_1m"
+               error_not_in_vm "bigger IO is way too fast: $t_1k vs $t_1m"
 
        $LCTL set_param -n llite.*.fast_read=$fast_read_sav
        rm -f $DIR/$tfile
@@ -13921,6 +14437,128 @@ test_252() {
 }
 run_test 252 "check lr_reader tool"
 
+test_253_fill_ost() {
+       local size_mb #how many MB should we write to pass watermark
+       local lwm=$3  #low watermark
+       local free_10mb #10% of free space
+
+       free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
+       size_mb=$((free_kb / 1024 - lwm))
+       free_10mb=$((free_kb / 10240))
+       #If 10% of free space cross low watermark use it
+       if (( free_10mb > size_mb )); then
+               size_mb=$free_10mb
+       else
+               #At least we need to store 1.1 of difference between
+               #free space and low watermark
+               size_mb=$((size_mb + size_mb / 10))
+       fi
+       if (( lwm <= $((free_kb / 1024)) )) || [ ! -f $DIR/$tdir/1 ]; then
+               dd if=/dev/zero of=$DIR/$tdir/1 bs=1M count=$size_mb \
+                        oflag=append conv=notrunc
+       fi
+
+       sleep_maxage
+
+       free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
+       echo "OST still has $((free_kb / 1024)) mbytes free"
+}
+
+test_253() {
+       local ostidx=0
+       local rc=0
+
+       [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && return
+
+       local ost_name=$($LFS osts |
+               sed -n 's/^'$ostidx': \(.*\)_UUID .*/\1/p')
+       # on the mdt's osc
+       local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
+       do_facet $SINGLEMDS $LCTL get_param -n \
+               osp.$mdtosc_proc1.reserved_mb_high ||
+               { skip  "remote MDS does not support reserved_mb_high" &&
+                 return; }
+
+       rm -rf $DIR/$tdir
+       wait_mds_ost_sync
+       wait_delete_completed
+       mkdir $DIR/$tdir
+
+       local last_wm_h=$(do_facet $SINGLEMDS $LCTL get_param -n \
+                       osp.$mdtosc_proc1.reserved_mb_high)
+       local last_wm_l=$(do_facet $SINGLEMDS $LCTL get_param -n \
+                       osp.$mdtosc_proc1.reserved_mb_low)
+       echo "prev high watermark $last_wm_h, prev low watermark $last_wm_l"
+
+       create_pool $FSNAME.$TESTNAME || error "Pool creation failed"
+       do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $ost_name ||
+               error "Adding $ost_name to pool failed"
+
+       # Wait for client to see a OST at pool
+       wait_update $HOSTNAME "$LCTL get_param -n
+               lov.$FSNAME-*.pools.$TESTNAME | sort -u |
+               grep $ost_name" "$ost_name""_UUID" $((TIMEOUT/2)) ||
+               error "Client can not see the pool"
+       $SETSTRIPE $DIR/$tdir -i $ostidx -c 1 -p $FSNAME.$TESTNAME ||
+               error "Setstripe failed"
+
+       dd if=/dev/zero of=$DIR/$tdir/0 bs=1M count=10
+       local blocks=$($LFS df $MOUNT | grep $ost_name | awk '{ print $4 }')
+       echo "OST still has $((blocks/1024)) mbytes free"
+
+       local new_lwm=$((blocks/1024-10))
+       do_facet $SINGLEMDS $LCTL set_param \
+                       osp.$mdtosc_proc1.reserved_mb_high=$((new_lwm+5))
+       do_facet $SINGLEMDS $LCTL set_param \
+                       osp.$mdtosc_proc1.reserved_mb_low=$new_lwm
+
+       test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
+
+       #First enospc could execute orphan deletion so repeat.
+       test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
+
+       local oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
+                       osp.$mdtosc_proc1.prealloc_status)
+       echo "prealloc_status $oa_status"
+
+       dd if=/dev/zero of=$DIR/$tdir/2 bs=1M count=1 &&
+               error "File creation should fail"
+       #object allocation was stopped, but we still able to append files
+       dd if=/dev/zero of=$DIR/$tdir/1 bs=1M seek=6 count=5 oflag=append ||
+               error "Append failed"
+       rm -f $DIR/$tdir/1 $DIR/$tdir/0 $DIR/$tdir/r*
+
+       wait_delete_completed
+
+       sleep_maxage
+
+       for i in $(seq 10 12); do
+               dd if=/dev/zero of=$DIR/$tdir/$i bs=1M count=1 2>/dev/null ||
+                       error "File creation failed after rm";
+       done
+
+       oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
+                       osp.$mdtosc_proc1.prealloc_status)
+       echo "prealloc_status $oa_status"
+
+       if (( oa_status != 0 )); then
+               error "Object allocation still disable after rm"
+       fi
+       do_facet $SINGLEMDS $LCTL set_param \
+                       osp.$mdtosc_proc1.reserved_mb_high=$last_wm_h
+       do_facet $SINGLEMDS $LCTL set_param \
+                       osp.$mdtosc_proc1.reserved_mb_low=$last_wm_l
+
+
+       do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $ost_name ||
+               error "Remove $ost_name from pool failed"
+       do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME ||
+               error "Pool destroy fialed"
+}
+run_test 253 "Check object allocation limit"
+
 test_254() {
        local cl_user
 
@@ -13962,38 +14600,299 @@ test_254() {
 }
 run_test 254 "Check changelog size"
 
-test_256() {
-       local cl_user
-       local cat_sl
-       local mdt_dev
-
-       [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
-       remote_mds_nodsh && skip "remote MDS with nodsh" && return
-       [ "$(facet_fstype mds1)" != "ldiskfs" ] &&
-               skip "non-ldiskfs backend" && return
+ladvise_no_type()
+{
+       local type=$1
+       local file=$2
 
-       mdt_dev=$(mdsdevname 1)
-       echo $mdt_dev
-       cl_user=$(do_facet mds1 \
-       "$LCTL get_param -n mdd.$MDT0.changelog_users | grep cl")
-       if [[ -n $cl_user ]]; then
-               skip "active changelog user"
-               return
+       lfs ladvise -a invalid $file 2>&1 | grep "Valid types" |
+               awk -F: '{print $2}' | grep $type > /dev/null
+       if [ $? -ne 0 ]; then
+               return 0
        fi
+       return 1
+}
 
-       cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
-       echo "Registered as changelog user $cl_user"
+ladvise_no_ioctl()
+{
+       local file=$1
 
-       rm -rf $DIR/$tdir
-       mkdir -p $DIR/$tdir
+       lfs ladvise -a willread $file > /dev/null 2>&1
+       if [ $? -eq 0 ]; then
+               return 1
+       fi
 
-       $LFS changelog_clear $MDT0 $cl_user 0
+       lfs ladvise -a willread $file 2>&1 |
+               grep "Inappropriate ioctl for device" > /dev/null
+       if [ $? -eq 0 ]; then
+               return 0
+       fi
+       return 1
+}
 
-       # change something
-       touch $DIR/$tdir/{1..10}
+percent() {
+       bc <<<"scale=2; ($1 - $2) * 100 / $2"
+}
 
-       # stop the MDT
-       stop mds1 || error "Fail to stop MDT."
+# run a random read IO workload
+# usage: random_read_iops <filename> <filesize> <iosize>
+random_read_iops() {
+       local file=$1
+       local fsize=$2
+       local iosize=${3:-4096}
+
+       $READS -f $file -s $fsize -b $iosize -n $((fsize / iosize)) -t 60 |
+               sed -e '/^$/d' -e 's#.*s, ##' -e 's#MB/s##'
+}
+
+drop_file_oss_cache() {
+       local file="$1"
+       local nodes="$2"
+
+       $LFS ladvise -a dontneed $file 2>/dev/null ||
+               do_nodes $nodes "echo 3 > /proc/sys/vm/drop_caches"
+}
+
+ladvise_willread_performance()
+{
+       local repeat=10
+       local average_origin=0
+       local average_cache=0
+       local average_ladvise=0
+
+       for ((i = 1; i <= $repeat; i++)); do
+               echo "Iter $i/$repeat: reading without willread hint"
+               cancel_lru_locks osc
+               drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
+               local speed_origin=$(random_read_iops $DIR/$tfile $size)
+               echo "Iter $i/$repeat: uncached speed: $speed_origin"
+               average_origin=$(bc <<<"$average_origin + $speed_origin")
+
+               cancel_lru_locks osc
+               local speed_cache=$(random_read_iops $DIR/$tfile $size)
+               echo "Iter $i/$repeat: OSS cache speed: $speed_cache"
+               average_cache=$(bc <<<"$average_cache + $speed_cache")
+
+               cancel_lru_locks osc
+               drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
+               $LFS ladvise -a willread $DIR/$tfile || error "ladvise failed"
+               local speed_ladvise=$(random_read_iops $DIR/$tfile $size)
+               echo "Iter $i/$repeat: ladvise speed: $speed_ladvise"
+               average_ladvise=$(bc <<<"$average_ladvise + $speed_ladvise")
+       done
+       average_origin=$(bc <<<"scale=2; $average_origin / $repeat")
+       average_cache=$(bc <<<"scale=2; $average_cache / $repeat")
+       average_ladvise=$(bc <<<"scale=2; $average_ladvise / $repeat")
+
+       speedup_cache=$(percent $average_cache $average_origin)
+       speedup_ladvise=$(percent $average_ladvise $average_origin)
+
+       echo "Average uncached read: $average_origin"
+       echo "Average speedup with OSS cached read: " \
+               "$average_cache = +$speedup_cache%"
+       echo "Average speedup with ladvise willread: " \
+               "$average_ladvise = +$speedup_ladvise%"
+
+       local lowest_speedup=20
+       if [ ${average_cache%.*} -lt $lowest_speedup ]; then
+               echo "Speedup with OSS cached read less than $lowest_speedup%, "
+                       "got $average_cache%. Skipping ladvise willread check."
+               return 0
+       fi
+
+       # the test won't work on ZFS until it supports 'ladvise dontneed', but
+       # it is still good to run until then to exercise 'ladvise willread'
+       ! $LFS ladvise -a dontneed $DIR/$tfile &&
+               [ "$(facet_fstype ost1)" = "zfs" ] &&
+               echo "osd-zfs does not support dontneed or drop_caches" &&
+               return 0
+
+       lowest_speedup=$(bc <<<"scale=2; $average_cache / 2")
+       [ ${average_ladvise%.*} -gt $lowest_speedup ] ||
+               error_not_in_vm "Speedup with willread is less than " \
+                       "$lowest_speedup%, got $average_ladvise%"
+}
+
+test_255a() {
+       [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
+               skip "lustre < 2.8.54 does not support ladvise " && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
+
+       lfs setstripe -c -1 -i 0 $DIR/$tfile || error "$tfile failed"
+
+       ladvise_no_type willread $DIR/$tfile &&
+               skip "willread ladvise is not supported" && return
+
+       ladvise_no_ioctl $DIR/$tfile &&
+               skip "ladvise ioctl is not supported" && return
+
+       local size_mb=100
+       local size=$((size_mb * 1048576))
+       dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
+               error "dd to $DIR/$tfile failed"
+
+       lfs ladvise -a willread $DIR/$tfile ||
+               error "Ladvise failed with no range argument"
+
+       lfs ladvise -a willread -s 0 $DIR/$tfile ||
+               error "Ladvise failed with no -l or -e argument"
+
+       lfs ladvise -a willread -e 1 $DIR/$tfile ||
+               error "Ladvise failed with only -e argument"
+
+       lfs ladvise -a willread -l 1 $DIR/$tfile ||
+               error "Ladvise failed with only -l argument"
+
+       lfs ladvise -a willread -s 2 -e 1 $DIR/$tfile &&
+               error "End offset should not be smaller than start offset"
+
+       lfs ladvise -a willread -s 2 -e 2 $DIR/$tfile &&
+               error "End offset should not be equal to start offset"
+
+       lfs ladvise -a willread -s $size -l 1 $DIR/$tfile ||
+               error "Ladvise failed with overflowing -s argument"
+
+       lfs ladvise -a willread -s 1 -e $((size + 1)) $DIR/$tfile ||
+               error "Ladvise failed with overflowing -e argument"
+
+       lfs ladvise -a willread -s 1 -l $size $DIR/$tfile ||
+               error "Ladvise failed with overflowing -l argument"
+
+       lfs ladvise -a willread -l 1 -e 2 $DIR/$tfile &&
+               error "Ladvise succeeded with conflicting -l and -e arguments"
+
+       echo "Synchronous ladvise should wait"
+       local delay=4
+#define OBD_FAIL_OST_LADVISE_PAUSE      0x237
+       do_nodes $(comma_list $(osts_nodes)) \
+               $LCTL set_param fail_val=$delay fail_loc=0x237
+
+       local start_ts=$SECONDS
+       lfs ladvise -a willread $DIR/$tfile ||
+               error "Ladvise failed with no range argument"
+       local end_ts=$SECONDS
+       local inteval_ts=$((end_ts - start_ts))
+
+       if [ $inteval_ts -lt $(($delay - 1)) ]; then
+               error "Synchronous advice didn't wait reply"
+       fi
+
+       echo "Asynchronous ladvise shouldn't wait"
+       local start_ts=$SECONDS
+       lfs ladvise -a willread -b $DIR/$tfile ||
+               error "Ladvise failed with no range argument"
+       local end_ts=$SECONDS
+       local inteval_ts=$((end_ts - start_ts))
+
+       if [ $inteval_ts -gt $(($delay / 2)) ]; then
+               error "Asynchronous advice blocked"
+       fi
+
+       do_nodes $(comma_list $(osts_nodes)) $LCTL set_param fail_loc=0
+       ladvise_willread_performance
+}
+run_test 255a "check 'lfs ladvise -a willread'"
+
+facet_meminfo() {
+       local facet=$1
+       local info=$2
+
+       do_facet $facet "cat /proc/meminfo | grep ^${info}:" | awk '{print $2}'
+}
+
+test_255b() {
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
+
+       lfs setstripe -c 1 -i 0 $DIR/$tfile
+
+       ladvise_no_type dontneed $DIR/$tfile &&
+               skip "dontneed ladvise is not supported" && return
+
+       ladvise_no_ioctl $DIR/$tfile &&
+               skip "ladvise ioctl is not supported" && return
+
+       [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
+               skip "lustre < 2.8.54 does not support ladvise" && return
+
+       ! $LFS ladvise -a dontneed $DIR/$tfile &&
+               [ "$(facet_fstype ost1)" = "zfs" ] &&
+               skip "zfs-osd does not support 'ladvise dontneed'" && return
+
+       local size_mb=100
+       local size=$((size_mb * 1048576))
+       # In order to prevent disturbance of other processes, only check 3/4
+       # of the memory usage
+       local kibibytes=$((size_mb * 1024 * 3 / 4))
+
+       dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
+               error "dd to $DIR/$tfile failed"
+
+       local total=$(facet_meminfo ost1 MemTotal)
+       echo "Total memory: $total KiB"
+
+       do_facet ost1 "sync && echo 3 > /proc/sys/vm/drop_caches"
+       local before_read=$(facet_meminfo ost1 Cached)
+       echo "Cache used before read: $before_read KiB"
+
+       lfs ladvise -a willread $DIR/$tfile ||
+               error "Ladvise willread failed"
+       local after_read=$(facet_meminfo ost1 Cached)
+       echo "Cache used after read: $after_read KiB"
+
+       lfs ladvise -a dontneed $DIR/$tfile ||
+               error "Ladvise dontneed again failed"
+       local no_read=$(facet_meminfo ost1 Cached)
+       echo "Cache used after dontneed ladvise: $no_read KiB"
+
+       if [ $total -lt $((before_read + kibibytes)) ]; then
+               echo "Memory is too small, abort checking"
+               return 0
+       fi
+
+       if [ $((before_read + kibibytes)) -gt $after_read ]; then
+               error "Ladvise willread should use more memory" \
+                       "than $kibibytes KiB"
+       fi
+
+       if [ $((no_read + kibibytes)) -gt $after_read ]; then
+               error "Ladvise dontneed should release more memory" \
+                       "than $kibibytes KiB"
+       fi
+}
+run_test 255b "check 'lfs ladvise -a dontneed'"
+
+test_256() {
+       local cl_user
+       local cat_sl
+       local mdt_dev
+
+       [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       [ "$(facet_fstype mds1)" != "ldiskfs" ] &&
+               skip "non-ldiskfs backend" && return
+
+       mdt_dev=$(mdsdevname 1)
+       echo $mdt_dev
+       cl_user=$(do_facet mds1 \
+       "$LCTL get_param -n mdd.$MDT0.changelog_users | grep cl")
+       if [[ -n $cl_user ]]; then
+               skip "active changelog user"
+               return
+       fi
+
+       cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
+       echo "Registered as changelog user $cl_user"
+
+       rm -rf $DIR/$tdir
+       mkdir -p $DIR/$tdir
+
+       $LFS changelog_clear $MDT0 $cl_user 0
+
+       # change something
+       touch $DIR/$tdir/{1..10}
+
+       # stop the MDT
+       stop mds1 || error "Fail to stop MDT."
 
        # remount the MDT
        start mds1 $mdt_dev $MDS_MOUNT_OPTS || error "Fail to start MDT."
@@ -14026,6 +14925,29 @@ test_256() {
 }
 run_test 256 "Check llog delete for empty and not full state"
 
+test_257() {
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
+               skip "Need MDS version at least 2.8.55" && return
+
+       test_mkdir -p $DIR/$tdir
+
+       setfattr -n trusted.name1 -v value1 $DIR/$tdir ||
+               error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
+       stat $DIR/$tdir
+
+#define OBD_FAIL_MDS_XATTR_REP                 0x161
+       local mdtidx=$($LFS getstripe -M $DIR/$tdir)
+       local facet=mds$((mdtidx + 1))
+       set_nodes_failloc $(facet_active_host $facet) 0x80000161
+       getfattr -n trusted.name1 $DIR/$tdir 2> /dev/null
+
+       stop $facet || error "stop MDS failed"
+       start $facet $(mdsdevname $((mdtidx + 1))) $MDS_MOUNT_OPTS ||
+               error "start MDS fail"
+}
+run_test 257 "xattr locks are not lost"
+
 test_260() {
 #define OBD_FAIL_MDC_CLOSE               0x806
        $LCTL set_param fail_loc=0x80000806
@@ -14059,7 +14981,11 @@ test_striped_dir() {
                error "getdirstripe failed"
        stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
        if [ "$stripe_count" != "2" ]; then
-               error "stripe_count is $stripe_count, expect 2"
+               error "1:stripe_count is $stripe_count, expect 2"
+       fi
+       stripe_count=$($LFS getdirstripe -T $DIR/$tdir/striped_dir)
+       if [ "$stripe_count" != "2" ]; then
+               error "2:stripe_count is $stripe_count, expect 2"
        fi
 
        stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
@@ -14225,13 +15151,13 @@ test_300e() {
        mkdir $DIR/$tdir/striped_dir/dir_c
 
        $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
-               error "set striped dir under striped dir error"
+               error "set striped adir under striped dir error"
 
-       $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_b ||
-               error "set striped dir under striped dir error"
+       $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_b ||
+               error "set striped bdir under striped dir error"
 
        $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
-               error "set striped dir under striped dir error"
+               error "set striped cdir under striped dir error"
 
        mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b ||
                error "rename dir under striped dir fails"
@@ -14349,6 +15275,24 @@ test_300g() {
        mkdir $DIR/$tdir
        mkdir $DIR/$tdir/normal_dir
 
+       #Checking when client cache stripe index
+       $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
+       $LFS setdirstripe -D -i1 $DIR/$tdir/striped_dir ||
+               error "create striped_dir failed"
+
+       mkdir $DIR/$tdir/striped_dir/dir1 ||
+               error "create dir1 fails"
+       stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir1)
+       [ $stripe_index -eq 1 ] ||
+               error "dir1 expect 1 got $stripe_index"
+
+       $LFS setdirstripe -i2 $DIR/$tdir/striped_dir/dir2 ||
+               error "create dir2 fails"
+       stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir2)
+       [ $stripe_index -eq 2 ] ||
+               error "dir2 expect 2 got $stripe_index"
+
+       #check default stripe count/stripe index
        test_300_check_default_striped_dir normal_dir $MDSCOUNT 1
        test_300_check_default_striped_dir normal_dir 1 0
        test_300_check_default_striped_dir normal_dir 2 1
@@ -14417,11 +15361,23 @@ test_300i() {
        createmany -o $DIR/$tdir/striped_dir/f- 10 ||
                error "create files under striped dir failed"
 
+       $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir ||
+               error "set striped hashdir error"
+
+       $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir/d0 ||
+               error "create dir0 under hash dir failed"
+       $LFS setdirstripe -i0 -c$MDSCOUNT -H fnv_1a_64 $DIR/$tdir/hashdir/d1 ||
+               error "create dir1 under hash dir failed"
+
        # unfortunately, we need to umount to clear dir layout cache for now
        # once we fully implement dir layout, we can drop this
        umount_client $MOUNT || error "umount failed"
        mount_client $MOUNT || error "mount failed"
 
+       $LFS find -H fnv_1a_64 $DIR/$tdir/hashdir
+       local dircnt=$($LFS find -H fnv_1a_64 $DIR/$tdir/hashdir | wc -l)
+       [ $dircnt -eq 1 ] || error "lfs find striped dir got:$dircnt,except:1"
+
        #set the stripe to be unknown hash type
        #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
        $LCTL set_param fail_loc=0x1901
@@ -14564,6 +15520,8 @@ test_300n() {
                skip "Need MDS version at least 2.7.55" && return
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+
        local stripe_index
        local list=$(comma_list $(mdts_nodes))
 
@@ -14756,6 +15714,7 @@ test_311() {
        [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.54) ] &&
                skip "lustre < 2.8.54 does not contain LU-4825 fix" && return
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
 
        local old_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
 
@@ -14791,16 +15750,211 @@ test_311() {
        local new_iused
        for i in $(seq 120); do
                new_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
-               [ $new_iused -lt $((old_iused - 900)) ] && break
+               # system may be too busy to destroy all objs in time, use
+               # a somewhat small value to not fail autotest
+               [ $((old_iused - new_iused)) -gt 400 ] && break
                sleep 1
        done
 
        echo "waited $i sec, old Iused $old_iused, new Iused $new_iused"
-       [ $new_iused -lt $((old_iused - 900)) ] ||
+       [ $((old_iused - new_iused)) -gt 400 ] ||
                error "objs not destroyed after unlink"
 }
 run_test 311 "disable OSP precreate, and unlink should destroy objs"
 
+zfs_oid_to_objid()
+{
+       local ost=$1
+       local objid=$2
+
+       local vdevdir=$(dirname $(facet_vdevice $ost))
+       local cmd="$ZDB -e -p $vdevdir -ddddd $(facet_device $ost)"
+       local zfs_zapid=$(do_facet $ost $cmd |
+                         grep -w "/O/0/d$((objid%32))" -C 5 |
+                         awk '/Object/{getline; print $1}')
+       local zfs_objid=$(do_facet $ost $cmd $zfs_zapid |
+                         awk "/$objid = /"'{printf $3}')
+
+       echo $zfs_objid
+}
+
+zfs_object_blksz() {
+       local ost=$1
+       local objid=$2
+
+       local vdevdir=$(dirname $(facet_vdevice $ost))
+       local cmd="$ZDB -e -p $vdevdir -dddd $(facet_device $ost)"
+       local blksz=$(do_facet $ost $cmd $objid |
+                     awk '/dblk/{getline; printf $4}')
+
+       case "${blksz: -1}" in
+               k|K) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024)) ;;
+               m|M) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024*1024)) ;;
+               *) ;;
+       esac
+
+       echo $blksz
+}
+
+test_312() { # LU-4856
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
+
+       [ $(facet_fstype ost1) = "zfs" ] ||
+               { skip "the test only applies to zfs" && return; }
+
+       local max_blksz=$(do_facet ost1 \
+                         $ZFS get -p recordsize $(facet_device ost1) |
+                         awk '!/VALUE/{print $3}')
+       local min_blksz=$(getconf PAGE_SIZE)
+
+       # to make life a little bit easier
+       $LFS mkdir -c 1 -i 0 $DIR/$tdir
+       $LFS setstripe -c 1 -i 0 $DIR/$tdir
+
+       local tf=$DIR/$tdir/$tfile
+       touch $tf
+       local oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
+
+       # Get ZFS object id
+       local zfs_objid=$(zfs_oid_to_objid ost1 $oid)
+
+       # block size change by sequential over write
+       local blksz
+       for ((bs=$min_blksz; bs <= max_blksz; bs <<= 2)); do
+               dd if=/dev/zero of=$tf bs=$bs count=1 oflag=sync conv=notrunc
+
+               blksz=$(zfs_object_blksz ost1 $zfs_objid)
+               [ $blksz -eq $bs ] || error "blksz error: $blksz, expected: $bs"
+       done
+       rm -f $tf
+
+       # block size change by sequential append write
+       dd if=/dev/zero of=$tf bs=$min_blksz count=1 oflag=sync conv=notrunc
+       oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
+       zfs_objid=$(zfs_oid_to_objid ost1 $oid)
+
+       for ((count = 1; count < $((max_blksz / min_blksz)); count *= 2)); do
+               dd if=/dev/zero of=$tf bs=$min_blksz count=$count seek=$count \
+                       oflag=sync conv=notrunc
+
+               blksz=$(zfs_object_blksz ost1 $zfs_objid)
+               [ $blksz -eq $((2 * count * min_blksz)) ] ||
+                       error "blksz error, actual $blksz, "    \
+                               "expected: 2 * $count * $min_blksz"
+       done
+       rm -f $tf
+
+       # random write
+       touch $tf
+       oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
+       zfs_objid=$(zfs_oid_to_objid ost1 $oid)
+
+       dd if=/dev/zero of=$tf bs=1K count=1 oflag=sync conv=notrunc
+       blksz=$(zfs_object_blksz ost1 $zfs_objid)
+       [ $blksz -eq $min_blksz ] ||
+               error "blksz error: $blksz, expected: $min_blksz"
+
+       dd if=/dev/zero of=$tf bs=64K count=1 oflag=sync conv=notrunc seek=128
+       blksz=$(zfs_object_blksz ost1 $zfs_objid)
+       [ $blksz -eq 65536 ] || error "blksz error: $blksz, expected: 64k"
+
+       dd if=/dev/zero of=$tf bs=1M count=1 oflag=sync conv=notrunc
+       blksz=$(zfs_object_blksz ost1 $zfs_objid)
+       [ $blksz -eq 65536 ] || error "rewrite error: $blksz, expected: 64k"
+}
+run_test 312 "make sure ZFS adjusts its block size by write pattern"
+
+test_313() {
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
+
+       local file=$DIR/$tfile
+       rm -f $file
+       $SETSTRIPE -c 1 -i 0 $file || error "setstripe failed"
+
+       # define OBD_FAIL_TGT_RCVD_EIO           0x720
+       do_facet ost1 "$LCTL set_param fail_loc=0x720"
+       dd if=/dev/zero of=$file bs=4096 oflag=direct count=1 &&
+               error "write should failed"
+       do_facet ost1 "$LCTL set_param fail_loc=0"
+       rm -f $file
+}
+run_test 313 "io should fail after last_rcvd update fail"
+
+test_fake_rw() {
+       local read_write=$1
+       if [ "$read_write" = "write" ]; then
+               local dd_cmd="dd if=/dev/zero of=$DIR/$tfile"
+       elif [ "$read_write" = "read" ]; then
+               local dd_cmd="dd of=/dev/null if=$DIR/$tfile"
+       else
+               error "argument error"
+       fi
+
+       # turn off debug for performance testing
+       local saved_debug=$($LCTL get_param -n debug)
+       $LCTL set_param debug=0
+
+       $SETSTRIPE -c 1 -i 0 $DIR/$tfile
+
+       # get ost1 size - lustre-OST0000
+       local ost1_avail_size=$($LFS df | awk /${ost1_svc}/'{ print $4 }')
+       local blocks=$((ost1_avail_size/2/1024)) # half avail space by megabytes
+       [ $blocks -gt 1000 ] && blocks=1000 # 1G in maximum
+
+       if [ "$read_write" = "read" ]; then
+               truncate -s $(expr 1048576 \* $blocks) $DIR/$tfile
+       fi
+
+       local start_time=$(date +%s.%N)
+       $dd_cmd bs=1M count=$blocks oflag=sync ||
+               error "real dd $read_write error"
+       local duration=$(bc <<< "$(date +%s.%N) - $start_time")
+
+       if [ "$read_write" = "write" ]; then
+               rm -f $DIR/$tfile
+       fi
+
+       # define OBD_FAIL_OST_FAKE_RW           0x238
+       do_facet ost1 $LCTL set_param fail_loc=0x238
+
+       local start_time=$(date +%s.%N)
+       $dd_cmd bs=1M count=$blocks oflag=sync ||
+               error "fake dd $read_write error"
+       local duration_fake=$(bc <<< "$(date +%s.%N) - $start_time")
+
+       if [ "$read_write" = "write" ]; then
+               # verify file size
+               cancel_lru_locks osc
+               $CHECKSTAT -t file -s $((blocks * 1024 * 1024)) $DIR/$tfile ||
+                       error "$tfile size not $blocks MB"
+       fi
+       do_facet ost1 $LCTL set_param fail_loc=0
+
+       echo "fake $read_write $duration_fake vs. normal $read_write" \
+               "$duration in seconds"
+       [ $(bc <<< "$duration_fake < $duration") -eq 1 ] ||
+               error_not_in_vm "fake write is slower"
+
+       $LCTL set_param -n debug="$saved_debug"
+       rm -f $DIR/$tfile
+}
+test_399a() { # LU-7655 for OST fake write
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
+
+       test_fake_rw write
+}
+run_test 399a "fake write should not be slower than normal write"
+
+test_399b() { # LU-8726 for OST fake read
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
+
+       if [ "$(facet_fstype ost1)" != "ldiskfs" ]; then
+               skip "only for ldiskfs" && return 0
+       fi
+       test_fake_rw read
+}
+run_test 399b "fake read should not be slower than normal read"
+
 test_400a() { # LU-1606, was conf-sanity test_74
        local extra_flags=''
        local out=$TMP/$tfile
@@ -14867,6 +16021,9 @@ test_401a() { #LU-7437
        #count the number of parameters by "list_param -R"
        local params=$($LCTL list_param -R '*' 2>/dev/null | wc -l)
        #count the number of parameters by listing proc files
+       local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
+       echo "proc_dirs='$proc_dirs'"
+       [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
        local procs=$(find -L $proc_dirs -mindepth 1 -printf '%P\n' 2>/dev/null|
                      sort -u | wc -l)
 
@@ -14953,6 +16110,14 @@ test_401d() {
 run_test 401d "Verify 'lctl set_param' accepts values containing '='"
 
 test_402() {
+       local server_version=$(lustre_version_code $SINGLEMDS)
+       [[ $server_version -ge $(version_code 2.7.66) ]] ||
+       [[ $server_version -ge $(version_code 2.7.18.4) &&
+               $server_version -lt $(version_code 2.7.50) ]] ||
+       [[ $server_version -ge $(version_code 2.7.2) &&
+               $server_version -lt $(version_code 2.7.11) ]] ||
+               { skip "Need MDS version 2.7.2+ or 2.7.18.4+ or 2.7.66+";
+                       return; }
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
        $LFS setdirstripe -i 0 $DIR/$tdir || error "setdirstripe -i 0 failed"
 #define OBD_FAIL_MDS_FLD_LOOKUP 0x15c
@@ -14992,6 +16157,10 @@ test_403() {
 run_test 403 "i_nlink should not drop to zero due to aliasing"
 
 test_404() { # LU-6601
+       local server_version=$(lustre_version_code $SINGLEMDS)
+       [[ $server_version -ge $(version_code 2.8.53) ]] ||
+               { skip "Need server version newer than 2.8.52"; return 0; }
+
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
        local mosps=$(do_facet $SINGLEMDS $LCTL dl |
                awk '/osp .*-osc-MDT/ { print $4}')
@@ -15108,6 +16277,336 @@ test_406() {
 }
 run_test 406 "DNE support fs default striping"
 
+test_407() {
+       [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+       [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
+               skip "Need MDS version at least 2.8.55" && return
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+
+       $LFS mkdir -i 0 -c 1 $DIR/$tdir.0 ||
+               error "$LFS mkdir -i 0 -c 1 $tdir.0 failed"
+       $LFS mkdir -i 1 -c 1 $DIR/$tdir.1 ||
+               error "$LFS mkdir -i 1 -c 1 $tdir.1 failed"
+       touch $DIR/$tdir.0/$tfile.0 || error "touch $tdir.0/$tfile.0 failed"
+
+       #define OBD_FAIL_DT_TXN_STOP    0x2019
+       for idx in $(seq $MDSCOUNT); do
+               do_facet mds$idx "lctl set_param fail_loc=0x2019"
+       done
+       $LFS mkdir -c 2 $DIR/$tdir && error "$LFS mkdir -c 2 $tdir should fail"
+       mv $DIR/$tdir.0/$tfile.0 $DIR/$tdir.1/$tfile.1 &&
+               error "mv $tdir.0/$tfile.0 $tdir.1/$tfile.1 should fail"
+       true
+}
+run_test 407 "transaction fail should cause operation fail"
+
+test_408() {
+       dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 oflag=direct
+
+       #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
+       lctl set_param fail_loc=0x8000040a
+       # let ll_prepare_partial_page() fail
+       dd if=/dev/zero of=$DIR/$tfile bs=2048 count=1 conv=notrunc || true
+
+       rm -f $DIR/$tfile
+
+       # create at least 100 unused inodes so that
+       # shrink_icache_memory(0) should not return 0
+       touch $DIR/$tfile-{0..100}
+       rm -f $DIR/$tfile-{0..100}
+       sync
+
+       echo 2 > /proc/sys/vm/drop_caches
+}
+run_test 408 "drop_caches should not hang due to page leaks"
+
+test_409()
+{
+       [ $MDSCOUNT -lt 2 ] &&
+               skip "We need at least 2 MDTs for this test" && return
+
+       check_mount_and_prep
+
+       mkdir -p $DIR/$tdir || error "(0) Fail to mkdir"
+       $LFS mkdir -i 1 -c 2 $DIR/$tdir/foo || error "(1) Fail to mkdir"
+       touch $DIR/$tdir/guard || error "(2) Fail to create"
+
+       local PREFIX=$(str_repeat 'A' 128)
+       echo "Create 1K hard links start at $(date)"
+       createmany -l $DIR/$tdir/guard $DIR/$tdir/foo/${PREFIX}_ 1000 ||
+               error "(3) Fail to hard link"
+
+       echo "Links count should be right although linkEA overflow"
+       stat $DIR/$tdir/guard || error "(4) Fail to stat"
+       local linkcount=$(stat --format=%h $DIR/$tdir/guard)
+       [ $linkcount -eq 1001 ] ||
+               error "(5) Unexpected hard links count: $linkcount"
+
+       echo "List all links start at $(date)"
+       ls -l $DIR/$tdir/foo > /dev/null ||
+               error "(6) Fail to list $DIR/$tdir/foo"
+
+       echo "Unlink hard links start at $(date)"
+       unlinkmany $DIR/$tdir/foo/${PREFIX}_ 1000 ||
+               error "(7) Fail to unlink"
+}
+run_test 409 "Large amount of cross-MDTs hard links on the same file"
+
+prep_801() {
+       [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
+       [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
+               skip "Need server version at least 2.9.55" & exit 0
+       start_full_debug_logging
+}
+
+post_801() {
+       stop_full_debug_logging
+}
+
+test_801a() {
+       prep_801
+
+       #define OBD_FAIL_BARRIER_DELAY          0x2202
+       do_facet mgs $LCTL set_param fail_val=3 fail_loc=0x2202
+       do_facet mgs $LCTL barrier_freeze $FSNAME 10 &
+
+       sleep 1
+       local b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME |
+                              awk '/The barrier for/ { print $7 }')
+       [ "$b_status" = "'freezing_p1'" ] ||
+               error "(1) unexpected barrier status $b_status"
+
+       do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
+       wait
+       b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME |
+                        awk '/The barrier for/ { print $7 }')
+       [ "$b_status" = "'frozen'" ] ||
+               error "(2) unexpected barrier status $b_status"
+
+       local expired=$(do_facet mgs $LCTL barrier_stat $FSNAME |
+                       awk '/will be expired/ { print $7 }')
+       echo "sleep $((expired + 3)) seconds, then the barrier will be expired"
+       sleep $((expired + 3))
+
+       b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME |
+                        awk '/The barrier for/ { print $7 }')
+       [ "$b_status" = "'expired'" ] ||
+               error "(3) unexpected barrier status $b_status"
+
+       do_facet mgs $LCTL barrier_freeze $FSNAME 10 ||
+               error "(4) fail to freeze barrier"
+
+       b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME |
+                        awk '/The barrier for/ { print $7 }')
+       [ "$b_status" = "'frozen'" ] ||
+               error "(5) unexpected barrier status $b_status"
+
+       #define OBD_FAIL_BARRIER_DELAY          0x2202
+       do_facet mgs $LCTL set_param fail_val=3 fail_loc=0x2202
+       do_facet mgs $LCTL barrier_thaw $FSNAME &
+
+       sleep 1
+       b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME |
+                        awk '/The barrier for/ { print $7 }')
+       [ "$b_status" = "'thawing'" ] ||
+               error "(6) unexpected barrier status $b_status"
+
+       do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
+       wait
+       b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME |
+                        awk '/The barrier for/ { print $7 }')
+       [ "$b_status" = "'thawed'" ] ||
+               error "(7) unexpected barrier status $b_status"
+
+       #define OBD_FAIL_BARRIER_FAILURE        0x2203
+       do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2203
+       do_facet mgs $LCTL barrier_freeze $FSNAME
+
+       b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME |
+                              awk '/The barrier for/ { print $7 }')
+       [ "$b_status" = "'failed'" ] ||
+               error "(8) unexpected barrier status $b_status"
+
+       do_facet $SINGLEMDS $LCTL set_param fail_loc=0
+       do_facet mgs $LCTL barrier_thaw $FSNAME
+
+       post_801
+}
+run_test 801a "write barrier user interfaces and stat machine"
+
+test_801b() {
+       prep_801
+
+       mkdir $DIR/$tdir || error "(1) fail to mkdir"
+       createmany -d $DIR/$tdir/d 6 || "(2) fail to mkdir"
+       touch $DIR/$tdir/d2/f10 || error "(3) fail to touch"
+       touch $DIR/$tdir/d3/f11 || error "(4) fail to touch"
+       touch $DIR/$tdir/d4/f12 || error "(5) fail to touch"
+
+       cancel_lru_locks mdc
+
+       # 180 seconds should be long enough
+       do_facet mgs $LCTL barrier_freeze $FSNAME 180
+
+       local b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME |
+                              awk '/The barrier for/ { print $7 }')
+       [ "$b_status" = "'frozen'" ] ||
+               error "(6) unexpected barrier status $b_status"
+
+       mkdir $DIR/$tdir/d0/d10 &
+       mkdir_pid=$!
+
+       touch $DIR/$tdir/d1/f13 &
+       touch_pid=$!
+
+       ln $DIR/$tdir/d2/f10 $DIR/$tdir/d2/f14 &
+       ln_pid=$!
+
+       mv $DIR/$tdir/d3/f11 $DIR/$tdir/d3/f15 &
+       mv_pid=$!
+
+       rm -f $DIR/$tdir/d4/f12 &
+       rm_pid=$!
+
+       stat $DIR/$tdir/d5 || error "(7) stat should succeed"
+
+       # To guarantee taht the 'stat' is not blocked
+       b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME |
+                        awk '/The barrier for/ { print $7 }')
+       [ "$b_status" = "'frozen'" ] ||
+               error "(8) unexpected barrier status $b_status"
+
+       # let above commands to run at background
+       sleep 5
+
+       ps -p $mkdir_pid || error "(9) mkdir should be blocked"
+       ps -p $touch_pid || error "(10) touch should be blocked"
+       ps -p $ln_pid || error "(11) link should be blocked"
+       ps -p $mv_pid || error "(12) rename should be blocked"
+       ps -p $rm_pid || error "(13) unlink should be blocked"
+
+       b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME |
+                        awk '/The barrier for/ { print $7 }')
+       [ "$b_status" = "'frozen'" ] ||
+               error "(14) unexpected barrier status $b_status"
+
+       do_facet mgs $LCTL barrier_thaw $FSNAME
+       b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME |
+                        awk '/The barrier for/ { print $7 }')
+       [ "$b_status" = "'thawed'" ] ||
+               error "(15) unexpected barrier status $b_status"
+
+       wait $mkdir_pid || error "(16) mkdir should succeed"
+       wait $touch_pid || error "(17) touch should succeed"
+       wait $ln_pid || error "(18) link should succeed"
+       wait $mv_pid || error "(19) rename should succeed"
+       wait $rm_pid || error "(20) unlink should succeed"
+
+       post_801
+}
+run_test 801b "modification will be blocked by write barrier"
+
+test_801c() {
+       [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
+
+       prep_801
+
+       stop mds2 || error "(1) Fail to stop mds2"
+
+       do_facet mgs $LCTL barrier_freeze $FSNAME 30
+
+       local b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME |
+                              awk '/The barrier for/ { print $7 }')
+       [ "$b_status" = "'expired'" -o "$b_status" = "'failed'" ] || {
+               do_facet mgs $LCTL barrier_thaw $FSNAME
+               error "(2) unexpected barrier status $b_status"
+       }
+
+       do_facet mgs $LCTL barrier_rescan $FSNAME ||
+               error "(3) Fail to rescan barrier bitmap"
+
+       do_facet mgs $LCTL barrier_freeze $FSNAME 10
+
+       b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME |
+                        awk '/The barrier for/ { print $7 }')
+       [ "$b_status" = "'frozen'" ] ||
+               error "(4) unexpected barrier status $b_status"
+
+       do_facet mgs $LCTL barrier_thaw $FSNAME
+       b_status=$(do_facet mgs $LCTL barrier_stat $FSNAME |
+                        awk '/The barrier for/ { print $7 }')
+       [ "$b_status" = "'thawed'" ] ||
+               error "(5) unexpected barrier status $b_status"
+
+       local devname=$(mdsdevname 2)
+
+       start mds2 $devname $MDS_MOUNT_OPTS || error "(6) Fail to start mds2"
+
+       do_facet mgs $LCTL barrier_rescan $FSNAME ||
+               error "(7) Fail to rescan barrier bitmap"
+
+       post_801
+}
+run_test 801c "rescan barrier bitmap"
+
+saved_MGS_MOUNT_OPTS=$MGS_MOUNT_OPTS
+saved_MDS_MOUNT_OPTS=$MDS_MOUNT_OPTS
+saved_OST_MOUNT_OPTS=$OST_MOUNT_OPTS
+
+cleanup_802() {
+       trap 0
+
+       stopall
+       MGS_MOUNT_OPTS=$saved_MGS_MOUNT_OPTS
+       MDS_MOUNT_OPTS=$saved_MDS_MOUNT_OPTS
+       OST_MOUNT_OPTS=$saved_OST_MOUNT_OPTS
+       setupall
+}
+
+test_802() {
+
+       [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
+       [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
+               skip "Need server version at least 2.9.55" & exit 0
+
+       mkdir $DIR/$tdir || error "(1) fail to mkdir"
+
+       cp $LUSTRE/tests/test-framework.sh $DIR/$tdir/ ||
+               error "(2) Fail to copy"
+
+       trap cleanup_802 EXIT
+
+       # sync by force before remount as readonly
+       sync; sync_all_data; sleep 3; sync_all_data
+
+       stopall
+
+       MGS_MOUNT_OPTS=$(csa_add "$MGS_MOUNT_OPTS" -o rdonly_dev)
+       MDS_MOUNT_OPTS=$(csa_add "$MDS_MOUNT_OPTS" -o rdonly_dev)
+       OST_MOUNT_OPTS=$(csa_add "$OST_MOUNT_OPTS" -o rdonly_dev)
+
+       echo "Mount the server as read only"
+       setupall server_only || error "(3) Fail to start servers"
+
+       echo "Mount client without ro should fail"
+       mount_client $MOUNT &&
+               error "(4) Mount client without 'ro' should fail"
+
+       echo "Mount client with ro should succeed"
+       mount_client $MOUNT ro ||
+               error "(5) Mount client with 'ro' should succeed"
+
+       echo "Modify should be refused"
+       touch $DIR/$tdir/guard && error "(6) Touch should fail under ro mode"
+
+       echo "Read should be allowed"
+       diff $LUSTRE/tests/test-framework.sh $DIR/$tdir/test-framework.sh ||
+               error "(7) Read should succeed under ro mode"
+
+       cleanup_802
+}
+run_test 802 "simulate readonly device"
+
 #
 # tests that do cleanup/setup should be run at the end
 #