Whamcloud - gitweb
LU-10059 tests: sanityn 32a error messages
[fs/lustre-release.git] / lustre / tests / sanityn.sh
index 546932d..d09a62f 100755 (executable)
@@ -3,44 +3,41 @@
 set -e
 
 ONLY=${ONLY:-"$*"}
-# bug number for skipped test: LU-1205 9977/LU-7105 LU-9452
-ALWAYS_EXCEPT="                18c     28           29      $SANITYN_EXCEPT"
-# UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
-
-SRCDIR=$(dirname $0)
-PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
 
 SIZE=${SIZE:-40960}
-CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
 OPENFILE=${OPENFILE:-openfile}
 OPENUNLINK=${OPENUNLINK:-openunlink}
-export MULTIOP=${MULTIOP:-multiop}
 export TMP=${TMP:-/tmp}
 MOUNT_2=${MOUNT_2:-"yes"}
 CHECK_GRANT=${CHECK_GRANT:-"yes"}
 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
 
-SAVE_PWD=$PWD
-
-export NAME=${NAME:-local}
-
-LUSTRE=${LUSTRE:-`dirname $0`/..}
+LUSTRE=${LUSTRE:-$(dirname $0)/..}
 . $LUSTRE/tests/test-framework.sh
-CLEANUP=${CLEANUP:-:}
-SETUP=${SETUP:-:}
 init_test_env $@
-. ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
 init_logging
 
-if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
-# bug number for skipped test:        LU-2776
-       ALWAYS_EXCEPT="$ALWAYS_EXCEPT 51a"
-# LU-2829 / LU-2887 - make allowances for ZFS slowness
+ALWAYS_EXCEPT="$SANITYN_EXCEPT "
+# bug number for skipped test:  LU-7105
+ALWAYS_EXCEPT+="                28 "
+# UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
+
+# skip tests for PPC until they are fixed
+if [[ $(uname -m) = ppc64 ]]; then
+       # bug number:    LU-11597 LU-11787
+       ALWAYS_EXCEPT+=" 16a      71a"
+fi
+
+if [ $mds1_FSTYPE = "zfs" ]; then
+       # LU-2829 / LU-2887 - make allowances for ZFS slowness
        TEST33_NFILES=${TEST33_NFILES:-1000}
 fi
+
 #                                  23   (min)"
 [ "$SLOW" = "no" ] && EXCEPT_SLOW="33a"
 
+build_test_filter
+
 FAIL_ON_ERROR=false
 
 SETUP=${SETUP:-:}
@@ -48,6 +45,8 @@ TRACE=${TRACE:-""}
 
 check_and_setup_lustre
 
+OSC=${OSC:-"osc"}
+
 assert_DIR
 rm -rf $DIR1/[df][0-9]* $DIR1/lnk $DIR/[df].${TESTSUITE}*
 
@@ -59,8 +58,6 @@ dd if=/dev/urandom of=$SAMPLE_FILE bs=1M count=1
 
 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
 
-build_test_filter
-
 test_1() {
        touch $DIR1/$tfile
        [ -f $DIR2/$tfile ] || error "Check create"
@@ -82,7 +79,8 @@ test_2a() {
        touch $DIR1/f2a
        ls -l $DIR2/f2a
        chmod 777 $DIR2/f2a
-       $CHECKSTAT -t file -p 0777 $DIR1/f2a || error
+       $CHECKSTAT -t file -p 0777 $DIR1/f2a ||
+               error "Either not file type or perms not 0777"
 }
 run_test 2a "check cached attribute updates on 2 mtpt's ========"
 
@@ -90,20 +88,23 @@ test_2b() {
        touch $DIR1/f2b
        ls -l $DIR2/f2b
        chmod 777 $DIR1/f2b
-       $CHECKSTAT -t file -p 0777 $DIR2/f2b || error
+       $CHECKSTAT -t file -p 0777 $DIR2/f2b ||
+               error "Either not file type or perms not 0777"
 }
 run_test 2b "check cached attribute updates on 2 mtpt's ========"
 
 # NEED TO SAVE ROOT DIR MODE
 test_2c() {
        chmod 777 $DIR1
-       $CHECKSTAT -t dir -p 0777 $DIR2 || error
+       $CHECKSTAT -t dir -p 0777 $DIR2 ||
+               error "Either not dir type or perms not 0777"
 }
 run_test 2c "check cached attribute updates on 2 mtpt's root ==="
 
 test_2d() {
        chmod 755 $DIR1
-       $CHECKSTAT -t dir -p 0755 $DIR2 || error
+       $CHECKSTAT -t dir -p 0755 $DIR2 ||
+               error "Either not file type or perms not 0775"
 }
 run_test 2d "check cached attribute updates on 2 mtpt's root ==="
 
@@ -112,7 +113,8 @@ test_2e() {
         ls -l $DIR1
         ls -l $DIR2
         chmod 777 $DIR1
-        $RUNAS dd if=/dev/zero of=$DIR2/$tfile count=1 || error
+               $RUNAS dd if=/dev/zero of=$DIR2/$tfile count=1 ||
+                       error "dd failed"
 }
 run_test 2e "check chmod on root is propagated to others"
 
@@ -159,7 +161,7 @@ test_2g() {
        local block2=$(stat $DIR2/$tfile | awk '/Blocks/ {print $4} ')
        echo "$DIR1/$tfile has $block1 blocks"
        echo "$DIR2/$tfile has $block2 blocks"
-       [ $block1 -eq $block2 ] || error
+       [ $block1 -eq $block2 ] || error "$block1 not equal to $block2"
 }
 run_test 2g "check blocks update on sync write"
 
@@ -179,7 +181,8 @@ run_test 4 "fstat validation on multiple mount points =========="
 test_5() {
        mcreate $DIR1/f5
        $TRUNCATE $DIR2/f5 100
-       $CHECKSTAT -t file -s 100 $DIR1/f5 || error
+       $CHECKSTAT -t file -s 100 $DIR1/f5 ||
+               error "Either not file type or size not equal to 100 bytes"
        rm $DIR1/f5
 }
 run_test 5 "create a file on one mount, truncate it on the other"
@@ -203,7 +206,7 @@ test_8() {
 }
 run_test 8 "remove of open special file on other node =========="
 
-test_9() {
+test_9a() {
        MTPT=1
        local dir
        > $DIR2/f9
@@ -215,7 +218,23 @@ test_9() {
        [ "`cat $DIR1/f9`" = "abcdefghijkl" ] || \
                error "`od -a $DIR1/f9` != abcdefghijkl"
 }
-run_test 9 "append of file with sub-page size on multiple mounts"
+run_test 9a "append of file with sub-page size on multiple mounts"
+
+#LU-10681 - tiny writes & appending to sparse striped file
+test_9b() {
+       [[ $OSTCOUNT -ge 2 ]] || { skip "needs >= 2 OSTs"; return; }
+
+       $LFS setstripe -c 2 -S 1M $DIR/$tfile
+       echo "foo" >> $DIR/$tfile
+       dd if=/dev/zero of=$DIR2/$tfile bs=1M count=1 seek=1 conv=notrunc ||
+               error "sparse dd $DIR2/$tfile failed"
+       echo "foo" >> $DIR/$tfile
+
+       data=$(dd if=$DIR2/$tfile bs=1 count=3 skip=$((2 * 1048576)) conv=notrunc)
+       echo "Data read (expecting 'foo')": $data
+       [ "$data" = "foo" ] || error "append to sparse striped file failed"
+}
+run_test 9b "append to striped sparse file"
 
 test_10a() {
        MTPT=1
@@ -258,94 +277,85 @@ test_11() {
        $DIR2/d11/f
        RC=$?
        kill -USR1 $MULTIPID
-       wait $MULTIPID || error
+       wait $MULTIPID || error "wait for PID $MULTIPID failed"
        [ $RC -eq 0 ] && error || true
 }
 run_test 11 "execution of file opened for write should return error ===="
 
 test_12() {
-       DIR=$DIR DIR2=$DIR2 sh lockorder.sh
+       DIR=$DIR DIR2=$DIR2 sh lockorder.sh
 }
-run_test 12 "test lock ordering (link, stat, unlink) ==========="
+run_test 12 "test lock ordering (link, stat, unlink)"
 
 test_13() {    # bug 2451 - directory coherency
-       test_mkdir $DIR1/d13 || error
-       cd $DIR1/d13 || error
-       ls
-       ( touch $DIR1/d13/f13 ) # needs to be a separate shell
-       ls
-       rm -f $DIR2/d13/f13 || error
-       ls 2>&1 | grep f13 && error "f13 shouldn't return an error (1)" || true
-       # need to run it twice
-       ( touch $DIR1/d13/f13 ) # needs to be a separate shell
-       ls
-       rm -f $DIR2/d13/f13 || error
-       ls 2>&1 | grep f13 && error "f13 shouldn't return an error (2)" || true
-}
-run_test 13 "test directory page revocation ===================="
+       test_mkdir $DIR1/d13
+       cd $DIR1/d13 || error "cd to $DIR1/d13 failed"
+       ls
+       ( touch $DIR1/d13/f13 ) # needs to be a separate shell
+       ls
+       rm -f $DIR2/d13/f13 || error "Cannot remove $DIR2/d13/f13"
+       ls 2>&1 | grep f13 && error "f13 shouldn't return an error (1)" || true
+       # need to run it twice
+       ( touch $DIR1/d13/f13 ) # needs to be a separate shell
+       ls
+       rm -f $DIR2/d13/f13 || error "Cannot remove $DIR2/d13/f13"
+       ls 2>&1 | grep f13 && error "f13 shouldn't return an error (2)" || true
+}
+run_test 13 "test directory page revocation"
 
 test_14aa() {
-       test_mkdir -p $DIR1/$tdir
+       test_mkdir $DIR1/$tdir
        cp -p /bin/ls $DIR1/$tdir/$tfile
        multiop_bg_pause $DIR1/$tdir/$tfile Ow_c || return 1
        MULTIPID=$!
 
        $DIR2/$tdir/$tfile && error || true
-       kill -USR1 $MULTIPID
-       wait $MULTIPID || return 2
+       kill $MULTIPID
 }
 run_test 14aa "execution of file open for write returns -ETXTBSY"
 
 test_14ab() {
-       test_mkdir -p $DIR1/d14
-       cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
-        MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
-        MULTIOP_PID=$!
-        $MULTIOP $DIR2/d14/multiop Oc && error "expected error, got success"
-        kill -USR1 $MULTIOP_PID || return 2
-        wait $MULTIOP_PID || return 3
-        rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
+       test_mkdir $DIR1/$tdir
+       cp -p $(which sleep) $DIR1/$tdir/sleep || error "cp failed"
+       $DIR1/$tdir/sleep 60 &
+       SLEEP_PID=$!
+       $MULTIOP $DIR2/$tdir/sleep Oc && error "expected error, got success"
+       kill $SLEEP_PID
 }
 run_test 14ab "open(RDWR) of executing file returns -ETXTBSY"
 
 test_14b() { # bug 3192, 7040
-       test_mkdir -p $DIR1/d14
-       cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
-        MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
-        MULTIOP_PID=$!
-        $TRUNCATE $DIR2/d14/multiop 0 && kill -9 $MULTIOP_PID && \
+       test_mkdir $DIR1/$tdir
+       cp -p $(which sleep) $DIR1/$tdir/sleep || error "cp failed"
+       $DIR1/$tdir/sleep 60 &
+       SLEEP_PID=$!
+       $TRUNCATE $DIR2/$tdir/sleep 60 && kill -9 $SLEEP_PID && \
                error "expected truncate error, got success"
-        kill -USR1 $MULTIOP_PID || return 2
-        wait $MULTIOP_PID || return 3
-       cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
-       rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
+       kill $SLEEP_PID
+       cmp $(which sleep) $DIR1/$tdir/sleep || error "binary changed"
 }
 run_test 14b "truncate of executing file returns -ETXTBSY ======"
 
 test_14c() { # bug 3430, 7040
-       test_mkdir -p $DIR1/d14
-       cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
-       MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
-        MULTIOP_PID=$!
-       cp /etc/hosts $DIR2/d14/multiop && error "expected error, got success"
-       kill -USR1 $MULTIOP_PID || return 2
-       wait $MULTIOP_PID || return 3
-       cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
-       rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
+       test_mkdir $DIR1/$tdir
+       cp -p $(which sleep) $DIR1/$tdir/sleep || error "cp failed"
+       $DIR1/$tdir/sleep 60 &
+       SLEEP_PID=$!
+       cp /etc/hosts $DIR2/$tdir/sleep && error "expected error, got success"
+       kill $SLEEP_PID
+       cmp $(which sleep) $DIR1/$tdir/sleep || error "binary changed"
 }
 run_test 14c "open(O_TRUNC) of executing file return -ETXTBSY =="
 
 test_14d() { # bug 10921
-       test_mkdir -p $DIR1/d14
-       cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
-       MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
-        MULTIOP_PID=$!
+       test_mkdir $DIR1/$tdir
+       cp -p $(which sleep) $DIR1/$tdir/sleep || error "cp failed"
+       $DIR1/$tdir/sleep 60 &
+       SLEEP_PID=$!
        log chmod
-       chmod 600 $DIR1/d14/multiop || error "chmod failed"
-       kill -USR1 $MULTIOP_PID || return 2
-       wait $MULTIOP_PID || return 3
-       cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
-       rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
+       chmod 600 $DIR1/$tdir/sleep || error "chmod failed"
+       kill $SLEEP_PID
+       cmp $(which sleep) $DIR1/$tdir/sleep || error "binary changed"
 }
 run_test 14d "chmod of executing file is still possible ========"
 
@@ -353,7 +363,7 @@ test_15() { # bug 974 - ENOSPC
        echo "PATH=$PATH"
        sh oos2.sh $MOUNT1 $MOUNT2
        wait_delete_completed
-       grant_error=`dmesg | grep "> available"`
+       grant_error=$(dmesg | grep "< tot_grant")
        [ -z "$grant_error" ] || error "$grant_error"
 }
 run_test 15 "test out-of-space with multiple writers ==========="
@@ -362,7 +372,7 @@ COUNT=${COUNT:-2500}
 # The FSXNUM reduction for ZFS is needed until ORI-487 is fixed.
 # We don't want to skip it entirely, but ZFS is VERY slow and cannot
 # pass a 2500 operation dual-mount run within the time limit.
-if [ "$(facet_fstype ost1)" = "zfs" ]; then
+if [ "$ost1_FSTYPE" = "zfs" ]; then
        FSXNUM=$((COUNT / 5))
        FSXP=1
 elif [ "$SLOW" = "yes" ]; then
@@ -373,26 +383,146 @@ else
        FSXP=100
 fi
 
-test_16() {
+test_16a() {
        local file1=$DIR1/$tfile
        local file2=$DIR2/$tfile
+       local stripe_size=$(do_facet $SINGLEMDS \
+               "$LCTL get_param -n lod.$(facet_svc $SINGLEMDS)*.stripesize")
 
        # to allocate grant because it may run out due to test_15.
        $LFS setstripe -c -1 $file1
-       dd if=/dev/zero of=$file1 bs=$STRIPE_BYTES count=$OSTCOUNT oflag=sync
-       dd if=/dev/zero of=$file2 bs=$STRIPE_BYTES count=$OSTCOUNT oflag=sync
+       dd if=/dev/zero of=$file1 bs=$stripe_size count=$OSTCOUNT oflag=sync
+       dd if=/dev/zero of=$file2 bs=$stripe_size count=$OSTCOUNT oflag=sync
        rm -f $file1
 
        $LFS setstripe -c -1 $file1 # b=10919
-       fsx -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 $file1 $file2 \
-               || error "fsx failed"
+       fsx -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 $file1 $file2 ||
+               error "fsx failed"
        rm -f $file1
 
        # O_DIRECT reads and writes must be aligned to the device block size.
        fsx -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 -Z -r 4096 \
                -w 4096 $file1 $file2 || error "fsx with O_DIRECT failed."
 }
-run_test 16 "$FSXNUM iterations of dual-mount fsx"
+run_test 16a "$FSXNUM iterations of dual-mount fsx"
+
+# Consistency check for tiny writes, LU-9409
+test_16b() {
+       local file1=$DIR1/$tfile
+       local file2=$DIR2/$tfile
+       local stripe_size=($($LFS getstripe -S $DIR))
+
+       # to allocate grant because it may run out due to test_15.
+       lfs setstripe -c -1 $file1
+       dd if=/dev/zero of=$file1 bs=$stripe_size count=$OSTCOUNT oflag=sync ||
+               error "dd failed writing to file=$file1"
+       dd if=/dev/zero of=$file2 bs=$stripe_size count=$OSTCOUNT oflag=sync ||
+               error "dd failed writing to file=$file2"
+       rm -f $file1
+
+       lfs setstripe -c -1 $file1 # b=10919
+       # -o is set to 8192 because writes < 1 page and between 1 and 2 pages
+       # create a mix of tiny writes & normal writes
+       fsx -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -o 8192 -S 0 \
+               $file1 $file2 || error "fsx with tiny write failed."
+}
+run_test 16b "$FSXNUM iterations of dual-mount fsx at small size"
+
+test_16c() {
+       local file1=$DIR1/$tfile
+       local file2=$DIR2/$tfile
+       local stripe_size=$(do_facet $SINGLEMDS \
+               "$LCTL get_param -n lod.$(facet_svc $SINGLEMDS)*.stripesize")
+
+       [ "$ost1_FSTYPE" != ldiskfs ] && skip "dio on ldiskfs only"
+
+       # to allocate grant because it may run out due to test_15.
+       $LFS setstripe -c -1 $file1
+       dd if=/dev/zero of=$file1 bs=$stripe_size count=$OSTCOUNT oflag=sync
+       dd if=/dev/zero of=$file2 bs=$stripe_size count=$OSTCOUNT oflag=sync
+       rm -f $file1
+       wait_delete_completed
+
+       local list=$(comma_list $(osts_nodes))
+       if ! get_osd_param $list '' read_cache_enable >/dev/null; then
+               skip "not cache-capable obdfilter"
+       fi
+
+       set_osd_param $list '' read_cache_enable 0
+       set_osd_param $list '' writethrough_cache_enable 0
+
+       $LFS setstripe -c -1 $file1 # b=10919
+       fsx -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 $file1 $file2 ||
+               error "fsx failed"
+       rm -f $file1
+
+       set_osd_param $list '' read_cache_enable 1
+       set_osd_param $list '' writethrough_cache_enable 1
+
+       return 0
+}
+run_test 16c "verify data consistency on ldiskfs with cache disabled (b=17397)"
+
+test_16d() {
+       local file1=$DIR1/$tfile
+       local file2=$DIR2/$tfile
+       local file3=$DIR1/file
+       local stripe_size=$(do_facet $SINGLEMDS \
+               "$LCTL get_param -n lod.$(facet_svc $SINGLEMDS)*.stripesize")
+
+       # to allocate grant because it may run out due to test_15.
+       $LFS setstripe -c -1 $file1
+       dd if=/dev/zero of=$file1 bs=$stripe_size count=$OSTCOUNT oflag=sync
+       dd if=/dev/zero of=$file2 bs=$stripe_size count=$OSTCOUNT oflag=sync
+       rm -f $file1
+
+       local tmpfile=`mktemp`
+       $LFS setstripe -c -1 $file1 # b=10919
+       $LCTL set_param ldlm.namespaces.*.lru_size=clear
+       
+       # direct write on one client and direct read from another
+       dd if=/dev/urandom of=$file1 bs=1M count=100 oflag=direct
+       dd if=$file2 of=$tmpfile iflag=direct bs=1M
+       diff $file1 $tmpfile || error "file different(1)"
+       rm -f $file1
+
+       # buffer write on one client, but direct read from another
+       dd if=$tmpfile of=$file1 bs=1M count=100
+       dd if=$file2 of=$file3 bs=1M iflag=direct count=100
+       diff $file3 $tmpfile || error "file different(2)"
+
+       rm -f $file3 $file2 $file1
+       # direct write on one client
+       dd if=$tmpfile of=$file1 bs=1M count=100 oflag=direct
+       # buffer read from another client
+       dd if=$file2 of=$file3 bs=1M count=100
+       diff $file3 $tmpfile || error "file different(3)"
+
+       rm -f $file1 $file2 $file3 $tmpfile
+
+}
+run_test 16d "Verify DIO and buffer IO with two clients"
+
+test_16e() { # LU-13227
+       local file1=$DIR1/$tfile
+       local file2=$DIR2/$tfile
+
+       # client1 write 10M data
+       dd if=/dev/zero of=$file1 bs=1M count=10
+       # drop locks
+       cancel_lru_locks osc > /dev/null
+       # use lockahead to generate one PW lock to keep LVB loaded.
+       $LFS ladvise -a lockahead --start 0 --length 1M \
+               --mode WRITE $file1
+       # direct write to extend file size on client2
+       dd if=/dev/zero of=$file2 bs=1M seek=20 count=1 \
+               oflag=direct conv=notrunc
+       local filesize=$(stat -c %s $file2)
+       [ "$filesize" -eq 22020096 ] ||
+               error "expected filesize 22020096 got $filesize"
+       rm -f $file1
+}
+run_test 16e "Verify size consistency for O_DIRECT write"
 
 test_17() { # bug 3513, 3667
        remote_ost_nodsh && skip "remote OST with nodsh" && return
@@ -420,7 +550,9 @@ test_18() {
                 excepts="$excepts -e $(($(printf %d \'$idx)-96))"
         done
 
-       $LUSTRE/tests/mmap_sanity -d $MOUNT1 -m $MOUNT2 $excepts
+       excepts="$excepts -e 7 -e 8 -e 9"
+       $LUSTRE/tests/mmap_sanity -d $MOUNT1 -m $MOUNT2 $excepts ||
+               error "mmap_sanity test failed"
        sync; sleep 1; sync
 }
 run_test 18 "mmap sanity check ================================="
@@ -428,21 +560,20 @@ run_test 18 "mmap sanity check ================================="
 test_19() { # bug3811
        local node=$(facet_active_host ost1)
 
+       [ "x$DOM" = "xyes" ] && node=$(facet_active_host $SINGLEMDS)
+
        # check whether obdfilter is cache capable at all
-       if ! get_osd_param $node '' read_cache_enable >/dev/null; then
-               echo "not cache-capable obdfilter"
-               return 0
-       fi
+       get_osd_param $node '' read_cache_enable >/dev/null ||
+               skip "not cache-capable obdfilter"
 
-       local MAX=$(get_osd_param $node '' readcache_max_filesize | \
-                   head -n 1)
+       local MAX=$(get_osd_param $node '' readcache_max_filesize | head -n 1)
        set_osd_param $node '' readcache_max_filesize 4096
        dd if=/dev/urandom of=$TMP/$tfile bs=512k count=32
        local SUM=$(cksum $TMP/$tfile | cut -d" " -f 1,2)
        cp $TMP/$tfile $DIR1/$tfile
        for i in `seq 1 20`; do
                [ $((i % 5)) -eq 0 ] && log "$testname loop $i"
-               cancel_lru_locks osc > /dev/null
+               cancel_lru_locks $OSC > /dev/null
                cksum $DIR1/$tfile | cut -d" " -f 1,2 > $TMP/sum1 & \
                cksum $DIR2/$tfile | cut -d" " -f 1,2 > $TMP/sum2
                wait
@@ -457,16 +588,16 @@ test_19() { # bug3811
 run_test 19 "test concurrent uncached read races ==============="
 
 test_20() {
-       test_mkdir $DIR1/d20
-       cancel_lru_locks osc
-       CNT=$((`lctl get_param -n llite.*.dump_page_cache | wc -l`))
-       $MULTIOP $DIR1/f20 Ow8190c
-       $MULTIOP $DIR2/f20 Oz8194w8190c
-       $MULTIOP $DIR1/f20 Oz0r8190c
-       cancel_lru_locks osc
-       CNTD=$((`lctl get_param -n llite.*.dump_page_cache | wc -l` - $CNT))
-       [ $CNTD -gt 0 ] && \
-           error $CNTD" page left in cache after lock cancel" || true
+       test_mkdir $DIR1/$tdir
+       cancel_lru_locks
+       CNT=$($LCTL get_param -n llite.*.dump_page_cache | wc -l)
+       $MULTIOP $DIR1/$tdir/$tfile Ow8190c
+       $MULTIOP $DIR2/$tdir/$tfile Oz8194w8190c
+       $MULTIOP $DIR1/$tdir/$tfile Oz0r8190c
+       cancel_lru_locks
+       CNT2=$($LCTL get_param -n llite.*.dump_page_cache | wc -l)
+       [[ $CNT2 == $CNT ]] ||
+               error $((CNT2 - CNT))" page left in cache after lock cancel"
 }
 run_test 20 "test extra readahead page left in cache ===="
 
@@ -494,7 +625,7 @@ test_23() { # Bug 5972
        echo "atime should be updated while another read" > $DIR1/$tfile
 
        # clear the lock(mode: LCK_PW) gotten from creating operation
-       cancel_lru_locks osc
+       cancel_lru_locks $OSC
        time1=$(date +%s)
        echo "now is $time1"
        sleep $((at_diff + 1))
@@ -526,9 +657,9 @@ test_24a() {
 
        OSC=`lctl dl | awk '/-osc-|OSC.*MNT/ {print $4}' | head -n 1`
 #      OSC=`lctl dl | awk '/-osc-/ {print $4}' | head -n 1`
-       lctl --device %$OSC deactivate
+       lctl --device %osc deactivate
        lfs df -i || error "lfs df -i with deactivated OSC failed"
-       lctl --device %$OSC activate
+       lctl --device %osc activate
        lfs df || error "lfs df with reactivated OSC failed"
 }
 run_test 24a "lfs df [-ih] [path] test ========================="
@@ -598,7 +729,7 @@ test_25b() {
 run_test 25b "change ACL under remote dir on one mountpoint be seen on another"
 
 test_26a() {
-        utime $DIR1/f26a -s $DIR2/f26a || error
+       utime $DIR1/f26a -s $DIR2/f26a || error "utime failed for $DIR1/f26a"
 }
 run_test 26a "allow mtime to get older"
 
@@ -618,11 +749,11 @@ test_26b() {
 run_test 26b "sync mtime between ost and mds"
 
 test_27() {
-       cancel_lru_locks osc
+       cancel_lru_locks $OSC
        lctl clear
        dd if=/dev/zero of=$DIR2/$tfile bs=$((4096+4))k conv=notrunc count=4 seek=3 &
        DD2_PID=$!
-       usleep 50
+       sleep 0.5
        log "dd 1 started"
 
        dd if=/dev/zero of=$DIR1/$tfile bs=$((16384-1024))k conv=notrunc count=1 seek=4 &
@@ -662,46 +793,33 @@ test_28() { # bug 9977
        EOF
 
        # reading of 1st stripe should pass
-       dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error
+       dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error "dd failed"
        # reading of 2nd stripe should fail (this stripe was destroyed)
        dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 && error
 
        # now, recreating test file
-       dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2 || error
+       dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2 || error "dd failed"
        # reading of 1st stripe should pass
-       dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error
+       dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error "dd failed"
        # reading of 2nd stripe should pass
-       dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 || error
+       dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 ||
+               error "dd failed"
 }
 run_test 28 "read/write/truncate file with lost stripes"
 
-test_29() { # bug 10999
-       touch $DIR1/$tfile
-       #define OBD_FAIL_LDLM_GLIMPSE  0x30f
-       lctl set_param fail_loc=0x8000030f
-       ls -l $DIR2/$tfile &
-       usleep 500
-       dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1
-       wait
-}
-#bug 11549 - permanently turn test off in b1_5
-run_test 29 "lock put race between glimpse and enqueue ========="
-
-test_30() { #bug #11110, LU-2523
-       test_mkdir -p $DIR1/$tdir
+test_30() { #b=11110, LU-2523
+       test_mkdir $DIR1/$tdir
        cp -f /bin/bash $DIR1/$tdir/bash
-       /bin/sh -c 'sleep 1; rm -f $DIR2/$tdir/bash;
-                   cp /bin/bash $DIR2/$tdir' &
+       /bin/sh -c 'sleep 1; rm -f $DIR2/$tdir/bash; cp /bin/bash $DIR2/$tdir' &
        $DIR1/$tdir/bash -c 'sleep 2;
                openfile -f O_RDONLY /proc/$$/exe >& /dev/null; echo $?'
        wait
        true
 }
-
 run_test 30 "recreate file race"
 
 test_31a() {
-       test_mkdir -p $DIR1/$tdir || error "Creating dir $DIR1/$tdir"
+       test_mkdir $DIR1/$tdir
        local writes=$(LANG=C dd if=/dev/zero of=$DIR/$tdir/$tfile \
                       count=1 2>&1 | awk 'BEGIN { FS="+" } /out/ {print $1}')
        #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
@@ -720,7 +838,7 @@ test_31b() {
        wait_mds_ost_sync || error "wait_mds_ost_sync()"
        wait_delete_completed || error "wait_delete_completed()"
 
-       test_mkdir -p $DIR1/$tdir || error "Creating dir $DIR1/$tdir"
+       test_mkdir $DIR1/$tdir
         lfs setstripe $DIR/$tdir/$tfile -i 0 -c 1
         cp /etc/hosts $DIR/$tdir/$tfile
         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
@@ -738,43 +856,48 @@ run_test 31b "voluntary OST cancel / blocking ast race=============="
 
 # enable/disable lockless truncate feature, depending on the arg 0/1
 enable_lockless_truncate() {
-        lctl set_param -n osc.*.lockless_truncate $1
+       lctl set_param -n $OSC.*.lockless_truncate $1
 }
 
 test_32a() { # bug 11270
-       local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
-       save_lustre_params client "osc.*.lockless_truncate" > $p
-       cancel_lru_locks osc
+       local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
+       local stripe_size=$(do_facet $SINGLEMDS \
+               "$LCTL get_param -n lod.$(facet_svc $SINGLEMDS)*.stripesize")
+
+       save_lustre_params client "$OSC.*.lockless_truncate" > $save
+       # restore lockless_truncate default values on exit
+       stack_trap "restore_lustre_params < $save; rm -f $save" EXIT
+       cancel_lru_locks $OSC
        enable_lockless_truncate 1
        rm -f $DIR1/$tfile
        lfs setstripe -c -1 $DIR1/$tfile
-       dd if=/dev/zero of=$DIR1/$tfile count=$OSTCOUNT bs=$STRIPE_BYTES > \
+       dd if=/dev/zero of=$DIR1/$tfile count=$OSTCOUNT bs=$stripe_size > \
                /dev/null 2>&1
-       clear_stats osc.*.osc_stats
+       clear_stats $OSC.*.${OSC}_stats
 
        log "checking cached lockless truncate"
        $TRUNCATE $DIR1/$tfile 8000000
-       $CHECKSTAT -s 8000000 $DIR2/$tfile || error "wrong file size"
-       [ $(calc_stats osc.*.osc_stats lockless_truncate) -ne 0 ] ||
+       $CHECKSTAT -s 8000000 $DIR2/$tfile ||
+               error "cached truncate - wrong file size"
+       [ $(calc_stats $OSC.*.${OSC}_stats lockless_truncate) -ne 0 ] ||
                error "cached truncate isn't lockless"
 
        log "checking not cached lockless truncate"
        $TRUNCATE $DIR2/$tfile 5000000
-       $CHECKSTAT -s 5000000 $DIR1/$tfile || error "wrong file size"
-       [ $(calc_stats osc.*.osc_stats lockless_truncate) -ne 0 ] ||
+       $CHECKSTAT -s 5000000 $DIR1/$tfile ||
+               error "not cached truncate - wrong file size"
+       [ $(calc_stats $OSC.*.${OSC}_stats lockless_truncate) -ne 0 ] ||
                error "not cached truncate isn't lockless"
 
        log "disabled lockless truncate"
        enable_lockless_truncate 0
-       clear_stats osc.*.osc_stats
+       clear_stats $OSC.*.${OSC}_stats
        $TRUNCATE $DIR2/$tfile 3000000
-       $CHECKSTAT -s 3000000 $DIR1/$tfile || error "wrong file size"
-       [ $(calc_stats osc.*.osc_stats lockless_truncate) -eq 0 ] ||
+       $CHECKSTAT -s 3000000 $DIR1/$tfile ||
+               error "lockless truncate disabled - wrong file size"
+       [ $(calc_stats $OSC.*.${OSC}_stats lockless_truncate) -eq 0 ] ||
                error "lockless truncate disabling failed"
-       rm $DIR1/$tfile
-       # restore lockless_truncate default values
-       restore_lustre_params < $p
-       rm -f $p
+       rm -f $DIR1/$tfile
 }
 run_test 32a "lockless truncate"
 
@@ -792,21 +915,21 @@ test_32b() { # bug 11270
                "ldlm.namespaces.filter-*.contended_locks" >> $p
        save_lustre_params $facets \
                "ldlm.namespaces.filter-*.contention_seconds" >> $p
-       clear_stats osc.*.osc_stats
+       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
+       lctl set_param -n $OSC.*.contention_seconds=60
        for i in {1..5}; do
                dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > \
                        /dev/null 2>&1
                dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > \
                        /dev/null 2>&1
        done
-       [ $(calc_stats osc.*.osc_stats lockless_write_bytes) -ne 0 ] ||
+       [ $(calc_stats $OSC.*.${OSC}_stats lockless_write_bytes) -ne 0 ] ||
                error "lockless i/o was not triggered"
        # disable lockless i/o (it is disabled by default)
        do_nodes $(comma_list $(osts_nodes)) \
@@ -815,15 +938,15 @@ test_32b() { # bug 11270
                        ldlm.namespaces.filter-*.contention_seconds=0"
        # set contention_seconds to 0 at client too, otherwise Lustre still
        # remembers lock contention
-       lctl set_param -n osc.*.contention_seconds=0
-       clear_stats osc.*.osc_stats
+       lctl set_param -n $OSC.*.contention_seconds=0
+       clear_stats $OSC.*.${OSC}_stats
        for i in {1..1}; do
                dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > \
                        /dev/null 2>&1
                dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > \
                        /dev/null 2>&1
        done
-       [ $(calc_stats osc.*.osc_stats lockless_write_bytes) -eq 0 ] ||
+       [ $(calc_stats $OSC.*.${OSC}_stats lockless_write_bytes) -eq 0 ] ||
                error "lockless i/o works when disabled"
        rm -f $DIR1/$tfile
        restore_lustre_params <$p
@@ -852,52 +975,52 @@ print_jbd_stat () {
 
 # commit on sharing tests
 test_33a() {
-    remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
 
-    [ -z "$CLIENTS" ] && skip "Need two or more clients, have $CLIENTS" && return 0
-    [ $CLIENTCOUNT -lt 2 ] &&
-       skip "Need two or more clients, have $CLIENTCOUNT" && return 0
+       [ -z "$CLIENTS" ] && skip "Need two or more clients, have $CLIENTS"
+       [ $CLIENTCOUNT -lt 2 ] &&
+               skip "Need two or more clients, have $CLIENTCOUNT"
 
-    local nfiles=${TEST33_NFILES:-10000}
-    local param_file=$TMP/$tfile-params
-    local fstype=$(facet_fstype $SINGLEMDS)
+       local nfiles=${TEST33_NFILES:-10000}
+       local param_file=$TMP/$tfile-params
+       local COS
+       local jbdold="N/A"
+       local jbdnew="N/A"
+       local jbd
 
        save_lustre_params $(get_facets MDS) \
                "mdt.*.commit_on_sharing" > $param_file
 
-    local COS
-    local jbdold="N/A"
-    local jbdnew="N/A"
-    local jbd
-
-    for COS in 0 1; do
-        do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
-        avgjbd=0
-        avgtime=0
-        for i in 1 2 3; do
-            do_nodes $CLIENT1,$CLIENT2 "mkdir -p $DIR1/$tdir-\\\$(hostname)-$i"
-
-            [ $fstype = ldiskfs ] && jbdold=$(print_jbd_stat)
-            echo "=== START createmany old: $jbdold transaction"
-            local elapsed=$(do_and_time "do_nodes $CLIENT1,$CLIENT2 createmany -o $DIR1/$tdir-\\\$(hostname)-$i/f- -r$DIR2/$tdir-\\\$(hostname)-$i/f- $nfiles > /dev/null 2>&1")
-            [ $fstype = ldiskfs ] && jbdnew=$(print_jbd_stat)
-            [ $fstype = ldiskfs ] && jbd=$(( jbdnew - jbdold ))
-            echo "=== END   createmany new: $jbdnew transaction :  $jbd transactions  nfiles $nfiles time $elapsed COS=$COS"
-            [ $fstype = ldiskfs ] && avgjbd=$(( avgjbd + jbd ))
-            avgtime=$(( avgtime + elapsed ))
-        done
-        eval cos${COS}_jbd=$((avgjbd / 3))
-        eval cos${COS}_time=$((avgtime / 3))
-    done
+       for COS in 0 1; do
+               do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
+               avgjbd=0
+               avgtime=0
+               for i in 1 2 3; do
+                       do_nodes $CLIENT1,$CLIENT2 "mkdir -p $DIR1/$tdir-\\\$(hostname)-$i"
+
+               [ "$mds1_FSTYPE" = ldiskfs ] && jbdold=$(print_jbd_stat)
+               echo "=== START createmany old: $jbdold transaction"
+               local elapsed=$(do_and_time "do_nodes $CLIENT1,$CLIENT2 createmany -o $DIR1/$tdir-\\\$(hostname)-$i/f- -r$DIR2/$tdir-\\\$(hostname)-$i/f- $nfiles > /dev/null 2>&1")
+               [ "$mds1_FSTYPE" = ldiskfs ] && jbdnew=$(print_jbd_stat)
+               [ "$mds1_FSTYPE" = ldiskfs ] && jbd=$(( jbdnew - jbdold ))
+               echo "=== END   createmany new: $jbdnew transaction :  $jbd transactions  nfiles $nfiles time $elapsed COS=$COS"
+               [ "$mds1_FSTYPE" = ldiskfs ] && avgjbd=$(( avgjbd + jbd ))
+               avgtime=$(( avgtime + elapsed ))
+               done
+       eval cos${COS}_jbd=$((avgjbd / 3))
+       eval cos${COS}_time=$((avgtime / 3))
+       done
 
-    echo "COS=0 transactions (avg): $cos0_jbd  time (avg): $cos0_time"
-    echo "COS=1 transactions (avg): $cos1_jbd  time (avg): $cos1_time"
-    [ "$cos0_jbd" != 0 ] && echo "COS=1 vs COS=0 jbd:  $((((cos1_jbd/cos0_jbd - 1)) * 100 )) %"
-    [ "$cos0_time" != 0 ] && echo "COS=1 vs COS=0 time: $((((cos1_time/cos0_time - 1)) * 100 )) %"
+       echo "COS=0 transactions (avg): $cos0_jbd  time (avg): $cos0_time"
+       echo "COS=1 transactions (avg): $cos1_jbd  time (avg): $cos1_time"
+       [ "$cos0_jbd" != 0 ] &&
+               echo "COS=1 vs COS=0 jbd:  $((((cos1_jbd/cos0_jbd - 1)) * 100 )) %"
+       [ "$cos0_time" != 0 ] &&
+               echo "COS=1 vs COS=0 time: $((((cos1_time/cos0_time - 1)) * 100 )) %"
 
-    restore_lustre_params < $param_file
-    rm -f $param_file
-    return 0
+       restore_lustre_params < $param_file
+       rm -f $param_file
+       return 0
 }
 run_test 33a "commit on sharing, cross crete/delete, 2 clients, benchmark"
 
@@ -962,95 +1085,111 @@ test_33b() {
 run_test 33b "COS: cross create/delete, 2 clients, benchmark under remote dir"
 
 test_33c() {
-       [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
-       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.63) ] &&
-               skip "DNE CoS not supported" && return
+       [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
+       [ "$MDS1_VERSION" -lt $(version_code 2.7.63) ] &&
+               skip "DNE CoS not supported"
 
-       sync
+       # LU-13522
+       stop mds1
+       start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS || error "start mds1 failed"
+
+       local sync_count
 
        mkdir $DIR/$tdir
-       # remote mkdir is done on MDT2, which enqueued lock of $tdir on MDT1
-       $LFS mkdir -i 1 $DIR/$tdir/d1
+       sync_all_data
        do_facet mds1 "lctl set_param -n mdt.*.sync_count=0"
-       mkdir $DIR/$tdir/d2
-       local sync_count=$(do_facet mds1 \
-               "lctl get_param -n mdt.*MDT0000.sync_count")
-       [ $sync_count -eq 1 ] || error "Sync-Lock-Cancel not triggered"
+       # do twice in case transaction is committed before unlock, see LU-8200
+       for i in 1 2; do
+               # remote dir is created on MDT1, which enqueued lock of $tdir on
+               # MDT0
+               $LFS mkdir -i 1 $DIR/$tdir/remote.$i
+               mkdir $DIR/$tdir/local.$i
+       done
+       sync_count=$(do_facet mds1 "lctl get_param -n mdt.*MDT0000.sync_count")
+       echo "sync_count $sync_count"
+       [ $sync_count -eq 0 ] && error "Sync-Lock-Cancel not triggered"
 
-       $LFS mkdir -i 1 $DIR/$tdir/d3
+       sync_all_data
        do_facet mds1 "lctl set_param -n mdt.*.sync_count=0"
+       $LFS mkdir -i 1 $DIR/$tdir/remote.3
        # during sleep remote mkdir should have been committed and canceled
        # remote lock spontaneously, which shouldn't trigger sync
        sleep 6
-       mkdir $DIR/$tdir/d4
-       local sync_count=$(do_facet mds1 \
-               "lctl get_param -n mdt.*MDT0000.sync_count")
+       mkdir $DIR/$tdir/local.3
+       sync_count=$(do_facet mds1 "lctl get_param -n mdt.*MDT0000.sync_count")
+       echo "sync_count $sync_count"
        [ $sync_count -eq 0 ] || error "Sync-Lock-Cancel triggered"
 }
 run_test 33c "Cancel cross-MDT lock should trigger Sync-Lock-Cancel"
 
-ops_do_cos() {
+# arg1 is operations done before CoS, arg2 is the operation that triggers CoS
+op_trigger_cos() {
+       local commit_nr
+       local total=0
        local nodes=$(comma_list $(mdts_nodes))
-       do_nodes $nodes "lctl set_param -n mdt.*.async_commit_count=0"
-       sh -c "$@"
-       local async_commit_count=$(do_nodes $nodes \
-               "lctl get_param -n mdt.*.async_commit_count" | calc_sum)
-       [ $async_commit_count -gt 0 ] || error "CoS not triggerred"
 
-       rm -rf $DIR/$tdir
-       sync
+       sync_all_data
+
+       # trigger CoS twice in case transaction commit before unlock
+       for i in 1 2; do
+               sh -c "$1"
+               do_nodes $nodes "lctl set_param -n mdt.*.async_commit_count=0"
+               sh -c "$2"
+               commit_nr=$(do_nodes $nodes \
+                       "lctl get_param -n mdt.*.async_commit_count" | calc_sum)
+               total=$((total + commit_nr));
+               rm -rf $DIR/$tdir
+               sync_all_data
+       done
+
+       echo "CoS count $total"
+       [ $total -gt 0 ] || error "$2 didn't trigger CoS"
 }
 
 test_33d() {
-       [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
-       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.63) ] &&
-               skip "DNE CoS not supported" && return
+       [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
+       [ "$MDS1_VERSION" -lt $(version_code 2.7.63) ] &&
+               skip "DNE CoS not supported"
 
-       sync
        # remote directory create
-       mkdir $DIR/$tdir
-       ops_do_cos "$LFS mkdir -i 1 $DIR/$tdir/subdir"
+       op_trigger_cos "mkdir $DIR/$tdir" "$LFS mkdir -i 1 $DIR/$tdir/subdir"
        # remote directory unlink
-       $LFS mkdir -i 1 $DIR/$tdir
-       ops_do_cos "rmdir $DIR/$tdir"
+       op_trigger_cos "$LFS mkdir -i 1 $DIR/$tdir" "rmdir $DIR/$tdir"
        # striped directory create
-       mkdir $DIR/$tdir
-       ops_do_cos "$LFS mkdir -c 2 $DIR/$tdir/subdir"
+       op_trigger_cos "mkdir $DIR/$tdir" "$LFS mkdir -c 2 $DIR/$tdir/subdir"
        # striped directory setattr
-       $LFS mkdir -c 2 $DIR/$tdir
-       touch $DIR/$tdir
-       ops_do_cos "chmod 713 $DIR/$tdir"
+       op_trigger_cos "$LFS mkdir -c 2 $DIR/$tdir; touch $DIR/$tdir" \
+               "chmod 713 $DIR/$tdir"
        # striped directory unlink
-       $LFS mkdir -c 2 $DIR/$tdir
-       touch $DIR/$tdir
-       ops_do_cos "rmdir $DIR/$tdir"
+       op_trigger_cos "$LFS mkdir -c 2 $DIR/$tdir; touch $DIR/$tdir" \
+               "rmdir $DIR/$tdir"
        # cross-MDT link
-       $LFS mkdir -c 2 $DIR/$tdir
-       $LFS mkdir -i 0 $DIR/$tdir/d1
-       $LFS mkdir -i 1 $DIR/$tdir/d2
-       touch $DIR/$tdir/d1/tgt
-       ops_do_cos "ln $DIR/$tdir/d1/tgt $DIR/$tdir/d2/src"
+       op_trigger_cos "$LFS mkdir -c 2 $DIR/$tdir; \
+                       $LFS mkdir -i 0 $DIR/$tdir/d1; \
+                       $LFS mkdir -i 1 $DIR/$tdir/d2; \
+                       touch $DIR/$tdir/d1/tgt" \
+               "ln $DIR/$tdir/d1/tgt $DIR/$tdir/d2/src"
        # cross-MDT rename
-       $LFS mkdir -c 2 $DIR/$tdir
-       $LFS mkdir -i 0 $DIR/$tdir/d1
-       $LFS mkdir -i 1 $DIR/$tdir/d2
-       touch $DIR/$tdir/d1/src
-       ops_do_cos "mv $DIR/$tdir/d1/src $DIR/$tdir/d2/tgt"
+       op_trigger_cos "$LFS mkdir -c 2 $DIR/$tdir; \
+                       $LFS mkdir -i 0 $DIR/$tdir/d1; \
+                       $LFS mkdir -i 1 $DIR/$tdir/d2; \
+                       touch $DIR/$tdir/d1/src" \
+               "mv $DIR/$tdir/d1/src $DIR/$tdir/d2/tgt"
        # migrate
-       $LFS mkdir -i 0 $DIR/$tdir
-       ops_do_cos "$LFS migrate -m 1 $DIR/$tdir"
+       op_trigger_cos "$LFS mkdir -i 0 $DIR/$tdir" \
+               "$LFS migrate -m 1 $DIR/$tdir"
+
        return 0
 }
 run_test 33d "DNE distributed operation should trigger COS"
 
 test_33e() {
-       [ -n "$CLIENTS" ] || { skip "Need two or more clients" && return 0; }
+       [ -n "$CLIENTS" ] || skip "Need two or more clients"
        [ $CLIENTCOUNT -ge 2 ] ||
-               { skip "Need two or more clients, have $CLIENTCOUNT" &&
-                                                               return 0; }
-       [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
-       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.63) ] &&
-               skip "DNE CoS not supported" && return
+               skip "Need two or more clients, have $CLIENTCOUNT"
+       [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
+       [ "$MDS1_VERSION" -lt $(version_code 2.7.63) ] &&
+               skip "DNE CoS not supported"
 
        local client2=${CLIENT2:-$(hostname)}
 
@@ -1090,7 +1229,7 @@ cleanup_34() {
        do_nodes $(comma_list $(osts_nodes)) \
                "lctl set_param -n fail_loc=0 2>/dev/null || true"
        for i in $(seq $OSTCOUNT); do
-               wait_osc_import_state client ost$i FULL
+               wait_osc_import_ready client ost$i
        done
 }
 
@@ -1143,58 +1282,60 @@ test_34() { #16129
 run_test 34 "no lock timeout under IO"
 
 test_35() { # bug 17645
-        local generation=[]
-        local count=0
+       local generation=[]
+       local count=0
        gen=$(lctl get_param mdc.$FSNAME-MDT*-mdc-*.import | grep generation |
-               awk '/generation/{print $2}')
+             awk '/generation/{print $2}')
        for g in $gen; do
-            generation[count]=$g
-            let count=count+1
-        done
+               generation[count]=$g
+               let count=count+1
+       done
 
-       test_mkdir -p $MOUNT1/$tfile
-        cancel_lru_locks mdc
+       test_mkdir $MOUNT1/$tdir
+       cancel_lru_locks mdc
 
-        # Let's initiate -EINTR situation by setting fail_loc and take
-        # write lock on same file from same client. This will not cause
-        # bl_ast yet as lock is already in local cache.
-#define OBD_FAIL_LDLM_INTR_CP_AST        0x317
-        do_facet client "lctl set_param fail_loc=0x80000317"
-        local timeout=`do_facet $SINGLEMDS lctl get_param  -n timeout`
-        let timeout=timeout*3
-        local nr=0
-        while test $nr -lt 10; do
-                log "Race attempt $nr"
-                local blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
-                test "x$blk1" = "x" && blk1=0
-                createmany -o $MOUNT2/$tfile/a 4000 &
-                pid1=$!
-                sleep 1
-
-                # Let's make conflict and bl_ast
-                ls -la $MOUNT1/$tfile > /dev/null &
-                pid2=$!
-
-                log "Wait for $pid1 $pid2 for $timeout sec..."
-                sleep $timeout
-                kill -9 $pid1 $pid2 > /dev/null 2>&1
-                wait
-                local blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
-                test "x$blk2" = "x" && blk2=0
-                test $blk2 -gt $blk1 && break
-                rm -fr $MOUNT1/$tfile/*
-                cancel_lru_locks mdc
-                let nr=nr+1
-        done
-        do_facet client "lctl set_param fail_loc=0x0"
-        df -h $MOUNT1 $MOUNT2
-        count=0
+       # Let's initiate -EINTR situation by setting fail_loc and take
+       # write lock on same file from same client. This will not cause
+       # bl_ast yet as lock is already in local cache.
+       #define OBD_FAIL_LDLM_INTR_CP_AST        0x317
+       do_facet client "lctl set_param fail_loc=0x80000317"
+       local timeout=$(do_facet $SINGLEMDS lctl get_param  -n timeout)
+       let timeout=timeout*3
+       local nr=0
+       while test $nr -lt 10; do
+               log "Race attempt $nr"
+               local blk1=$(lctl get_param -n ldlm.services.ldlm_cbd.stats |
+                            awk '/ldlm_bl_callback/ { print $2 }')
+               test "x$blk1" = "x" && blk1=0
+               createmany -o $MOUNT2/$tdir/a 4000 &
+               pid1=$!
+               sleep 1
+
+               # Let's make conflict and bl_ast
+               ls -la $MOUNT1/$tdir > /dev/null &
+               pid2=$!
+
+               log "Wait for $pid1 $pid2 for $timeout sec..."
+               sleep $timeout
+               kill -9 $pid1 $pid2 > /dev/null 2>&1
+               wait
+               local blk2=$(lctl get_param -n ldlm.services.ldlm_cbd.stats |
+                            awk '/ldlm_bl_callback/ { print $2 }')
+               test "x$blk2" = "x" && blk2=0
+               test $blk2 -gt $blk1 && break
+               rm -fr $MOUNT1/$tdir
+               cancel_lru_locks mdc
+               let nr=nr+1
+       done
+       do_facet client "lctl set_param fail_loc=0x0"
+       df -h $MOUNT1 $MOUNT2
+       count=0
        gen=$(lctl get_param mdc.$FSNAME-MDT*-mdc-*.import | grep generation |
                awk '/generation/{print $2}')
        for g in $gen; do
            if ! test "$g" -eq "${generation[count]}"; then
                list=$(lctl list_param mdc.$FSNAME-MDT*-mdc-*.import)
-               local c = 0
+               local c=0
                for imp in $list; do
                        if [ $c = $count ]; then
                                break
@@ -1214,7 +1355,7 @@ test_36() { #bug 16417
        local SIZE_B
        local i
 
-       test_mkdir -p $DIR1/$tdir
+       test_mkdir $DIR1/$tdir
        $LFS setstripe -c -1 $DIR1/$tdir
        i=0
        SIZE=50
@@ -1251,7 +1392,7 @@ test_36() { #bug 16417
 run_test 36 "handle ESTALE/open-unlink correctly"
 
 test_37() { # bug 18695
-       test_mkdir -p $DIR1/$tdir
+       test_mkdir $DIR1/$tdir
        multiop_bg_pause $DIR1/$tdir D_c || return 1
        MULTIPID=$!
        # create large directory (32kB seems enough from e2fsck, ~= 1000 files)
@@ -1375,7 +1516,7 @@ test_39d() { # LU-7310
 
        $LCTL set_param fail_loc=0
 
-       cancel_lru_locks osc
+       cancel_lru_locks $OSC
 
        local mtime2=$(stat -c %Y $DIR2/$tfile)
        [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] ||
@@ -1383,13 +1524,32 @@ test_39d() { # LU-7310
 }
 run_test 39d "sync write should update mtime"
 
+pdo_sched() {
+       # how long 40-47 take with specific delay
+       # sleep 0.1 # 78s
+       # sleep 0.2 # 103s
+       # sleep 0.3 # 124s
+       sleep 0.5 # 164s
+}
+
+# for pdo testing, we must cancel MDT-MDT locks as well as client locks to
+# avoid unexpected delays due to previous tests
+pdo_lru_clear() {
+       cancel_lru_locks mdc
+       do_nodes $(comma_list $(mdts_nodes)) \
+               $LCTL set_param -n ldlm.namespaces.*mdt*.lru_size=clear
+       do_nodes $(comma_list $(mdts_nodes)) \
+               $LCTL get_param ldlm.namespaces.*mdt*.lock_unused_count \
+                       ldlm.namespaces.*mdt*.lock_count | grep -v '=0'
+}
+
 # check that pid exists hence second operation wasn't blocked by first one
 # if it is so then there is no conflict, return 0
 # else second operation is conflicting with first one, return 1
 check_pdo_conflict() {
        local pid=$1
        local conflict=0
-       sleep 1 # to ensure OP1 is finished on client if OP2 is blocked by OP1
+       pdo_sched # to ensure OP1 is finished on client if OP2 is blocked by OP1
        if [[ `ps --pid $pid | wc -l` == 1 ]]; then
                conflict=1
                echo "Conflict"
@@ -1403,12 +1563,13 @@ check_pdo_conflict() {
 # test 40: check non-blocking operations
 test_40a() {
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       pdo_lru_clear
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        touch $DIR2
        mkdir $DIR1/$tfile &
-       PID1=$!
-       sleep 1
+       PID1=$!; pdo_sched
        touch $DIR2/$tfile-2
        check_pdo_conflict $PID1 || error "create is blocked"
        mkdir $DIR2/$tfile-3
@@ -1425,6 +1586,8 @@ test_40a() {
 
        #  all operations above shouldn't wait the first one
        check_pdo_conflict $PID1 || error "parallel operation is blocked"
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        wait $PID1
        rm -rf $DIR/$tfile*
        return 0
@@ -1433,11 +1596,12 @@ run_test 40a "pdirops: create vs others =============="
 
 test_40b() {
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       pdo_lru_clear
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        touch $DIR1/$tfile &
-       PID1=$!
-       sleep 1
+       PID1=$!; pdo_sched
        # open|create
        touch $DIR2/$tfile-2
        check_pdo_conflict $PID1 || error "create is blocked"
@@ -1455,6 +1619,8 @@ test_40b() {
        # all operations above shouldn't wait the first one
 
         check_pdo_conflict $PID1 || error "parallel operation is blocked"
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        wait $PID1
        rm -rf $DIR/$tfile*
        return 0
@@ -1463,12 +1629,13 @@ run_test 40b "pdirops: open|create and others =============="
 
 test_40c() {
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       pdo_lru_clear
        touch $DIR1/$tfile
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        link $DIR1/$tfile $DIR1/$tfile-0 &
-       PID1=$!
-       sleep 1
+       PID1=$!; pdo_sched
        # open|create
        touch $DIR2/$tfile-2
        check_pdo_conflict $PID1 || error "create is blocked"
@@ -1486,6 +1653,8 @@ test_40c() {
 
         # all operations above shouldn't wait the first one
        check_pdo_conflict $PID1 || error "parallel operation is blocked"
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        wait $PID1
        rm -rf $DIR/$tfile*
        return 0
@@ -1494,12 +1663,13 @@ run_test 40c "pdirops: link and others =============="
 
 test_40d() {
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       pdo_lru_clear
        touch $DIR1/$tfile
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        rm $DIR1/$tfile &
-       PID1=$!
-       sleep 1
+       PID1=$!; pdo_sched
        # open|create
        touch $DIR2/$tfile-2
        check_pdo_conflict $PID1 || error "create is blocked"
@@ -1517,6 +1687,8 @@ test_40d() {
 
        # all operations above shouldn't wait the first one
        check_pdo_conflict $PID1 || error "parallel operation is blocked"
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        wait $PID1
        return 0
 }
@@ -1524,12 +1696,13 @@ run_test 40d "pdirops: unlink and others =============="
 
 test_40e() {
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       pdo_lru_clear
        touch $DIR1/$tfile
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mv $DIR1/$tfile $DIR1/$tfile-0 &
-       PID1=$!
-       sleep 1
+       PID1=$!; pdo_sched
        # open|create
        touch $DIR2/$tfile-2
        check_pdo_conflict $PID1 || error "create is blocked"
@@ -1545,6 +1718,8 @@ test_40e() {
 
        # all operations above shouldn't wait the first one
        check_pdo_conflict $PID1 || error "parallel operation is blocked"
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        wait $PID1
        rm -rf $DIR/$tfile*
        return 0
@@ -1553,106 +1728,146 @@ run_test 40e "pdirops: rename and others =============="
 
 # test 41: create blocking operations
 test_41a() {
+       pdo_lru_clear
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
-       PID1=$!
-       sleep 1
-       mkdir $DIR2/$tfile && error "mkdir must fail"
+       PID1=$! ; pdo_sched
+       mkdir $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; echo "mkdir isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 41a "pdirops: create vs mkdir =============="
 
 test_41b() {
+       pdo_lru_clear
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
-       PID1=$!
-       sleep 1
-       $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
+       PID1=$! ; pdo_sched
+       $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 41b "pdirops: create vs create =============="
 
 test_41c() {
+       pdo_lru_clear
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
-       PID1=$!
-       sleep 1
-       link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
+       PID1=$! ; pdo_sched
+       link $DIR2/$tfile-2 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 41c "pdirops: create vs link =============="
 
 test_41d() {
+       pdo_lru_clear
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
-       PID1=$!
-       sleep 1
-       rm $DIR2/$tfile || error "unlink must succeed"
+       PID1=$! ; pdo_sched
+       rm $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "unlink must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 41d "pdirops: create vs unlink =============="
 
 test_41e() {
+       pdo_lru_clear
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
-       PID1=$!
-       sleep 1
-       mv $DIR2/$tfile-2 $DIR2/$tfile || error "rename must succeed"
+       PID1=$! ; pdo_sched
+       mv $DIR2/$tfile-2 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 41e "pdirops: create and rename (tgt) =============="
 
 test_41f() {
+       pdo_lru_clear
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
-       PID1=$!
-       sleep 1
-       mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
+       PID1=$! ; pdo_sched
+       mv $DIR2/$tfile $DIR2/$tfile-2 &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 41f "pdirops: create and rename (src) =============="
 
 test_41g() {
+       pdo_lru_clear
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
-       PID1=$!
-       sleep 1
-       stat $DIR2/$tfile > /dev/null || error "stat must succeed"
+       PID1=$! ; pdo_sched
+       stat $DIR2/$tfile > /dev/null &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 41g "pdirops: create vs getattr =============="
 
 test_41h() {
+       pdo_lru_clear
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
-       PID1=$!
-       sleep 1
-       ls -lia $DIR2/ > /dev/null
+       PID1=$! ; pdo_sched
+       ls -lia $DIR2/ > /dev/null &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
+       wait $PID2
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -1660,221 +1875,291 @@ run_test 41h "pdirops: create vs readdir =============="
 
 # test 42: unlink and blocking operations
 test_42a() {
+       pdo_lru_clear
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mkdir $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       mkdir $DIR2/$tfile && error "mkdir must fail"
+       PID1=$! ; pdo_sched
+       mkdir $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 42a "pdirops: mkdir vs mkdir =============="
 
 test_42b() {
+       pdo_lru_clear
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mkdir $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
+       PID1=$! ; pdo_sched
+       $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 42b "pdirops: mkdir vs create =============="
 
 test_42c() {
+       pdo_lru_clear
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mkdir $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
+       PID1=$! ; pdo_sched
+       link $DIR2/$tfile-2 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 42c "pdirops: mkdir vs link =============="
 
 test_42d() {
+       pdo_lru_clear
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mkdir $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       rmdir $DIR2/$tfile || error "unlink must succeed"
+       PID1=$! ; pdo_sched
+       rmdir $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "unlink must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 42d "pdirops: mkdir vs unlink =============="
 
 test_42e() {
+       pdo_lru_clear
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mkdir $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       mv -T $DIR2/$tfile-2 $DIR2/$tfile && error "rename must fail"
+       PID1=$! ; pdo_sched
+       mv -T $DIR2/$tfile-2 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "rename must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 42e "pdirops: mkdir and rename (tgt) =============="
 
 test_42f() {
+       pdo_lru_clear
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mkdir $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
+       PID1=$! ; pdo_sched
+       mv $DIR2/$tfile $DIR2/$tfile-2 &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 42f "pdirops: mkdir and rename (src) =============="
 
 test_42g() {
+       pdo_lru_clear
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mkdir $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       stat $DIR2/$tfile > /dev/null || error "stat must succeed"
+       PID1=$! ; pdo_sched
+       stat $DIR2/$tfile > /dev/null &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 42g "pdirops: mkdir vs getattr =============="
 
 test_42h() {
+       pdo_lru_clear
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mkdir $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       ls -lia $DIR2/ > /dev/null
+       PID1=$! ; pdo_sched
+       ls -lia $DIR2/ > /dev/null &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
+       wait $PID2
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 42h "pdirops: mkdir vs readdir =============="
 
-# test 43: unlink and blocking operations
+# test 43: rmdir,mkdir won't return -EEXIST
 test_43a() {
-       touch $DIR1/$tfile
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
-       rm $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       mkdir $DIR2/$tfile || error "mkdir must succeed"
-       check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
-       rm -rf $DIR/$tfile*
+       for i in {1..1000}; do
+               mkdir $DIR1/$tdir || error "mkdir $tdir failed"
+               rmdir $DIR2/$tdir || error "rmdir $tdir failed"
+       done
        return 0
 }
-run_test 43a "pdirops: unlink vs mkdir =============="
+run_test 43a "rmdir,mkdir doesn't return -EEXIST =============="
 
 test_43b() {
+       pdo_lru_clear
        touch $DIR1/$tfile
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        rm $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c || error "create must succeed"
+       PID1=$! ; pdo_sched
+       $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "create must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 43b "pdirops: unlink vs create =============="
 
 test_43c() {
+       pdo_lru_clear
        touch $DIR1/$tfile
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        rm $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       link $DIR2/$tfile-2 $DIR2/$tfile || error "link must succeed"
+       PID1=$! ; pdo_sched
+       link $DIR2/$tfile-2 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "link must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 43c "pdirops: unlink vs link =============="
 
 test_43d() {
+       pdo_lru_clear
        touch $DIR1/$tfile
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        rm $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       rm $DIR2/$tfile && error "unlink must fail"
+       PID1=$! ; pdo_sched
+       rm $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "unlink must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 43d "pdirops: unlink vs unlink =============="
 
 test_43e() {
+       pdo_lru_clear
        touch $DIR1/$tfile
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        rm $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       mv -u $DIR2/$tfile-2 $DIR2/$tfile || error "rename must succeed"
+       PID1=$! ; pdo_sched
+       mv -u $DIR2/$tfile-2 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 43e "pdirops: unlink and rename (tgt) =============="
 
 test_43f() {
+       pdo_lru_clear
        touch $DIR1/$tfile
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        rm $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       mv $DIR2/$tfile $DIR2/$tfile-2 && error "rename must fail"
+       PID1=$! ; pdo_sched
+       mv $DIR2/$tfile $DIR2/$tfile-2 &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "rename must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 43f "pdirops: unlink and rename (src) =============="
 
 test_43g() {
+       pdo_lru_clear
        touch $DIR1/$tfile
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        rm $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       stat $DIR2/$tfile > /dev/null && error "stat must fail"
+       PID1=$! ; pdo_sched
+       stat $DIR2/$tfile > /dev/null &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "stat must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 43g "pdirops: unlink vs getattr =============="
 
 test_43h() {
+       pdo_lru_clear
        touch $DIR1/$tfile
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        rm $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       ls -lia $DIR2/ > /dev/null
+       PID1=$! ; pdo_sched
+       ls -lia $DIR2/ > /dev/null &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
+       wait $PID2
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -1882,132 +2167,200 @@ run_test 43h "pdirops: unlink vs readdir =============="
 
 test_43i() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+       pdo_lru_clear
        touch $DIR1/$tfile
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        rm $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       $LFS mkdir -i 1 $DIR2/$tfile || error "remote mkdir must succeed"
+       PID1=$! ; pdo_sched
+       $LFS mkdir -i 1 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 &&
                { wait $PID1; error "remote mkdir isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "remote mkdir must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 43i "pdirops: unlink vs remote mkdir"
 
+test_43j() {
+       [[ $MDS1_VERSION -lt $(version_code 2.13.52) ]] &&
+               skip "Need MDS version newer than 2.13.52"
+
+       for i in {1..100}; do
+#define OBD_FAIL_ONCE|OBD_FAIL_MDS_CREATE_RACE         0x167
+               do_nodes $(comma_list $(mdts_nodes)) \
+                       "lctl set_param -n fail_loc=0x80000167 2>/dev/null ||
+                               true"
+               OK=0
+               mkdir $DIR1/$tdir &
+               PID1=$!
+               mkdir $DIR2/$tdir && ((OK++))
+               wait $PID1 && ((OK++))
+               (( OK == 1 )) || error "exactly one mkdir should succeed"
+
+               rmdir $DIR1/$tdir || error "rmdir failed"
+       done
+       return 0
+}
+run_test 43j "racy mkdir return EEXIST =============="
+
 # test 44: rename tgt and blocking operations
 test_44a() {
+       pdo_lru_clear
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
        mv $DIR1/$tfile-2 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       mkdir $DIR2/$tfile && error "mkdir must fail"
-       check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
+       PID1=$! ; pdo_sched
+       mkdir $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
+       check_pdo_conflict $PID1 && { wait $PID1; date;error "mkdir isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
+       date
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 44a "pdirops: rename tgt vs mkdir =============="
 
 test_44b() {
+       pdo_lru_clear
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
        mv $DIR1/$tfile-2 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
+       PID1=$! ; pdo_sched
+       $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 44b "pdirops: rename tgt vs create =============="
 
 test_44c() {
+       pdo_lru_clear
        touch $DIR1/$tfile-2
        touch $DIR1/$tfile-3
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
        mv $DIR1/$tfile-2 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       link $DIR2/$tfile-3 $DIR2/$tfile && error "link must fail"
+       PID1=$! ; pdo_sched
+       link $DIR2/$tfile-3 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 44c "pdirops: rename tgt vs link =============="
 
 test_44d() {
+       pdo_lru_clear
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
        mv $DIR1/$tfile-2 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       rm $DIR2/$tfile || error "unlink must succeed"
+       PID1=$! ; pdo_sched
+       rm $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "unlink must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 44d "pdirops: rename tgt vs unlink =============="
 
 test_44e() {
+       pdo_lru_clear
        touch $DIR1/$tfile
        touch $DIR1/$tfile-2
        touch $DIR1/$tfile-3
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
        mv $DIR1/$tfile-2 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
+       PID1=$! ; pdo_sched
+       mv $DIR2/$tfile-3 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 44e "pdirops: rename tgt and rename (tgt) =============="
 
 test_44f() {
+       pdo_lru_clear
        touch $DIR1/$tfile-2
        touch $DIR1/$tfile-3
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
        mv $DIR1/$tfile-2 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       mv $DIR2/$tfile $DIR2/$tfile-3 || error "rename must succeed"
+       PID1=$! ; pdo_sched
+       mv $DIR2/$tfile $DIR2/$tfile-3 &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 44f "pdirops: rename tgt and rename (src) =============="
 
 test_44g() {
+       pdo_lru_clear
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
        mv $DIR1/$tfile-2 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       stat $DIR2/$tfile > /dev/null || error "stat must succeed"
+       PID1=$! ; pdo_sched
+       stat $DIR2/$tfile > /dev/null &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 44g "pdirops: rename tgt vs getattr =============="
 
 test_44h() {
+       pdo_lru_clear
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
        mv $DIR1/$tfile-2 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       ls -lia $DIR2/ > /dev/null
+       PID1=$! ; pdo_sched
+       ls -lia $DIR2/ > /dev/null &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
+       wait $PID2
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -2016,130 +2369,166 @@ run_test 44h "pdirops: rename tgt vs readdir =============="
 # test 44: rename tgt and blocking operations
 test_44i() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+       pdo_lru_clear
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
        mv $DIR1/$tfile-2 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       $LFS mkdir -i 1 $DIR2/$tfile && error "remote mkdir must fail"
+       PID1=$! ; pdo_sched
+       $LFS mkdir -i 1 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1;
                                error "remote mkdir isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "remote mkdir must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 44i "pdirops: rename tgt vs remote mkdir"
 
-# test 45: rename src and blocking operations
+# test 45: rename,mkdir doesn't fail with -EEXIST
 test_45a() {
-       touch $DIR1/$tfile
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
-       mv $DIR1/$tfile $DIR1/$tfile-2 &
-       PID1=$!
-       sleep 1
-       mkdir $DIR2/$tfile || error "mkdir must succeed"
-       check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
-       rm -rf $DIR/$tfile*
+       for i in {1..1000}; do
+               mkdir $DIR1/$tdir || error "mkdir $tdir failed"
+               mrename $DIR2/$tdir $DIR2/$tdir.$i > /dev/null ||
+                       error "mrename to $tdir.$i failed"
+       done
+       rm -rf $DIR/$tdir*
        return 0
 }
-run_test 45a "pdirops: rename src vs mkdir =============="
+run_test 45a "rename,mkdir doesn't return -EEXIST =============="
 
 test_45b() {
+       pdo_lru_clear
        touch $DIR1/$tfile
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mv $DIR1/$tfile $DIR1/$tfile-2 &
-       PID1=$!
-       sleep 1
-       $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c || error "create must succeed"
+       PID1=$! ; pdo_sched
+       $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "create must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 45b "pdirops: rename src vs create =============="
 
 test_45c() {
+       pdo_lru_clear
        touch $DIR1/$tfile
        touch $DIR1/$tfile-3
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mv $DIR1/$tfile $DIR1/$tfile-2 &
-       PID1=$!
-       sleep 1
-       link $DIR2/$tfile-3 $DIR2/$tfile || error "link must succeed"
+       PID1=$! ; pdo_sched
+       link $DIR2/$tfile-3 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "link must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 45c "pdirops: rename src vs link =============="
 
 test_45d() {
+       pdo_lru_clear
        touch $DIR1/$tfile
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mv $DIR1/$tfile $DIR1/$tfile-2 &
-       PID1=$!
-       sleep 1
-       rm $DIR2/$tfile && error "unlink must fail"
+       PID1=$! ; pdo_sched
+       rm $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "unlink must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 45d "pdirops: rename src vs unlink =============="
 
 test_45e() {
+       pdo_lru_clear
        touch $DIR1/$tfile
        touch $DIR1/$tfile-3
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mv $DIR1/$tfile $DIR1/$tfile-2 &
-       PID1=$!
-       sleep 1
-       mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
+       PID1=$! ; pdo_sched
+       mv $DIR2/$tfile-3 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 45e "pdirops: rename src and rename (tgt) =============="
 
 test_45f() {
+       pdo_lru_clear
        touch $DIR1/$tfile
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mv $DIR1/$tfile $DIR1/$tfile-2 &
-       PID1=$!
-       sleep 1
-       mv $DIR2/$tfile $DIR2/$tfile-3 && error "rename must fail"
+       PID1=$! ; pdo_sched
+       mv $DIR2/$tfile $DIR2/$tfile-3 &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "rename must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 45f "pdirops: rename src and rename (src) =============="
 
 test_45g() {
+       pdo_lru_clear
        touch $DIR1/$tfile
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mv $DIR1/$tfile $DIR1/$tfile-2 &
-       PID1=$!
-       sleep 1
-       stat $DIR2/$tfile > /dev/null && error "stat must fail"
+       PID1=$! ; pdo_sched
+       stat $DIR2/$tfile > /dev/null &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "stat must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 45g "pdirops: rename src vs getattr =============="
 
 test_45h() {
+       pdo_lru_clear
        touch $DIR1/$tfile
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mv $DIR1/$tfile $DIR1/$tfile-2 &
-       PID1=$!
-       sleep 1
-       ls -lia $DIR2/ > /dev/null
+       PID1=$! ; pdo_sched
+       ls -lia $DIR2/ > /dev/null &
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
+       wait $PID2
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -2147,15 +2536,20 @@ run_test 45h "pdirops: unlink vs readdir =============="
 
 test_45i() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+       pdo_lru_clear
        touch $DIR1/$tfile
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mv $DIR1/$tfile $DIR1/$tfile-2 &
-       PID1=$!
-       sleep 1
-       $LFS mkdir -i 1 $DIR2/$tfile || error "create remote dir must succeed"
+       PID1=$! ; pdo_sched
+       $LFS mkdir -i 1 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1;
                                error "create remote dir isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "create remote dir must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -2163,115 +2557,154 @@ run_test 45i "pdirops: rename src vs remote mkdir"
 
 # test 46: link and blocking operations
 test_46a() {
+       pdo_lru_clear
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        link $DIR1/$tfile-2 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       mkdir $DIR2/$tfile && error "mkdir must fail"
+       PID1=$! ; pdo_sched
+       mkdir $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 46a "pdirops: link vs mkdir =============="
 
 test_46b() {
+       pdo_lru_clear
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        link $DIR1/$tfile-2 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
+       PID1=$! ; pdo_sched
+       $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 46b "pdirops: link vs create =============="
 
 test_46c() {
+       pdo_lru_clear
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        link $DIR1/$tfile-2 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       link $DIR2/$tfile $DIR2/$tfile && error "link must fail"
+       PID1=$! ; pdo_sched
+       link $DIR2/$tfile $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 46c "pdirops: link vs link =============="
 
 test_46d() {
+       pdo_lru_clear
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        link $DIR1/$tfile-2 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       rm $DIR2/$tfile || error "unlink must succeed"
+       PID1=$! ; pdo_sched
+       rm $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "unlink must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 46d "pdirops: link vs unlink =============="
 
 test_46e() {
+       pdo_lru_clear
        touch $DIR1/$tfile-2
        touch $DIR1/$tfile-3
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        link $DIR1/$tfile-2 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
+       PID1=$! ; pdo_sched
+       mv $DIR2/$tfile-3 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 46e "pdirops: link and rename (tgt) =============="
 
 test_46f() {
+       pdo_lru_clear
        touch $DIR1/$tfile-2
        touch $DIR1/$tfile-3
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        link $DIR1/$tfile-2 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       mv $DIR2/$tfile $DIR2/$tfile-3 || error "rename must succeed"
+       PID1=$! ; pdo_sched
+       mv $DIR2/$tfile $DIR2/$tfile-3 &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 46f "pdirops: link and rename (src) =============="
 
 test_46g() {
+       pdo_lru_clear
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        link $DIR1/$tfile-2 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       stat $DIR2/$tfile > /dev/null || error "stat must succeed"
+       PID1=$! ; pdo_sched
+       stat $DIR2/$tfile > /dev/null &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
 run_test 46g "pdirops: link vs getattr =============="
 
 test_46h() {
+       pdo_lru_clear
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        link $DIR1/$tfile-2 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       ls -lia $DIR2/ > /dev/null
-       check_pdo_conflict $PID1 && { wait $PID1;
-                       error "readdir isn't blocked"; }
+       PID1=$! ; pdo_sched
+       ls -lia $DIR2/ > /dev/null &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
+       check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
+       wait $PID2
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -2279,15 +2712,20 @@ run_test 46h "pdirops: link vs readdir =============="
 
 test_46i() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+       pdo_lru_clear
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        link $DIR1/$tfile-2 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       $LFS mkdir -i 1 $DIR2/$tfile && error "remote mkdir must fail"
+       PID1=$! ; pdo_sched
+       $LFS mkdir -i 1 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1;
                                error "remote mkdir isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "remote mkdir must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -2297,12 +2735,17 @@ run_test 46i "pdirops: link vs remote mkdir"
 test_47a() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       pdo_lru_clear
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $LFS mkdir -i 1 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       mkdir $DIR2/$tfile && error "mkdir must fail"
+       PID1=$! ; pdo_sched
+       mkdir $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -2311,13 +2754,19 @@ run_test 47a "pdirops: remote mkdir vs mkdir"
 test_47b() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       pdo_lru_clear
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $LFS mkdir -i 1 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       multiop $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
+       PID1=$! ; pdo_sched
+       sleep 1 # please do not remove this sleep, see LU-10754
+       multiop $DIR2/$tfile oO_CREAT:O_EXCL:c &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1;
                                        error "create isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -2325,14 +2774,19 @@ run_test 47b "pdirops: remote mkdir vs create"
 
 test_47c() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+       pdo_lru_clear
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $LFS mkdir -i 1 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
+       PID1=$! ; pdo_sched
+       link $DIR2/$tfile-2 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -2340,14 +2794,19 @@ run_test 47c "pdirops: remote mkdir vs link"
 
 test_47d() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+       pdo_lru_clear
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $LFS mkdir -i 1 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       rmdir $DIR2/$tfile || error "unlink must succeed"
+       PID1=$! ; pdo_sched
+       rmdir $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1;
                                        error "unlink isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "rmdir must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -2355,15 +2814,20 @@ run_test 47d "pdirops: remote mkdir vs unlink"
 
 test_47e() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+       pdo_lru_clear
        touch $DIR1/$tfile-2
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $LFS mkdir -i 1 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       mv -T $DIR2/$tfile-2 $DIR2/$tfile && error "rename must fail"
+       PID1=$! ; pdo_sched
+       mv -T $DIR2/$tfile-2 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1;
                                        error "rename isn't blocked"; }
+       wait $PID2 ; [ $? -ne 0 ] || error "rename must fail"
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -2371,14 +2835,19 @@ run_test 47e "pdirops: remote mkdir and rename (tgt)"
 
 test_47f() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+       pdo_lru_clear
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $LFS mkdir -i 1 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
+       PID1=$! ; pdo_sched
+       mv $DIR2/$tfile $DIR2/$tfile-2 &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1;
                                        error "rename isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -2386,14 +2855,21 @@ run_test 47f "pdirops: remote mkdir and rename (src)"
 
 test_47g() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+       sync
+       sync_all_data
+       pdo_lru_clear
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
-       do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $LFS mkdir -i 1 $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       stat $DIR2/$tfile > /dev/null || error "stat must succeed"
+       PID1=$! ; pdo_sched
+       stat $DIR2/$tfile > /dev/null &
+       PID2=$! ; pdo_sched
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1;
                                        error "getattr isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -2434,7 +2910,10 @@ test_51a() {
                error "dd $DIR1/$tfile failed"
 
        # MULTIOP proc should be able to read enough bytes and exit
-       sleep 2
+       for ((i = 0; i < 6; i++)); do
+               sleep 1
+               kill -0 $pid || break
+       done
        kill -0 $pid 2> /dev/null && error "multiop is still there"
        cmp $origfile $DIR2/$tfile || error "$origfile and $DIR2/$tfile differs"
 
@@ -2443,36 +2922,39 @@ test_51a() {
 run_test 51a "layout lock: refresh layout should work"
 
 test_51b() {
-       [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.59) ]] ||
-               { skip "Need MDS version at least 2.3.59"; return 0; }
+       [[ "$MDS1_VERSION" -ge $(version_code 2.3.59) ]] ||
+               skip "Need MDS version at least 2.3.59"
 
        local tmpfile=`mktemp`
 
-       # create an empty file
-       $MCREATE $DIR1/$tfile || error "mcreate $DIR1/$tfile failed"
+       $LFS setstripe -E 1M -c 1 -E -1 --extension-size 64M $DIR1/$tfile ||
+               error "Create $DIR1/$tfile failed"
+
+       dd if=/dev/zero of=$DIR1/$tfile bs=1k count=1 conv=notrunc ||
+               error "dd $DIR1/$tfile failed"
 
        # delay glimpse so that layout has changed when glimpse finish
 #define OBD_FAIL_GLIMPSE_DELAY 0x1404
-       $LCTL set_param fail_loc=0x1404
+       $LCTL set_param fail_loc=0x1404 fail_val=4
        stat -c %s $DIR2/$tfile |tee $tmpfile &
        local pid=$!
-       sleep 1
+       sleep 0.2
 
-       # create layout of testing file
-       dd if=/dev/zero of=$DIR1/$tfile bs=1k count=1 conv=notrunc >/dev/null ||
+       # extend layout of testing file
+       dd if=/dev/zero of=$DIR1/$tfile bs=1M count=1 seek=2 conv=notrunc ||
                error "dd $DIR1/$tfile failed"
 
        wait $pid
        local fsize=$(cat $tmpfile)
 
-       [ x$fsize = x1024 ] || error "file size is $fsize, should be 1024"
+       [ x$fsize = x3145728 ] || error "file size is $fsize, should be 3145728"
 
        rm -f $DIR1/$tfile $tmpfile
 }
 run_test 51b "layout lock: glimpse should be able to restart if layout changed"
 
 test_51c() {
-       [ $OSTCOUNT -ge 2 ] || { skip "need at least 2 osts"; return; }
+       [ $OSTCOUNT -ge 2 ] || { skip "needs >= 2 osts"; return; }
 
        # set default layout to have 1 stripe
        mkdir $DIR1/$tdir
@@ -2493,14 +2975,14 @@ test_51c() {
 
        # write something to the file, it should be blocked on fetching layout
        dd if=/dev/zero of=$DIR2/$tdir/$tfile bs=1k count=1 conv=notrunc
-       local stripecnt=$($LFS getstripe -c $DIR2/$tdir/$tfile)
+       local stripe_count=$($LFS getstripe -c $DIR2/$tdir/$tfile)
        wait $pid
 
        # lod_qos.c::min_stripe_count() allows setstripe with a default stripe
        # count to succeed with only 3/4 of the number of stripes (rounded up),
        # so creating striped files does not fail if an OST is offline or full
-       [ $stripecnt -ge $((OSTCOUNT - $OSTCOUNT / 4)) ] ||
-               error "layout wrong: getstripe -c $stripecnt < $OSTCOUNT * 3/4"
+       [ $stripe_count -ge $((OSTCOUNT - $OSTCOUNT / 4)) ] ||
+               error "bad layout: getstripe -c $stripe_count < $OSTCOUNT * 3/4"
 
        rm -fr $DIR1/$tdir
 }
@@ -2519,19 +3001,40 @@ test_51d() {
        local br=$(grep -A 10 $tfile /proc/$PID/smaps | awk '/^Rss/{print $2}')
        echo "Before revoking layout lock: $br KB mapped"
 
-       # delete the file will revoke layout lock
-       rm -f $DIR2/$tfile
+       # cancel layout lock manually
+       cancel_lru_locks mdc
 
        # rss after revoking
        local ar=$(grep -A 10 $tfile /proc/$PID/smaps | awk '/^Rss/{print $2}')
 
        kill -USR1 $PID
-       wait $PID || error
+       wait $PID || error "wait PID $PID failed"
 
        [ $ar -eq 0 ] || error "rss before: $br, after $ar, some pages remained"
 }
 run_test 51d "layout lock: losing layout lock should clean up memory map region"
 
+test_51e() {
+       local pid
+
+       $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eW_E+eUc &
+       pid=$!
+       sleep 1
+
+       $LFS getstripe $DIR2/$tfile
+       kill -USR1 $pid
+       wait $pid || error "multiop failed"
+
+       $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
+       pid=$!
+       sleep 1
+
+       $LFS getstripe $DIR2/$tfile
+       kill -USR1 $pid
+       wait $pid || error "multiop failed"
+}
+run_test 51e "lfs getstripe does not break leases, part 2"
+
 test_54_part1()
 {
        echo "==> rename vs getattr vs setxattr should not deadlock"
@@ -2685,12 +3188,11 @@ test_55d()
 run_test 55d "rename file vs link"
 
 test_60() {
-       local MDSVER=$(lustre_build_version $SINGLEMDS)
-       [ $(version_code $MDSVER) -lt $(version_code 2.3.0) ] &&
-               skip "MDS version $MDSVER must be >= 2.3.0" && return 0
+       [ $MDS1_VERSION -lt $(version_code 2.3.0) ] &&
+               skip "MDS version must be >= 2.3.0"
 
        # Create a file
-       test_mkdir -p $DIR1/$tdir
+       test_mkdir $DIR1/$tdir
        file1=$DIR1/$tdir/file
        file2=$DIR2/$tdir/file
 
@@ -2773,22 +3275,19 @@ test_70b() { # LU-2781
 run_test 70b "remove files after calling rm_entry"
 
 test_71a() {
-       local server_version=$(lustre_version_code $SINGLEMDS)
-
-       [[ $server_version -lt $(version_code 2.1.6) ]] &&
-               skip "Need MDS version at least 2.1.6" && return
+       [[ "$MDS1_VERSION" -lt $(version_code 2.1.6) ]] &&
+               skip "Need MDS version at least 2.1.6"
 
        # Patch not applied to 2.2 and 2.3 branches
-       [[ $server_version -ge $(version_code 2.2.0) ]] &&
-       [[ $server_version -lt $(version_code 2.4.0) ]] &&
-               skip "Need MDS version earlier than 2.2.0 or at least 2.4.0" &&
-                       return
+       [[ "$MDS1_VERSION" -ge $(version_code 2.2.0) ]] &&
+       [[ "$MDS1_VERSION" -lt $(version_code 2.4.0) ]] &&
+               skip "Need MDS version earlier than 2.2.0 or at least 2.4.0"
 
        checkfiemap --test ||
-               { skip "checkfiemap not runnable: $?" && return; }
+               skip "checkfiemap not runnable: $?"
        # write data this way: hole - data - hole - data
        dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
-       [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR1/$tfile) + 1)))" = \
+       [ "$(facet_fstype ost$(($($LFS getstripe -i $DIR1/$tfile) + 1)))" = \
                "zfs" ] &&
                skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return 0
        dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
@@ -2817,26 +3316,23 @@ test_71a() {
 run_test 71a "correct file map just after write operation is finished"
 
 test_71b() {
-       local server_version=$(lustre_version_code $SINGLEMDS)
-
-       [[ $server_version -lt $(version_code 2.1.6) ]] &&
-               skip "Need MDS version at least 2.1.6" && return
+       [[ "$MDS1_VERSION" -lt $(version_code 2.1.6) ]] &&
+               skip "Need MDS version at least 2.1.6"
 
        # Patch not applied to 2.2 and 2.3 branches
-       [[ $server_version -ge $(version_code 2.2.0) ]] &&
-       [[ $server_version -lt $(version_code 2.4.0) ]] &&
-               skip "Need MDS version earlier than 2.2.0 or at least 2.4.0" &&
-                       return
-       [[ $OSTCOUNT -ge 2 ]] || { skip "need at least 2 osts"; return; }
+       [[ "$MDS1_VERSION" -ge $(version_code 2.2.0) ]] &&
+       [[ "$MDS1_VERSION" -lt $(version_code 2.4.0) ]] &&
+               skip "Need MDS version earlier than 2.2.0 or at least 2.4.0"
+       [[ $OSTCOUNT -ge 2 ]] || skip "needs >= 2 OSTs"
 
        checkfiemap --test ||
-               { skip "error $?: checkfiemap failed" && return; }
+               skip "error $?: checkfiemap failed"
 
        mkdir -p $DIR1/$tdir
 
        $LFS setstripe -c -1 $DIR1/$tdir || error "setstripe failed"
        dd if=/dev/urandom of=$DIR1/$tdir/$tfile bs=40K count=1
-       [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR1/$tdir/$tfile) + 1)))" = \
+       [ "$(facet_fstype ost$(($($LFS getstripe -i $DIR1/$tdir/$tfile) + 1)))" = \
                "zfs" ] &&
                skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return 0
        checkfiemap $DIR1/$tdir/$tfile 40960 || error "checkfiemap failed"
@@ -2904,8 +3400,8 @@ test_73() {
 run_test 73 "getxattr should not cause xattr lock cancellation"
 
 test_74() {
-       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.93) ] &&
-               skip "Need MDS version at least 2.4.93" && return
+       [ "$MDS1_VERSION" -lt $(version_code 2.4.93) ] &&
+               skip "Need MDS version at least 2.4.93"
 
        dd if=/dev/zero of=$DIR1/$tfile-1 bs=1K count=1
        dd if=/dev/zero of=$DIR1/$tfile-2 bs=1K count=1
@@ -2936,10 +3432,10 @@ test_75() {
 run_test 75 "osc: upcall after unuse lock==================="
 
 test_76() { #LU-946
-       [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
-               skip "Need MDS version at least 2.5.53" && return
+       [[ "$MDS1_VERSION" -lt $(version_code 2.5.53) ]] &&
+               skip "Need MDS version at least 2.5.53"
 
-       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       remote_mds_nodsh && skip "remote MDS with nodsh"
        local fcount=$((MDSCOUNT * 256))
        declare -a fd_list
        declare -a fid_list
@@ -2951,7 +3447,7 @@ test_76() { #LU-946
        fi
 
        rm -rf $DIR/$tdir
-       test_mkdir -p $DIR/$tdir
+       test_mkdir $DIR/$tdir
 
        # drop all open locks and close any cached "open" files on the client
        cancel_lru_locks mdc
@@ -3029,36 +3525,57 @@ nrs_write_read() {
        chmod 777 $dir
 
        do_nodes $CLIENTS $myRUNAS \
-               dd if=/dev/zero of="$dir/nrs_r_$HOSTNAME" bs=1M count=$n ||
+               dd if=/dev/zero of="$dir/nrs_r_\$HOSTNAME" bs=1M count=$n ||
                error "dd at 0 on client failed (1)"
 
-       for ((i = 0; i < $n; i++)); do
-               do_nodes $CLIENTS $myRUNAS dd if=/dev/zero \
-                       of="$dir/nrs_w_$HOSTNAME" bs=1M seek=$i count=1 ||
-                        error "dd at ${i}MB on client failed (2)" &
-               local pids_w[$i]=$!
-       done
+       do_nodes $CLIENTS $myRUNAS \
+               "declare -a pids_w;
+               for ((i = 0; i < $n; i++)); do
+                       dd if=/dev/zero of=$dir/nrs_w_\$HOSTNAME bs=1M \
+seek=\\\$i count=1 conv=notrunc &
+                       pids_w[\\\$i]=\\\$!;
+               done;
+               rc_w=0;
+               for ((i = 0; i < $n; i++)); do
+                       wait \\\${pids_w[\\\$i]};
+                       newrc=\\\$?;
+                       [ \\\$newrc -gt \\\$rc_w ] && rc_w=\\\$newrc;
+               done;
+               exit \\\$rc_w" &
+       local pid_w=$!
        do_nodes $CLIENTS sync;
        cancel_lru_locks osc
 
-       for ((i = 0; i < $n; i++)); do
-               do_nodes $CLIENTS $myRUNAS dd if="$dir/nrs_w_$HOSTNAME" \
-                       of=/dev/zero bs=1M seek=$i count=1 > /dev/null ||
-                       error "dd at ${i}MB on client failed (3)" &
-               local pids_r[$i]=$!
-       done
+       do_nodes $CLIENTS $myRUNAS \
+               "declare -a pids_r;
+               for ((i = 0; i < $n; i++)); do
+                       dd if=$dir/nrs_r_\$HOSTNAME bs=1M of=/dev/null \
+seek=\\\$i count=1 &
+                       pids_r[\\\$i]=\\\$!;
+               done;
+               rc_r=0;
+               for ((i = 0; i < $n; i++)); do
+                       wait \\\${pids_r[\\\$i]};
+                       newrc=\\\$?;
+                       [ \\\$newrc -gt \\\$rc_r ] && rc_r=\\\$newrc;
+               done;
+               exit \\\$rc_r" &
+       local pid_r=$!
        cancel_lru_locks osc
 
-       for ((i = 0; i < $n; i++)); do
-               wait ${pids_w[$i]}
-               wait ${pids_r[$i]}
-       done
-       rm -rf $dir || error "rm -rf $dir failed"
+       wait $pid_w || error "dd (write) failed (2)"
+       wait $pid_r || error "dd (read) failed (3)"
+       rm -rvf $dir || error "rm -rf $dir failed"
 }
 
 test_77a() { #LU-3266
+       local rc
+
        oss=$(comma_list $(osts_nodes))
-       do_nodes $oss lctl set_param ost.OSS.*.nrs_policies="fifo"
+       do_nodes $oss lctl set_param ost.OSS.*.nrs_policies="fifo" ||
+               rc=$?
+       [[ $rc -eq 3 ]] && skip "no NRS exists" && return
+       [[ $rc -ne 0 ]] && error "failed to set fifo policy"
        nrs_write_read
 
        return 0
@@ -3066,21 +3583,29 @@ test_77a() { #LU-3266
 run_test 77a "check FIFO NRS policy"
 
 test_77b() { #LU-3266
+       local rc
+
        oss=$(comma_list $(osts_nodes))
 
        do_nodes $oss lctl set_param ost.OSS.*.nrs_policies="crrn" \
-                          ost.OSS.*.nrs_crrn_quantum=1
+               ost.OSS.*.nrs_crrn_quantum=1 || rc=$?
+       [[ $rc -eq 3 ]] && skip "no NRS exists" && return
+       [[ $rc -ne 0 ]] && error "failed to set crrn_quantum to 1"
 
        echo "policy: crr-n, crrn_quantum 1"
        nrs_write_read
 
-       do_nodes $oss lctl set_param ost.OSS.*.nrs_crrn_quantum=64
+       do_nodes $oss lctl set_param \
+               ost.OSS.*.nrs_crrn_quantum=64 || rc=$?
+       [[ $rc -ne 0 ]] && error "failed to set crrn_quantum to 64"
 
        echo "policy: crr-n, crrn_quantum 64"
        nrs_write_read
 
        # cleanup
-       do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
+       do_nodes $oss lctl set_param \
+               ost.OSS.ost_io.nrs_policies="fifo" || rc=$?
+       [[ $rc -ne 0 ]] && error "failed to set fifo policy"
        return 0
 }
 run_test 77b "check CRR-N NRS policy"
@@ -3091,37 +3616,49 @@ orr_trr() {
        oss=$(comma_list $(osts_nodes))
 
        do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies=$policy \
-                                    ost.OSS.*.nrs_"$policy"_quantum=1 \
-                                    ost.OSS.*.nrs_"$policy"_offset_type="physical" \
-                                    ost.OSS.*.nrs_"$policy"_supported="reads"
+               ost.OSS.*.nrs_"$policy"_quantum=1 \
+               ost.OSS.*.nrs_"$policy"_offset_type="physical" \
+               ost.OSS.*.nrs_"$policy"_supported="reads" || return $?
 
-       echo "policy: $policy, ${policy}_quantum 1, ${policy}_offset_type physical, ${policy}_supported reads"
+       echo "policy: $policy, ${policy}_quantum 1, ${policy}_offset_type " \
+               "physical, ${policy}_supported reads"
        nrs_write_read
 
-       do_nodes $oss lctl set_param ost.OSS.*.nrs_${policy}_supported="writes" \
-                                    ost.OSS.*.nrs_${policy}_quantum=64
+       do_nodes $oss lctl set_param \
+               ost.OSS.*.nrs_${policy}_supported="writes" \
+               ost.OSS.*.nrs_${policy}_quantum=64 || return $?
 
-       echo "policy: $policy, ${policy}_quantum 64, ${policy}_offset_type physical, ${policy}_supported writes"
+       echo "policy: $policy, ${policy}_quantum 64, ${policy}_offset_type " \
+               "physical, ${policy}_supported writes"
        nrs_write_read
 
-       do_nodes $oss lctl set_param ost.OSS.*.nrs_${policy}_supported="reads_and_writes" \
-                                    ost.OSS.*.nrs_${policy}_offset_type="logical"
-       echo "policy: $policy, ${policy}_quantum 64, ${policy}_offset_type logical, ${policy}_supported reads_and_writes"
+       do_nodes $oss lctl set_param \
+               ost.OSS.*.nrs_${policy}_supported="reads_and_writes" \
+               ost.OSS.*.nrs_${policy}_offset_type="logical" || return $?
+       echo "policy: $policy, ${policy}_quantum 64, ${policy}_offset_type " \
+               "logical, ${policy}_supported reads_and_writes"
        nrs_write_read
 
        # cleanup
-       do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
+       do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo" ||
+               return $?
        return 0
 }
 
 test_77c() { #LU-3266
-       orr_trr "orr"
+       local rc
+       orr_trr "orr" || rc=$?
+       [[ $rc -eq 3 ]] && skip "no NRS exists" && return
+       [[ $rc -ne 0 ]] && error "orr_trr failed rc:$rc"
        return 0
 }
 run_test 77c "check ORR NRS policy"
 
 test_77d() { #LU-3266
-       orr_trr "trr"
+       local rc
+       orr_trr "trr" || rc=$?
+       [[ $rc -eq 3 ]] && skip "no NRS exists" && return
+       [[ $rc -ne 0 ]] && error "orr_trr failed rc:$rc"
        return 0
 }
 run_test 77d "check TRR nrs policy"
@@ -3153,51 +3690,59 @@ tbf_verify() {
        local client1=${CLIENT1:-$(hostname)}
        local myRUNAS="$3"
 
+       local np=$(check_cpt_number ost1)
+       [ $np -gt 0 ] || error "CPU partitions should not be $np."
+       echo "cpu_npartitions on ost1 is $np"
+
        mkdir $dir || error "mkdir $dir failed"
-       $LFS setstripe -c 1 $dir || error "setstripe to $dir failed"
+       $LFS setstripe -c 1 -i 0 $dir || error "setstripe to $dir failed"
        chmod 777 $dir
 
        trap cleanup_tbf_verify EXIT
        echo "Limited write rate: $1, read rate: $2"
        echo "Verify the write rate is under TBF control"
-       local runtime=$(do_node $client1 $myRUNAS dd if=/dev/zero of=$dir/tbf \
-               bs=1M count=100 oflag=direct 2>&1 | awk '/bytes/ {print $6}')
+       local start=$SECONDS
+       do_node $client1 $myRUNAS dd if=/dev/zero of=$dir/tbf \
+               bs=1M count=100 oflag=direct 2>&1
+       local runtime=$((SECONDS - start + 1))
        local rate=$(bc <<< "scale=6; 100 / $runtime")
        echo "Write runtime is $runtime s, speed is $rate IOPS"
 
-       # verify the write rate does not exceed 110% of TBF limited rate
-       [ $(bc <<< "$rate < 1.1 * $1") -eq 1 ] ||
-               error "The write rate ($rate) exceeds 110% of preset rate ($1)"
+       # verify the write rate does not exceed TBF rate limit
+       [ $(bc <<< "$rate < 1.1 * $np * $1") -eq 1 ] ||
+               error "The write rate ($rate) exceeds 110% of rate limit ($1 * $np)"
 
        cancel_lru_locks osc
 
        echo "Verify the read rate is under TBF control"
-       runtime=$(do_node $client1 $myRUNAS dd if=$dir/tbf of=/dev/null \
-               bs=1M count=100 iflag=direct 2>&1 | awk '/bytes/ {print $6}')
+       start=$SECONDS
+       do_node $client1 $myRUNAS dd if=$dir/tbf of=/dev/null \
+               bs=1M count=100 iflag=direct 2>&1
+       runtime=$((SECONDS - start + 1))
        rate=$(bc <<< "scale=6; 100 / $runtime")
        echo "Read runtime is $runtime s, speed is $rate IOPS"
 
-       # verify the read rate does not exceed 110% of TBF limited rate
-       [ $(bc <<< "$rate < 1.1 * $2") -eq 1 ] ||
-               error "The read rate ($rate) exceeds 110% of preset rate ($2)"
+       # verify the read rate does not exceed TBF rate limit
+       [ $(bc <<< "$rate < 1.1 * $np * $2") -eq 1 ] ||
+               error "The read rate ($rate) exceeds 110% of rate limit ($2 * $np)"
 
        cancel_lru_locks osc
        cleanup_tbf_verify || error "rm -rf $dir failed"
 }
 
 test_77e() {
-       local server_version=$(lustre_version_code ost1)
-       [[ $server_version -ge $(version_code 2.7.58) ]] ||
-               { skip "Need server version newer than 2.7.57"; return 0; }
+       local rc
 
        oss=$(comma_list $(osts_nodes))
 
-       do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid"
-       [ $? -ne 0 ] && error "failed to set TBF policy"
+       do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid" ||
+               rc=$?
+       [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
+       [[ $rc -ne 0 ]] && error "failed to set TBF NID policy"
 
        local idis
        local rateis
-       if [ $(lustre_version_code ost1) -ge $(version_code 2.8.54) ]; then
+       if [ "$OST1_VERSION" -ge $(version_code 2.8.54) ]; then
                idis="nid="
                rateis="rate="
        fi
@@ -3232,26 +3777,28 @@ test_77e() {
 run_test 77e "check TBF NID nrs policy"
 
 test_77f() {
-       local server_version=$(lustre_version_code ost1)
-       [[ $server_version -ge $(version_code 2.7.58) ]] ||
-               { skip "Need server version newer than 2.7.57"; return 0; }
+       local rc
 
        oss=$(comma_list $(osts_nodes))
 
+       do_nodes $oss $LCTL set_param \
+               ost.OSS.ost_io.nrs_policies="tbf\ jobid" || rc=$?
+       [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
+       [[ $rc -ne 0 ]] && error "failed to set TBF JOBID policy"
+
        # Configure jobid_var
        local saved_jobid_var=$($LCTL get_param -n jobid_var)
+       rc=$?
+       [[ $rc -eq 3 ]] && skip "jobid_var not found" && return
+       [[ $rc -ne 0 ]] && error "failed to get param jobid_var"
        if [ $saved_jobid_var != procname_uid ]; then
-               set_conf_param_and_check client                 \
-                       "$LCTL get_param -n jobid_var"          \
-                       "$FSNAME.sys.jobid_var" procname_uid
+               set_persistent_param_and_check client \
+                       "jobid_var" "$FSNAME.sys.jobid_var" procname_uid
        fi
 
-       do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ jobid"
-       [ $? -ne 0 ] && error "failed to set TBF policy"
-
        local idis
        local rateis
-       if [ $(lustre_version_code ost1) -ge $(version_code 2.8.54) ]; then
+       if [ "$OST1_VERSION" -ge $(version_code 2.8.54) ]; then
                idis="jobid="
                rateis="rate="
        fi
@@ -3281,31 +3828,32 @@ test_77f() {
        nrs_write_read "$RUNAS"
 
        local current_jobid_var=$($LCTL get_param -n jobid_var)
+       [[ $? -ne 0 ]] && error "failed to get param jobid_var"
        if [ $saved_jobid_var != $current_jobid_var ]; then
-               set_conf_param_and_check client                 \
-                       "$LCTL get_param -n jobid_var"          \
-                       "$FSNAME.sys.jobid_var" $saved_jobid_var
+               set_persistent_param_and_check client \
+                       "jobid_var" "$FSNAME.sys.jobid_var" $saved_jobid_var
        fi
        return 0
 }
 run_test 77f "check TBF JobID nrs policy"
 
 test_77g() {
-       local server_version=$(lustre_version_code ost1)
-       [[ $server_version -ge $(version_code 2.7.58) ]] ||
-               { skip "Need server version newer than 2.7.57"; return 0; }
+       local rc=0
 
        oss=$(comma_list $(osts_nodes))
 
-       do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid"
-       [ $? -ne 0 ] && error "failed to set TBF policy"
+       do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid" ||
+               rc=$?
+       [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
+       [[ $rc -ne 0 ]] && error "failed to set TBF NID policy"
 
-       do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ jobid"
-       [ $? -ne 0 ] && error "failed to set TBF policy"
+       do_nodes $oss lctl set_param \
+               ost.OSS.ost_io.nrs_policies="tbf\ jobid" || rc=$?
+       [[ $rc -ne 0 ]] && error "failed to set TBF JOBID policy"
 
        local idis
        local rateis
-       if [ $(lustre_version_code ost1) -ge $(version_code 2.8.54) ]; then
+       if [ "$OST1_VERSION" -ge $(version_code 2.8.54) ]; then
                idis="jobid="
                rateis="rate="
        fi
@@ -3322,8 +3870,8 @@ test_77g() {
 run_test 77g "Change TBF type directly"
 
 test_77h() {
-       [ $(lustre_version_code ost1) -ge $(version_code 2.8.55) ] ||
-               { skip "Need OST version at least 2.8.55"; return 0; }
+       [ "$OST1_VERSION" -ge $(version_code 2.8.55) ] ||
+               skip "Need OST version at least 2.8.55"
 
        local old_policy=$(do_facet ost1 \
                lctl get_param ost.OSS.ost_io.nrs_policies)
@@ -3377,8 +3925,8 @@ tbf_rule_check()
 }
 
 test_77i() {
-    [ $(lustre_version_code ost1) -ge $(version_code 2.8.55) ] ||
-               { skip "Need OST version at least 2.8.55"; return 0; }
+       [ "$OST1_VERSION" -ge $(version_code 2.8.55) ] ||
+               skip "Need OST version at least 2.8.55"
 
        for i in $(seq 1 $OSTCOUNT)
        do
@@ -3432,7 +3980,10 @@ run_test 77i "Change rank of TBF rule"
 test_77j() {
        local idis
        local rateis
-       if [ $(lustre_version_code ost1) -ge $(version_code 2.8.60) ]; then
+
+       [ "$OST1_VERSION" -ge $(version_code 2.9.53) ] ||
+               skip "Need OST version at least 2.9.53"
+       if [ "$OST1_VERSION" -ge $(version_code 2.8.60) ]; then
                idis="opcode="
                rateis="rate="
        fi
@@ -3459,9 +4010,60 @@ test_77j() {
 }
 run_test 77j "check TBF-OPCode NRS policy"
 
+test_id() {
+       local idstr="${1}id"
+       local policy="${idstr}={$2}"
+       local rate="rate=$3"
+
+       do_nodes $(comma_list $(osts_nodes)) \
+               lctl set_param jobid_var=procname_uid \
+                       ost.OSS.ost_io.nrs_policies="tbf\ ${idstr}" \
+                       ost.OSS.ost_io.nrs_tbf_rule="start\ ost_${idstr}\ ${policy}\ ${rate}"
+       [ $? -ne 0 ] && error "failed to set tbf ${idstr} policy"
+
+       nrs_write_read "runas $4"
+       tbf_verify $3 $3 "runas $4"
+
+       do_nodes $(comma_list $(osts_nodes)) \
+               lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ost_${idstr}" \
+                       ost.OSS.ost_io.nrs_policies="fifo"
+
+       # sleep 3 seconds to wait the tbf policy stop completely,
+       # or the next test case is possible get -eagain when
+       # setting the tbf policy
+       sleep 3
+}
+
+test_77ja(){
+       if [ "$OST1_VERSION" -lt $(version_code 2.11.50) ]; then
+               skip "Need OST version at least 2.11.50"
+       fi
+
+       test_id "u" "500" "5" "-u 500"
+       test_id "g" "500" "5" "-u 500 -g 500"
+}
+run_test 77ja "check TBF-UID/GID NRS policy"
+
+cleanup_77k()
+{
+       local rule_lists=$1
+       local old_nrs=$2
+
+       trap 0
+       for rule in $rule_lists; do
+               do_nodes $(comma_list $(osts_nodes)) \
+                       lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ $rule"
+       done
+
+       do_nodes $(comma_list $(osts_nodes)) \
+               lctl set_param ost.OSS.ost_io.nrs_policies="$old_nrs"
+
+       sleep 3
+}
+
 test_77k() {
-       [[ $(lustre_version_code ost1) -ge $(version_code 2.9.53) ]] ||
-               { skip "Need OST version at least 2.9.53"; return 0; }
+       [[ "$OST1_VERSION" -ge $(version_code 2.9.53) ]] ||
+               skip "Need OST version at least 2.9.53"
 
        do_nodes $(comma_list $(osts_nodes)) \
                lctl set_param ost.OSS.ost_io.nrs_policies="tbf" \
@@ -3501,19 +4103,61 @@ test_77k() {
        tbf_verify 10 10 "$RUNAS"
        tbf_verify 20 10
 
+       trap "cleanup_77k \"ext_a ext_b\" \"fifo\"" EXIT
+
+       [[ "$OST1_VERSION" -ge $(version_code 2.10.58) ]] ||
+               skip "Need OST version at least 2.10.58"
+
        do_nodes $(comma_list $(osts_nodes)) \
                lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_a" \
                        ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_b" \
-                       ost.OSS.ost_io.nrs_policies="fifo"
+                       ost.OSS.ost_io.nrs_tbf_rule="start\ ext_ug\ uid={500}\&gid={1000}\ rate=5"
+       nrs_write_read "runas -u 500 -g 1000"
+       tbf_verify 5 5 "runas -u 500 -g 1000"
 
-       sleep 3
+       do_nodes $(comma_list $(osts_nodes)) \
+               lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_ug" \
+                       ost.OSS.ost_io.nrs_tbf_rule="start\ ext_uw\ uid={500}\&opcode={ost_write}\ rate=20" \
+                       ost.OSS.ost_io.nrs_tbf_rule="start\ ext_ur\ uid={500}\&opcode={ost_read}\ rate=10"
+
+       nrs_write_read "runas -u 500"
+       tbf_verify 20 10 "runas -u 500"
+
+       do_nodes $(comma_list $(osts_nodes)) \
+               lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_uw" \
+                       ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_ur" \
+                       ost.OSS.ost_io.nrs_tbf_rule="start\ ext_a\ uid={500},opcode={ost_write}\ rate=20" \
+                       ost.OSS.ost_io.nrs_tbf_rule="start\ ext_b\ uid={500},opcode={ost_read}\ rate=10"
+       nrs_write_read "runas -u 500"
+       tbf_verify 10 10 "runas -u 500"
+       tbf_verify 20 10 "runas -u 500"
+       cleanup_77k "ext_a ext_b" "fifo"
 }
-run_test 77k "check the extended TBF policy with NID/JobID/OPCode expression"
+run_test 77k "check TBF policy with NID/JobID/OPCode expression"
 
 test_77l() {
-       if [ $(lustre_version_code ost1) -lt $(version_code 2.9.54) ]; then
+       [[ "$OST1_VERSION" -ge $(version_code 2.10.56) ]] ||
+               skip "Need OST version at least 2.10.56"
+
+       do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid"
+       do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="tbf"
+
+       local output=$(do_facet ost1 lctl get_param \
+                       ost.OSS.ost_io.nrs_policies | \
+                       awk '/name: tbf/ {print;exit}' | \
+                       awk -F ': ' '{print $2}')
+
+       if [ "$output" != "tbf" ]; then
+               error "The generic TBF output is '$output', not 'tbf'"
+       fi
+
+       do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
+}
+run_test 77l "check the output of NRS policies for generic TBF"
+
+test_77m() {
+       if [ "$OST1_VERSION" -lt $(version_code 2.9.54) ]; then
                skip "Need OST version at least 2.9.54"
-               return 0
        fi
 
        local dir=$DIR/$tdir
@@ -3560,19 +4204,57 @@ test_77l() {
 
        return 0
 }
-run_test 77l "check NRS Delay slows write RPC processing"
+run_test 77m "check NRS Delay slows write RPC processing"
 
-test_78() { #LU-6673
-       local server_version=$(lustre_version_code ost1)
-       [[ $server_version -ge $(version_code 2.7.58) ]] ||
-               { skip "Need server version newer than 2.7.57"; return 0; }
+test_77n() { #LU-10802
+       if [ "$OST1_VERSION" -lt $(version_code 2.10.58) ]; then
+               skip "Need OST version at least 2.10.58"
+       fi
 
+       # Configure jobid_var
+       local saved_jobid_var=$($LCTL get_param -n jobid_var)
+       if [ $saved_jobid_var != procname_uid ]; then
+               set_persistent_param_and_check client \
+                       "jobid_var" "$FSNAME.sys.jobid_var" procname_uid
+       fi
+
+       do_nodes $(comma_list $(osts_nodes)) \
+               lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ jobid" \
+                       ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
+                       ost.OSS.ost_io.nrs_tbf_rule="start\ dd_runas\ jobid={*.$RUNAS_ID}\ rate=20"
+
+       nrs_write_read
+       tbf_verify 20 20 "$RUNAS"
+
+       do_nodes $(comma_list $(osts_nodes)) \
+               lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
+                       ost.OSS.ost_io.nrs_tbf_rule="start\ dd_runas\ jobid={dd.*}\ rate=20"
+
+       nrs_write_read
+       tbf_verify 20 20
+
+       do_nodes $(comma_list $(osts_nodes)) \
+               lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
+                       ost.OSS.ost_io.nrs_policies="fifo"
+
+       sleep 3
+
+       local current_jobid_var=$($LCTL get_param -n jobid_var)
+       if [ $saved_jobid_var != $current_jobid_var ]; then
+               set_persistent_param_and_check client \
+                       "jobid_var" "$FSNAME.sys.jobid_var" $saved_jobid_var
+       fi
+}
+run_test 77n "check wildcard support for TBF JobID NRS policy"
+
+test_78() { #LU-6673
        local rc
 
        oss=$(comma_list $(osts_nodes))
        do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="orr" &
        do_nodes $oss lctl set_param ost.OSS.*.nrs_orr_quantum=1
        rc=$?
+       [[ $rc -eq 3 ]] && skip "no NRS exists" && return
        # Valid return codes are:
        # 0: Tuning succeeded
        # ENODEV: Policy is still stopped
@@ -3589,7 +4271,7 @@ run_test 78 "Enable policy and specify tunings right away"
 
 test_79() {
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
-       test_mkdir -p $DIR/$tdir
+       test_mkdir $DIR/$tdir
 
        # Prevent interference from layout intent RPCs due to
        # asynchronous writeback. These will be tested in 130c below.
@@ -3599,7 +4281,7 @@ test_79() {
                error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
 
 #define OBD_FAIL_MDS_INTENT_DELAY              0x160
-       local mdtidx=$($LFS getstripe -M $DIR/$tdir)
+       local mdtidx=$($LFS getstripe -m $DIR/$tdir)
        local facet=mds$((mdtidx + 1))
        stat $DIR/$tdir
        set_nodes_failloc $(facet_active_host $facet) 0x80000160
@@ -3645,7 +4327,7 @@ test_80a() {
 
        echo "Finish migration, then checking.."
        for file in $(find $DIR1/$tdir); do
-               mdt_index=$($LFS getstripe -M $file)
+               mdt_index=$($LFS getstripe -m $file)
                [ $mdt_index == $MDTIDX ] ||
                        error "$file is not on MDT${MDTIDX}"
        done
@@ -3780,7 +4462,7 @@ test_80b() {
 }
 run_test 80b "Accessing directory during migration"
 
-test_81() {
+test_81a() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
 
        rm -rf $DIR1/$tdir
@@ -3806,11 +4488,85 @@ test_81() {
 
        return 0
 }
-run_test 81 "rename and stat under striped directory"
+run_test 81a "rename and stat under striped directory"
+
+test_81b() {
+       [ $MDSCOUNT -lt 2 ] &&
+               skip "We need at least 2 MDTs for this test"
+
+       local total
+       local setattr_pid
+
+       total=1000
+
+       $LFS mkdir -c $MDSCOUNT $DIR1/$tdir || error "$LFS mkdir"
+       createmany -o $DIR1/$tdir/$tfile. $total || error "createmany"
+
+       (
+               while true; do
+                       touch $DIR1/$tdir
+               done
+       ) &
+       setattr_pid=$!
+
+       for i in $(seq $total); do
+               mrename $DIR2/$tdir/$tfile.$i $DIR2/$tdir/$tfile-new.$i \
+                       > /dev/null
+       done
+
+       kill -9 $setattr_pid
+}
+run_test 81b "rename under striped directory doesn't deadlock"
+
+test_81c() {
+       [ $MDSCOUNT -lt 4 ] && skip_env "needs >= 4 MDTs"
+       [ $MDS1_VERSION -lt $(version_code 2.13.52) ] &&
+               skip "Need MDS version at least 2.13.52"
+
+       # source is local, source parent is remote
+       $LFS mkdir -i 0 $DIR1/${tdir}_src || error "mkdir ${tdir}_src"
+       $LFS mkdir -i 1 $DIR1/${tdir}_tgt || error "mkdir ${tdir}_tgt"
+       $LFS mkdir -i 3 $DIR1/${tdir}_src/sub || error "mkdir sub"
+       $LFS mkdir -i 3 $DIR1/${tdir}_tgt/sub || error "mkdir sub"
+       stat $DIR2/${tdir}_src/sub || error "stat sub failed"
+       mv $DIR1/${tdir}_src/sub $DIR1/${tdir}_tgt/ || error "mv failed"
+       [ -f $DIR2/${tdir}_src/sub ] && error "sub should be gone"
+       rm -rf $DIR1/${tdir}_src $DIR1/${tdir}_tgt
+
+       # source is remote, source parent is local
+       $LFS mkdir -i 3 $DIR1/${tdir}_src || error "mkdir ${tdir}_src"
+       $LFS mkdir -i 1 $DIR1/${tdir}_tgt || error "mkdir ${tdir}_tgt"
+       $LFS mkdir -i 0 $DIR1/${tdir}_src/sub || error "mkdir sub"
+       $LFS mkdir -i 3 $DIR1/${tdir}_tgt/sub || error "mkdir sub"
+       stat $DIR2/${tdir}_src/sub || error "stat sub failed"
+       mv $DIR1/${tdir}_src/sub $DIR1/${tdir}_tgt/ || error "mv failed"
+       [ -f $DIR2/${tdir}_src/sub ] && error "sub should be gone"
+       rm -rf $DIR1/${tdir}_src $DIR1/${tdir}_tgt
+
+       # source and source parent are remote
+       $LFS mkdir -i 0 $DIR1/${tdir}_src || error "mkdir ${tdir}_src"
+       $LFS mkdir -i 1 $DIR1/${tdir}_tgt || error "mkdir ${tdir}_tgt"
+       mkdir $DIR1/${tdir}_src/sub || error "mkdir sub"
+       $LFS mkdir -i 3 $DIR1/${tdir}_tgt/sub || error "mkdir sub"
+       stat $DIR2/${tdir}_src/sub || error "stat sub failed"
+       mv $DIR1/${tdir}_src/sub $DIR1/${tdir}_tgt/ || error "mv failed"
+       [ -f $DIR2/${tdir}_src/sub ] && error "sub should be gone"
+       rm -rf $DIR1/${tdir}_src $DIR1/${tdir}_tgt
+
+       # source and source parent are remote, and source is remote object
+       $LFS mkdir -i 0 $DIR1/${tdir}_src || error "mkdir ${tdir}_src"
+       $LFS mkdir -i 1 $DIR1/${tdir}_tgt || error "mkdir ${tdir}_tgt"
+       $LFS mkdir -i 2 $DIR1/${tdir}_src/sub || error "mkdir sub"
+       $LFS mkdir -i 3 $DIR1/${tdir}_tgt/sub || error "mkdir sub"
+       stat $DIR2/${tdir}_src/sub || error "stat sub failed"
+       mv $DIR1/${tdir}_src/sub $DIR1/${tdir}_tgt/ || error "mv failed"
+       [ -f $DIR2/${tdir}_src/sub ] && error "sub should be gone" || true
+}
+run_test 81c "rename revoke LOOKUP lock for remote object"
 
 test_82() {
-       [[ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.91) ]] ||
-               { skip "Need MDS version at least 2.6.92"; return 0; }
+       [[ "$MDS1_VERSION" -gt $(version_code 2.6.91) ]] ||
+               skip "Need MDS version at least 2.6.92"
 
        # Client 1 creates a file.
        multiop_bg_pause $DIR1/$tfile O_ac || error "multiop_bg_pause 1"
@@ -3865,6 +4621,31 @@ test_83() {
 }
 run_test 83 "access striped directory while it is being created/unlinked"
 
+test_84() {
+       [ $MDS1_VERSION -lt $(version_code 2.12.55) ] &&
+               skip "lustre < 2.12.55 does not contain LU-12485 fix"
+
+       local mtime
+
+       $MULTIOP $DIR/$tfile oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:c ||
+               error "create $tfile failed"
+       mtime=$(stat -c%Y $DIR/$tfile)
+       mtime=$((mtime + 200))
+
+       #define OBD_FAIL_OBD_0NLINK_RACE  0x60b
+       do_facet mds1 $LCTL set_param fail_loc=0x8000060b
+
+       touch -c -m $mtime $DIR/$tfile &
+       setattr_pid=$!
+       # sleep a while to let 'touch' run first
+       sleep 5
+       rm -f $DIR2/$tfile || error "unlink $tfile failed"
+
+       # touch may fail
+       wait $setattr_pid || true
+}
+run_test 84 "0-nlink race in lu_object_find()"
+
 test_90() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
        local pid1
@@ -3969,29 +4750,29 @@ test_93() {
 
        mkdir -p $DIR1/$tfile-1/
        mkdir -p $DIR2/$tfile-2/
-       local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
-               'lod.lustre-MDT*/qos_threshold_rr' | sed -e 's/%//')
-       do_facet $SINGLEMDS lctl set_param -n \
-               'lod.lustre-MDT*/qos_threshold_rr' 100
+       local old_rr=$(do_facet $SINGLEMDS "$LCTL get_param -n \
+               lod.$FSNAME-MDT0000-*/qos_threshold_rr" | sed -e 's/%//')
+       do_facet $SINGLEMDS "$LCTL set_param -n \
+               lod.$FSNAME-MDT0000-*/qos_threshold_rr=100"
        #define OBD_FAIL_MDS_LOV_CREATE_RACE     0x163
-       do_facet $SINGLEMDS "lctl set_param fail_loc=0x00000163"
+       do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x00000163"
 
-       $SETSTRIPE -c -1 $DIR1/$tfile-1/file1 &
+       $LFS setstripe -c -1 $DIR1/$tfile-1/file1 &
        local PID1=$!
        sleep 1
-       $SETSTRIPE -c -1 $DIR2/$tfile-2/file2 &
+       $LFS setstripe -c -1 $DIR2/$tfile-2/file2 &
        local PID2=$!
        wait $PID2
        wait $PID1
-       do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
-       do_facet $SINGLEMDS "lctl set_param -n \
-               'lod.lustre-MDT*/qos_threshold_rr' $old_rr"
+       do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x0"
+       do_facet $SINGLEMDS "$LCTL set_param -n \
+               lod.$FSNAME-MDT0000-*/qos_threshold_rr=$old_rr"
 
-       $GETSTRIPE $DIR1/$tfile-1/file1
-       rc1=$($GETSTRIPE -q $DIR1/$tfile-1/file1 |
+       $LFS getstripe $DIR1/$tfile-1/file1
+       rc1=$($LFS getstripe -q $DIR1/$tfile-1/file1 |
                awk '{if (/[0-9]/) print $1 }' | sort | uniq -d | wc -l)
-       $GETSTRIPE $DIR2/$tfile-2/file2
-       rc2=$($GETSTRIPE -q $DIR2/$tfile-2/file2 |
+       $LFS getstripe $DIR2/$tfile-2/file2
+       rc2=$($LFS getstripe -q $DIR2/$tfile-2/file2 |
                awk '{if (/[0-9]/) print $1 }' | sort | uniq -d | wc -l)
        echo "rc1=$rc1 and rc2=$rc2 "
        [ $rc1 -eq 0 ] && [ $rc2 -eq 0 ] ||
@@ -3999,6 +4780,623 @@ test_93() {
 }
 run_test 93 "alloc_rr should not allocate on same ost"
 
+test_94() {
+       $LCTL set_param osc.*.idle_timeout=0
+       dd if=/dev/zero of=$DIR2/$tfile bs=4k count=2 conv=fsync
+
+       local before=$(date +%s)
+       local evict
+
+       $LCTL mark write
+#define OBD_FAIL_LDLM_PAUSE_CANCEL       0x312
+       $LCTL set_param fail_val=5 fail_loc=0x80000312
+       dd if=/dev/zero of=$DIR/$tfile conv=notrunc oflag=append bs=4k count=1 &
+       local pid=$!
+       sleep 2
+
+#define OBD_FAIL_LDLM_PAUSE_CANCEL_LOCAL 0x329
+       $LCTL set_param fail_val=6 fail_loc=0x80000329
+       $LCTL mark kill $pid
+       kill -ALRM $pid
+
+       dd if=/dev/zero of=$DIR2/$tfile conv=notrunc oflag=append bs=4k count=1
+
+       wait $pid
+       dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 conv=fsync
+
+       evict=$(do_facet client $LCTL get_param \
+               osc.$FSNAME-OST*-osc-*/state |
+           awk -F"[ [,]" '/EVICTED ]$/ { if (t<$5) {t=$5;} } END { print t }')
+
+       [ -z "$evict" ] || [[ $evict -le $before ]] ||
+               (do_facet client $LCTL get_param \
+                       osc.$FSNAME-OST*-osc-*/state;
+                   error "eviction happened: $evict before:$before")
+       $LCTL set_param osc.*.idle_timeout=debug
+}
+run_test 94 "signal vs CP callback race"
+
+# Data-on-MDT tests
+test_100a() {
+       skip "Reserved for glimpse-ahead" && return
+       [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
+               skip "Need MDS version at least 2.10.55"
+
+       mkdir -p $DIR/$tdir
+
+       $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
+
+       lctl set_param -n mdc.*.stats=clear
+       dd if=/dev/zero of=$DIR2/$tdir/dom bs=4096 count=1 || return 1
+
+       $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #1"
+       # first stat from server should return size data and save glimpse
+       local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
+       [ $gls -eq 0 ] || error "Unexpected $gls glimpse RPCs"
+       # second stat to check size is NOT cached on client without IO lock
+       $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #2"
+
+       local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
+       [ $gls -ge 1 ] || error "Expect glimpse RPCs but none"
+       rm -f $dom
+}
+run_test 100a "DoM: glimpse RPCs for stat without IO lock (DoM only file)"
+
+test_100b() {
+       [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
+               skip "Need MDS version at least 2.10.55"
+
+       mkdir -p $DIR/$tdir
+
+       $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
+
+       lctl set_param -n mdc.*.stats=clear
+       dd if=/dev/zero of=$DIR2/$tdir/dom bs=4096 count=1 || return 1
+       cancel_lru_locks mdc
+       # first stat data from server should have size
+       $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #1"
+       # second stat to check size is cached on client
+       $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #2"
+
+       local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
+       # both stats should cause no glimpse requests
+       [ $gls == 0 ] || error "Unexpected $gls glimpse RPCs"
+       rm -f $dom
+}
+run_test 100b "DoM: no glimpse RPC for stat with IO lock (DoM only file)"
+
+test_100c() {
+       [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
+               skip "Need MDS version at least 2.10.55"
+
+       mkdir -p $DIR/$tdir
+
+       $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
+
+       lctl set_param -n mdc.*.stats=clear
+       lctl set_param -n osc.*.stats=clear
+       dd if=/dev/zero of=$DIR2/$tdir/dom bs=2048K count=1 || return 1
+
+       # check that size is merged from MDT and OST correctly
+       $CHECKSTAT -t file -s 2097152 $DIR/$tdir/dom ||
+               error "Wrong size from stat #1"
+
+       local gls=$(lctl get_param -n osc.*.stats | grep -c ldlm_glimpse)
+       [ $gls -eq 0 ] && error "Expect OST glimpse RPCs but got none"
+
+       rm -f $dom
+}
+run_test 100c "DoM: write vs stat without IO lock (combined file)"
+
+test_100d() {
+       [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
+               skip "Need MDS version at least 2.10.55"
+
+       mkdir -p $DIR/$tdir
+
+       $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
+
+
+       dd if=/dev/zero of=$DIR2/$tdir/dom bs=2048K count=1 || return 1
+       lctl set_param -n mdc.*.stats=clear
+       $TRUNCATE $DIR2/$tdir/dom 4096
+
+       # check that reported size is valid after file grows to OST and
+       # is truncated back to MDT stripe size
+       $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom ||
+               error "Wrong size from stat #1"
+
+       local gls=$(lctl get_param -n osc.*.stats | grep -c ldlm_glimpse)
+       [ $gls -eq 0 ] && error "Expect OST glimpse but got none"
+
+       rm -f $dom
+}
+run_test 100d "DoM: write+truncate vs stat without IO lock (combined file)"
+
+test_100e() {
+       [ "$MDS1_VERSION" -lt $(version_code 2.11.50) ] &&
+               skip "Need MDS version at least 2.11.50"
+
+       local dom=$DIR/$tdir/dom
+       local dom2=$DIR2/$tdir/dom
+       mkdir -p $DIR/$tdir
+
+       $LFS setstripe -E 1024K -L mdt $DIR/$tdir
+
+       cancel_lru_locks mdc
+       dd if=/dev/urandom of=$dom bs=12000 count=1
+       $TRUNCATE $dom2 6000
+       cancel_lru_locks mdc
+       lctl set_param -n mdc.*.stats=clear
+       # expect read-on-open to return all data before write
+       cat /etc/hosts >> $dom
+       local read=$(lctl get_param -n mdc.*.stats | grep -c ost_read)
+       [[ $read -eq 0 ]] || error "Unexpected $read READ RPCs"
+}
+run_test 100e "DoM: read on open and file size"
+
+test_101a() {
+       [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
+               skip "Need MDS version at least 2.10.55"
+
+       $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
+       # to get layout
+       $CHECKSTAT -t file $DIR1/$tfile
+
+       local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
+       sysctl -wq vm.dirty_writeback_centisecs=0
+
+       trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
+
+       # open + IO lock
+       dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 ||
+               error_noexit "Write fails"
+       # must discard pages
+       lctl set_param -n mdc.*.stats=clear
+       rm $DIR2/$tfile || error "Unlink fails"
+
+       local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
+       [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
+}
+run_test 101a "Discard DoM data on unlink"
+
+test_101b() {
+       [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
+               skip "Need MDS version at least 2.10.55"
+
+       $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
+       touch $DIR1/${tfile}_2
+       # to get layout
+       $CHECKSTAT -t file $DIR1/$tfile
+
+       local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
+       sysctl -wq vm.dirty_writeback_centisecs=0
+
+       trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
+
+       # open + IO lock
+       dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 || error "Write fails"
+       # must discard pages
+       lctl set_param -n mdc.*.stats=clear
+       mv $DIR2/${tfile}_2 $DIR2/$tfile || error "Rename fails"
+
+       local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
+       [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
+}
+run_test 101b "Discard DoM data on rename"
+
+test_101c() {
+       [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
+               skip "Need MDS version at least 2.10.55"
+
+       $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
+       # to get layout
+       $CHECKSTAT -t file $DIR1/$tfile
+
+       local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
+       sysctl -wq vm.dirty_writeback_centisecs=0
+
+       trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
+
+       # open + IO lock
+       dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 || error "Write fails"
+       $MULTIOP $DIR1/$tfile O_c &
+       MULTIOP_PID=$!
+       sleep 1
+       lctl set_param -n mdc.*.stats=clear
+       rm $DIR2/$tfile > /dev/null || error "Unlink fails for opened file"
+       kill -USR1 $MULTIOP_PID && wait $MULTIOP_PID || error "multiop failure"
+
+       local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
+       [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
+}
+run_test 101c "Discard DoM data on close-unlink"
+
+# test to verify file handle related system calls
+# (name_to_handle_at/open_by_handle_at)
+# The new system calls are supported in glibc >= 2.14.
+
+# test to verify we can open by handle an unlinked file from > 1 client
+# This test opens the file normally on $DIR1, which is on one mount, and then
+# opens it by handle on $DIR2, which is on a different mount.
+test_102() {
+       [ "$MDS1_VERSION" -lt $(version_code 2.11.57) ] &&
+               skip "Needs MDS version 2.11.57 or later"
+
+       echo "Test file_handle syscalls" > $DIR/$tfile ||
+               error "write failed"
+       check_fhandle_syscalls $DIR/$tfile $DIR2 ||
+               error "check_fhandle_syscalls failed"
+       rm -f $DIR2/$tfile
+}
+run_test 102 "Test open by handle of unlinked file"
+
+# Compare file size between first & second mount, ensuring the client correctly
+# glimpses even with unused speculative locks - LU-11670
+test_103() {
+       [ $OST1_VERSION -lt $(version_code 2.10.50) ] &&
+               skip "Lockahead needs OST version at least 2.10.50"
+
+       local locktest=23
+
+       test_mkdir -p $DIR/$tdir
+
+       # Force file on to OST0
+       $LFS setstripe -i 0 $DIR/$tdir
+
+       # Do not check multiple locks on glimpse
+       # OBD_FAIL_OSC_NO_SIZE_DATA 0x415
+       $LCTL set_param fail_loc=0x415
+
+       # Delay write commit by 2 seconds to guarantee glimpse wins race
+       # The same fail_loc is used on client & server so it can work in the
+       # single node sanity setup
+       do_facet ost1 $LCTL set_param fail_loc=0x415 fail_val=2
+
+       echo "Incorrect size expected (no glimpse fix):"
+       lockahead_test -d $DIR/$tdir -D $DIR2/$tdir -t $locktest -f $tfile
+       rc=$?
+       if [ $rc -eq 0 ]; then
+               echo "This doesn't work 100%, but this is just reproducing the bug, not testing the fix, so OK to not fail test."
+       fi
+
+       # guarantee write commit timeout has expired
+       sleep 2
+
+       # Clear fail_loc on client
+       $LCTL set_param fail_loc=0
+
+       # Delay write commit by 2 seconds to guarantee glimpse wins race
+       # OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
+       do_facet ost1 $LCTL set_param fail_loc=0x214 fail_val=2
+
+       # Write commit is still delayed by 2 seconds
+       lockahead_test -d $DIR/$tdir -D $DIR2/$tdir -t $locktest -f $tfile
+       rc=$?
+       [ $rc -eq 0 ] || error "Lockahead test$locktest failed, $rc"
+
+       # guarantee write commit timeout has expired
+       sleep 2
+
+       rm -f $DIR/$tfile || error "unable to delete $DIR/$tfile"
+}
+run_test 103 "Test size correctness with lockahead"
+
+get_stat_xtimes()
+{
+       local xtimes
+
+       xtimes=$(stat -c "%X %Y %Z" $DIR/$tfile)
+
+       echo ${xtimes[*]}
+}
+
+get_mdt_xtimes()
+{
+       local mdtdev=$1
+       local output
+       local xtimes
+
+       output=$(do_facet mds1 "$DEBUGFS -c -R 'stat ROOT/$tfile' $mdtdev")
+       ((xtimes[0]=$(awk -F ':' /atime/'{ print $2 }' <<< "$output")))
+       ((xtimes[1]=$(awk -F ':' /mtime/'{ print $2 }' <<< "$output")))
+       ((xtimes[2]=$(awk -F ':' /ctime/'{ print $2 }' <<< "$output")))
+
+       echo ${xtimes[*]}
+}
+
+check_mdt_xtimes()
+{
+       local mdtdev=$1
+       local xtimes=($(get_stat_xtimes))
+       local mdt_xtimes=($(get_mdt_xtimes $mdtdev))
+
+       echo "STAT a|m|ctime ${xtimes[*]}"
+       echo "MDT a|m|ctime ${mdt_xtimes[*]}"
+       [[ ${xtimes[0]} == ${mdt_xtimes[0]} ]] ||
+               error "$DIR/$tfile atime (${xtimes[0]}:${mdt_xtimes[0]}) diff"
+       [[ ${xtimes[1]} == ${mdt_xtimes[1]} ]] ||
+               error "$DIR/$tfile mtime (${xtimes[1]}:${mdt_xtimes[1]}) diff"
+       [[ ${xtimes[2]} == ${mdt_xtimes[2]} ]] ||
+               error "$DIR/$tfile ctime (${xtimes[2]}:${mdt_xtimes[2]}) diff"
+}
+
+test_104() {
+       [ "$mds1_FSTYPE" == "ldiskfs" ] || skip_env "ldiskfs only test"
+       [ $MDS1_VERSION -lt $(version_code 2.12.4) ] &&
+               skip "Need MDS version at least 2.12.4"
+
+       local pid
+       local mdtdev=$(mdsdevname ${SINGLEMDS//mds/})
+       local atime_diff=$(do_facet $SINGLEMDS \
+               lctl get_param -n mdd.*MDT0000*.atime_diff)
+
+       do_facet $SINGLEMDS \
+               lctl set_param -n mdd.*MDT0000*.atime_diff=0
+
+       stack_trap "do_facet $SINGLEMDS \
+               lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff" EXIT
+
+       dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
+       check_mdt_xtimes $mdtdev
+       sleep 2
+
+       dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
+       check_mdt_xtimes $mdtdev
+       sleep 2
+       $MULTIOP $DIR2/$tfile Oz8192w8192_c &
+       pid=$!
+       sleep 2
+       dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
+       sleep 2
+       kill -USR1 $pid && wait $pid || error "multiop failure"
+       check_mdt_xtimes $mdtdev
+
+       local xtimes
+       local mdt_xtimes
+
+       # Verify mtime/ctime is NOT upated on MDS when there is no modification
+       # on the client side
+       xtimes=($(get_stat_xtimes))
+       $MULTIOP $DIR/$tfile O_c &
+       pid=$!
+       sleep 2
+       kill -USR1 $pid && wait $pid || error "multiop failure"
+       mdt_xtimes=($(get_mdt_xtimes $mdtdev))
+       [[ ${xtimes[1]} == ${mdt_xtimes[1]} ]] ||
+               error "$DIR/$tfile mtime (${xtimes[1]}:${mdt_xtimes[1]}) diff"
+       [[ ${xtimes[2]} == ${mdt_xtimes[2]} ]] ||
+               error "$DIR/$tfile ctime (${xtimes[2]}:${mdt_xtimes[2]}) diff"
+       check_mdt_xtimes $mdtdev
+
+       sleep 2
+       # Change ctime via chmod
+       $MULTIOP $DIR/$tfile o_tc &
+       pid=$!
+       sleep 2
+       kill -USR1 $pid && wait $pid || error "multiop failure"
+       check_mdt_xtimes $mdtdev
+}
+run_test 104 "Verify that MDS stores atime/mtime/ctime during close"
+
+test_105() {
+       test_mkdir -p $DIR/$tdir
+       echo test > $DIR/$tdir/$tfile
+       $LCTL set_param fail_loc=0x416
+       cancel_lru_locks osc & sleep 1
+       fsize1=$(stat -c %s $DIR2/$tdir/$tfile)
+       wait
+       [[ $fsize1 = 5 ]] ||  error "Glimpse returned wrong file size $fsize1"
+}
+run_test 105 "Glimpse and lock cancel race"
+
+test_106a() {
+       [ "$mds1_FSTYPE" == "ldiskfs" ] && statx_supported ||
+               skip_env "Test only for ldiskfs and statx() supported"
+
+       local btime
+       local mdt_btime
+       local output
+       local mdtdev=$(mdsdevname ${SINGLEMDS//mds/})
+
+       dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
+       btime=$($STATX -c %W $DIR/$tfile)
+       output=$(do_facet mds1 "$DEBUGFS -c -R 'stat ROOT/$tfile' $mdtdev")
+       echo $output
+       ((mdt_btime=$(awk -F ':' /crtime/'{ print $2 }' <<< "$output")))
+       [[ $btime == $mdt_btime ]] ||
+               error "$DIR/$tfile btime ($btime:$mdt_btime) diff"
+
+}
+run_test 106a "Verify the btime via statx()"
+
+test_106b() {
+       statx_supported || skip_env "statx() only test"
+
+       local rpcs_before
+       local rpcs_after
+
+       $LFS setstripe -c 1 $DIR/$tfile || error "$DIR/$tfile setstripe failed"
+       dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
+       cancel_lru_locks $OSC
+       rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+       $STATX $DIR/$tfile
+       rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+       [ $rpcs_after -eq $((rpcs_before + 1)) ] ||
+               error "$STATX should send 1 glimpse RPC to $OSC"
+
+       cancel_lru_locks $OSC
+       rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+       # %n: FILENAME; %i: STATX_INO; %A STATX_MODE; %h STATX_NLINK;
+       # %u: STATX_UID; %g: STATX_GID; %W STATX_BTIME; %X STATX_ATIME;
+       # %Z: STATX_CTIME
+       $STATX -c "%n %i %A %h %u %g %W %X %Z" $DIR/$tfile
+       rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+       [ $rpcs_after -eq $rpcs_before ] ||
+               error "$STATX should not send glimpse RPCs to $OSC"
+
+       cancel_lru_locks $OSC
+       rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+       $STATX --cached=always $DIR/$tfile
+       rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+       [ $rpcs_after -eq $rpcs_before ] ||
+               error "$STATX should not send glimpse RPCs to $OSC"
+
+       cancel_lru_locks $OSC
+       rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+       $STATX -c %Y $DIR/$tfile
+       rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+       [ $rpcs_after -eq $((rpcs_before + 1)) ] ||
+               error "$STATX -c %Y should send 1 glimpse RPC to $OSC"
+
+       cancel_lru_locks $OSC
+       rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+       $STATX -c %s $DIR/$tfile
+       rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+       [ $rpcs_after -eq $((rpcs_before + 1)) ] ||
+               error "$STATX -c %s should send 1 glimpse RPC to $OSC"
+
+       cancel_lru_locks $OSC
+       rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+       $STATX -c %b $DIR/$tfile
+       rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+       [ $rpcs_after -eq $((rpcs_before + 1)) ] ||
+               error "$STATX -c %b should send 1 glimpse RPC to $OSC"
+}
+run_test 106b "Glimpse RPCs test for statx"
+
+test_106c() {
+       statx_supported || skip_env "statx() only test"
+
+       local mask
+
+       touch $DIR/$tfile
+       # Mask supported in stx_attributes by Lustre is
+       # STATX_ATTR_IMMUTABLE(0x10) | STATX_ATTR_APPEND(0x20) : (0x30).
+       mask=$($STATX -c %p $DIR/$tfile)
+       [[ $mask == "30" ]] ||
+               error "supported stx_attributes: got '$mask', expected '30'"
+       chattr +i $DIR/$tfile || error "chattr +i $DIR/$tfile failed"
+       mask=$($STATX -c %r $DIR/$tfile)
+       [[ $mask == "10" ]] ||
+               error "got immutable flags '$mask', expected '10'"
+       chattr -i $DIR/$tfile || error "chattr -i $DIR/$tfile failed"
+       mask=$($STATX -c %r $DIR/$tfile)
+       [[ $mask == "0" ]] || error "got flags '$mask', expected '0'"
+       chattr +a $DIR/$tfile || error "chattr +a $DIR/$tfile failed"
+       mask=$($STATX -c %r $DIR/$tfile)
+       [[ $mask == "20" ]] || error "got flags '$mask', expected '20'"
+       chattr -a $DIR/$tfile || error "chattr -a $DIR/$tfile failed"
+       mask=$($STATX -c %r $DIR/$tfile)
+       [[ $mask == "0" ]] || error "got flags '$mask', expected '0'"
+       chattr +ia $DIR/$tfile || error "chattr +ia $DIR/$tfile failed"
+       mask=$($STATX -c %r $DIR/$tfile)
+       [[ $mask == "30" ]] || error "got flags '$mask', expected '30'"
+       chattr -ia $DIR/$tfile || error "chattr -ia $DIR/$tfile failed"
+       mask=$($STATX -c %r $DIR/$tfile)
+       [[ $mask == "0" ]] || error "got flags '$mask', expected '0'"
+}
+run_test 106c "Verify statx attributes mask"
+
+test_107a() { # LU-1031
+       dd if=/dev/zero of=$DIR1/$tfile bs=1M count=10
+       local gid1=14091995
+       local gid2=16022000
+
+       $LFS getstripe $DIR1/$tfile
+
+       multiop_bg_pause $DIR1/$tfile OG${gid1}_g${gid1}c || return 1
+       local MULTIPID1=$!
+       multiop_bg_pause $DIR2/$tfile O_G${gid2}r10g${gid2}c || return 2
+       local MULTIPID2=$!
+       kill -USR1 $MULTIPID2
+       sleep 2
+       if [[ $(ps h -o comm -p $MULTIPID2) == "" ]]; then
+               error "First grouplock does not block second one"
+       else
+               echo "First grouplock blocks second one"
+       fi
+       kill -USR1 $MULTIPID1
+       wait $MULTIPID1
+       wait $MULTIPID2
+}
+run_test 107a "Basic grouplock conflict"
+
+test_107b() {
+       dd if=/dev/zero of=$DIR1/$tfile bs=1M count=10
+       local gid1=14091995
+       local gid2=16022000
+
+       $LFS getstripe $DIR1/$tfile
+
+       multiop_bg_pause $DIR1/$tfile OG${gid1}_g${gid1}c || return 1
+       local MULTIPID1=$!
+       multiop $DIR2/$tfile Or10c &
+       local MULTIPID2=$!
+       sleep 2
+
+       if [[ $(ps h -o comm -p $MULTIPID2) == "" ]]; then
+               error "Grouplock does not block IO"
+       else
+               echo "Grouplock blocks IO"
+       fi
+
+       multiop $DIR2/$tfile OG${gid2}_g${gid2}c &
+       local MULTIPID3=$!
+       sleep 2
+       if [[ $(ps h -o comm -p $MULTIPID3) == "" ]]; then
+               error "First grouplock does not block second one"
+       else
+               echo "First grouplock blocks second one"
+       fi
+
+       kill -USR1 $MULTIPID1
+       sleep 2
+
+       if [[ $(ps h -o comm -p $MULTIPID3) == "" ]]; then
+               error "Second grouplock thread disappeared"
+       fi
+
+       if [[ $(ps h -o comm -p $MULTIPID2) == "" ]]; then
+               error "Second grouplock does not block IO"
+       else
+               echo "Second grouplock blocks IO"
+       fi
+
+       kill -USR1 $MULTIPID3
+       wait $MULTIPID1
+       wait $MULTIPID2
+       wait $MULTIPID3
+}
+run_test 107b "Grouplock is added to the head of waiting list"
+
+test_108a() {
+       local offset
+
+       $LFS setstripe -E 1M -c 1 -E -1 $DIR1/$tfile ||
+               error "Create $DIR1/$tfile failed"
+
+       dd if=/dev/zero of=$DIR1/$tfile bs=10000 count=1 ||
+               error "dd $DIR1/$tfile failed"
+       offset=$(lseek_test -d 5000 $DIR2/$tfile)
+       [[ $offset == 5000 ]] || error "offset $offset != 5000"
+
+       $TRUNCATE $DIR1/$tfile 2000
+       offset=$(lseek_test -l 1000 $DIR2/$tfile)
+       [[ $offset == 2000 ]] || error "offset $offset != 2000"
+
+       #define OBD_FAIL_OSC_DELAY_IO 0x414
+       $LCTL set_param fail_val=4 fail_loc=0x80000414
+       dd if=/dev/zero of=$DIR1/$tfile count=1 bs=8M conv=notrunc oflag=dsync &
+       local pid=$!
+       sleep 2
+
+       offset=$(lseek_test -l 8000 $DIR2/$tfile)
+       wait $pid
+       [[ $offset == 8388608 ]] || error "offset $offset != 8388608"
+}
+run_test 108a "lseek: parallel updates"
+
 log "cleanup: ======================================================"
 
 # kill and wait in each test only guarentee script finish, but command in script