Whamcloud - gitweb
LU-2233 tests: improve tests sanityn/40-47
[fs/lustre-release.git] / lustre / tests / sanityn.sh
index 835e3b9..e22911a 100755 (executable)
@@ -3,8 +3,9 @@
 set -e
 
 ONLY=${ONLY:-"$*"}
-# bug number for skipped test: 9977/LU-7105 LU-9452
-ALWAYS_EXCEPT="                28           29      $SANITYN_EXCEPT"
+# bug number for skipped test: 9977/LU-7105
+#              LU-7105
+ALWAYS_EXCEPT=" 28     $SANITYN_EXCEPT"
 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
 
 SRCDIR=$(dirname $0)
@@ -30,6 +31,7 @@ CLEANUP=${CLEANUP:-:}
 SETUP=${SETUP:-:}
 init_test_env $@
 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
+get_lustre_env
 init_logging
 
 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
@@ -84,7 +86,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 ========"
 
@@ -92,20 +95,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 ==="
 
@@ -114,7 +120,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"
 
@@ -161,7 +168,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"
 
@@ -181,7 +188,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"
@@ -205,7 +213,7 @@ test_8() {
 }
 run_test 8 "remove of open special file on other node =========="
 
-test_9() {
+test_9a() {
        MTPT=1
        local dir
        > $DIR2/f9
@@ -217,7 +225,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
@@ -260,7 +284,7 @@ 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 ===="
@@ -272,16 +296,16 @@ run_test 12 "test lock ordering (link, stat, unlink)"
 
 test_13() {    # bug 2451 - directory coherency
        test_mkdir $DIR1/d13
-       cd $DIR1/d13 || error
+       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
+       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
+       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"
@@ -293,65 +317,52 @@ test_14aa() {
        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 $DIR1/$tdir
-       cp -p $(which multiop) $DIR1/$tdir/multiop || error "cp failed"
-       MULTIOP_PROG=$DIR1/$tdir/multiop multiop_bg_pause $TMP/$tfile O_c ||
-               return 1
-       MULTIOP_PID=$!
-       $MULTIOP $DIR2/$tdir/multiop Oc && error "expected error, got success"
-       kill -USR1 $MULTIOP_PID || return 2
-       wait $MULTIOP_PID || return 3
-       rm $TMP/$tfile $DIR1/$tdir/multiop || error "removing multiop"
+       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 $DIR1/$tdir
-       cp -p $(which multiop) $DIR1/$tdir/multiop || error "cp failed"
-       MULTIOP_PROG=$DIR1/$tdir/multiop multiop_bg_pause $TMP/$tfile O_c ||
-               return 1
-       MULTIOP_PID=$!
-       $TRUNCATE $DIR2/$tdir/multiop 0 && kill -9 $MULTIOP_PID && \
+       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/$tdir/multiop || error "binary changed"
-       rm $TMP/$tfile $DIR1/$tdir/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 $DIR1/$tdir
-       cp -p $(which multiop) $DIR1/$tdir/multiop || error "cp failed"
-       MULTIOP_PROG=$DIR1/$tdir/multiop multiop_bg_pause $TMP/$tfile O_c ||
-               return 1
-       MULTIOP_PID=$!
-       cp /etc/hosts $DIR2/$tdir/multiop && error "expected error, got success"
-       kill -USR1 $MULTIOP_PID || return 2
-       wait $MULTIOP_PID || return 3
-       cmp $(which multiop) $DIR1/$tdir/multiop || error "binary changed"
-       rm $TMP/$tfile $DIR1/$tdir/multiop || error "removing multiop"
+       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 $DIR1/$tdir
-       cp -p $(which multiop) $DIR1/$tdir/multiop || error "cp failed"
-       MULTIOP_PROG=$DIR1/$tdir/multiop multiop_bg_pause $TMP/$tfile O_c ||
-               return 1
-       MULTIOP_PID=$!
+       cp -p $(which sleep) $DIR1/$tdir/sleep || error "cp failed"
+       $DIR1/$tdir/sleep 60 &
+       SLEEP_PID=$!
        log chmod
-       chmod 600 $DIR1/$tdir/multiop || error "chmod failed"
-       kill -USR1 $MULTIOP_PID || return 2
-       wait $MULTIOP_PID || return 3
-       cmp $(which multiop) $DIR1/$tdir/multiop || error "binary changed"
-       rm $TMP/$tfile $DIR1/$tdir/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 ========"
 
@@ -379,14 +390,16 @@ 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
@@ -398,7 +411,62 @@ test_16() {
        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
+
+       # 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
+       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
+}
+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")
+
+       [ $(facet_fstype ost1) != 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_17() { # bug 3513, 3667
        remote_ost_nodsh && skip "remote OST with nodsh" && return
@@ -437,13 +505,10 @@ test_19() { # bug3811
        [ "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)
@@ -606,7 +671,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"
 
@@ -670,32 +735,21 @@ 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_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' &
@@ -704,7 +758,6 @@ test_30() { #bug #11110, LU-2523
        wait
        true
 }
-
 run_test 30 "recreate file race"
 
 test_31a() {
@@ -749,14 +802,18 @@ enable_lockless_truncate() {
 }
 
 test_32a() { # bug 11270
-       local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
+       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" > $p
+       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
 
@@ -779,10 +836,7 @@ test_32a() { # bug 11270
        $CHECKSTAT -s 3000000 $DIR1/$tfile || error "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"
 
@@ -974,39 +1028,57 @@ test_33c() {
        [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.63) ] &&
                skip "DNE CoS not supported" && return
 
-       sync
+       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() {
@@ -1014,39 +1086,34 @@ test_33d() {
        [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.63) ] &&
                skip "DNE CoS not supported" && return
 
-       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"
@@ -1098,7 +1165,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
 }
 
@@ -1204,7 +1271,7 @@ test_35() { # bug 17645
        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
@@ -1393,13 +1460,21 @@ 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
+}
+
 # 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"
@@ -1417,8 +1492,7 @@ test_40a() {
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        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
@@ -1435,6 +1509,7 @@ test_40a() {
 
        #  all operations above shouldn't wait the first one
        check_pdo_conflict $PID1 || error "parallel operation is blocked"
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        wait $PID1
        rm -rf $DIR/$tfile*
        return 0
@@ -1446,8 +1521,7 @@ test_40b() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        touch $DIR1/$tfile &
-       PID1=$!
-       sleep 1
+       PID1=$!; pdo_sched
        # open|create
        touch $DIR2/$tfile-2
        check_pdo_conflict $PID1 || error "create is blocked"
@@ -1465,6 +1539,7 @@ test_40b() {
        # all operations above shouldn't wait the first one
 
         check_pdo_conflict $PID1 || error "parallel operation is blocked"
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        wait $PID1
        rm -rf $DIR/$tfile*
        return 0
@@ -1477,8 +1552,7 @@ test_40c() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        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"
@@ -1496,6 +1570,7 @@ test_40c() {
 
         # all operations above shouldn't wait the first one
        check_pdo_conflict $PID1 || error "parallel operation is blocked"
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        wait $PID1
        rm -rf $DIR/$tfile*
        return 0
@@ -1508,8 +1583,7 @@ test_40d() {
 #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
+       PID1=$!; pdo_sched
        # open|create
        touch $DIR2/$tfile-2
        check_pdo_conflict $PID1 || error "create is blocked"
@@ -1527,6 +1601,7 @@ test_40d() {
 
        # all operations above shouldn't wait the first one
        check_pdo_conflict $PID1 || error "parallel operation is blocked"
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        wait $PID1
        return 0
 }
@@ -1538,8 +1613,7 @@ test_40e() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        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"
@@ -1555,6 +1629,7 @@ test_40e() {
 
        # all operations above shouldn't wait the first one
        check_pdo_conflict $PID1 || error "parallel operation is blocked"
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        wait $PID1
        rm -rf $DIR/$tfile*
        return 0
@@ -1566,10 +1641,12 @@ test_41a() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        $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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1579,10 +1656,12 @@ test_41b() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        $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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1593,10 +1672,12 @@ test_41c() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        $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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1606,10 +1687,12 @@ test_41d() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        $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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1620,10 +1703,12 @@ test_41e() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        $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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1633,10 +1718,12 @@ test_41f() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        $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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1646,10 +1733,12 @@ test_41g() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        $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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1659,10 +1748,12 @@ test_41h() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        $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_facet $SINGLEMDS lctl set_param fail_loc=0
        check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
+       wait $PID2
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -1673,10 +1764,12 @@ test_42a() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        mkdir $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       mkdir $DIR2/$tfile && error "mkdir must fail"
+       PID1=$! ; pdo_sched
+       mkdir $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1686,10 +1779,12 @@ test_42b() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1700,10 +1795,12 @@ test_42c() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1713,10 +1810,12 @@ test_42d() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        mkdir $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       rmdir $DIR2/$tfile || error "unlink must succeed"
+       PID1=$! ; pdo_sched
+       rmdir $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1727,10 +1826,12 @@ test_42e() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1740,10 +1841,12 @@ test_42f() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1753,10 +1856,12 @@ test_42g() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1766,10 +1871,12 @@ test_42h() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        mkdir $DIR1/$tfile &
-       PID1=$!
-       sleep 1
-       ls -lia $DIR2/ > /dev/null
+       PID1=$! ; pdo_sched
+       ls -lia $DIR2/ > /dev/null &
+       PID2=$! ; pdo_sched
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
+       wait $PID2
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -1781,10 +1888,12 @@ test_43a() {
 #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"
+       PID1=$! ; pdo_sched
+       mkdir $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "mkdir must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -1795,10 +1904,12 @@ test_43b() {
 #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
-       $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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1810,10 +1921,12 @@ test_43c() {
 #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
-       link $DIR2/$tfile-2 $DIR2/$tfile || error "link must succeed"
+       PID1=$! ; pdo_sched
+       link $DIR2/$tfile-2 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1824,10 +1937,12 @@ test_43d() {
 #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
-       rm $DIR2/$tfile && error "unlink must fail"
+       PID1=$! ; pdo_sched
+       rm $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1839,10 +1954,12 @@ test_43e() {
 #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
-       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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1853,10 +1970,12 @@ test_43f() {
 #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
-       mv $DIR2/$tfile $DIR2/$tfile-2 && error "rename must fail"
+       PID1=$! ; pdo_sched
+       mv $DIR2/$tfile $DIR2/$tfile-2 &
+       PID2=$! ; pdo_sched
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1867,10 +1986,12 @@ test_43g() {
 #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
-       stat $DIR2/$tfile > /dev/null && error "stat must fail"
+       PID1=$! ; pdo_sched
+       stat $DIR2/$tfile > /dev/null &
+       PID2=$! ; pdo_sched
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1881,10 +2002,12 @@ test_43h() {
 #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
-       ls -lia $DIR2/ > /dev/null
+       PID1=$! ; pdo_sched
+       ls -lia $DIR2/ > /dev/null &
+       PID2=$! ; pdo_sched
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
+       wait $PID2
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -1896,11 +2019,13 @@ test_43i() {
 #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
-       $LFS mkdir -i 1 $DIR2/$tfile || error "remote mkdir must succeed"
+       PID1=$! ; pdo_sched
+       $LFS mkdir -i 1 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1912,10 +2037,13 @@ test_44a() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
        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_facet $SINGLEMDS lctl set_param fail_loc=0
+       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
 }
@@ -1926,10 +2054,12 @@ test_44b() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1941,10 +2071,12 @@ test_44c() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1955,10 +2087,12 @@ test_44d() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1971,10 +2105,12 @@ test_44e() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -1986,10 +2122,12 @@ test_44f() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2000,10 +2138,12 @@ test_44g() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2014,10 +2154,12 @@ test_44h() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
+       wait $PID2
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -2030,11 +2172,13 @@ test_44i() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2046,10 +2190,12 @@ test_45a() {
 #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"
+       PID1=$! ; pdo_sched
+       mkdir $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
+       wait $PID2 ; [ $? -eq 0 ] || error "mkdir must succeed"
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -2060,10 +2206,12 @@ test_45b() {
 #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
-       $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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2075,10 +2223,12 @@ test_45c() {
 #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
-       link $DIR2/$tfile-3 $DIR2/$tfile || error "link must succeed"
+       PID1=$! ; pdo_sched
+       link $DIR2/$tfile-3 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2089,10 +2239,12 @@ test_45d() {
 #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
-       rm $DIR2/$tfile && error "unlink must fail"
+       PID1=$! ; pdo_sched
+       rm $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2104,10 +2256,12 @@ test_45e() {
 #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
-       mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
+       PID1=$! ; pdo_sched
+       mv $DIR2/$tfile-3 $DIR2/$tfile &
+       PID2=$! ; pdo_sched
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2118,10 +2272,12 @@ test_45f() {
 #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
-       mv $DIR2/$tfile $DIR2/$tfile-3 && error "rename must fail"
+       PID1=$! ; pdo_sched
+       mv $DIR2/$tfile $DIR2/$tfile-3 &
+       PID2=$! ; pdo_sched
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2132,10 +2288,12 @@ test_45g() {
 #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
-       stat $DIR2/$tfile > /dev/null && error "stat must fail"
+       PID1=$! ; pdo_sched
+       stat $DIR2/$tfile > /dev/null &
+       PID2=$! ; pdo_sched
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2146,10 +2304,11 @@ test_45h() {
 #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
-       ls -lia $DIR2/ > /dev/null
+       PID1=$! ; pdo_sched
+       ls -lia $DIR2/ > /dev/null &
+       do_facet $SINGLEMDS lctl set_param fail_loc=0
        check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
+       wait $PID2
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -2161,11 +2320,13 @@ test_45i() {
 #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
-       $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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2177,10 +2338,12 @@ test_46a() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2191,10 +2354,12 @@ test_46b() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2205,10 +2370,12 @@ test_46c() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2219,10 +2386,12 @@ test_46d() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2234,10 +2403,12 @@ test_46e() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2249,10 +2420,12 @@ test_46f() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2263,10 +2436,12 @@ test_46g() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2277,11 +2452,12 @@ test_46h() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        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_facet $SINGLEMDS lctl set_param fail_loc=0
+       check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
+       wait $PID2
        rm -rf $DIR/$tfile*
        return 0
 }
@@ -2293,11 +2469,13 @@ test_46i() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2309,10 +2487,12 @@ test_47a() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        $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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2323,11 +2503,13 @@ test_47b() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        $LFS mkdir -i 1 $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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2339,10 +2521,12 @@ test_47c() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        $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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2353,11 +2537,13 @@ test_47d() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        $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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2369,11 +2555,13 @@ test_47e() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        $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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2384,11 +2572,13 @@ test_47f() {
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        $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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2396,14 +2586,18 @@ run_test 47f "pdirops: remote mkdir and rename (src)"
 
 test_47g() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+       sync
+       sync_all_data
 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
        $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_facet $SINGLEMDS lctl set_param fail_loc=0
        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
 }
@@ -2532,14 +2726,14 @@ 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"
 }
@@ -2801,7 +2995,7 @@ test_71a() {
                { skip "checkfiemap not runnable: $?" && return; }
        # 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
@@ -2849,7 +3043,7 @@ test_71b() {
 
        $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"
@@ -3042,36 +3236,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
@@ -3079,21 +3294,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"
@@ -3104,37 +3327,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"
@@ -3166,47 +3401,55 @@ 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
@@ -3245,23 +3488,25 @@ 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
@@ -3294,27 +3539,28 @@ 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
@@ -3390,7 +3636,7 @@ tbf_rule_check()
 }
 
 test_77i() {
-    [ $(lustre_version_code ost1) -ge $(version_code 2.8.55) ] ||
+       [ $(lustre_version_code ost1) -ge $(version_code 2.8.55) ] ||
                { skip "Need OST version at least 2.8.55"; return 0; }
 
        for i in $(seq 1 $OSTCOUNT)
@@ -3445,7 +3691,11 @@ 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
+       local ost_version=$(lustre_version_code ost1)
+
+       [ $ost_version -ge $(version_code 2.9.53) ] ||
+               { skip "Need OST version at least 2.9.53"; return 0; }
+       if [ $ost_version -ge $(version_code 2.8.60) ]; then
                idis="opcode="
                rateis="rate="
        fi
@@ -3472,6 +3722,57 @@ 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 [ $(lustre_version_code ost1) -lt $(version_code 2.11.50) ]; then
+               skip "Need OST version at least 2.11.50"
+               return 0
+       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; }
@@ -3514,16 +3815,59 @@ test_77k() {
        tbf_verify 10 10 "$RUNAS"
        tbf_verify 20 10
 
+       trap "cleanup_77k \"ext_a ext_b\" \"fifo\"" EXIT
+
+       [[ $(lustre_version_code ost1) -ge $(version_code 2.10.58) ]] ||
+               { skip "Need OST version at least 2.10.58"; return 0; }
+
        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() {
+       [[ $(lustre_version_code ost1) -ge $(version_code 2.10.56) ]] ||
+               { skip "Need OST version at least 2.10.56"; return 0; }
+
+       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 [ $(lustre_version_code ost1) -lt $(version_code 2.9.54) ]; then
                skip "Need OST version at least 2.9.54"
                return 0
@@ -3573,19 +3917,58 @@ 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 [ $(lustre_version_code ost1) -lt $(version_code 2.10.58) ]; then
+               skip "Need OST version at least 2.10.58"
+               return 0
+       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
@@ -3612,7 +3995,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
@@ -3658,7 +4041,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
@@ -3793,7 +4176,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
@@ -3819,7 +4202,35 @@ 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_82() {
        [[ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.91) ]] ||
@@ -3989,10 +4400,10 @@ test_93() {
        #define OBD_FAIL_MDS_LOV_CREATE_RACE     0x163
        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
@@ -4000,11 +4411,11 @@ test_93() {
        do_facet $SINGLEMDS "lctl set_param -n \
                'lod.lustre-MDT*/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 ] ||
@@ -4015,6 +4426,9 @@ run_test 93 "alloc_rr should not allocate on same ost"
 # Data-on-MDT tests
 test_100a() {
        skip "Reserved for glimpse-ahead" && return
+       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
+               skip "Need MDS version at least 2.10.55" && return
+
        mkdir -p $DIR/$tdir
 
        $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
@@ -4024,19 +4438,21 @@ test_100a() {
 
        $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 | \
-               awk '/ldlm_glimpse/ {print $2}')
-       [ -z $gls ] || error "Unexpected $gls glimpse RPCs"
+       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 ldlm_glimpse | wc -l)
-       [ "1" == "$gls" ] || error "Expect 1 glimpse RPCs but got $gls"
+       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() {
+       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
+               skip "Need MDS version at least 2.10.55" && return
+
        mkdir -p $DIR/$tdir
 
        $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
@@ -4049,15 +4465,17 @@ test_100b() {
        # 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 |
-                       awk '/ldlm_glimpse/ {print $2}')
+       local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
        # both stats should cause no glimpse requests
-       [ -z $gls ] || error "Unexpected $gls glimpse RPCs"
+       [ $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() {
+       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
+               skip "Need MDS version at least 2.10.55" && return
+
        mkdir -p $DIR/$tdir
 
        $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
@@ -4070,7 +4488,7 @@ test_100c() {
        $CHECKSTAT -t file -s 2097152 $DIR/$tdir/dom ||
                error "Wrong size from stat #1"
 
-       local gls=$(lctl get_param -n osc.*.stats | grep ldlm_glimpse | wc -l)
+       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
@@ -4078,6 +4496,9 @@ test_100c() {
 run_test 100c "DoM: write vs stat without IO lock (combined file)"
 
 test_100d() {
+       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
+               skip "Need MDS version at least 2.10.55" && return
+
        mkdir -p $DIR/$tdir
 
        $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
@@ -4092,62 +4513,109 @@ test_100d() {
        $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom ||
                error "Wrong size from stat #1"
 
-       local gls=$(lctl get_param -n osc.*.stats | grep ldlm_glimpse | wc -l)
+       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_101a() {
+       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
+               skip "Need MDS version at least 2.10.55" && return
+
        $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
-       lctl set_param -n mdc.*.stats=clear
        # 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"
+       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 ost_write | wc -l)
+
+       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() {
+       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
+               skip "Need MDS version at least 2.10.55" && return
+
        $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
        touch $DIR1/${tfile}_2
-       lctl set_param -n mdc.*.stats=clear
        # 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 ost_write | wc -l)
+
+       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() {
+       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
+               skip "Need MDS version at least 2.10.55" && return
+
        $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
-       lctl set_param -n mdc.*.stats=clear
        # 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 2
-       rm $DIR2/$tfile > /dev/null || error "Unlink fails"
-       kill -USR1 $MULTIOP_PID || return 2
-       wait $MULTIOP_PID || return 3
-       local writes=$(lctl get_param -n mdc.*.stats | grep ost_write | wc -l)
+       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"
+
 log "cleanup: ======================================================"
 
 # kill and wait in each test only guarentee script finish, but command in script