Whamcloud - gitweb
LU-17705 ptlrpc: replace synchronize_rcu() with rcu_barrier()
[fs/lustre-release.git] / lustre / tests / sanityn.sh
index 07932e5..1efffbc 100755 (executable)
@@ -19,16 +19,12 @@ init_logging
 
 ALWAYS_EXCEPT="$SANITYN_EXCEPT "
 # bug number for skipped test:  LU-7105
-ALWAYS_EXCEPT+="                28 "
+ALWAYS_EXCEPT+="                28"
 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
 
-# skip tests for PPC until they are fixed
-if [[ $(uname -m) = ppc64 ]]; then
-       # bug number:    LU-11597 LU-11787
-       ALWAYS_EXCEPT+=" 16a      71a"
-fi
-
 if [ $mds1_FSTYPE = "zfs" ]; then
+       # bug number:    LU-15757 (test_102() causes crash in umount later)
+       ALWAYS_EXCEPT+=" 102"
        # LU-2829 / LU-2887 - make allowances for ZFS slowness
        TEST33_NFILES=${TEST33_NFILES:-1000}
 fi
@@ -58,6 +54,34 @@ dd if=/dev/urandom of=$SAMPLE_FILE bs=1M count=1
 
 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
 
+test_0() {
+       local client2=${CLIENT2:-$HOSTNAME}
+       local tmp=$(mktemp)
+
+       printf 'a b\n' > $tmp
+
+       do_node_vp "$HOSTNAME" printf 'a b\n' |
+       diff $tmp - || error "do_node_vp mismatch"
+
+       do_node_vp "$client2" printf 'a b\n' |
+       diff $tmp - || error "do_node_vp mismatch"
+
+       do_facet_vp mds1 printf 'a b\n' |
+       diff $tmp - || error "do_facet_vp mismatch"
+
+       printf '%s' 1 2 3 4 5 6 7 8 \ 9 10 ' ' '"' "'" \! \' \( \) $'\n' > $tmp
+
+       do_node_vp "$HOSTNAME" printf '%s' 1 2 3 4 5 6 7 8 \ 9 10 ' ' '"' "'" \! \' \( \) $'\n' |
+       diff $tmp - || error "do_node_vp mismatch"
+
+       do_node_vp "$client2" printf '%s' 1 2 3 4 5 6 7 8 \ 9 10 ' ' '"' "'" \! \' \( \) $'\n' |
+       diff $tmp - || error "do_node_vp mismatch"
+
+       do_facet_vp mds1 printf '%s' 1 2 3 4 5 6 7 8 \ 9 10 ' ' '"' "'" \! \' \( \) $'\n' |
+       diff $tmp - || error "do_facet_vp mismatch"
+}
+run_test 0 "do_node_vp() and do_facet_vp() do the right thing"
+
 test_1() {
        touch $DIR1/$tfile
        [ -f $DIR2/$tfile ] || error "Check create"
@@ -283,7 +307,7 @@ test_11() {
 run_test 11 "execution of file opened for write should return error ===="
 
 test_12() {
-       DIR=$DIR DIR2=$DIR2 sh lockorder.sh
+       DIR=$DIR DIR2=$DIR2 bash lockorder.sh
 }
 run_test 12 "test lock ordering (link, stat, unlink)"
 
@@ -361,7 +385,7 @@ run_test 14d "chmod of executing file is still possible ========"
 
 test_15() {    # bug 974 - ENOSPC
        echo "PATH=$PATH"
-       sh oos2.sh $MOUNT1 $MOUNT2
+       bash oos2.sh $MOUNT1 $MOUNT2
        wait_delete_completed
        grant_error=$(dmesg | grep "< tot_grant")
        [ -z "$grant_error" ] || error "$grant_error"
@@ -389,6 +413,8 @@ test_16a() {
        local stripe_size=$(do_facet $SINGLEMDS \
                "$LCTL get_param -n lod.$(facet_svc $SINGLEMDS)*.stripesize")
 
+       check_set_fallocate
+
        # 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
@@ -396,13 +422,13 @@ test_16a() {
        rm -f $file1
 
        $LFS setstripe -c -1 $file1 # b=10919
-       fsx -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 $file1 $file2 ||
+       $FSX -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 $file1 $file2 ||
                error "fsx failed"
        rm -f $file1
 
-       # O_DIRECT reads and writes must be aligned to the device block size.
-       fsx -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 -Z -r 4096 \
-               -w 4096 $file1 $file2 || error "fsx with O_DIRECT failed."
+       # O_DIRECT reads and writes must be aligned to the PAGE_SIZE.
+       $FSX -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 -Z -r $PAGE_SIZE \
+               -w $PAGE_SIZE $file1 $file2 || error "fsx with O_DIRECT failed."
 }
 run_test 16a "$FSXNUM iterations of dual-mount fsx"
 
@@ -412,6 +438,8 @@ test_16b() {
        local file2=$DIR2/$tfile
        local stripe_size=($($LFS getstripe -S $DIR))
 
+       check_set_fallocate
+
        # 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 ||
@@ -423,7 +451,7 @@ test_16b() {
        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 \
+       $FSX -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -o 8192 -S 0 \
                $file1 $file2 || error "fsx with tiny write failed."
 }
 run_test 16b "$FSXNUM iterations of dual-mount fsx at small size"
@@ -436,6 +464,8 @@ test_16c() {
 
        [ "$ost1_FSTYPE" != ldiskfs ] && skip "dio on ldiskfs only"
 
+       check_set_fallocate
+
        # 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
@@ -452,7 +482,7 @@ test_16c() {
        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 ||
+       $FSX -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 $file1 $file2 ||
                error "fsx failed"
        rm -f $file1
 
@@ -467,19 +497,20 @@ test_16d() {
        local file1=$DIR1/$tfile
        local file2=$DIR2/$tfile
        local file3=$DIR1/file
+       local tmpfile=$(mktemp)
        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
+       stack_trap "rm -f $file1 $file2 $file3 $tmpfile"
        dd if=/dev/zero of=$file1 bs=$stripe_size count=$OSTCOUNT oflag=sync
        dd if=/dev/zero of=$file2 bs=$stripe_size count=$OSTCOUNT oflag=sync
        rm -f $file1
 
-       local tmpfile=`mktemp`
        $LFS setstripe -c -1 $file1 # b=10919
        $LCTL set_param ldlm.namespaces.*.lru_size=clear
-       
+
        # direct write on one client and direct read from another
        dd if=/dev/urandom of=$file1 bs=1M count=100 oflag=direct
        dd if=$file2 of=$tmpfile iflag=direct bs=1M
@@ -497,13 +528,15 @@ test_16d() {
        # buffer read from another client
        dd if=$file2 of=$file3 bs=1M count=100
        diff $file3 $tmpfile || error "file different(3)"
-
-       rm -f $file1 $file2 $file3 $tmpfile
-
 }
 run_test 16d "Verify DIO and buffer IO with two clients"
 
 test_16e() { # LU-13227
+       # issue:        LU-14314
+
+       (( "$MDS1_VERSION" >= $(version_code 2.13.53) )) ||
+               skip "Need MDS version at least 2.13.53"
+
        local file1=$DIR1/$tfile
        local file2=$DIR2/$tfile
 
@@ -524,13 +557,315 @@ test_16e() { # LU-13227
 }
 run_test 16e "Verify size consistency for O_DIRECT write"
 
+test_16f() { # LU-14541
+       local file1=$DIR1/$tfile
+       local file2=$DIR2/$tfile
+       local duration=20
+       local status
+
+       (( $MDS1_VERSION > $(version_code 2.15.51) )) ||
+               skip "Need MDS version at least 2.15.51"
+
+       timeout --preserve-status --signal=USR1 $duration \
+               rw_seq_cst_vs_drop_caches $file1 $file2
+       status=$?
+
+       case $((status & 0x7f)) in
+               0)
+                       echo OK # Computers must be fast now.
+                       ;;
+               6) # SIGABRT
+                       error "sequential consistency violation detected"
+                       ;;
+               10) # SIGUSR1
+                       echo TIMEOUT # This is fine.
+                       ;;
+               *)
+                       error "strange status '$status'"
+                       ;;
+       esac
+
+       rm -f $file1
+}
+run_test 16f "rw sequential consistency vs drop_caches"
+
+test_16g() {
+       local file1=$DIR1/$tfile
+       local file2=$DIR2/$tfile
+       local duration=20
+       local status
+
+       timeout --preserve-status --signal=USR1 $duration \
+               rw_seq_cst_vs_drop_caches -m $file1 $file2
+       status=$?
+
+       case $((status & 0x7f)) in
+               0)
+                       echo OK # Computers must be fast now.
+                       ;;
+               6) # SIGABRT
+                       error "sequential consistency violation detected"
+                       ;;
+               10) # SIGUSR1
+                       echo TIMEOUT # This is fine.
+                       ;;
+               *)
+                       error "strange status '$status'"
+                       ;;
+       esac
+
+       rm -f $file1
+}
+run_test 16g "mmap rw sequential consistency vs drop_caches"
+
+test_16h() {
+       local tf=$DIR/$tdir/$tfile
+       local tf2=$DIR2/$tdir/$tfile
+       local cmd="$MMAP_CAT $tf | od -x | tail -q -n4"
+       local cmd2="$MMAP_CAT $tf2 | od -x | tail -q -n4"
+
+       test_mkdir $DIR/$tdir
+
+       # create file and populate data
+       cp /etc/passwd $tf || error "cp failed"
+
+       local size=$(stat -c %s $tf)
+       c1=$(eval $cmd)
+       c2=$(eval $cmd2)
+       if [[ "$c1" != "$c2" ]]; then
+               echo "  ------- mount 1 read --------"
+               echo $c1
+               echo "  ------- mount 2 read --------"
+               echo $c2
+               error "content mismatch"
+       fi
+
+       echo "  ------- before truncate --------"
+       echo $c1
+
+       # truncate file
+       $TRUNCATE $tf $((size / 2)) || error "truncate file"
+
+       #cancel_lru_locks
+       echo "  ------- after truncate --------"
+
+       # repeat the comparison
+       c1=$(eval $cmd)
+       c2=$(eval $cmd2)
+       if [[ "$c1" != "$c2" ]]; then
+               echo "  ------- mount 1 read --------"
+               echo $c1
+               echo "  ------- mount 2 read --------"
+               echo $c2
+               error "content mismatch after truncate"
+       fi
+       echo $c2
+}
+run_test 16h "mmap read after truncate file"
+
+test_16i() {
+       local tf=$DIR/$tdir/$tfile
+       local tf2=$DIR2/$tdir/$tfile
+
+       test_mkdir $DIR/$tdir
+
+       # create file and populate data
+       cp /etc/passwd $tf || error "cp failed"
+
+       local size=$(stat -c %s $tf)
+
+       c1=$(dd if=$tf bs=1 2>/dev/null | od -x | tail -q -n4)
+       c2=$(dd if=$tf2 bs=1 2>/dev/null | od -x | tail -q -n4)
+
+       if [[ "$c1" != "$c2" ]]; then
+               echo "  ------- mount 1 read --------"
+               echo $c1
+               echo "  ------- mount 2 read --------"
+               echo $c2
+               error "content mismatch"
+       fi
+
+       echo "  ------- before truncate --------"
+       echo $c1
+
+       # truncate file
+       $TRUNCATE $tf $((size / 2)) || error "truncate file"
+
+       echo "  ------- after truncate --------"
+
+       # repeat the comparison
+       c1=$(dd if=$tf bs=1 2>/dev/null | od -x | tail -q -n4)
+       c2=$(dd if=$tf2 bs=1 2>/dev/null | od -x | tail -q -n4)
+
+       if [[ "$c1" != "$c2" ]]; then
+               echo "  ------- mount 1 read --------"
+               echo $c1
+               echo "  ------- mount 2 read --------"
+               echo $c2
+               error "content mismatch after truncate"
+       fi
+       echo $c2
+}
+run_test 16i "read after truncate file"
+
+test_16j()
+{
+       (( $OSTCOUNT >= 2 )) || skip "needs >= 2 OSTs"
+
+       local stripe_size=$((1024 * 1024)) #1 MiB
+       # Max i/o below is ~ 4 * stripe_size, so this gives ~5 i/os
+       local file_size=$((25 * stripe_size))
+       local bsizes
+
+       $LFS setstripe -c 2 -S $stripe_size $DIR/$tfile.1
+       stack_trap "rm -f $DIR/$tfile.1"
+
+       # Just a bit bigger than the largest size in the test set below
+       dd if=/dev/urandom bs=$file_size count=1 of=$DIR/$tfile.1 ||
+               error "buffered i/o to create file failed"
+
+       if zfs_or_rotational; then
+               # DIO on ZFS can take up to 2 seconds per IO
+               # rotational is better, but still slow.
+               # Limit testing on those media to larger sizes
+               bsizes="$((stripe_size - PAGE_SIZE)) $stripe_size \
+                       $((stripe_size + 1024))"
+       else
+               bsizes="$((PAGE_SIZE / 4)) $((PAGE_SIZE - 1024)) \
+                       $((PAGE_SIZE - 1)) $PAGE_SIZE $((PAGE_SIZE + 1024)) \
+                       $((PAGE_SIZE * 3/2)) $((PAGE_SIZE * 4)) \
+                       $((stripe_size - 1)) $stripe_size \
+                       $((stripe_size + 1)) $((stripe_size * 3/2)) \
+                       $((stripe_size * 4)) $((stripe_size * 4 + 1))"
+       fi
+
+       # 1 process (BIO or DIO) on each client
+       for bs in $bsizes; do
+               $LFS setstripe -c 2 -S $stripe_size $DIR/$tfile.2
+               echo "bs: $bs, file_size $file_size"
+               dd if=$DIR/$tfile.1 bs=$((bs *2 )) of=$DIR/tfile.2 \
+                       conv=notrunc oflag=direct iflag=direct &
+               pid_dio1=$!
+               # Buffered I/O with similar but not the same block size
+               dd if=$DIR2/$tfile.1 bs=$((bs * 2)) of=$DIR2/$tfile.2 \
+                       conv=notrunc &
+               pid_bio2=$!
+               wait $pid_dio1
+               rc1=$?
+               wait $pid_bio2
+               rc2=$?
+               if (( rc1 != 0 )); then
+                       error "dio copy 1 w/bsize $bs failed: $rc1"
+               fi
+               if (( rc2 != 0 )); then
+                       error "buffered copy 2 w/bsize $bs failed: $rc2"
+               fi
+
+               $CHECKSTAT -t file -s $file_size $DIR/$tfile.2 ||
+                       error "size incorrect"
+               $CHECKSTAT -t file -s $file_size $DIR2/$tfile.2 ||
+                       error "size incorrect - mount 2"
+               cmp --verbose $DIR/$tfile.1 $DIR/$tfile.2 ||
+                       error "files differ, bsize $bs"
+               cmp --verbose $DIR2/$tfile.1 $DIR2/$tfile.2 ||
+                       error "files differ, bsize $bs - mount 2"
+               rm -f $DIR/$tfile.2
+       done
+
+       # 2 processes - both DIO and BIO - on each client
+       for bs in $bsizes; do
+               $LFS setstripe -c 2 -S $stripe_size $DIR/$tfile.2
+               echo "bs: $bs, file_size $file_size"
+               # Client 1
+               dd if=$DIR/$tfile.1 bs=$((bs *2 )) of=$DIR/tfile.2 \
+                       conv=notrunc oflag=direct iflag=direct &
+               pid_dio1=$!
+               # Buffered I/O with similar but not the same block size
+               dd if=$DIR/$tfile.1 bs=$((bs * 2)) of=$DIR/$tfile.2 \
+                       conv=notrunc &
+               pid_bio2=$!
+               # Client 2
+               dd if=$DIR2/$tfile.1 bs=$((bs *2 )) of=$DIR2/tfile.2 \
+                       conv=notrunc oflag=direct iflag=direct &
+               pid_dio3=$!
+               # Buffered I/O with similar but not the same block size
+               dd if=$DIR2/$tfile.1 bs=$((bs * 2)) of=$DIR2/$tfile.2 \
+                       conv=notrunc &
+               pid_bio4=$!
+               wait $pid_dio1
+               rc1=$?
+               wait $pid_bio2
+               rc2=$?
+               wait $pid_dio3
+               rc3=$?
+               wait $pid_bio4
+               rc4=$?
+
+               if (( rc1 != 0 )); then
+                       error "dio copy 1 w/bsize $bs failed: $rc1"
+               fi
+               if (( rc2 != 0 )); then
+                       error "buffered copy 2 w/bsize $bs failed: $rc2"
+               fi
+               if (( rc3 != 0 )); then
+                       error "dio copy 3 w/bsize $bs failed: $rc1"
+               fi
+               if (( rc4 != 0 )); then
+                       error "buffered copy 4 w/bsize $bs failed: $rc2"
+               fi
+
+               $CHECKSTAT -t file -s $file_size $DIR/$tfile.2 ||
+                       error "size incorrect"
+               $CHECKSTAT -t file -s $file_size $DIR2/$tfile.2 ||
+                       error "size incorrect - mount 2"
+               cmp --verbose $DIR/$tfile.1 $DIR/$tfile.2 ||
+                       error "files differ, bsize $bs"
+               cmp --verbose $DIR2/$tfile.1 $DIR2/$tfile.2 ||
+                       error "files differ, bsize $bs - mount 2"
+               rm -f $DIR/$tfile.2
+       done
+}
+run_test 16j "race dio with buffered i/o"
+
+test_16k() {
+       local fsxN=${FSX_NP:-5}
+       local fsxNops=${FSX_NOPS:-10000}
+       local fsxNparams=${FSXPARAMS_16k:-""}
+       local dropsleep=${DROP_SLEEP:-3}
+       local dpipd
+       local -a fsxpids
+       local cmd
+
+       [ "$SLOW" = "no" ] && fsxNops=1000
+
+       while true; do
+               echo 3 > /proc/sys/vm/drop_caches
+               sleep $dropsleep
+       done &
+       dpipd=$!
+       stack_trap "kill -9 $dpipd"
+
+       for ((i = 1; i <= fsxN; i++)); do
+               cmd="$FSX $fsxNparams -N $fsxNops $DIR/fsxfile.${i} -l $((64 * 1024 * 1024))"
+               echo "+ $cmd"
+               eval $cmd &
+               fsxpids[$i]=$!
+       done
+       for ((i = 1; i <= fsxN; i++)); do
+               wait ${fsxpids[$i]} && echo "+ fsx $i done: rc=$?" ||
+                       error "- fsx $i FAILURE! rc=$?"
+               date
+       done
+}
+run_test 16k "Parallel FSX and drop caches should not panic"
+
 test_17() { # bug 3513, 3667
        remote_ost_nodsh && skip "remote OST with nodsh" && return
 
        lfs setstripe $DIR1/$tfile -i 0 -c 1
        cp $SAMPLE_FILE $DIR1/$tfile
        cancel_lru_locks osc > /dev/null
-       #define OBD_FAIL_ONCE|OBD_FAIL_LDLM_CREATE_RESOURCE    0x30a
+       #define CFS_FAIL_ONCE|OBD_FAIL_LDLM_CREATE_RESOURCE    0x30a
        do_facet ost1 lctl set_param fail_loc=0x8000030a
        ls -ls $DIR1/$tfile | awk '{ print $1,$6 }' > $DIR1/$tfile-1 & \
        ls -ls $DIR2/$tfile | awk '{ print $1,$6 }' > $DIR2/$tfile-2
@@ -550,22 +885,27 @@ test_18() {
                 excepts="$excepts -e $(($(printf %d \'$idx)-96))"
         done
 
-       $LUSTRE/tests/mmap_sanity -d $MOUNT1 -m $MOUNT2 $excepts
+       excepts="$excepts -e 7 -e 8 -e 9"
+       $LUSTRE/tests/mmap_sanity -d $MOUNT1 -m $MOUNT2 $excepts ||
+               error "mmap_sanity test failed"
        sync; sleep 1; sync
 }
 run_test 18 "mmap sanity check ================================="
 
 test_19() { # bug3811
        local node=$(facet_active_host ost1)
+       local device="$FSNAME-OST*"
 
-       [ "x$DOM" = "xyes" ] && node=$(facet_active_host $SINGLEMDS)
+       [ "x$DOM" = "xyes" ] && node=$(facet_active_host $SINGLEMDS) &&
+               device="$FSNAME-MDT*"
 
        # check whether obdfilter is cache capable at all
-       get_osd_param $node '' read_cache_enable >/dev/null ||
+       get_osd_param $node $device read_cache_enable >/dev/null ||
                skip "not cache-capable obdfilter"
 
-       local MAX=$(get_osd_param $node '' readcache_max_filesize | head -n 1)
-       set_osd_param $node '' readcache_max_filesize 4096
+       local max=$(get_osd_param $node $device readcache_max_filesize |\
+               head -n 1)
+       set_osd_param $node $device readcache_max_filesize 4096
        dd if=/dev/urandom of=$TMP/$tfile bs=512k count=32
        local SUM=$(cksum $TMP/$tfile | cut -d" " -f 1,2)
        cp $TMP/$tfile $DIR1/$tfile
@@ -580,22 +920,22 @@ test_19() { # bug3811
                [ "$(cat $TMP/sum2)" = "$SUM" ] || \
                        error "$DIR2/$tfile $(cat $TMP/sum2) != $SUM"
        done
-       set_osd_param $node '' readcache_max_filesize $MAX
+       set_osd_param $node $device readcache_max_filesize $max
        rm $DIR1/$tfile
 }
 run_test 19 "test concurrent uncached read races ==============="
 
 test_20() {
-       test_mkdir $DIR1/d20
+       test_mkdir $DIR1/$tdir
        cancel_lru_locks
-       CNT=$((`lctl get_param -n llite.*.dump_page_cache | wc -l`))
-       $MULTIOP $DIR1/f20 Ow8190c
-       $MULTIOP $DIR2/f20 Oz8194w8190c
-       $MULTIOP $DIR1/f20 Oz0r8190c
+       CNT=$($LCTL get_param -n llite.*.dump_page_cache | wc -l)
+       $MULTIOP $DIR1/$tdir/$tfile Ow8190c
+       $MULTIOP $DIR2/$tdir/$tfile Oz8194w8190c
+       $MULTIOP $DIR1/$tdir/$tfile Oz0r8190c
        cancel_lru_locks
-       CNTD=$((`lctl get_param -n llite.*.dump_page_cache | wc -l` - $CNT))
-       [ $CNTD -gt 0 ] && \
-           error $CNTD" page left in cache after lock cancel" || true
+       CNT2=$($LCTL get_param -n llite.*.dump_page_cache | wc -l)
+       [[ $CNT2 == $CNT ]] ||
+               error $((CNT2 - CNT))" page left in cache after lock cancel"
 }
 run_test 20 "test extra readahead page left in cache ===="
 
@@ -751,7 +1091,7 @@ test_27() {
        lctl clear
        dd if=/dev/zero of=$DIR2/$tfile bs=$((4096+4))k conv=notrunc count=4 seek=3 &
        DD2_PID=$!
-       usleep 50
+       sleep 0.5
        log "dd 1 started"
 
        dd if=/dev/zero of=$DIR1/$tfile bs=$((16384-1024))k conv=notrunc count=1 seek=4 &
@@ -768,47 +1108,14 @@ test_27() {
 run_test 27 "align non-overlapping extent locks from request ==="
 
 test_28() { # bug 9977
-       ECHO_UUID="ECHO_osc1_UUID"
-       tOST=$($LCTL dl | awk '/-osc-|OSC.*MNT/ { print $4 }' | head -n1)
-
-       $LFS setstripe $DIR1/$tfile -S 1048576 -i 0 -c 2
-       tOBJID=`$LFS getstripe $DIR1/$tfile | awk '$1 == 1 {print $2}'`
-       dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2
-
-       $LCTL <<-EOF
-               newdev
-               attach echo_client ECHO_osc1 $ECHO_UUID
-               setup $tOST
-       EOF
-
-       tECHOID=`$LCTL dl | grep $ECHO_UUID | awk '{ print $1 }'`
-       $LCTL --device $tECHOID destroy "${tOBJID}:0"
-
-       $LCTL <<-EOF
-               cfg_device ECHO_osc1
-               cleanup
-               detach
-       EOF
-
-       # reading of 1st stripe should pass
-       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 failed"
-       # reading of 1st stripe should pass
-       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 failed"
+       skip "echo_client on osc is no longer supported"
 }
 run_test 28 "read/write/truncate file with lost stripes"
 
 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' &
+       bash -c 'sleep 1; rm -f $DIR2/$tdir/bash; cp /bin/bash $DIR2/$tdir' &
        $DIR1/$tdir/bash -c 'sleep 2;
                openfile -f O_RDONLY /proc/$$/exe >& /dev/null; echo $?'
        wait
@@ -852,49 +1159,29 @@ test_31b() {
 }
 run_test 31b "voluntary OST cancel / blocking ast race=============="
 
-# enable/disable lockless truncate feature, depending on the arg 0/1
-enable_lockless_truncate() {
-       lctl set_param -n $OSC.*.lockless_truncate $1
-}
-
-test_32a() { # bug 11270
-       local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
-       local stripe_size=$(do_facet $SINGLEMDS \
-               "$LCTL get_param -n lod.$(facet_svc $SINGLEMDS)*.stripesize")
+#LU-14949 - multi-client version of the test 31r in sanity.
+test_31r() {
+       touch $DIR/$tfile.target
+       touch $DIR/$tfile.source
 
-       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_size > \
-               /dev/null 2>&1
-       clear_stats $OSC.*.${OSC}_stats
+       ls -l $DIR/$tfile.target # cache it for sure
 
-       log "checking cached lockless truncate"
-       $TRUNCATE $DIR1/$tfile 8000000
-       $CHECKSTAT -s 8000000 $DIR2/$tfile || error "wrong file size"
-       [ $(calc_stats $OSC.*.${OSC}_stats lockless_truncate) -ne 0 ] ||
-               error "cached truncate isn't lockless"
+       #OBD_FAIL_LLITE_OPEN_DELAY 0x1419
+       $LCTL set_param fail_loc=0x1419 fail_val=3
+       cat $DIR/$tfile.target &
+       CATPID=$!
 
-       log "checking not cached lockless truncate"
-       $TRUNCATE $DIR2/$tfile 5000000
-       $CHECKSTAT -s 5000000 $DIR1/$tfile || error "wrong file size"
-       [ $(calc_stats $OSC.*.${OSC}_stats lockless_truncate) -ne 0 ] ||
-               error "not cached truncate isn't lockless"
+       # Guarantee open is waiting before we get here
+       sleep 1
+       mv $DIR2/$tfile.source $DIR2/$tfile.target
 
-       log "disabled lockless truncate"
-       enable_lockless_truncate 0
-       clear_stats $OSC.*.${OSC}_stats
-       $TRUNCATE $DIR2/$tfile 3000000
-       $CHECKSTAT -s 3000000 $DIR1/$tfile || error "wrong file size"
-       [ $(calc_stats $OSC.*.${OSC}_stats lockless_truncate) -eq 0 ] ||
-               error "lockless truncate disabling failed"
-       rm -f $DIR1/$tfile
+       wait $CATPID
+       RC=$?
+       if [[ $RC -ne 0 ]]; then
+               error "open with cat failed, rc=$RC"
+       fi
 }
-run_test 32a "lockless truncate"
+run_test 31r "open-rename(replace) race"
 
 test_32b() { # bug 11270
        remote_ost_nodsh && skip "remote OST with nodsh" && return
@@ -947,32 +1234,33 @@ test_32b() { # bug 11270
        restore_lustre_params <$p
        rm -f $p
 }
-run_test 32b "lockless i/o"
+# Disable test 32b prior to full removal
+#run_test 32b "lockless i/o"
 
 print_jbd_stat () {
-    local dev
-    local mdts=$(get_facets MDS)
-    local varcvs
-    local mds
-
-    local stat=0
-    for mds in ${mdts//,/ }; do
-        varsvc=${mds}_svc
-        dev=$(basename $(do_facet $mds "lctl get_param -n osd*.${!varsvc}.mntdev|\
-               xargs readlink -f" ))
-       val=$(do_facet $mds "cat /proc/fs/jbd*/${dev}{,:*,-*}/info 2>/dev/null |
-               head -n1")
-        val=${val%% *};
-        stat=$(( stat + val))
-    done
-    echo $stat
+       local mdts=$(get_facets MDS)
+       local stat=0
+       local varsvc
+       local dev
+       local mds
+
+       for mds in ${mdts//,/ }; do
+               varsvc=${mds}_svc
+
+               dev=$(basename $(do_facet $mds "lctl get_param -n \
+                       osd*.${!varsvc}.mntdev | xargs readlink -f"))
+               val=$(do_facet $mds "cat /proc/fs/jbd*/${dev}{,:*,-*}/info \
+                       2>/dev/null | head -n1")
+               val=${val%% *};
+               stat=$((stat + val))
+       done
+       echo $stat
 }
 
 # commit on sharing tests
 test_33a() {
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
 
-       [ -z "$CLIENTS" ] && skip "Need two or more clients, have $CLIENTS"
        [ $CLIENTCOUNT -lt 2 ] &&
                skip "Need two or more clients, have $CLIENTCOUNT"
 
@@ -1023,7 +1311,6 @@ run_test 33a "commit on sharing, cross crete/delete, 2 clients, benchmark"
 test_33b() {
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
 
-       [ -n "$CLIENTS" ] || { skip "Need two or more clients" && return 0; }
        [ $CLIENTCOUNT -ge 2 ] ||
                { skip "Need two or more clients, have $CLIENTCOUNT" &&
                                                                return 0; }
@@ -1079,45 +1366,94 @@ test_33b() {
 }
 run_test 33b "COS: cross create/delete, 2 clients, benchmark under remote dir"
 
+# arg1 is description, arg2 is operations before Sync-on-Lock-Cancel, arg3 is
+# the operation that triggers SoLC
+op_trigger_solc() {
+       local sync_count
+       local total=0
+       local nodes=$(comma_list $(mdts_nodes))
+
+       sync_all_data
+
+       # trigger CoS twice in case transaction commit before unlock
+       for i in 1 2; do
+               bash -c "$2"
+               do_nodes $nodes "$LCTL set_param -n mdt.*.sync_count=0"
+               bash -c "$3"
+               sync_count=$(do_nodes $nodes \
+                       "lctl get_param -n mdt.*MDT*.sync_count" | calc_sum)
+               total=$((total + sync_count));
+               rm -rf $DIR/$tdir/*
+               sync_all_data
+       done
+
+       echo $1
+       echo "  $2"
+       echo "  $3"
+       echo "  SoLC count $total"
+       (( total > 0 )) || error "$3 didn't trigger SoLC"
+}
+
+test_33_run() {
+       echo $1
+       echo "  $2"
+       eval $2
+}
+
 test_33c() {
-       [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
-       [ "$MDS1_VERSION" -lt $(version_code 2.7.63) ] &&
+       (( MDSCOUNT >= 2 )) || skip "needs >= 2 MDTs"
+       (( MDS1_VERSION >= $(version_code 2.7.63) )) ||
                skip "DNE CoS not supported"
 
        # LU-13522
        stop mds1
        start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS || error "start mds1 failed"
 
-       local sync_count
-
-       mkdir $DIR/$tdir
+       mkdir_on_mdt0 $DIR/$tdir
        sync_all_data
-       do_facet mds1 "lctl set_param -n mdt.*.sync_count=0"
-       # 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"
 
+       if (( MDS1_VERSION < $(version_code 2.15.55.204) )); then
+               op_trigger_solc "create remote dir and local dir" \
+                       "$LFS mkdir -i 1 $DIR/$tdir/remote" \
+                       "$LFS mkdir -i 0 $DIR/$tdir/local"
+               (( MDSCOUNT > 2 )) &&
+               op_trigger_solc "create remote dirs on different MDTs" \
+                       "$LFS mkdir -i 1 $DIR/$tdir/remote.1" \
+                       "$LFS mkdir -i 2 $DIR/$tdir/remote.2"
+       fi
+       op_trigger_solc "create file on 2nd stripe under striped directory" \
+               "$LFS mkdir -i 0 -c 2 $DIR/$tdir/striped" \
+               "touch $DIR2/$tdir/striped/subfile"
+
+       echo
+       echo "Below operations shouldn't trigger Solc:"
+       $LFS mkdir -i 0 -c 2 $DIR/$tdir/striped
        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/local.3
+       if (( MDS1_VERSION >= $(version_code 2.15.55.204) )); then
+               test_33_run "create file on 2nd stripe after setattr" \
+                       "chmod 777 $DIR/$tdir/striped; \
+                        touch $DIR2/$tdir/striped/subfile"
+               test_33_run "create remote dir and local dir" \
+                       "$LFS mkdir -i 1 $DIR/$tdir/remote" \
+                       "$LFS mkdir -i 0 $DIR/$tdir/local"
+               (( MDSCOUNT > 2 )) &&
+               test_33_run "create remote dirs on different MDTs" \
+                       "$LFS mkdir -i 1 $DIR/$tdir/remote.1" \
+                       "$LFS mkdir -i 2 $DIR/$tdir/remote.2"
+       fi
+       test_33_run "create local dir after remote dir creation transaction commit" \
+               "$LFS mkdir -i 1 $DIR/$tdir/remote.3; \
+                do_facet mds2 $LCTL set_param -n osd*.*MDT0001.force_sync 1;
+                mkdir $DIR/$tdir/local.3"
        sync_count=$(do_facet mds1 "lctl get_param -n mdt.*MDT0000.sync_count")
-       echo "sync_count $sync_count"
+       echo "Solc count $sync_count"
        [ $sync_count -eq 0 ] || error "Sync-Lock-Cancel triggered"
 }
-run_test 33c "Cancel cross-MDT lock should trigger Sync-Lock-Cancel"
+run_test 33c "Cancel cross-MDT lock should trigger Sync-on-Lock-Cancel"
 
-# arg1 is operations done before CoS, arg2 is the operation that triggers CoS
+# arg1 is description, arg2 is operations done before CoS, arg3 is the operation
+# that triggers CoS
 op_trigger_cos() {
        local commit_nr
        local total=0
@@ -1127,9 +1463,9 @@ op_trigger_cos() {
 
        # trigger CoS twice in case transaction commit before unlock
        for i in 1 2; do
-               sh -c "$1"
+               bash -c "$2"
                do_nodes $nodes "lctl set_param -n mdt.*.async_commit_count=0"
-               sh -c "$2"
+               bash -c "$3"
                commit_nr=$(do_nodes $nodes \
                        "lctl get_param -n mdt.*.async_commit_count" | calc_sum)
                total=$((total + commit_nr));
@@ -1137,75 +1473,101 @@ op_trigger_cos() {
                sync_all_data
        done
 
-       echo "CoS count $total"
-       [ $total -gt 0 ] || error "$2 didn't trigger CoS"
+       echo $1
+       echo "  $2"
+       echo "  $3"
+       echo "  CoS count $total"
+       (( total > 0 )) || error "$3 didn't trigger CoS"
 }
 
 test_33d() {
-       [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
-       [ "$MDS1_VERSION" -lt $(version_code 2.7.63) ] &&
+       (( MDSCOUNT > 1 )) || skip "needs >= 2 MDTs"
+       (( MDS1_VERSION >= $(version_code 2.7.63) )) ||
                skip "DNE CoS not supported"
 
-       # remote directory create
-       op_trigger_cos "mkdir $DIR/$tdir" "$LFS mkdir -i 1 $DIR/$tdir/subdir"
-       # remote directory unlink
-       op_trigger_cos "$LFS mkdir -i 1 $DIR/$tdir" "rmdir $DIR/$tdir"
-       # striped directory create
-       op_trigger_cos "mkdir $DIR/$tdir" "$LFS mkdir -c 2 $DIR/$tdir/subdir"
-       # striped directory setattr
-       op_trigger_cos "$LFS mkdir -c 2 $DIR/$tdir; touch $DIR/$tdir" \
-               "chmod 713 $DIR/$tdir"
-       # striped directory unlink
-       op_trigger_cos "$LFS mkdir -c 2 $DIR/$tdir; touch $DIR/$tdir" \
-               "rmdir $DIR/$tdir"
-       # cross-MDT link
-       op_trigger_cos "$LFS mkdir -c 2 $DIR/$tdir; \
+       if (( $MDS1_VERSION < $(version_code 2.15.55.133) )); then
+               op_trigger_cos "remote directory unlink" \
+                       "$LFS mkdir -i 1 $DIR/$tdir" "rmdir $DIR2/$tdir"
+               op_trigger_cos "striped directory create" "mkdir $DIR/$tdir" \
+                       "$LFS mkdir -c 2 $DIR2/$tdir/subdir"
+               op_trigger_cos "striped directory setattr" \
+                       "$LFS mkdir -c 2 $DIR/$tdir" "chmod 713 $DIR2/$tdir"
+               op_trigger_cos "striped directory unlink" \
+                       "$LFS mkdir -c 2 $DIR/$tdir" "rmdir $DIR2/$tdir"
+               op_trigger_cos "cross-MDT link" \
+                       "mkdir $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
-       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
-       op_trigger_cos "$LFS mkdir -i 0 $DIR/$tdir" \
-               "$LFS migrate -m 1 $DIR/$tdir"
+                       "ln $DIR2/$tdir/d1/tgt $DIR2/$tdir/d2/src"
+       fi
+
+       op_trigger_cos "remote directory create" "$LFS mkdir -i 0 $DIR/$tdir" \
+               "$LFS mkdir -i 1 $DIR2/$tdir/subdir"
+       op_trigger_cos "cross-MDT rename" \
+               "mkdir $DIR/$tdir; \
+               $LFS mkdir -i 0 $DIR/$tdir/d1; \
+               $LFS mkdir -i 1 $DIR/$tdir/d2; \
+               touch $DIR/$tdir/d1/src" \
+               "mv $DIR2/$tdir/d1/src $DIR2/$tdir/d2/tgt"
+       op_trigger_cos "migrate" \
+               "$LFS mkdir -i 0 $DIR/$tdir" \
+               "$LFS migrate -m 1 $DIR2/$tdir"
 
        return 0
 }
-run_test 33d "DNE distributed operation should trigger COS"
+run_test 33d "dependent transactions should trigger COS"
 
 test_33e() {
-       [ -n "$CLIENTS" ] || skip "Need two or more clients"
-       [ $CLIENTCOUNT -ge 2 ] ||
-               skip "Need two or more clients, have $CLIENTCOUNT"
-       [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
-       [ "$MDS1_VERSION" -lt $(version_code 2.7.63) ] &&
+       (( MDSCOUNT > 1 )) || skip "needs >= 2 MDTs"
+       (( MDS1_VERSION >= $(version_code 2.7.63) )) ||
                skip "DNE CoS not supported"
 
-       local client2=${CLIENT2:-$(hostname)}
-
-       sync
+       $LFS mkdir -i 0 $DIR/$tdir
+       $LFS mkdir -i 0 $DIR/$tdir/d1
+       $LFS mkdir -i 1 $DIR/$tdir/d2
 
        local nodes=$(comma_list $(mdts_nodes))
        do_nodes $nodes "lctl set_param -n mdt.*.async_commit_count=0"
 
-       $LFS mkdir -c 2 $DIR/$tdir
-       mkdir $DIR/$tdir/subdir
-       echo abc > $DIR/$tdir/$tfile
-       do_node $client2 echo dfg >> $DIR/$tdir/$tfile
-       do_node $client2 touch $DIR/$tdir/subdir
+       test_33_run "plain dir creation" "mkdir $DIR2/$tdir/plain"
+       test_33_run "open file and write" "echo abc > $DIR2/$tdir/$tfile"
+       test_33_run "append write" "echo dfg >> $DIR2/$tdir/$tfile"
+       test_33_run "setattr" "touch $DIR2/$tdir/$tfile"
+       test_33_run "file unlink" "rm $DIR2/$tdir/$tfile"
+       test_33_run "plain dir unlink" "rmdir $DIR2/$tdir/plain"
+       if (( MDS1_VERSION >= $(version_code 2.15.55.133) )); then
+               test_33_run "striped directory creation" \
+                       "$LFS mkdir -i 0 -c 2 $DIR2/$tdir/striped"
+               test_33_run "set default LMV to create striped subdir" \
+                       "$LFS setdirstripe -D -c 2 $DIR/$tdir"
+               test_33_run "striped subdir creation" \
+                       "createmany -d $DIR/$tdir/subdir 100"
+               test_33_run "sub file creation and write" \
+                       "createmany -o $DIR/$tdir/subfile 100; \
+                       echo abc > $DIR/$tdir/subfile1"
+               test_33_run "sub file append write" \
+                       "echo dfg >> $DIR2/$tdir/subfile2"
+               test_33_run "subdir setatttr" "touch $DIR2/$tdir/subdir1"
+               test_33_run "subdir unlink" \
+                       "unlinkmany -d $DIR/$tdir/subdir 100"
+               test_33_run "sub file unlink" \
+                       "unlinkmany $DIR2/$tdir/subfile 100"
+               test_33_run "sub file creation follows striped dir chmod" \
+                       "chmod 777 $DIR/$tdir/striped; \
+                        touch $DIR/$tdir/striped/subfile"
+               test_33_run "striped directory unlink" \
+                       "rm -rf $DIR2/$tdir/striped"
+       fi
+
+       test_33_run "directory unlink" "rm -rf $DIR2/$tdir"
 
        local async_commit_count=$(do_nodes $nodes \
                "lctl get_param -n mdt.*.async_commit_count" | calc_sum)
-       [ $async_commit_count -gt 0 ] && error "CoS triggerred"
-
-       return 0
+       echo "CoS count $async_commit_count"
+       (( async_commit_count == 0 )) || error "CoS triggerred"
 }
-run_test 33e "DNE local operation shouldn't trigger COS"
+run_test 33e "independent transactions shouldn't trigger COS"
 
 # End commit on sharing tests
 
@@ -1435,7 +1797,7 @@ test_39a() {
                if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
        done
 }
-run_test 39a "test from 11063 =================================="
+run_test 39a "file mtime does not change after rename"
 
 test_39b() {
        local client1=${CLIENT1:-`hostname`}
@@ -1462,7 +1824,7 @@ test_39b() {
                if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
        done
 }
-run_test 39b "11063 problem 1 =================================="
+run_test 39b "file mtime the same on clients with/out lock"
 
 test_39c() {
        local client1=${CLIENT1:-`hostname`}
@@ -1558,25 +1920,26 @@ check_pdo_conflict() {
 # test 40: check non-blocking operations
 test_40a() {
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
+
+       mkdir_on_mdt0 $DIR2/$tdir
        pdo_lru_clear
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
-       touch $DIR2
-       mkdir $DIR1/$tfile &
+       mkdir $DIR1/$tdir/$tfile &
        PID1=$!; pdo_sched
-       touch $DIR2/$tfile-2
+       touch $DIR2/$tdir/$tfile-2
        check_pdo_conflict $PID1 || error "create is blocked"
-       mkdir $DIR2/$tfile-3
+       mkdir $DIR2/$tdir/$tfile-3
        check_pdo_conflict $PID1 || error "mkdir is blocked"
-       link $DIR2/$tfile-2 $DIR2/$tfile-4
+       link $DIR2/$tdir/$tfile-2 $DIR2/$tdir/$tfile-4
        check_pdo_conflict $PID1 || error "link is blocked"
-       mv $DIR2/$tfile-2 $DIR2/$tfile-5
+       mv $DIR2/$tdir/$tfile-2 $DIR2/$tdir/$tfile-5
        check_pdo_conflict $PID1 || error "rename is blocked"
-       stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
+       stat $DIR2/$tdir/$tfile-3 $DIR2/$tdir/$tfile-4 > /dev/null
        check_pdo_conflict $PID1 || error "getattr is blocked"
-       rm $DIR2/$tfile-4 $DIR2/$tfile-5
-       rmdir $DIR2/$tfile-3
+       rm $DIR2/$tdir/$tfile-4 $DIR2/$tdir/$tfile-5
+       rmdir $DIR2/$tdir/$tfile-3
        check_pdo_conflict $PID1 || error "unlink is blocked"
 
        #  all operations above shouldn't wait the first one
@@ -1584,32 +1947,34 @@ test_40a() {
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0 2>/dev/null || true"
        wait $PID1
-       rm -rf $DIR/$tfile*
+       rm -rf $DIR/$tdir
        return 0
 }
 run_test 40a "pdirops: create vs others =============="
 
 test_40b() {
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
+
+       mkdir_on_mdt0 $DIR2/$tdir
        pdo_lru_clear
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
-       touch $DIR1/$tfile &
+       touch $DIR1/$tdir/$tfile &
        PID1=$!; pdo_sched
        # open|create
-       touch $DIR2/$tfile-2
+       touch $DIR2/$tdir/$tfile-2
        check_pdo_conflict $PID1 || error "create is blocked"
-       mkdir $DIR2/$tfile-3
+       mkdir $DIR2/$tdir/$tfile-3
        check_pdo_conflict $PID1 || error "mkdir is blocked"
-       link $DIR2/$tfile-2 $DIR2/$tfile-4
+       link $DIR2/$tdir/$tfile-2 $DIR2/$tdir/$tfile-4
        check_pdo_conflict $PID1 || error "link is blocked"
-       mv $DIR2/$tfile-2 $DIR2/$tfile-5
+       mv $DIR2/$tdir/$tfile-2 $DIR2/$tdir/$tfile-5
        check_pdo_conflict $PID1 || error "rename is blocked"
-       stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
+       stat $DIR2/$tdir/$tfile-3 $DIR2/$tdir/$tfile-4 > /dev/null
        check_pdo_conflict $PID1 || error "getattr is blocked"
-       rm $DIR2/$tfile-4 $DIR2/$tfile-5
-       rmdir $DIR2/$tfile-3
+       rm $DIR2/$tdir/$tfile-4 $DIR2/$tdir/$tfile-5
+       rmdir $DIR2/$tdir/$tfile-3
        check_pdo_conflict $PID1 || error "unlink is blocked"
        # all operations above shouldn't wait the first one
 
@@ -1617,33 +1982,35 @@ test_40b() {
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0 2>/dev/null || true"
        wait $PID1
-       rm -rf $DIR/$tfile*
+       rm -rf $DIR/$tdir
        return 0
 }
 run_test 40b "pdirops: open|create and others =============="
 
 test_40c() {
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
+
+       mkdir_on_mdt0 $DIR2/$tdir
        pdo_lru_clear
-       touch $DIR1/$tfile
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+       touch $DIR1/$tdir/$tfile
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
-       link $DIR1/$tfile $DIR1/$tfile-0 &
+       link $DIR1/$tdir/$tfile $DIR1/$tdir/$tfile-0 &
        PID1=$!; pdo_sched
        # open|create
-       touch $DIR2/$tfile-2
+       touch $DIR2/$tdir/$tfile-2
        check_pdo_conflict $PID1 || error "create is blocked"
-       mkdir $DIR2/$tfile-3
+       mkdir $DIR2/$tdir/$tfile-3
        check_pdo_conflict $PID1 || error "mkdir is blocked"
-       link $DIR2/$tfile-2 $DIR2/$tfile-4
+       link $DIR2/$tdir/$tfile-2 $DIR2/$tdir/$tfile-4
        check_pdo_conflict $PID1 || error "link is blocked"
-       mv $DIR2/$tfile-2 $DIR2/$tfile-5
+       mv $DIR2/$tdir/$tfile-2 $DIR2/$tdir/$tfile-5
        check_pdo_conflict $PID1 || error "rename is blocked"
-       stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
+       stat $DIR2/$tdir/$tfile-3 $DIR2/$tdir/$tfile-4 > /dev/null
        check_pdo_conflict $PID1 || error "getattr is blocked"
-       rm $DIR2/$tfile-4 $DIR2/$tfile-5
-       rmdir $DIR2/$tfile-3
+       rm $DIR2/$tdir/$tfile-4 $DIR2/$tdir/$tfile-5
+       rmdir $DIR2/$tdir/$tfile-3
        check_pdo_conflict $PID1 || error "unlink is blocked"
 
         # all operations above shouldn't wait the first one
@@ -1651,33 +2018,35 @@ test_40c() {
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0 2>/dev/null || true"
        wait $PID1
-       rm -rf $DIR/$tfile*
+       rm -rf $DIR/$tdir
        return 0
 }
 run_test 40c "pdirops: link and others =============="
 
 test_40d() {
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
+
+       mkdir_on_mdt0 $DIR2/$tdir
        pdo_lru_clear
-       touch $DIR1/$tfile
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+       touch $DIR1/$tdir/$tfile
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
-       rm $DIR1/$tfile &
+       rm $DIR1/$tdir/$tfile &
        PID1=$!; pdo_sched
        # open|create
-       touch $DIR2/$tfile-2
+       touch $DIR2/$tdir/$tfile-2
        check_pdo_conflict $PID1 || error "create is blocked"
-       mkdir $DIR2/$tfile-3
+       mkdir $DIR2/$tdir/$tfile-3
        check_pdo_conflict $PID1 || error "mkdir is blocked"
-       link $DIR2/$tfile-2 $DIR2/$tfile-4
+       link $DIR2/$tdir/$tfile-2 $DIR2/$tdir/$tfile-4
        check_pdo_conflict $PID1 || error "link is blocked"
-       mv $DIR2/$tfile-2 $DIR2/$tfile-5
+       mv $DIR2/$tdir/$tfile-2 $DIR2/$tdir/$tfile-5
        check_pdo_conflict $PID1 || error "rename is blocked"
-       stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
+       stat $DIR2/$tdir/$tfile-3 $DIR2/$tdir/$tfile-4 > /dev/null
        check_pdo_conflict $PID1 || error "getattr is blocked"
-       rm $DIR2/$tfile-4 $DIR2/$tfile-5
-       rmdir $DIR2/$tfile-3
+       rm $DIR2/$tdir/$tfile-4 $DIR2/$tdir/$tfile-5
+       rmdir $DIR2/$tdir/$tfile-3
        check_pdo_conflict $PID1 || error "unlink is blocked"
 
        # all operations above shouldn't wait the first one
@@ -1691,24 +2060,26 @@ run_test 40d "pdirops: unlink and others =============="
 
 test_40e() {
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
+
+       mkdir_on_mdt0 $DIR2/$tdir
        pdo_lru_clear
-       touch $DIR1/$tfile
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+       touch $DIR1/$tdir/$tfile
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
-       mv $DIR1/$tfile $DIR1/$tfile-0 &
+       mv $DIR1/$tdir/$tfile $DIR1/$tdir/$tfile-0 &
        PID1=$!; pdo_sched
        # open|create
-       touch $DIR2/$tfile-2
+       touch $DIR2/$tdir/$tfile-2
        check_pdo_conflict $PID1 || error "create is blocked"
-       mkdir $DIR2/$tfile-3
+       mkdir $DIR2/$tdir/$tfile-3
        check_pdo_conflict $PID1 || error "mkdir is blocked"
-       link $DIR2/$tfile-2 $DIR2/$tfile-4
+       link $DIR2/$tdir/$tfile-2 $DIR2/$tdir/$tfile-4
        check_pdo_conflict $PID1 || error "link is blocked"
-       stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
+       stat $DIR2/$tdir/$tfile-3 $DIR2/$tdir/$tfile-4 > /dev/null
        check_pdo_conflict $PID1 || error "getattr is blocked"
-       rm $DIR2/$tfile-4 $DIR2/$tfile-2
-       rmdir $DIR2/$tfile-3
+       rm $DIR2/$tdir/$tfile-4 $DIR2/$tdir/$tfile-2
+       rmdir $DIR2/$tdir/$tfile-3
        check_pdo_conflict $PID1 || error "unlink is blocked"
 
        # all operations above shouldn't wait the first one
@@ -1716,7 +2087,7 @@ test_40e() {
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0 2>/dev/null || true"
        wait $PID1
-       rm -rf $DIR/$tfile*
+       rm -rf $DIR/$tdir
        return 0
 }
 run_test 40e "pdirops: rename and others =============="
@@ -1724,7 +2095,7 @@ run_test 40e "pdirops: rename and others =============="
 # test 41: create blocking operations
 test_41a() {
        pdo_lru_clear
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
@@ -1742,7 +2113,7 @@ run_test 41a "pdirops: create vs mkdir =============="
 
 test_41b() {
        pdo_lru_clear
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
@@ -1761,7 +2132,7 @@ run_test 41b "pdirops: create vs create =============="
 test_41c() {
        pdo_lru_clear
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
@@ -1779,7 +2150,7 @@ run_test 41c "pdirops: create vs link =============="
 
 test_41d() {
        pdo_lru_clear
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
@@ -1798,7 +2169,7 @@ run_test 41d "pdirops: create vs unlink =============="
 test_41e() {
        pdo_lru_clear
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
@@ -1816,7 +2187,7 @@ run_test 41e "pdirops: create and rename (tgt) =============="
 
 test_41f() {
        pdo_lru_clear
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
@@ -1834,7 +2205,7 @@ run_test 41f "pdirops: create and rename (src) =============="
 
 test_41g() {
        pdo_lru_clear
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
@@ -1852,7 +2223,7 @@ run_test 41g "pdirops: create vs getattr =============="
 
 test_41h() {
        pdo_lru_clear
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
@@ -1868,10 +2239,61 @@ test_41h() {
 }
 run_test 41h "pdirops: create vs readdir =============="
 
+sub_test_41i() {
+       local PID1 PID2
+       local fail_loc="$1"
+       local ret=0
+
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=${fail_loc} || true" &>/dev/null
+
+       $MULTIOP $DIR1/$tfile oO_CREAT:O_EXCL:c 2>/dev/null &
+       PID1=$!
+       sleep 0.2
+       $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c 2>/dev/null &
+       PID2=$!
+
+       if ! wait $PID1 && ! wait $PID2; then
+               echo "Both creates failed (1 should fail, 1 should succeed)"
+               ret=1
+       elif wait $PID1 && wait $PID2; then
+               echo "Both creates succeeded (1 should fail, 1 should succeed)"
+               ret=2
+       fi
+
+       #Clean
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x0 || true" &>/dev/null
+       rm -f $DIR/$tfile
+
+       return $ret
+}
+
+test_41i() {
+       (( $MDS1_VERSION >= $(version_code 2.13.56) )) ||
+               skip "Need MDS version newer than 2.13.56"
+       local msg fail_loc
+
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_REINT_OPEN         0x169
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_REINT_OPEN2        0x16a
+       for fail_loc in "0x80000169" "0x8000016a"; do
+               echo "Begin 100 tests with fail_loc=$fail_loc"
+               printf "Progress: "
+               for i in {1..100}; do
+                       printf "*"
+                       msg=$(sub_test_41i "$fail_loc") ||
+                               { echo; error "iter=$i : $msg"; }
+               done
+               echo
+       done
+}
+run_test 41i "reint_open: create vs create"
+
+
 # test 42: unlink and blocking operations
 test_42a() {
        pdo_lru_clear
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mkdir $DIR1/$tfile &
@@ -1889,7 +2311,7 @@ run_test 42a "pdirops: mkdir vs mkdir =============="
 
 test_42b() {
        pdo_lru_clear
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mkdir $DIR1/$tfile &
@@ -1908,7 +2330,7 @@ run_test 42b "pdirops: mkdir vs create =============="
 test_42c() {
        pdo_lru_clear
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mkdir $DIR1/$tfile &
@@ -1926,7 +2348,7 @@ run_test 42c "pdirops: mkdir vs link =============="
 
 test_42d() {
        pdo_lru_clear
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mkdir $DIR1/$tfile &
@@ -1945,7 +2367,7 @@ run_test 42d "pdirops: mkdir vs unlink =============="
 test_42e() {
        pdo_lru_clear
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mkdir $DIR1/$tfile &
@@ -1963,7 +2385,7 @@ run_test 42e "pdirops: mkdir and rename (tgt) =============="
 
 test_42f() {
        pdo_lru_clear
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mkdir $DIR1/$tfile &
@@ -1980,26 +2402,26 @@ test_42f() {
 run_test 42f "pdirops: mkdir and rename (src) =============="
 
 test_42g() {
+       mkdir_on_mdt0 $DIR1/$tdir
        pdo_lru_clear
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
-       mkdir $DIR1/$tfile &
+       mkdir $DIR1/$tdir/$tfile &
        PID1=$! ; pdo_sched
-       stat $DIR2/$tfile > /dev/null &
+       stat $DIR2/$tdir/$tfile > /dev/null &
        PID2=$! ; pdo_sched
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0 2>/dev/null || true"
        check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
        wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
-       rm -rf $DIR/$tfile*
-       return 0
+       rm -rf $DIR/$tdir
 }
 run_test 42g "pdirops: mkdir vs getattr =============="
 
 test_42h() {
        pdo_lru_clear
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mkdir $DIR1/$tfile &
@@ -2028,7 +2450,7 @@ run_test 43a "rmdir,mkdir doesn't return -EEXIST =============="
 test_43b() {
        pdo_lru_clear
        touch $DIR1/$tfile
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        rm $DIR1/$tfile &
@@ -2048,7 +2470,7 @@ test_43c() {
        pdo_lru_clear
        touch $DIR1/$tfile
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        rm $DIR1/$tfile &
@@ -2067,7 +2489,7 @@ run_test 43c "pdirops: unlink vs link =============="
 test_43d() {
        pdo_lru_clear
        touch $DIR1/$tfile
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        rm $DIR1/$tfile &
@@ -2087,7 +2509,7 @@ test_43e() {
        pdo_lru_clear
        touch $DIR1/$tfile
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        rm $DIR1/$tfile &
@@ -2106,7 +2528,7 @@ run_test 43e "pdirops: unlink and rename (tgt) =============="
 test_43f() {
        pdo_lru_clear
        touch $DIR1/$tfile
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        rm $DIR1/$tfile &
@@ -2125,7 +2547,7 @@ run_test 43f "pdirops: unlink and rename (src) =============="
 test_43g() {
        pdo_lru_clear
        touch $DIR1/$tfile
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        rm $DIR1/$tfile &
@@ -2144,7 +2566,7 @@ run_test 43g "pdirops: unlink vs getattr =============="
 test_43h() {
        pdo_lru_clear
        touch $DIR1/$tfile
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        rm $DIR1/$tfile &
@@ -2164,7 +2586,7 @@ test_43i() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
        pdo_lru_clear
        touch $DIR1/$tfile
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        rm $DIR1/$tfile &
@@ -2185,29 +2607,87 @@ test_43j() {
        [[ $MDS1_VERSION -lt $(version_code 2.13.52) ]] &&
                skip "Need MDS version newer than 2.13.52"
 
+       mkdir_on_mdt0 $DIR1/$tdir
        for i in {1..100}; do
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_CREATE_RACE         0x167
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_CREATE_RACE         0x167
                do_nodes $(comma_list $(mdts_nodes)) \
                        "lctl set_param -n fail_loc=0x80000167 2>/dev/null ||
                                true"
                OK=0
-               mkdir $DIR1/$tdir &
+               mkdir $DIR1/$tdir/sub &
                PID1=$!
-               mkdir $DIR2/$tdir && ((OK++))
+               mkdir $DIR2/$tdir/sub && ((OK++))
                wait $PID1 && ((OK++))
                (( OK == 1 )) || error "exactly one mkdir should succeed"
 
-               rmdir $DIR1/$tdir || error "rmdir failed"
+               rmdir $DIR1/$tdir/sub || error "rmdir failed"
        done
        return 0
 }
 run_test 43j "racy mkdir return EEXIST =============="
 
+sub_test_43k() {
+       local PID1 PID2
+       local fail_loc="$1"
+       local ret=0
+
+       # We test in a separate directory to be able to unblock server thread in
+       # cfs_race() if LCK_PW is taken on the parent by mdt_reint_unlink.
+       test_mkdir $DIR2/$tdir
+       touch $DIR2/$tdir/$tfile
+       pdo_lru_clear
+
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=${fail_loc} || true" &>/dev/null
+       echo content > $DIR1/$tdir/$tfile & PID1=$!
+       pdo_sched
+       multiop $DIR2/$tdir/$tfile u & PID2=$!
+
+       wait $PID1 ||
+               { ret=$?; \
+               echo -n "overwriting $tfile should succeed (err=$ret); "; }
+       wait $PID2 ||
+               { ret=$?; \
+               echo -n "unlinking $tfile should succeed (err=$ret);"; }
+
+       #Clean
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x0 || true" &>/dev/null
+       rm -rf $DIR/$tdir
+
+       return $ret
+}
+
+test_43k() {
+       (( $MDS1_VERSION >= $(version_code 2.13.56) )) ||
+               skip "Need MDS version newer than 2.13.56"
+       local msg fail_loc
+
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_REINT_OPEN         0x169
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_REINT_OPEN2        0x16a
+       for fail_loc in "0x80000169" "0x8000016a"; do
+               echo "Begin 100 tests with fail_loc=$fail_loc"
+               printf "Progress: "
+               for i in {1..100}; do
+                       printf "*"
+                       msg=$(sub_test_43k "$fail_loc") ||
+                               { echo; error "iter=$i : $msg"; }
+               done
+               echo
+       done
+
+       #Clean
+       reset_fail_loc
+
+       return 0
+}
+run_test 43k "unlink vs create"
+
 # test 44: rename tgt and blocking operations
 test_44a() {
        pdo_lru_clear
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
        mv $DIR1/$tfile-2 $DIR1/$tfile &
@@ -2227,7 +2707,7 @@ run_test 44a "pdirops: rename tgt vs mkdir =============="
 test_44b() {
        pdo_lru_clear
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
        mv $DIR1/$tfile-2 $DIR1/$tfile &
@@ -2247,7 +2727,7 @@ test_44c() {
        pdo_lru_clear
        touch $DIR1/$tfile-2
        touch $DIR1/$tfile-3
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
        mv $DIR1/$tfile-2 $DIR1/$tfile &
@@ -2266,7 +2746,7 @@ run_test 44c "pdirops: rename tgt vs link =============="
 test_44d() {
        pdo_lru_clear
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
        mv $DIR1/$tfile-2 $DIR1/$tfile &
@@ -2287,7 +2767,7 @@ test_44e() {
        touch $DIR1/$tfile
        touch $DIR1/$tfile-2
        touch $DIR1/$tfile-3
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
        mv $DIR1/$tfile-2 $DIR1/$tfile &
@@ -2307,7 +2787,7 @@ test_44f() {
        pdo_lru_clear
        touch $DIR1/$tfile-2
        touch $DIR1/$tfile-3
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
        mv $DIR1/$tfile-2 $DIR1/$tfile &
@@ -2326,7 +2806,7 @@ run_test 44f "pdirops: rename tgt and rename (src) =============="
 test_44g() {
        pdo_lru_clear
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
        mv $DIR1/$tfile-2 $DIR1/$tfile &
@@ -2345,7 +2825,7 @@ run_test 44g "pdirops: rename tgt vs getattr =============="
 test_44h() {
        pdo_lru_clear
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
        mv $DIR1/$tfile-2 $DIR1/$tfile &
@@ -2366,7 +2846,7 @@ test_44i() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
        pdo_lru_clear
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
        mv $DIR1/$tfile-2 $DIR1/$tfile &
@@ -2398,7 +2878,7 @@ run_test 45a "rename,mkdir doesn't return -EEXIST =============="
 test_45b() {
        pdo_lru_clear
        touch $DIR1/$tfile
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mv $DIR1/$tfile $DIR1/$tfile-2 &
@@ -2418,7 +2898,7 @@ test_45c() {
        pdo_lru_clear
        touch $DIR1/$tfile
        touch $DIR1/$tfile-3
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mv $DIR1/$tfile $DIR1/$tfile-2 &
@@ -2437,7 +2917,7 @@ run_test 45c "pdirops: rename src vs link =============="
 test_45d() {
        pdo_lru_clear
        touch $DIR1/$tfile
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mv $DIR1/$tfile $DIR1/$tfile-2 &
@@ -2457,7 +2937,7 @@ test_45e() {
        pdo_lru_clear
        touch $DIR1/$tfile
        touch $DIR1/$tfile-3
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mv $DIR1/$tfile $DIR1/$tfile-2 &
@@ -2476,7 +2956,7 @@ run_test 45e "pdirops: rename src and rename (tgt) =============="
 test_45f() {
        pdo_lru_clear
        touch $DIR1/$tfile
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mv $DIR1/$tfile $DIR1/$tfile-2 &
@@ -2495,7 +2975,7 @@ run_test 45f "pdirops: rename src and rename (src) =============="
 test_45g() {
        pdo_lru_clear
        touch $DIR1/$tfile
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mv $DIR1/$tfile $DIR1/$tfile-2 &
@@ -2514,7 +2994,7 @@ run_test 45g "pdirops: rename src vs getattr =============="
 test_45h() {
        pdo_lru_clear
        touch $DIR1/$tfile
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mv $DIR1/$tfile $DIR1/$tfile-2 &
@@ -2533,7 +3013,7 @@ test_45i() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
        pdo_lru_clear
        touch $DIR1/$tfile
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        mv $DIR1/$tfile $DIR1/$tfile-2 &
@@ -2550,11 +3030,66 @@ test_45i() {
 }
 run_test 45i "pdirops: rename src vs remote mkdir"
 
+sub_test_45j() {
+       local PID1 PID2
+       local fail_loc="$1"
+       local ret=0
+
+       # We test in a sparate directory to be able to unblock server thread in
+       # cfs_race if LCK_PW is taken on the parent by mdt_reint_rename.
+       test_mkdir $DIR2/$tdir
+       echo file1 > $DIR2/$tdir/$tfile
+       echo file2 > $DIR2/$tdir/$tfile-2
+       pdo_lru_clear
+
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=${fail_loc} || true" &>/dev/null
+
+       cat $DIR1/$tdir/$tfile >/dev/null &
+       PID1=$!
+       pdo_sched
+       mrename $DIR2/$tdir/$tfile-2 $DIR2/$tdir/$tfile > /dev/null &
+       PID2=$!
+
+       wait $PID1 ||
+               { ret=$?; echo -n "cat $tfile should succeed (err=$ret); "; }
+       wait $PID2 ||
+               { ret=$?; \
+               echo -n "mrename $tfile-2 to $tfile failed (err=$ret);"; }
+
+       #Clean
+       do_nodes $(comma_list $(mdts_nodes)) \
+               "lctl set_param -n fail_loc=0x0 || true" &>/dev/null
+       rm -rf $DIR/$tdir
+
+       return $ret
+}
+
+test_45j() {
+       (( $MDS1_VERSION >= $(version_code 2.13.56) )) ||
+               skip "Need MDS version newer than 2.13.56"
+       local msg fail_loc
+
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_REINT_OPEN         0x169
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_REINT_OPEN2        0x16a
+       for fail_loc in "0x80000169" "0x8000016a"; do
+               echo "Begin 100 tests with fail_loc=$fail_loc"
+               printf "Progress: "
+               for i in {1..100}; do
+                       printf "*"
+                       msg=$(sub_test_45j "$fail_loc") ||
+                               { echo; error "iter=$i : $msg"; }
+               done
+               echo
+       done
+}
+run_test 45j "read vs rename =============="
+
 # test 46: link and blocking operations
 test_46a() {
        pdo_lru_clear
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        link $DIR1/$tfile-2 $DIR1/$tfile &
@@ -2573,7 +3108,7 @@ run_test 46a "pdirops: link vs mkdir =============="
 test_46b() {
        pdo_lru_clear
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        link $DIR1/$tfile-2 $DIR1/$tfile &
@@ -2592,7 +3127,7 @@ run_test 46b "pdirops: link vs create =============="
 test_46c() {
        pdo_lru_clear
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        link $DIR1/$tfile-2 $DIR1/$tfile &
@@ -2611,7 +3146,7 @@ run_test 46c "pdirops: link vs link =============="
 test_46d() {
        pdo_lru_clear
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        link $DIR1/$tfile-2 $DIR1/$tfile &
@@ -2631,7 +3166,7 @@ test_46e() {
        pdo_lru_clear
        touch $DIR1/$tfile-2
        touch $DIR1/$tfile-3
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        link $DIR1/$tfile-2 $DIR1/$tfile &
@@ -2651,7 +3186,7 @@ test_46f() {
        pdo_lru_clear
        touch $DIR1/$tfile-2
        touch $DIR1/$tfile-3
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        link $DIR1/$tfile-2 $DIR1/$tfile &
@@ -2670,7 +3205,7 @@ run_test 46f "pdirops: link and rename (src) =============="
 test_46g() {
        pdo_lru_clear
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        link $DIR1/$tfile-2 $DIR1/$tfile &
@@ -2689,7 +3224,7 @@ run_test 46g "pdirops: link vs getattr =============="
 test_46h() {
        pdo_lru_clear
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        link $DIR1/$tfile-2 $DIR1/$tfile &
@@ -2709,7 +3244,7 @@ test_46i() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
        pdo_lru_clear
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        link $DIR1/$tfile-2 $DIR1/$tfile &
@@ -2728,7 +3263,7 @@ run_test 46i "pdirops: link vs remote mkdir"
 
 # test 47: remote mkdir and blocking operations
 test_47a() {
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
        pdo_lru_clear
        do_nodes $(comma_list $(mdts_nodes)) \
@@ -2747,7 +3282,7 @@ test_47a() {
 run_test 47a "pdirops: remote mkdir vs mkdir"
 
 test_47b() {
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
        pdo_lru_clear
        do_nodes $(comma_list $(mdts_nodes)) \
@@ -2771,7 +3306,7 @@ test_47c() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
        pdo_lru_clear
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $LFS mkdir -i 1 $DIR1/$tfile &
@@ -2790,7 +3325,7 @@ run_test 47c "pdirops: remote mkdir vs link"
 test_47d() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
        pdo_lru_clear
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $LFS mkdir -i 1 $DIR1/$tfile &
@@ -2811,7 +3346,7 @@ test_47e() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
        pdo_lru_clear
        touch $DIR1/$tfile-2
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $LFS mkdir -i 1 $DIR1/$tfile &
@@ -2831,7 +3366,7 @@ run_test 47e "pdirops: remote mkdir and rename (tgt)"
 test_47f() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
        pdo_lru_clear
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $LFS mkdir -i 1 $DIR1/$tfile &
@@ -2853,7 +3388,7 @@ test_47g() {
        sync
        sync_all_data
        pdo_lru_clear
-#define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
+#define CFS_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
        do_nodes $(comma_list $(mdts_nodes)) \
                "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
        $LFS mkdir -i 1 $DIR1/$tfile &
@@ -2917,12 +3452,12 @@ test_51a() {
 run_test 51a "layout lock: refresh layout should work"
 
 test_51b() {
-       [[ "$MDS1_VERSION" -ge $(version_code 2.3.59) ]] ||
+       (( $MDS1_VERSION >= $(version_code 2.3.59) )) ||
                skip "Need MDS version at least 2.3.59"
 
        local tmpfile=`mktemp`
 
-       $LFS setstripe -E 1M -c 1 -E -1 --extension-size 64M $DIR1/$tfile ||
+       $LFS setstripe -E 1m -S 1M -c 1 -E -1 -c 1 $DIR1/$tfile ||
                error "Create $DIR1/$tfile failed"
 
        dd if=/dev/zero of=$DIR1/$tfile bs=1k count=1 conv=notrunc ||
@@ -2930,10 +3465,10 @@ test_51b() {
 
        # delay glimpse so that layout has changed when glimpse finish
 #define OBD_FAIL_GLIMPSE_DELAY 0x1404
-       $LCTL set_param fail_loc=0x1404
+       $LCTL set_param fail_loc=0x1404 fail_val=4
        stat -c %s $DIR2/$tfile |tee $tmpfile &
        local pid=$!
-       sleep 1
+       sleep 0.2
 
        # extend layout of testing file
        dd if=/dev/zero of=$DIR1/$tfile bs=1M count=1 seek=2 conv=notrunc ||
@@ -3009,6 +3544,30 @@ test_51d() {
 }
 run_test 51d "layout lock: losing layout lock should clean up memory map region"
 
+test_51e() {
+       (( $MDS1_VERSION >= $(version_code 2.13.54.148) )) ||
+               skip "MDS version must be at least 2.13.54.148"
+
+       local pid
+
+       $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eW_E+eUc &
+       pid=$!
+       sleep 1
+
+       $LFS getstripe $DIR2/$tfile
+       kill -USR1 $pid
+       wait $pid || error "multiop failed"
+
+       $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
+       pid=$!
+       sleep 1
+
+       $LFS getstripe $DIR2/$tfile
+       kill -USR1 $pid
+       wait $pid || error "multiop failed"
+}
+run_test 51e "lfs getstripe does not break leases, part 2"
+
 test_54_part1()
 {
        echo "==> rename vs getattr vs setxattr should not deadlock"
@@ -3078,56 +3637,59 @@ test_54() {
 run_test 54 "rename locking"
 
 test_55a() {
-       mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
+       mkdir_on_mdt0 $DIR/$tdir
+       mkdir -p $DIR/$tdir/d1/d2 $DIR/$tdir/d3 || error "(1) mkdir failed"
 
 #define OBD_FAIL_MDS_RENAME4              0x156
        do_facet mds1 $LCTL set_param fail_loc=0x80000156
 
-       mv -T $DIR/d1/d2 $DIR/d3/d2 &
+       mv -T $DIR/$tdir/d1/d2 $DIR/$tdir/d3/d2 &
        PID1=$!
        sleep 1
 
-       rm -r $DIR2/d3
+       rm -r $DIR2/$tdir/d3
        wait $PID1 && error "(2) mv succeeded"
 
-       rm -rf $DIR/d1
+       rm -rf $DIR/$tdir
 }
 run_test 55a "rename vs unlink target dir"
 
 test_55b()
 {
-       mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
+       mkdir_on_mdt0 $DIR/$tdir
+       mkdir -p $DIR/$tdir/d1/d2 $DIR/$tdir/d3 || error "(1) mkdir failed"
 
 #define OBD_FAIL_MDS_RENAME4             0x156
        do_facet mds1 $LCTL set_param fail_loc=0x80000156
 
-       mv -T $DIR/d1/d2 $DIR/d3/d2 &
+       mv -T $DIR/$tdir/d1/d2 $DIR/$tdir/d3/d2 &
        PID1=$!
        sleep 1
 
-       rm -r $DIR2/d1
+       rm -r $DIR2/$tdir/d1
        wait $PID1 && error "(2) mv succeeded"
 
-       rm -rf $DIR/d3
+       rm -rf $DIR/$tdir
 }
 run_test 55b "rename vs unlink source dir"
 
 test_55c()
 {
-       mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
+       mkdir_on_mdt0 $DIR/$tdir
+       mkdir -p $DIR/$tdir/d1/d2 $DIR/$tdir/d3 || error "(1) mkdir failed"
 
 #define OBD_FAIL_MDS_RENAME4              0x156
        do_facet mds1 $LCTL set_param fail_loc=0x156
 
-       mv -T $DIR/d1/d2 $DIR/d3/d2 &
+       mv -T $DIR/$tdir/d1/d2 $DIR/$tdir/d3/d2 &
        PID1=$!
        sleep 1
 
        # while rename is sleeping, open and remove d3
-       $MULTIOP $DIR2/d3 D_c &
+       $MULTIOP $DIR2/$tdir/d3 D_c &
        PID2=$!
        sleep 1
-       rm -rf $DIR2/d3
+       rm -rf $DIR2/$tdir/d3
        sleep 5
 
        # while rename is sleeping 2nd time, close d3
@@ -3136,31 +3698,51 @@ test_55c()
 
        wait $PID1 && error "(2) mv succeeded"
 
-       rm -rf $DIR/d1
+       rm -rf $DIR/$tdir
 }
 run_test 55c "rename vs unlink orphan target dir"
 
 test_55d()
 {
-       touch $DIR/f1
+       mkdir_on_mdt0 $DIR/$tdir
+
+       touch $DIR/$tdir/f1
 
 #define OBD_FAIL_MDS_RENAME3              0x155
        do_facet mds1 $LCTL set_param fail_loc=0x155
-       mv $DIR/f1 $DIR/$tdir &
+       mv $DIR/$tdir/f1 $DIR/$tdir/$tdir &
        PID1=$!
        sleep 2
 
        # while rename is sleeping, create $tdir, but as a directory
-       mkdir -p $DIR2/$tdir || error "(1) mkdir failed"
+       mkdir -p $DIR2/$tdir/$tdir || error "(1) mkdir failed"
 
        # link in reverse locking order
-       ln $DIR2/f1 $DIR2/$tdir/
+       ln $DIR2/$tdir/f1 $DIR2/$tdir/$tdir/f1 || error "(2) ln failed"
 
-       wait $PID1 && error "(2) mv succeeded"
-       rm -rf $DIR/f1
+       ! wait $PID1 || error "(3) mv succeeded"
+       rm -rf $DIR/$tdir
 }
 run_test 55d "rename file vs link"
 
+test_56a() {
+       $LFS setstripe -c 1 $MOUNT/$tfile || error "creating $MOUNT/$tfile"
+       stack_trap "rm -f $MOUNT/$tfile"
+       echo "run_llverdev $MOUNT/$tfile -p -s $((16000000)) -c 4k"
+       run_llverdev $MOUNT/$tfile -p -s $((16000000)) -c 4k ||
+               error "llverdev failed with rc=$?"
+}
+run_test 56a "test llverdev with single large stripe"
+
+test_56b() {
+       $LFS setstripe -C 2000 $MOUNT/$tfile || error "creating $MOUNT/$tfile"
+       stack_trap "rm -f $MOUNT/$tfile"
+       echo "run_llverdev $MOUNT/$tfile -p -s $((16000000 * OSTCOUNT)) -c 4k"
+       run_llverdev $MOUNT/$tfile -p -s $((16000000 * OSTCOUNT)) -c 4k ||
+               error "llverdev failed with rc=$?"
+}
+run_test 56b "test llverdev and partial verify of wide stripe file"
+
 test_60() {
        [ $MDS1_VERSION -lt $(version_code 2.3.0) ] &&
                skip "MDS version must be >= 2.3.0"
@@ -3260,28 +3842,28 @@ test_71a() {
        checkfiemap --test ||
                skip "checkfiemap not runnable: $?"
        # write data this way: hole - data - hole - data
-       dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
+       dd if=/dev/urandom of=$DIR1/$tfile bs=64K seek=1 count=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
+       dd if=/dev/urandom of=$DIR1/$tfile bs=64K seek=3 count=1
        GET_STAT="lctl get_param -n ldlm.services.ldlm_cbd.stats"
        stat $DIR2/$tfile
        local can1=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
        echo $can1
-       checkfiemap $DIR2/$tfile 81920 ||
+       checkfiemap $DIR2/$tfile 131072 ||
                error "data is not flushed from client"
        local can2=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
        echo $can2
 
        # common case of "create file, copy file" on a single node
        # should not flush data from ost
-       dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
-       dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
+       dd if=/dev/urandom of=$DIR1/$tfile bs=64K seek=1 count=1
+       dd if=/dev/urandom of=$DIR1/$tfile bs=64K seek=3 count=1
        stat $DIR1/$tfile
        local can3=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
        echo $can3
-       checkfiemap $DIR1/$tfile 81920 ||
+       checkfiemap $DIR1/$tfile 131072 ||
        error 4
        local can4=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
        echo $can2
@@ -3305,14 +3887,76 @@ test_71b() {
        mkdir -p $DIR1/$tdir
 
        $LFS setstripe -c -1 $DIR1/$tdir || error "setstripe failed"
-       dd if=/dev/urandom of=$DIR1/$tdir/$tfile bs=40K count=1
+       dd if=/dev/urandom of=$DIR1/$tdir/$tfile bs=64K count=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"
+       checkfiemap $DIR1/$tdir/$tfile 65536 || error "checkfiemap failed"
 }
 run_test 71b "check fiemap support for stripecount > 1"
 
+_check_last_flag_with_filefrag()
+{
+       local file=$1
+       local count=$2
+       local i
+       local offset
+
+       echo "check last flag for file with $count extents"
+       rm -f $file
+       for ((i=0; i<$count; i++)); do
+               offset=$((i * 256))
+               dd if=/dev/zero of=$file bs=4K count=1 seek=$offset 2> /dev/null
+       done
+
+       filefrag -s -v $file | grep "last" ||
+               error "test file with $i extents failed"
+
+       rm -f $file
+}
+
+test_71c() {
+       local file="$DIR1/$tdir/$tfile"
+
+       (( $CLIENT_VERSION >= $(version_code 2.15.57) )) ||
+               skip "Need client version >= 2.15.57"
+       [ $(facet_fstype ost1) = "ldiskfs" ] ||
+               skip "support only ldiskfs ost"
+       filefrag -V | grep wc ||
+               skip "need whamcloud version of e2fsprogs"
+
+       mkdir -p $DIR1/$tdir
+
+       # filefrag uses u64[2028] buffer to fetch fiemap. The number of extents
+       # in the buffer is (8 * 2048 - 32) / 56 = 292. Test file with 291, 292
+       # and 293 extents
+       _check_last_flag_with_filefrag $file 291
+       _check_last_flag_with_filefrag $file 292
+       _check_last_flag_with_filefrag $file 293
+}
+run_test 71c "check FIEMAP_EXTENT_LAST flag with different extents number"
+
+test_71d() { #LU-17110
+       checkfiemap --test ||
+               skip "error $?: checkfiemap failed"
+
+       local f=$DIR/$tfile
+
+       # write data this way: hole - data - hole - data
+       dd if=/dev/urandom of=$f bs=64K count=1
+       [[ "$(facet_fstype ost$(($($LFS getstripe -i $f) + 1)))" != "zfs" ]] ||
+               skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS"
+       dd if=/dev/urandom of=$f bs=64K seek=2 count=1
+       dd if=/dev/urandom of=$f bs=64K seek=4 count=1
+       dd if=/dev/urandom of=$f bs=64K seek=6 count=1 conv=fsync
+       echo "disk usage: $(du -B1 $f)"
+       echo "file size: $(du -b $f)"
+
+       checkfiemap --corruption_test $f $((4 * 64 *1024)) ||
+               error "checkfiemap failed"
+}
+run_test 71d "fiemap corruption test with fm_extent_count=0"
+
 test_72() {
        local p="$TMP/sanityN-$TESTNAME.parameters"
        local tlink1
@@ -3493,11 +4137,21 @@ nrs_write_read() {
        local n=16
        local dir=$DIR/$tdir
        local myRUNAS="$1"
+       local create_as="$2"
 
        mkdir $dir || error "mkdir $dir failed"
        $LFS setstripe -c $OSTCOUNT $dir || error "setstripe to $dir failed"
        chmod 777 $dir
 
+       if [[ -n "$create_as" ]]; then
+               do_nodes $CLIENTS $create_as "touch $dir/nrs_r_\$HOSTNAME;" ||
+                       error "touch failed for $dir/nrs_r_*"
+               do_nodes $CLIENTS $create_as touch "$dir/nrs_w_\$HOSTNAME" ||
+                       error "touch failed for $dir/nrs_w_*"
+               do_nodes $CLIENTS $create_as "chmod 777 $dir/nrs_*_\$HOSTNAME;" ||
+                       error "chmod failed for $dir/nrs_*"
+       fi
+
        do_nodes $CLIENTS $myRUNAS \
                dd if=/dev/zero of="$dir/nrs_r_\$HOSTNAME" bs=1M count=$n ||
                error "dd at 0 on client failed (1)"
@@ -3663,6 +4317,7 @@ tbf_verify() {
        local dir=$DIR/$tdir
        local client1=${CLIENT1:-$(hostname)}
        local myRUNAS="$3"
+       local create_as="$4"
 
        local np=$(check_cpt_number ost1)
        [ $np -gt 0 ] || error "CPU partitions should not be $np."
@@ -3672,6 +4327,11 @@ tbf_verify() {
        $LFS setstripe -c 1 -i 0 $dir || error "setstripe to $dir failed"
        chmod 777 $dir
 
+       if [[ -n "$create_as" ]]; then
+               $create_as touch $dir/tbf
+               chmod 777 $dir/tbf
+       fi
+
        trap cleanup_tbf_verify EXIT
        echo "Limited write rate: $1, read rate: $2"
        echo "Verify the write rate is under TBF control"
@@ -3988,6 +4648,8 @@ test_id() {
        local idstr="${1}id"
        local policy="${idstr}={$2}"
        local rate="rate=$3"
+       local runas_args="$4"
+       local createas_args="${5:-$runas_args}"
 
        do_nodes $(comma_list $(osts_nodes)) \
                lctl set_param jobid_var=procname_uid \
@@ -3995,8 +4657,8 @@ test_id() {
                        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"
+       nrs_write_read "runas $runas_args" "runas $createas_args"
+       tbf_verify $3 $3 "runas $runas_args" "runas $createas_args"
 
        do_nodes $(comma_list $(osts_nodes)) \
                lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ost_${idstr}" \
@@ -4013,11 +4675,20 @@ test_77ja(){
                skip "Need OST version at least 2.11.50"
        fi
 
-       test_id "u" "500" "5" "-u 500"
-       test_id "g" "500" "5" "-u 500 -g 500"
+       test_id "u" "$RUNAS_ID" "5" "-u $RUNAS_ID"
+       test_id "g" "$RUNAS_GID" "5" "-u $RUNAS_ID -g $RUNAS_GID"
 }
 run_test 77ja "check TBF-UID/GID NRS policy"
 
+test_77jb() { # LU-16077
+       (( "$OST1_VERSION" >= $(version_code 2.15.51) )) ||
+               skip "Need OST version at least 2.15.51"
+
+       test_id "u" "$RUNAS_ID" "5" "-u $RUNAS_ID" "-u 0 -g $RUNAS_GID"
+       test_id "g" "$RUNAS_GID" "5" "-u $RUNAS_ID -g $RUNAS_GID" "-u $RUNAS_ID -g 0"
+}
+run_test 77jb "check TBF-UID/GID NRS policy on files that don't belong to us"
+
 cleanup_77k()
 {
        local rule_lists=$1
@@ -4085,26 +4756,26 @@ test_77k() {
        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_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"
+                       ost.OSS.ost_io.nrs_tbf_rule="start\ ext_ug\ uid={$RUNAS_ID}\&gid={$RUNAS_GID}\ rate=5"
+       nrs_write_read "runas -u $RUNAS_ID -g $RUNAS_GID"
+       tbf_verify 5 5 "runas -u $RUNAS_ID -g $RUNAS_GID"
 
        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"
+                       ost.OSS.ost_io.nrs_tbf_rule="start\ ext_uw\ uid={$RUNAS_ID}\&opcode={ost_write}\ rate=20" \
+                       ost.OSS.ost_io.nrs_tbf_rule="start\ ext_ur\ uid={$RUNAS_ID}\&opcode={ost_read}\ rate=10"
 
-       nrs_write_read "runas -u 500"
-       tbf_verify 20 10 "runas -u 500"
+       nrs_write_read "runas -u $RUNAS_ID"
+       tbf_verify 20 10 "runas -u $RUNAS_ID"
 
        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"
+                       ost.OSS.ost_io.nrs_tbf_rule="start\ ext_a\ uid={$RUNAS_ID},opcode={ost_write}\ rate=20" \
+                       ost.OSS.ost_io.nrs_tbf_rule="start\ ext_b\ uid={$RUNAS_ID},opcode={ost_read}\ rate=10"
+       nrs_write_read "runas -u $RUNAS_ID"
+       tbf_verify 10 10 "runas -u $RUNAS_ID"
+       tbf_verify 20 10 "runas -u $RUNAS_ID"
        cleanup_77k "ext_a ext_b" "fifo"
 }
 run_test 77k "check TBF policy with NID/JobID/OPCode expression"
@@ -4221,6 +4892,203 @@ test_77n() { #LU-10802
 }
 run_test 77n "check wildcard support for TBF JobID NRS policy"
 
+test_77o() {
+       (( $OST1_VERSION > $(version_code 2.14.54) )) ||
+               skip "need OST > 2.14.54"
+
+       do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_policies="tbf\ nid"
+       do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="start\ name\ nid={192.168.*.*@tcp}\ rate=10000"
+       do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="start\ name1\ nid={192.168.*.*@tcp}\ rate=10000"
+       do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="change\ name1\ rank=name"
+       do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="stop\ name"
+       do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_policies="fifo"
+}
+run_test 77o "Changing rank should not panic"
+
+test_77q() {
+       local i
+       local gidlist="500 10 33   100 "
+       local uidlist=" 500  11 3"
+
+       (( $MDS1_VERSION > $(version_code 2.14.54) )) ||
+               skip "need MDS >= 2.14.54"
+
+       do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_policies="tbf"
+       stack_trap "do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_policies=fifo"
+
+       # require 44cc782/LU-9859 to support list with unexpected spaces
+       (( MDS1_VERSION >= $(version_code 2.15.57) )) ||
+               gidlist=$(echo $gidlist) uidlist=$(echo $uidlist)
+
+       for i in {1..50}; do
+               local pid1 pid2
+
+               do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="'start rule77q_1 uid={$uidlist}&gid={$gidlist} rate=100'" &
+               pid1=$!
+               do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="'start rule77q_2 uid={1000}&gid={1000} rate=100'" &
+               pid2=$!
+               wait $pid1 || error "$i: Fail to start TBF rule 'rule77q_1'"
+               wait $pid2 || error "$i: Fail to start TBF rule 'rule77q_2'"
+
+               do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="'stop rule77q_1'" &
+               pid1=$!
+               do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="'stop rule77q_2'" &
+               pid2=$!
+               wait $pid1 || error "$i: Fail to stop TBF rule 'rule77q_1'"
+               wait $pid2 || error "$i: Fail to stop TBF rule 'rule77q_2'"
+       done
+}
+run_test 77q "Parallel TBF rule definitions should not panic"
+
+test_77p() {
+       local c
+       local -a spec_chars=(
+               '@' '.' '~' '#' '/' '^' '%' '*' ';' ',' '?' '<' '>' ':'
+               '+' '=' ')' '(' '{' '}' '|' '[' ']' '!' '&' '\$' '\`' '\\')
+
+       (( $MDS1_VERSION > $(version_code 2.14.54) )) ||
+               skip "need MDS >= 2.14.54"
+
+       do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_policies="tbf"
+       stack_trap "do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_policies=fifo"
+
+       # TBF rule name size is 16 bytes
+       do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="start\ test_77p_overflo\ uid={500}\ rate=500" &&
+               error "The length of tbf rule name is not checked" || true
+       do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="start\ \ uid={500}\ rate=500" &&
+               error "The server should not accept empty tbf rule name" || true
+       do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="start\ test_77p_empty" &&
+               error "The server should not accept 'start <tbf_rule_name>' without an expression" || true
+
+       # Test with special chars
+       for c in "${spec_chars[@]}"; do
+               do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="'start test77p${c}spec uid={500} rate=500'" &&
+               error "Special char '${c}' should not be accepted in a tbf rule name" || true
+       done
+
+}
+run_test 77p "Check validity of rule names for TBF policies"
+
+cleanup_77r() {
+       local pid=$1
+       local saved_jobid=$2
+       local current_jobid_var
+
+       echo "cleanup 77r $pid"
+
+       do_facet mds1 $LCTL set_param -n mds.MDS.mdt.nrs_policies=fifo
+       kill $pid || echo "fail to kill md thread"
+
+       current_jobid_var=$($LCTL get_param -n jobid_var)
+       if [ $saved_jobid != $current_jobid_var ]; then
+               set_persistent_param_and_check client \
+                       "jobid_var" "$FSNAME.sys.jobid_var" $saved_jobid
+       fi
+
+       sleep 2
+       rm -rf $DIR1/$tdir
+}
+
+md_thread_run="true"
+md_thread_77r() {
+       local pid
+
+       while $md_thread_run; do
+               printf '%s\n' {$DIR1,$DIR2}/$tdir/${tfile}-{01..20} |
+                       xargs -P20 -I{} $RUNAS bash -c 'touch {}; rm -f {}' \
+                               &> /dev/null & pid=$!
+               trap "echo kill md_thread xargs; md_thread_run=false; kill $pid" INT TERM
+               wait $pid
+       done
+}
+
+wait_policy_state() {
+       local state="$1"
+       local policy="$2"
+       local change_pid="$3"
+       local time
+
+       for time in {1..60}; do
+               local nbr_started
+
+               nbr_started=$(do_facet mds1 $LCTL get_param mds.MDS.mdt.nrs_policies |
+                       egrep -A2 "name: ${policy}$" | grep -c "state: $state")
+
+               [[ "$nbr_started" != 2 ]] || return 0
+               sleep 1
+       done
+
+       [[ -z "$change_pid" ]] || kill $change_pid || true
+       return 1
+}
+
+test_77r() { #LU-14976
+
+       (( MDS1_VERSION > $(version_code 2.15.56) )) ||
+               skip "need MDS >= 2.15.56 c098c095 change nrs policies at run time"
+
+       local pid
+       local -A rules
+       local -a policies
+       local saved_jobid_var
+
+       rules["tbf uid"]="start md_rule uid={$RUNAS_ID} rate=1"
+       rules["tbf gid"]="start md_rule gid={$RUNAS_GID} rate=1"
+       rules["tbf jobid"]="start md_rule jobid={*.$RUNAS_ID} rate=1"
+       rules["tbf"]="start md_rule uid={$RUNAS_ID} rate=1"
+       policies=(
+       "tbf uid"
+       "tbf gid"
+       "tbf jobid"
+       "tbf"
+       "fifo"
+       )
+
+       test_mkdir -i 0 -c 1 $DIR1/$tdir
+       chmod 777 $DIR1/$tdir
+
+       # Configure jobid_var
+       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
+
+       # start md thread
+       md_thread_77r & pid=$!
+       stack_trap "cleanup_77r $pid '$saved_jobid_var'"
+
+       local policy
+       for policy in "${policies[@]}"; do
+               local change_pid
+
+               # wait to queue requests
+               sleep 5
+
+               do_facet mds1 "$LCTL set_param mds.MDS.mdt.nrs_policies='$policy'" &
+               change_pid=$!
+
+               wait_policy_state "started" "$policy" "$change_pid" ||
+                       error "timeout to start '$policy' policy"
+
+               [[ -n "${rules[$policy]}" ]] || continue
+
+               do_facet mds1 "$LCTL set_param mds.MDS.mdt.nrs_tbf_rule='${rules[$policy]}'" ||
+                       error "fail to set rule '${rules[$policy]}' to '$policy'"
+       done
+
+       wait_policy_state "stopped" "tbf" ||
+               error "fail to stop tbf policy"
+
+       echo "check the number of requests in queue:"
+       local awkcmd='/name: / {last = $3} '
+       awkcmd+='/queued: / {printf "    %s: %d\n", last, $2;'
+       awkcmd+='       if (last == "tbf" && $2 > 0) exit 1;}'
+       do_facet mds1 $LCTL get_param mds.MDS.mdt.nrs_policies | awk "$awkcmd" ||
+               error "request leak in tbf policies"
+}
+run_test 77r "Change type of tbf policy at run time"
+
 test_78() { #LU-6673
        local rc
 
@@ -4279,6 +5147,7 @@ test_80a() {
        local file
        local pid
 
+       mkdir_on_mdt0 $DIR1/$tdir
        mkdir -p $DIR1/$tdir/dir
        createmany -o $DIR1/$tdir/dir/f 10 ||
                error "create files under remote dir failed $i"
@@ -4318,121 +5187,79 @@ cleanup_80b() {
        kill -9 $migrate_pid
 }
 
+success_count=0
+failure_count=0
+
+run_and_count()
+{
+       eval $@ &>/dev/null && success_count=$((success_count + 1)) ||
+               failure_count=$((failure_count + 1))
+}
+
 test_80b() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
-       local migrate_dir1=$DIR1/$tdir/migrate_dir
-       local migrate_dir2=$DIR2/$tdir/migrate_dir
-       local migrate_run=$LUSTRE/tests/migrate.sh
+       local migdir1=$DIR1/$tdir/migrate_dir
+       local migdir2=$DIR2/$tdir/migrate_dir
        local start_time
-       local end_time
-       local show_time=1
        local mdt_idx
        local rc=0
        local rc1=0
 
        trap cleanup_80b EXIT
-       #prepare migrate directory
-       mkdir -p $migrate_dir1
+       # prepare migrate directory
+       mkdir -p $migdir1
        for F in {1,2,3,4,5}; do
-               echo "$F$F$F$F$F" > $migrate_dir1/file$F
+               echo "$F$F$F$F$F" > $migdir1/file$F
                echo "$F$F$F$F$F" > $DIR/$tdir/file$F
        done
 
-       #migrate the directories among MDTs
+       # migrate the directories among MDTs
        (
                while true; do
                        mdt_idx=$((RANDOM % MDSCOUNT))
-                       $LFS migrate -m $mdt_idx $migrate_dir1 &>/dev/null ||
-                               rc=$?
-                       [ $rc -ne 0 -o $rc -ne 16 ] || break
+                       # migrate may fail
+                       $LFS migrate -m $mdt_idx $migdir1 &>/dev/null
                done
        ) &
        migrate_pid=$!
 
        echo "start migration thread $migrate_pid"
-       #Access the files at the same time
-       start_time=$(date +%s)
-       echo "accessing the migrating directory for 5 minutes..."
-       while true; do
-               ls $migrate_dir2 > /dev/null || {
-                       echo "read dir fails"
-                       break
-               }
-               diff -u $DIR2/$tdir/file1 $migrate_dir2/file1 || {
-                       echo "access file1 fails"
-                       break
-               }
-
-               cat $migrate_dir2/file2 > $migrate_dir2/file3 || {
-                       echo "access file2/3 fails"
-                       break
-               }
-
-               echo "aaaaa" > $migrate_dir2/file4 > /dev/null || {
-                       echo "access file4 fails"
-                       break
-               }
-
-               stat $migrate_dir2/file5 > /dev/null || {
-                       echo "stat file5 fails"
-                       break
-               }
-
-               touch $migrate_dir2/source_file > /dev/null || rc1=$?
-               [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
-                       echo "touch file failed with $rc1"
-                       break;
-               }
-
-               if [ -e $migrate_dir2/source_file ]; then
-                       ln $migrate_dir2/source_file $migrate_dir2/link_file \
-                                       &>/dev/null || rc1=$?
-                       if [ -e $migrate_dir2/link_file ]; then
-                               rm -rf $migrate_dir2/link_file
-                       fi
-
-                       mrename $migrate_dir2/source_file \
-                               $migrate_dir2/target_file &>/dev/null || rc1=$?
-                       [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
-                               echo "rename failed with $rc1"
-                               break
-                       }
-
-                       if [ -e $migrate_dir2/target_file ]; then
-                               rm -rf $migrate_dir2/target_file &>/dev/null ||
-                                                               rc1=$?
-                       else
-                               rm -rf $migrate_dir2/source_file &>/dev/null ||
-                                                               rc1=$?
-                       fi
-                       [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
-                               echo "unlink failed with $rc1"
-                               break
-                       }
-               fi
-
-               end_time=$(date +%s)
-               duration=$((end_time - start_time))
-               if [ $((duration % 10)) -eq 0 ]; then
-                       if [ $show_time -eq 1 ]; then
-                               echo "...$duration seconds"
-                               show_time=0
-                       fi
-               else
-                       show_time=1
+       # access the files at the same time
+       start_time=$SECONDS
+       echo "accessing the migrating directory for 1 minute..."
+       while ((SECONDS - start_time < 60)); do
+               run_and_count ls $migdir2
+               run_and_count diff -u $DIR2/$tdir/file1 $migdir2/file1
+               run_and_count "cat $migdir2/file2 > $migdir2/file3"
+               run_and_count "echo "aaaaa" > $migdir2/file4"
+               run_and_count stat $migdir2/file5
+               run_and_count touch $migdir2/source_file
+               if [ -e $migdir2/source_file ]; then
+                       run_and_count ln $migdir2/source_file \
+                               $migdir2/link_file
+
+                       [ -e $migdir2/link_file ] &&
+                               rm -rf $migdir2/link_file
+
+                       run_and_count mrename $migdir2/source_file \
+                               $migdir2/target_file
+
+                       [ -e $migdir2/target_file ] &&
+                               run_and_count rm -rf $migdir2/target_file ||
+                               run_and_count rm -rf $migdir2/source_file
                fi
 
                kill -0 $migrate_pid || {
                        echo "migration stopped 1"
                        break
                }
-
-               [ $duration -ge 300 ] && break
        done
 
-       #check migration are still there
+       # check migration are still there
        kill -0 $migrate_pid || error "migration stopped 2"
        cleanup_80b
+       # access during migration may fail
+       echo "concurrent access $failure_count failures, $success_count successes"
 }
 run_test 80b "Accessing directory during migration"
 
@@ -4468,13 +5295,10 @@ 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"
+       createmany -o $DIR1/$tdir/$tfile. $COUNT || error "createmany"
 
        (
                while true; do
@@ -4483,7 +5307,7 @@ test_81b() {
        ) &
        setattr_pid=$!
 
-       for i in $(seq $total); do
+       for ((i = 0; i < COUNT; i++)); do
                mrename $DIR2/$tdir/$tfile.$i $DIR2/$tdir/$tfile-new.$i \
                        > /dev/null
        done
@@ -4492,6 +5316,112 @@ test_81b() {
 }
 run_test 81b "rename under striped directory doesn't deadlock"
 
+test_81c() {
+       [ $MDSCOUNT -lt 4 ] && skip_env "needs >= 4 MDTs"
+       [ $MDS1_VERSION -lt $(version_code 2.13.52) ] &&
+               skip "Need MDS version at least 2.13.52"
+
+       # source is local, source parent is remote
+       $LFS mkdir -i 0 $DIR1/${tdir}_src || error "mkdir ${tdir}_src"
+       $LFS mkdir -i 1 $DIR1/${tdir}_tgt || error "mkdir ${tdir}_tgt"
+       $LFS mkdir -i 3 $DIR1/${tdir}_src/sub || error "mkdir sub"
+       $LFS mkdir -i 3 $DIR1/${tdir}_tgt/sub || error "mkdir sub"
+       stat $DIR2/${tdir}_src/sub || error "stat sub failed"
+       mv $DIR1/${tdir}_src/sub $DIR1/${tdir}_tgt/ || error "mv failed"
+       [ -f $DIR2/${tdir}_src/sub ] && error "sub should be gone"
+       rm -rf $DIR1/${tdir}_src $DIR1/${tdir}_tgt
+
+       # source is remote, source parent is local
+       $LFS mkdir -i 3 $DIR1/${tdir}_src || error "mkdir ${tdir}_src"
+       $LFS mkdir -i 1 $DIR1/${tdir}_tgt || error "mkdir ${tdir}_tgt"
+       $LFS mkdir -i 0 $DIR1/${tdir}_src/sub || error "mkdir sub"
+       $LFS mkdir -i 3 $DIR1/${tdir}_tgt/sub || error "mkdir sub"
+       stat $DIR2/${tdir}_src/sub || error "stat sub failed"
+       mv $DIR1/${tdir}_src/sub $DIR1/${tdir}_tgt/ || error "mv failed"
+       [ -f $DIR2/${tdir}_src/sub ] && error "sub should be gone"
+       rm -rf $DIR1/${tdir}_src $DIR1/${tdir}_tgt
+
+       # source and source parent are remote
+       $LFS mkdir -i 0 $DIR1/${tdir}_src || error "mkdir ${tdir}_src"
+       $LFS mkdir -i 1 $DIR1/${tdir}_tgt || error "mkdir ${tdir}_tgt"
+       mkdir $DIR1/${tdir}_src/sub || error "mkdir sub"
+       $LFS mkdir -i 3 $DIR1/${tdir}_tgt/sub || error "mkdir sub"
+       stat $DIR2/${tdir}_src/sub || error "stat sub failed"
+       mv $DIR1/${tdir}_src/sub $DIR1/${tdir}_tgt/ || error "mv failed"
+       [ -f $DIR2/${tdir}_src/sub ] && error "sub should be gone"
+       rm -rf $DIR1/${tdir}_src $DIR1/${tdir}_tgt
+
+       # source and source parent are remote, and source is remote object
+       $LFS mkdir -i 0 $DIR1/${tdir}_src || error "mkdir ${tdir}_src"
+       $LFS mkdir -i 1 $DIR1/${tdir}_tgt || error "mkdir ${tdir}_tgt"
+       $LFS mkdir -i 2 $DIR1/${tdir}_src/sub || error "mkdir sub"
+       $LFS mkdir -i 3 $DIR1/${tdir}_tgt/sub || error "mkdir sub"
+       stat $DIR2/${tdir}_src/sub || error "stat sub failed"
+       mv $DIR1/${tdir}_src/sub $DIR1/${tdir}_tgt/ || error "mv failed"
+       [ -f $DIR2/${tdir}_src/sub ] && error "sub should be gone" || true
+}
+run_test 81c "rename revoke LOOKUP lock for remote object"
+
+cleanup_81d() {
+       for ((mds = 0; mds < $MDSCOUNT; mds++)); do
+               local d2=$DIR2/$tdir-$mds
+
+               rm -rf $d2 &
+       done
+       wait || error "rm failed"
+}
+
+test_81d() {
+       local setattr_pid
+       local mdts=$(comma_list $(mdts_nodes))
+
+       do_nodes $mdts "$LCTL set_param mdt.*.md_stats=clear > /dev/null"
+
+       stack_trap cleanup_81d
+       for ((mds = 0; mds < $MDSCOUNT; mds++)); do
+               local d1=$DIR1/$tdir-$mds
+
+               $LFS mkdir -i $mds $d1 $d1/_temporary || error "mkdir failed"
+               createmany -o $d1/_temporary/$tfile. $COUNT ||
+                       error "createmany failed for $d1/_temporary"
+       done
+
+       for ((mds = 0; mds < $MDSCOUNT; mds++)); do
+               local d1=$DIR1/$tdir-$mds
+               local d2=$DIR2/$tdir-$mds
+
+               for ((i = 0; i < COUNT; i++)); do
+                       mrename $d1/_temporary/$tfile.$i $d1/$tfile.$i &
+                       ((i++))
+                       mrename $d2/_temporary/$tfile.$i $d2/$tfile.$i &
+               done
+       done
+       wait || error "rename failed"
+
+       cleanup_81d
+       local stats=$DIR1/md_stats
+       local total=$((MDSCOUNT * COUNT))
+
+       do_nodes $mdts "$LCTL get_param -n mdt.*.md_stats" > $stats
+       cat $stats
+       crossdir=$(awk '/crossdir_rename/ {sum+=$2} END {print sum}' $stats)
+       (( crossdir == total )) ||
+               error "not crossdir: $crossdir != $total"
+       samedir=$(awk '/samedir_rename/ {sum+=$2} END {print sum}' $stats)
+       (( samedir == 0 )) || error "considered samedir: $samedir"
+       pardir=$(awk '/parallel_rename_dir/ {sum+=$2} END {print sum}' $stats)
+       (( pardir == 0 )) || error "considered directory: $pardir"
+
+
+       (( MDS1_VERSION >= $(version_code 2.15.60) )) ||
+               { echo "need MDS >= 2.15.60 for parallel cross-dir"; return 0; }
+
+       parfile=$(awk '/parallel_rename_file/ {sum+=$2} END {print sum}' $stats)
+       (( parfile == total )) ||
+               error "not considered file: $parfile != $total"
+}
+run_test 81d "parallel rename file cross-dir on same MDT"
+
 test_82() {
        [[ "$MDS1_VERSION" -gt $(version_code 2.6.91) ]] ||
                skip "Need MDS version at least 2.6.92"
@@ -4574,6 +5504,11 @@ test_84() {
 }
 run_test 84 "0-nlink race in lu_object_find()"
 
+test_85() {
+       llapi_root_test $DIR/$tfile $DIR2/$tfile
+}
+run_test 85 "Lustre API root cache race"
+
 test_90() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
        local pid1
@@ -4744,6 +5679,69 @@ test_94() {
 }
 run_test 94 "signal vs CP callback race"
 
+test_95a() {
+       local file=$DIR/$tfile
+       local file2=$DIR2/$tfile
+       local fast_read_save
+       local pid
+
+       fast_read_save=$($LCTL get_param -n llite.*.fast_read | head -n 1)
+       [ -z "$fast_read_save" ] && skip "no fast read support"
+
+       stack_trap "$LCTL set_param llite.*.fast_read=$fast_read_save" EXIT
+       $LCTL set_param llite.*.fast_read=0
+
+       $LFS setstripe -c $OSTCOUNT $file || error "failed to setstripe $file"
+       dd if=/dev/zero of=$file bs=1M count=2 || error "failed to write $file"
+       cancel_lru_locks $OSC
+       $MULTIOP $file Oz1048576w4096c || error "failed to write $file"
+       $MULTIOP $file oz1044480r4096c || error "failed to read $file"
+
+       # OBD_FAIL_LLITE_PAGE_INVALIDATE_PAUSE  0x1421
+       $LCTL set_param fail_loc=0x80001421 fail_val=7
+       $MULTIOP $file2 Oz1048576w4096_c &
+       pid=$!
+
+       sleep 2
+       # OBD_FAIL_LLITE_READPAGE_PAUSE         0x1422
+       $LCTL set_param fail_loc=0x80001422 fail_val=10
+       $MULTIOP $file oz1044480r4096c || error "failed to read $file"
+
+       kill -USR1 $pid && wait $pid || error "wait for PID $pid failed"
+}
+run_test 95a "Check readpage() on a page that was removed from page cache"
+
+test_95b() {
+       local file=$DIR/$tfile
+       local file2=$DIR2/$tfile
+       local fast_read_save
+       local pid
+
+       fast_read_save=$($LCTL get_param -n llite.*.fast_read | head -n 1)
+       [ -z "$fast_read_save" ] && skip "no fast read support"
+
+       stack_trap "$LCTL set_param llite.*.fast_read=$fast_read_save" EXIT
+       $LCTL set_param llite.*.fast_read=0
+
+       $LFS setstripe -c $OSTCOUNT $file || error "failed to setstripe $file"
+       dd if=/dev/zero of=$file bs=$((PAGE_SIZE * 3)) count=1 ||
+               error "failed to write $file"
+
+       # This does the read from the second mount, so this flushes the pages
+       # the first mount and creates new ones on the second mount
+       # OBD_FAIL_LLITE_READPAGE_PAUSE2        0x1424
+       $LCTL set_param fail_loc=0x80001424 fail_val=5
+       $MULTIOP $file2 or${PAGE_SIZE}c &
+       pid=$!
+
+       sleep 2
+       fadvise_dontneed_helper $file2
+       $LCTL set_param fail_loc=0
+       sleep 4
+       wait $pid || error "failed to read file"
+}
+run_test 95b "Check readpage() on a page that is no longer uptodate"
+
 # Data-on-MDT tests
 test_100a() {
        skip "Reserved for glimpse-ahead" && return
@@ -4948,14 +5946,34 @@ run_test 101c "Discard DoM data on close-unlink"
 # 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) ] &&
+       (( "$MDS1_VERSION" >= $(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
+               error "check_fhandle_syscalls $tfile failed"
+
+       # test this is working on DNE directories also
+       if (( MDSCOUNT > 1 && MDS1_VERSION >= $(version_code 2.14.52) )); then
+               $LFS mkdir -i 1 $DIR/$tdir.remote
+               cancel_lru_locks mdc
+               check_fhandle_syscalls $DIR/$tdir.remote $DIR2 ||
+                       error "check_fhandle_syscalls $tdir.remote failed"
+               $LFS mkdir -c -1 $DIR/$tdir.remote/subdir
+               cancel_lru_locks mdc
+               check_fhandle_syscalls $DIR/$tdir.remote/subdir $DIR2 ||
+                       error "check_fhandle_syscalls $tdir.remote/subdir fail"
+
+               $LFS mkdir -c -1 $DIR/$tdir.stripe
+               cancel_lru_locks mdc
+               check_fhandle_syscalls $DIR/$tdir.stripe $DIR2 ||
+                       error "check_fhandle_syscalls $tdir.stripe failed"
+               $LFS mkdir -c -1 $DIR/$tdir.stripe/subdir
+               cancel_lru_locks mdc
+               check_fhandle_syscalls $DIR/$tdir.stripe/subdir $DIR2 ||
+                       error "check_fhandle_syscalls $tdir.stripe/subdir fail"
+       fi
 }
 run_test 102 "Test open by handle of unlinked file"
 
@@ -5040,7 +6058,7 @@ check_mdt_xtimes()
        local mdt_xtimes=($(get_mdt_xtimes $mdtdev))
 
        echo "STAT a|m|ctime ${xtimes[*]}"
-       echo "MDT a|m|ctime ${xtimes[*]}"
+       echo "MDT a|m|ctime ${mdt_xtimes[*]}"
        [[ ${xtimes[0]} == ${mdt_xtimes[0]} ]] ||
                error "$DIR/$tfile atime (${xtimes[0]}:${mdt_xtimes[0]}) diff"
        [[ ${xtimes[1]} == ${mdt_xtimes[1]} ]] ||
@@ -5130,7 +6148,8 @@ test_106a() {
        dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
        btime=$($STATX -c %W $DIR/$tfile)
        output=$(do_facet mds1 "$DEBUGFS -c -R 'stat ROOT/$tfile' $mdtdev")
-       ((mdt_btime=$(awk -F ':' /btime/'{ print $2 }' <<< "$output")))
+       echo $output
+       ((mdt_btime=$(awk -F ':' /crtime/'{ print $2 }' <<< "$output")))
        [[ $btime == $mdt_btime ]] ||
                error "$DIR/$tfile btime ($btime:$mdt_btime) diff"
 
@@ -5200,9 +6219,9 @@ test_106c() {
        touch $DIR/$tfile
        # Mask supported in stx_attributes by Lustre is
        # STATX_ATTR_IMMUTABLE(0x10) | STATX_ATTR_APPEND(0x20) : (0x30).
-       mask=$($STATX -c %q $DIR/$tfile)
-       [[ $mask == "30" ]] ||
-               error "supported stx_attributes: got '$mask', expected '30'"
+       mask=$($STATX -c %p $DIR/$tfile)
+       (( (0x$mask & 0x30) == 0x30 )) ||
+               error "supported stx_attributes: got '0x$mask', expected '0x30' at least"
        chattr +i $DIR/$tfile || error "chattr +i $DIR/$tfile failed"
        mask=$($STATX -c %r $DIR/$tfile)
        [[ $mask == "10" ]] ||
@@ -5225,6 +6244,442 @@ test_106c() {
 }
 run_test 106c "Verify statx attributes mask"
 
+test_107a() { # LU-1031
+       dd if=/dev/zero of=$DIR1/$tfile bs=1M count=10
+       local gid1=14091995
+       local gid2=16022000
+
+       $LFS getstripe $DIR1/$tfile
+
+       multiop_bg_pause $DIR1/$tfile OG${gid1}_g${gid1}c || return 1
+       local MULTIPID1=$!
+       multiop_bg_pause $DIR2/$tfile O_G${gid2}r10g${gid2}c || return 2
+       local MULTIPID2=$!
+       kill -USR1 $MULTIPID2
+       sleep 2
+       if [[ $(ps h -o comm -p $MULTIPID2) == "" ]]; then
+               error "First grouplock does not block second one"
+       else
+               echo "First grouplock blocks second one"
+       fi
+       kill -USR1 $MULTIPID1
+       wait $MULTIPID1
+       wait $MULTIPID2
+}
+run_test 107a "Basic grouplock conflict"
+
+test_107b() {
+       dd if=/dev/zero of=$DIR1/$tfile bs=1M count=10
+       local gid1=14091995
+       local gid2=16022000
+
+       $LFS getstripe $DIR1/$tfile
+
+       multiop_bg_pause $DIR1/$tfile OG${gid1}_g${gid1}c || return 1
+       local MULTIPID1=$!
+       multiop $DIR2/$tfile Or10c &
+       local MULTIPID2=$!
+       sleep 2
+
+       if [[ $(ps h -o comm -p $MULTIPID2) == "" ]]; then
+               error "Grouplock does not block IO"
+       else
+               echo "Grouplock blocks IO"
+       fi
+
+       multiop $DIR2/$tfile OG${gid2}_g${gid2}c &
+       local MULTIPID3=$!
+       sleep 2
+       if [[ $(ps h -o comm -p $MULTIPID3) == "" ]]; then
+               error "First grouplock does not block second one"
+       else
+               echo "First grouplock blocks second one"
+       fi
+
+       kill -USR1 $MULTIPID1
+       sleep 2
+
+       if [[ $(ps h -o comm -p $MULTIPID3) == "" ]]; then
+               error "Second grouplock thread disappeared"
+       fi
+
+       if [[ $(ps h -o comm -p $MULTIPID2) == "" ]]; then
+               error "Second grouplock does not block IO"
+       else
+               echo "Second grouplock blocks IO"
+       fi
+
+       kill -USR1 $MULTIPID3
+       wait $MULTIPID1
+       wait $MULTIPID2
+       wait $MULTIPID3
+}
+run_test 107b "Grouplock is added to the head of waiting list"
+
+test_108a() {
+       local offset
+
+       $LFS setstripe -E 1M -c 1 -E -1 $DIR1/$tfile ||
+               error "Create $DIR1/$tfile failed"
+
+       dd if=/dev/zero of=$DIR1/$tfile bs=10000 count=1 ||
+               error "dd $DIR1/$tfile failed"
+       offset=$(lseek_test -d 5000 $DIR2/$tfile)
+       [[ $offset == 5000 ]] || error "offset $offset != 5000"
+
+       $TRUNCATE $DIR1/$tfile 2000
+       offset=$(lseek_test -l 1000 $DIR2/$tfile)
+       [[ $offset == 2000 ]] || error "offset $offset != 2000"
+
+       #define OBD_FAIL_OSC_DELAY_IO 0x414
+       $LCTL set_param fail_val=4 fail_loc=0x80000414
+       dd if=/dev/zero of=$DIR1/$tfile count=1 bs=8M conv=notrunc oflag=dsync &
+       local pid=$!
+       sleep 2
+
+       offset=$(lseek_test -l 8000 $DIR2/$tfile)
+       wait $pid
+       [[ $offset == 8388608 ]] || error "offset $offset != 8388608"
+}
+run_test 108a "lseek: parallel updates"
+
+# LU-14110
+test_109() {
+       local i
+       local pid1 pid2
+
+       ! local_mode ||
+               skip "Clients need to be on different nodes than the servers"
+
+       umount_client $MOUNT
+       umount_client $MOUNT2
+
+       echo "Starting race between client mount instances (50 iterations):"
+       for i in {1..50}; do
+               log "Iteration $i"
+
+#define CFS_FAIL_ONCE|OBD_FAIL_LLITE_RACE_MOUNT        0x80001417
+               $LCTL set_param -n fail_loc=0x80001417
+
+               mount_client $MOUNT  & pid1=$!
+               mount_client $MOUNT2 & pid2=$!
+               wait $pid1 || error "Mount $MOUNT fails with $?"
+               wait $pid2 || error "Mount $MOUNT2 fails with $?"
+
+               umount_client $MOUNT  & pid1=$!
+               umount_client $MOUNT2 & pid2=$!
+               wait $pid1 || error "Umount $MOUNT fails with $?"
+               wait $pid2 || error "Umount $MOUNT2 fails with $?"
+
+               $LUSTRE_RMMOD || error "Fail to remove lustre modules"
+               load_modules
+               echo
+       done
+
+       mount_client $MOUNT
+       mount_client $MOUNT2
+}
+
+run_test 109 "Race with several mount instances on 1 node"
+
+test_110() {
+       local before=$(date +%s)
+       local evict
+
+       mkdir -p $DIR/$tdir
+       touch $DIR/$tdir/f1
+       touch $DIR/$tfile
+
+       #define OBD_FAIL_PTLRPC_RESEND_RACE      0x525
+       do_facet mds1 lctl set_param fail_loc=0x525 fail_val=3
+
+       # disable last_xid logic by dropping link reply
+       ln $DIR/$tdir/f1 $DIR/$tdir/f2 &
+       sleep 1
+
+       #define OBD_FAIL_PTLRPC_ENQ_RESEND      0x534
+       do_facet mds1 lctl set_param fail_loc=0x534
+
+       # RPC will race with its Resend and the Resend will sleep to let
+       # the original lock to get granted & cancelled.
+       #
+       # AST_SENT is set artificially, so an explicit conflict is not needed
+       #
+       # The woken up Resend gets a new lock, but client does not wait for it
+       stat $DIR/$tfile
+       sleep $TIMEOUT
+       do_facet mds1 lctl set_param fail_loc=0 fail_val=0
+
+       # Take a conflict to wait long enough to see the eviction
+       touch $DIR2/$tfile
+
+       # let the client reconnect
+       client_reconnect
+       evict=$(do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state |
+         awk -F"[ [,]" '/EVICTED ]$/ { if (mx<$5) {mx=$5;} } END { print mx }')
+
+       [ -z "$evict" ] || [[ $evict -le $before ]] ||
+               (do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state;
+                   error "eviction happened: $evict before:$before")
+}
+run_test 110 "do not grant another lock on resend"
+
+test_111() {
+       [ $MDSCOUNT -ge 2 ] || skip "needs >= 2 MDTs"
+       [[ $(facet_active_host mds1) = $(facet_active_host mds2) ]] ||
+               skip "MDT0 and MDT1 should be on the same node"
+
+       mkdir $DIR1/$tdir
+       $LFS mkdir -i 0 $DIR1/$tdir/mdt0dir
+       $LFS mkdir -i 1 $DIR1/$tdir/mdt1dir
+
+       mkdir $DIR1/$tdir/mdt0dir/foodir
+       touch $DIR1/$tdir/mdt0dir/foodir/{file1,file2}
+
+       $MULTIOP $DIR2/$tdir/mdt0dir/foodir/file2 Ow4096_c &
+       MULTIOP_PID=$!
+       ln $DIR1/$tdir/mdt0dir/foodir/file2 $DIR1/$tdir/mdt1dir/file2
+
+       #define OBD_FAIL_MDS_LINK_RENAME_RACE   0x18a
+       do_facet mds1 $LCTL set_param fail_loc=0x8000018a
+
+       ln $DIR1/$tdir/mdt0dir/foodir/file2 $DIR1/$tdir/mdt1dir/file2x &
+       sleep 1
+
+       rm $DIR2/$tdir/mdt1dir/file2
+       sleep 1
+
+       mv $DIR2/$tdir/mdt0dir/foodir/file1 $DIR2/$tdir/mdt0dir/foodir/file2
+       sleep 1
+
+       kill $MULTIOP_PID
+       wait
+       rm -r $DIR1/$tdir || error "Removing test dir failed"
+}
+run_test 111 "A racy rename/link an open file should not cause fs corruption"
+
+test_112() {
+       (( MDSCOUNT >= 2 )) ||
+               skip "We need at least 2 MDTs for this test"
+
+       (( MDS1_VERSION >= $(version_code 2.14.54) )) ||
+               skip "Need server version at least 2.14.54"
+
+       local rr
+       local count
+
+       rr=$($LCTL get_param -n lmv.*.qos_threshold_rr | head -n1)
+       rr=${rr%%%}
+       stack_trap "$LCTL set_param lmv.*.qos_threshold_rr=$rr > /dev/null"
+
+       mkdir -p $DIR1/$tdir/s1/s2 || error "mkdir s2 failed"
+       $LFS mkdir -i 0 $DIR1/$tdir/s1/s2/s3 || error "mkdir s3 failed"
+       $LFS setdirstripe -D -i -1 --max-inherit-rr=0 $DIR1/$tdir/s1/s2/s3 ||
+               error "setdirstripe s3 failed"
+       $LCTL set_param lmv.*.qos_threshold_rr=90
+       mkdir $DIR2/$tdir/s1/s2/s3/d{1..64}
+       count=$($LFS getstripe -m $DIR2/$tdir/s1/s2/s3/d* | grep ^0 | wc -l)
+       (( count == 64 )) || error "only $count subdirs created on MDT0"
+
+       $LFS setdirstripe -D -i -1 --max-inherit-rr=3 $DIR1/$tdir/s1/s2/s3 ||
+               error "setdirstripe s3 failed"
+       mkdir $DIR2/$tdir/s1/s2/s3/s{1..64}
+       count=$($LFS getstripe -m $DIR2/$tdir/s1/s2/s3/s* | grep ^0 | wc -l)
+       (( count == 64 / MDSCOUNT )) || error "$count subdirs created on MDT0"
+}
+run_test 112 "update max-inherit in default LMV"
+
+test_113 () {
+       (( MDS1_VERSION >= $(version_code 2.15.50) )) ||
+               skip "Need server version at least 2.15.50"
+
+       local instance
+       local nid
+
+       instance=$($LFS getname -i $DIR1) ||
+               error "cannot get instance of $DIR1"
+
+       $LFS check osts $DIR1 | grep $instance ||
+               error "cannot find OSTs of instance $instance"
+
+       $LFS check osts $DIR1 | grep -v $instance
+       if (( $? == 0 )); then
+               error "find OSTs other than instance $instance"
+       fi
+
+       $LFS check osts | grep $instance ||
+               error "cannot find other OSTs"
+
+       nid=$(df $DIR2 | tail -1 | sed 's%:/.*%%') ||
+               error "cannot parse nid for $DIR2"
+
+       $LFS check mgts $DIR2 | grep MGC$nid ||
+               error "cannot find mgc of $nid"
+
+       $LFS check mgts $DIR2 | grep -v MGC$nid
+       if (( $? == 0 )); then
+               error "find MGTs other than nid $nid"
+       fi
+}
+run_test 113 "check servers of specified fs"
+
+check_default_lmv() {
+       local dir=$1
+
+       local enabled
+       local dmv
+       local index
+       local count
+       local inherit
+       local inherit_rr
+       local raw
+
+       enabled=$(do_facet mds1 \
+               $LCTL get_param -n mdt.*-MDT0000*.enable_dmv_implicit_inherit)
+
+       dmv=$($LFS getdirstripe -D $dir)
+       echo $dir $dmv
+       index=$(echo $dmv | awk '{ print $4 }')
+       (( index == $2 )) || error "$dir default stripe index $index != $2"
+
+       count=$(echo $dmv | awk '{ print $2 }')
+       (( count == $3 )) || error "$dir default stripe count $count != $3"
+
+       inherit=$(echo $dmv | awk '{ print $8 }')
+       (( inherit == $4 )) || error "$dir default max-inherit $inherit != $4"
+
+       if [ $index -eq -1 ]; then
+               inherit_rr=$(echo $dmv | awk '{ print $10 }')
+               (( inherit_rr == $5 )) ||
+                       error "$dir default max-inherit-rr $inherit_rr != $5"
+       fi
+
+       # with --raw, print default LMV stored in inode, otherwise print nothing
+       raw=$($LFS getdirstripe -D --raw $dir)
+       if (( enabled == 1 )); then
+               [ -z $raw ] ||
+                       error "implicit inherited DMV is printed with --raw"
+       else
+               # if disabled, dmv is stored in inode, which will always
+               # print max-inherit-rr
+               echo $dir $raw
+               [[ $raw =~ $dmv.* ]] || error "$dir raw $raw != dmv $dmv"
+       fi
+}
+
+test_dmv_imp_inherit() {
+       local dmv
+       local raw
+       local index
+       local count
+       local inherit
+       local inherit_rr
+
+       rm -rf $DIR/$tdir || error "rm $tdir failed"
+       mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
+
+       # set dir default LMV
+       $LFS setdirstripe -D -c1 -X4 --max-inherit-rr 2 $DIR/$tdir ||
+               error "setdirstripe -D $tdir failed"
+       dmv=$($LFS getdirstripe -D $DIR/$tdir)
+       raw=$($LFS getdirstripe -D --raw $DIR/$tdir)
+       [ "$dmv" == "$raw" ] || error "$dmv != $raw"
+
+       mkdir -p $DIR/$tdir/l1/l2/l3 || error "mkdir $DIR/$tdir/l1/l2/l3 failed"
+       check_default_lmv $DIR/$tdir/l1/l2/l3 -1 1 1 0
+       check_default_lmv $DIR2/$tdir/l1/l2/l3 -1 1 1 0
+
+       # below tests are valid only when this feature is enabled
+       local enabled=$(do_facet mds1 \
+               $LCTL get_param -n mdt.*-MDT0000*.enable_dmv_implicit_inherit)
+
+       (( enabled == 1 )) || return 0
+
+       # set l2 default LMV, dmv of l3 should change immediately
+       $LFS setdirstripe -D -i1 -c2 -X4 $DIR/$tdir/l1/l2 ||
+               error "setdirstripe -D $tdir/l1/l2 failed"
+
+       check_default_lmv $DIR/$tdir/l1/l2/l3 1 2 3
+       check_default_lmv $DIR2/$tdir/l1/l2/l3 1 2 3
+
+       # change tdir default LMV, dmv of l3 should be unchanged because dmv
+       # of l2 is explicitly set
+       $LFS setdirstripe -D -i2 -c2 -X3 $DIR/$tdir ||
+               error "setdirstripe -D $tdir failed"
+
+       check_default_lmv $DIR/$tdir/l1 2 2 2
+       check_default_lmv $DIR2/$tdir/l1 2 2 2
+       check_default_lmv $DIR/$tdir/l1/l2/l3 1 2 3
+       check_default_lmv $DIR2/$tdir/l1/l2/l3 1 2 3
+}
+
+test_114() {
+       (( MDSCOUNT >= 2 )) ||
+               skip "We need at least 2 MDTs for this test"
+
+       (( MDS1_VERSION >= $(version_code 2.15.55.45) )) ||
+               skip "Need server version at least 2.15.54.45"
+
+       test_dmv_imp_inherit
+
+       # disable dmv_imp_inherit to simulate old client
+       local mdts=$(comma_list $(mdts_nodes))
+
+       do_nodes $mdts $LCTL set_param -n \
+               mdt.*MDT*.enable_dmv_implicit_inherit=0
+       test_dmv_imp_inherit
+       do_nodes $mdts $LCTL set_param -n \
+               mdt.*MDT*.enable_dmv_implicit_inherit=1
+}
+run_test 114 "implicit default LMV inherit"
+
+test_115() {
+       local td=$DIR/$tdir
+
+       [ "$mds1_FSTYPE" == "ldiskfs" ] || skip_env "ldiskfs only test"
+
+       mkdir_on_mdt0 $td || error "can't mkdir"
+       # turn it htree (don't really needed)
+       createmany -m $td/f 3000 || error "can't createmany"
+
+       # here is an example of debugfs output for htree command:
+       # Entry #0: Hash 0x00000000, block 27
+       # Reading directory block 27, phys 16760
+       # 938 0x0016fb58-7f3d21f5 (32) f775   834 0x001db8c8-d31a4e0e (32) f671
+       # 1085 0x0040cb70-4498abd4 (32) f922   1850 0x0066a1e6-f6f0dc69 (32) f1687
+       # 2005 0x006c1a46-ef466058 (32) f1842   2025 0x007e64d4-8b28b734 (32) f1862
+       # 642 0x008b53a0-77adc601 (32) f479   447 0x009ec152-af54eea3 (32) f284
+       # 1740 0x00c38f56-ed310e61 (32) f1577   2165 0x00cdfd66-f429a93f (32) f2002
+       # 930 0x00d7ada4-b80421c9 (32) f767   1946 0x00da6a7a-e8080600 (32) f1783
+       # 273 0x00f8ea00-760bf97c (32) f110   1589 0x0103c4ee-94fad5dd (32) f1426
+       # 1383 0x01193516-83120b48 (32) f1220   2379 0x01431e3c-e85b5bd9 (32) f2216
+       #
+       # find couple names in a same htree block of the same size
+       mdt_dev=$(facet_device $SINGLEMDS)
+       de=( $(do_facet $SINGLEMDS "debugfs -c -R 'htree /ROOT/$tdir' $mdt_dev" |
+               awk '/Reading directory block/ { getline; print $4,$8; exit; }' ))
+       local de1=${de[0]}
+       local de2=${de[1]}
+       [[ $de1 == "" || $de2 == "" ]] && error "de1=$de1 de2=$de2"
+       echo "USE: $de1 $de2"
+       # release one mkdir will lookup
+       rm $DIR/$tdir/$de2
+#define OBD_FAIL_MDS_PAUSE_CREATE_AFTER_LOOKUP 0x2401
+       do_facet $SINGLEMDS $LCTL set_param fail_loc=0x80002401 fail_val=5
+       mkdir $DIR/$tdir/$de2 &
+       sleep 0.3
+       local PID1=$!
+       # recreate $de2
+       mkdir $DIR2/$tdir/$de2
+       # release space $de1 (should be enough to save $de2)
+       rm $DIR2/$tdir/$de1
+       # ready to create a dup of $de2
+       wait $PID1
+       local found=$(ls $DIR/$tdir/|grep "^$de2\$"|wc -l)
+       (( $found == 1 )) || error "found $found"
+}
+run_test 115 "ldiskfs doesn't check direntry for uniqueness"
+
 log "cleanup: ======================================================"
 
 # kill and wait in each test only guarentee script finish, but command in script
@@ -5233,7 +6688,7 @@ log "cleanup: ======================================================"
 [ "$(mount | grep $MOUNT2)" ] && wait_update $HOSTNAME "fuser -m $MOUNT2" "" ||
        true
 
-complete $SECONDS
+complete_test $SECONDS
 rm -f $SAMPLE_FILE
 check_and_cleanup_lustre
 exit_status