Whamcloud - gitweb
LU-13909 tests: get lustre_inode_cache count from sysfs
[fs/lustre-release.git] / lustre / tests / sanity.sh
index fb48a67..207d6b5 100755 (executable)
@@ -31,8 +31,8 @@ GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
 export PARALLEL=${PARALLEL:-"no"}
 
 TRACE=${TRACE:-""}
-LUSTRE_TESTS_API_DIR=${LUSTRE_TESTS_API_DIR:-${LUSTRE}/tests/clientapi}
 LUSTRE=${LUSTRE:-$(dirname $0)/..}
+LUSTRE_TESTS_API_DIR=${LUSTRE_TESTS_API_DIR:-${LUSTRE}/tests/clientapi}
 . $LUSTRE/tests/test-framework.sh
 init_test_env $@
 
@@ -42,7 +42,7 @@ ALWAYS_EXCEPT="$SANITY_EXCEPT "
 # bug number for skipped test: LU-9693 LU-6493 LU-9693
 ALWAYS_EXCEPT+="               42a     42b     42c "
 # bug number:    LU-8411 LU-9054
-ALWAYS_EXCEPT+=" 407     312 "
+ALWAYS_EXCEPT+=" 407     312"
 
 if $SHARED_KEY; then
        # bug number:    LU-9795 LU-9795 LU-9795 LU-9795
@@ -63,8 +63,8 @@ if [[ $(uname -m) = aarch64 ]]; then
        ALWAYS_EXCEPT+=" 45       317"
 fi
 
-# skip nfs tests on kernels >= 4.14.0 until they are fixed
-if [ $LINUX_VERSION_CODE -ge $(version_code 4.14.0) ]; then
+# skip nfs tests on kernels >= 4.12.0 until they are fixed
+if [ $LINUX_VERSION_CODE -ge $(version_code 4.12.0) ]; then
        # bug number:   LU-12661
        ALWAYS_EXCEPT+=" 817"
 fi
@@ -75,7 +75,7 @@ if (( $LINUX_VERSION_CODE >= $(version_code 4.18.0) &&
        ALWAYS_EXCEPT+=" 411"
 fi
 
-#                                  5          12          (min)"
+#                                  5          12     8   12  (min)"
 [ "$SLOW" = "no" ] && EXCEPT_SLOW="27m 64b 68 71 115 135 136 300o"
 
 if [ "$mds1_FSTYPE" = "zfs" ]; then
@@ -144,6 +144,13 @@ check_swap_layouts_support()
                skip "Does not support layout lock."
 }
 
+check_swap_layout_no_dom()
+{
+       local FOLDER=$1
+       local SUPP=$(lfs getstripe $FOLDER | grep "pattern:       mdt" | wc -l)
+       [ $SUPP -eq 0 ] || skip "layout swap does not support DOM files so far"
+}
+
 check_and_setup_lustre
 DIR=${DIR:-$MOUNT}
 assert_DIR
@@ -1635,6 +1642,28 @@ test_27ce() {
 }
 run_test 27ce "more stripes than OSTs with -o"
 
+test_27cf() {
+       local osp_proc="osp.$FSNAME-OST0000-osc-MDT000*.active"
+       local pid=0
+
+       test_mkdir -p $DIR/$tdir || error "failed to mkdir $DIR/$tdir"
+       do_facet $SINGLEMDS "$LCTL set_param -n $osp_proc=0"
+       stack_trap "do_facet $SINGLEMDS $LCTL set_param -n $osp_proc=1" EXIT
+       wait_update_facet $SINGLEMDS "$LCTL get_param -n $osp_proc | grep 1" ||
+               error "failed to set $osp_proc=0"
+
+       $LFS setstripe -o 0 $DIR/$tdir/$tfile &
+       pid=$!
+       sleep 1
+       do_facet $SINGLEMDS "$LCTL set_param -n $osp_proc=1"
+       wait_update_facet $SINGLEMDS "$LCTL get_param -n $osp_proc | grep 0" ||
+               error "failed to set $osp_proc=1"
+       wait $pid
+       [[ $pid -ne 0 ]] ||
+               error "should return error due to $osp_proc=0"
+}
+run_test 27cf "'setstripe -o' on inactive OSTs should return error"
+
 test_27d() {
        test_mkdir $DIR/$tdir
        $LFS setstripe -c 0 -i -1 -S 0 $DIR/$tdir/$tfile ||
@@ -1758,17 +1787,24 @@ run_test 27m "create file while OST0 was full"
 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
 # if the OST isn't full anymore.
 reset_enospc() {
-       local OSTIDX=${1:-""}
+       local ostidx=${1:-""}
+       local delay
+       local ready
+       local get_prealloc
 
        local list=$(comma_list $(osts_nodes))
-       [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
+       [ "$ostidx" ] && list=$(facet_host ost$((ostidx + 1)))
 
        do_nodes $list lctl set_param fail_loc=0
-       sync    # initiate all OST_DESTROYs from MDS to OST
-       sleep_maxage
+       wait_delete_completed   # initiate all OST_DESTROYs from MDS to OST
+       delay=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage |
+               awk '{print $1 * 2;exit;}')
+       get_prealloc="$LCTL get_param -n osc.*MDT*.prealloc_status |
+                       grep -v \"^0$\""
+       wait_update_facet $SINGLEMDS "$get_prealloc" "" $delay
 }
 
-exhaust_precreations() {
+__exhaust_precreations() {
        local OSTIDX=$1
        local FAILLOC=$2
        local FAILIDX=${3:-$OSTIDX}
@@ -1799,14 +1835,19 @@ exhaust_precreations() {
        createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
        do_facet $mfacet lctl get_param osp.$mdtosc_proc2.prealloc*
        do_facet $ofacet lctl set_param fail_loc=$FAILLOC
+}
+
+exhaust_precreations() {
+       __exhaust_precreations $1 $2 $3
        sleep_maxage
 }
 
 exhaust_all_precreations() {
        local i
        for (( i=0; i < OSTCOUNT; i++ )) ; do
-               exhaust_precreations $i $1 -1
+               __exhaust_precreations $i $1 -1
        done
+       sleep_maxage
 }
 
 test_27n() {
@@ -2578,6 +2619,7 @@ test_27G() { #LU-10629
        local ostrange="0 0 1"
 
        test_mkdir $DIR/$tdir
+       touch $DIR/$tdir/$tfile.nopool
        pool_add $POOL || error "pool_add failed"
        pool_add_targets $POOL $ostrange || error "pool_add_targets failed"
        $LFS setstripe -p $POOL $DIR/$tdir
@@ -2585,14 +2627,18 @@ test_27G() { #LU-10629
        local pool=$($LFS getstripe -p $DIR/$tdir)
 
        [ "$pool" = "$POOL" ] || error "Striping failed got '$pool' not '$POOL'"
+       touch $DIR/$tdir/$tfile.default
+       $LFS setstripe -E 1M --pool $POOL -c 1 -E eof -c 1 $DIR/$tdir/$tfile.pfl
+       $LFS find $DIR/$tdir -type f --pool $POOL
+       local found=$($LFS find $DIR/$tdir -type f --pool $POOL | wc -l)
+       [[ "$found" == "2" ]] ||
+               error "found $found != 2 files in '$DIR/$tdir' in '$POOL'"
 
        $LFS setstripe -d $DIR/$tdir
 
-       pool=$($LFS getstripe -p $DIR/$tdir)
-
-       rmdir $DIR/$tdir
+       pool=$($LFS getstripe -p -d $DIR/$tdir)
 
-       [ -z "$pool" ] || error "'$pool' is not empty"
+       [[ "$pool" != "$POOL" ]] || error "$DIR/$tdir is still '$pool'"
 }
 run_test 27G "Clear OST pool from stripe"
 
@@ -2642,7 +2688,7 @@ test_27I() {
 run_test 27I "check that root dir striping does not break parent dir one"
 
 test_27J() {
-       [[ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.12.51) ]] &&
+       [[ $MDS1_VERSION -le $(version_code 2.12.51) ]] &&
                skip "Need MDS version newer than 2.12.51"
 
        test_mkdir $DIR/$tdir
@@ -2737,7 +2783,7 @@ test_27J() {
 run_test 27J "basic ops on file with foreign LOV"
 
 test_27K() {
-       [[ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.12.49) ]] &&
+       [[ $MDS1_VERSION -le $(version_code 2.12.49) ]] &&
                skip "Need MDS version newer than 2.12.49"
 
        test_mkdir $DIR/$tdir
@@ -3053,7 +3099,7 @@ run_test 30b "execute binary from Lustre as non-root ==========="
 test_30c() { # b=22376
        [ $PARALLEL == "yes" ] && skip "skip parallel run"
 
-       cp `which ls` $DIR || cp /bin/ls $DIR
+       cp $(which ls) $DIR || cp /bin/ls $DIR
        chmod a-rw $DIR/ls
        cancel_lru_locks mdc
        cancel_lru_locks osc
@@ -3062,6 +3108,22 @@ test_30c() { # b=22376
 }
 run_test 30c "execute binary from Lustre without read perms ===="
 
+test_30d() {
+       cp $(which dd) $DIR || error "failed to copy dd to $DIR/dd"
+
+       for i in {1..10}; do
+               $DIR/dd bs=1M count=128 if=/dev/zero of=$DIR/$tfile &
+               local PID=$!
+               sleep 1
+               $LCTL set_param ldlm.namespaces.*MDT*.lru_size=clear
+               wait $PID || error "executing dd from Lustre failed"
+               rm -f $DIR/$tfile
+       done
+
+       rm -f $DIR/dd
+}
+run_test 30d "execute binary from Lustre while clear locks"
+
 test_31a() {
        $OPENUNLINK $DIR/f31 $DIR/f31 || error "openunlink failed"
        $CHECKSTAT -a $DIR/f31 || error "$DIR/f31 exists"
@@ -3749,6 +3811,46 @@ test_33g() {
 }
 run_test 33g "nonroot user create already existing root created file"
 
+test_33h() {
+       [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
+       [ $MDS1_VERSION -lt $(version_code 2.13.50) ] &&
+               skip "Need MDS version at least 2.13.50"
+
+       test_mkdir -c $MDSCOUNT -H crush $DIR/$tdir ||
+               error "mkdir $tdir failed"
+       touch $DIR/$tdir/$tfile || error "touch $tfile failed"
+
+       local index=$($LFS getstripe -m $DIR/$tdir/$tfile)
+       local index2
+
+       for fname in $DIR/$tdir/$tfile.bak \
+                    $DIR/$tdir/$tfile.SAV \
+                    $DIR/$tdir/$tfile.orig \
+                    $DIR/$tdir/$tfile~; do
+               touch $fname  || error "touch $fname failed"
+               index2=$($LFS getstripe -m $fname)
+               [ $index -eq $index2 ] ||
+                       error "$fname MDT index mismatch $index != $index2"
+       done
+
+       local failed=0
+       for i in {1..250}; do
+               for fname in $(mktemp -u $DIR/$tdir/.$tfile.XXXXXX) \
+                            $(mktemp $DIR/$tdir/$tfile.XXXXXXXX); do
+                       touch $fname  || error "touch $fname failed"
+                       index2=$($LFS getstripe -m $fname)
+                       if [[ $index != $index2 ]]; then
+                               failed=$((failed + 1))
+                               echo "$fname MDT index mismatch $index != $index2"
+                       fi
+               done
+       done
+       echo "$failed MDT index mismatches"
+       (( failed < 20 )) || error "MDT index mismatch $failed times"
+
+}
+run_test 33h "temp file is located on the same MDT as target"
+
 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
 test_34a() {
        rm -f $DIR/f34
@@ -4468,6 +4570,49 @@ test_39p() {
 }
 run_test 39p "remote directory cached attributes updated after create ========"
 
+test_39r() {
+       [ $OST1_VERSION -ge $(version_code 2.13.52) ] ||
+               skip "no atime update on old OST"
+       if [ "$ost1_FSTYPE" != ldiskfs ]; then
+               skip_env "ldiskfs only test"
+       fi
+
+       local saved_adiff
+       saved_adiff=$(do_facet ost1 \
+               lctl get_param -n obdfilter.*OST0000.atime_diff)
+       stack_trap "do_facet ost1 \
+               lctl set_param obdfilter.*.atime_diff=$saved_adiff"
+
+       do_facet ost1 "lctl set_param obdfilter.*.atime_diff=5"
+
+       $LFS setstripe -i 0 $DIR/$tfile
+       dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 ||
+               error "can't write initial file"
+       cancel_lru_locks osc
+
+       # exceed atime_diff and access file
+       sleep 6
+       dd if=$DIR/$tfile of=/dev/null || error "can't udpate atime"
+
+       local atime_cli=$(stat -c %X $DIR/$tfile)
+       echo "client atime: $atime_cli"
+       # allow atime update to be written to device
+       do_facet ost1 "$LCTL set_param -n osd*.*OST*.force_sync 1"
+       sleep 5
+
+       local ostdev=$(ostdevname 1)
+       local fid=($(lfs getstripe -y $DIR/$tfile |
+                       awk '/l_fid:/ { print $2 }' | tr ':' ' '))
+       local objpath="O/0/d$((${fid[1]} % 32))/$((${fid[1]}))"
+       local cmd="debugfs -c -R \\\"stat $objpath\\\" $ostdev"
+
+       echo "OST atime: $(do_facet ost1 "$cmd" |& grep atime)"
+       local atime_ost=$(do_facet ost1 "$cmd" |&
+                         awk -F'[: ]' '/atime:/ { print $4 }')
+       (( atime_cli == atime_ost )) ||
+               error "atime on client $atime_cli != ost $atime_ost"
+}
+run_test 39r "lazy atime update on OST"
 
 test_39q() { # LU-8041
        local testdir=$DIR/$tdir
@@ -4735,6 +4880,8 @@ test_43A() { # was test_43
 
        $DIR/$tdir/$tfile && error "execute $DIR/$tdir/$tfile succeeded" || true
        kill -USR1 $pid
+       # Wait for multiop to exit
+       wait $pid
 }
 run_test 43A "execution of file opened for write should return -ETXTBSY"
 
@@ -4984,6 +5131,27 @@ test_48e() { # bug 4134
 }
 run_test 48e "Access to recreated parent subdir (should return errors)"
 
+test_48f() {
+       [[ $MDS1_VERSION -ge $(version_code 2.13.55) ]] ||
+               skip "need MDS >= 2.13.55"
+       [[ $MDSCOUNT -ge 2 ]] || skip "needs >= 2 MDTs"
+       [[ "$(facet_host mds1)" != "$(facet_host mds2)" ]] ||
+               skip "needs different host for mdt1 mdt2"
+       [[ $(facet_fstype mds1) == ldiskfs ]] || skip "ldiskfs only"
+
+       $LFS mkdir -i0 $DIR/$tdir
+       $LFS mkdir -i 1 $DIR/$tdir/sub1 $DIR/$tdir/sub2 $DIR/$tdir/sub3
+
+       for d in sub1 sub2 sub3; do
+               #define OBD_FAIL_OSD_REF_DEL    0x19c
+               do_facet mds1 $LCTL set_param fail_loc=0x8000019c
+               rm -rf $DIR/$tdir/$d && error "rm $d should fail"
+       done
+
+       rm -d --interactive=never $DIR/$tdir || error "rm $tdir fail"
+}
+run_test 48f "non-zero nlink dir unlink won't LBUG()"
+
 test_49() { # LU-1030
        [ $PARALLEL == "yes" ] && skip "skip parallel run"
        remote_ost_nodsh && skip "remote OST with nodsh"
@@ -5503,16 +5671,24 @@ test_56c() {
        local ost_idx=0
        local ost_name=$(ostname_from_index $ost_idx)
        local old_status=$(ost_dev_status $ost_idx)
+       local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
 
        [[ -z "$old_status" ]] ||
                skip_env "OST $ost_name is in $old_status status"
 
        do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
-       [[ $OST1_VERSION -ge $(version_code 2.12.55) ]] && do_facet ost1 \
+       [[ $OST1_VERSION -lt $(version_code 2.12.55) ]] || do_facet ost1 \
                $LCTL set_param -n obdfilter.$ost_name.no_precreate=1
+       if [[ $OST1_VERSION -ge $(version_code 2.12.57) ]]; then
+               save_lustre_params ost1 osd-*.$ost_name.nonrotational > $p
+               do_facet ost1 $LCTL set_param -n osd-*.$ost_name.nonrotational=1
+       fi
+
+       [[ $($LFS df -v $MOUNT |& grep -c "inactive device") -eq 0 ]] ||
+               error "$LFS df -v showing inactive devices"
        sleep_maxage
 
-       local new_status=$(ost_dev_status $ost_idx)
+       local new_status=$(ost_dev_status $ost_idx $MOUNT -v)
 
        [[ "$new_status" =~ "D" ]] ||
                error "$ost_name status is '$new_status', missing 'D'"
@@ -5520,18 +5696,37 @@ test_56c() {
                [[ "$new_status" =~ "N" ]] ||
                        error "$ost_name status is '$new_status', missing 'N'"
        fi
+       if [[ $OST1_VERSION -ge $(version_code 2.12.57) ]]; then
+               [[ "$new_status" =~ "f" ]] ||
+                       error "$ost_name status is '$new_status', missing 'f'"
+       fi
 
        do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
-       [[ $OST1_VERSION -ge $(version_code 2.12.55) ]] && do_facet ost1 \
+       [[ $OST1_VERSION -lt $(version_code 2.12.55) ]] || do_facet ost1 \
                $LCTL set_param -n obdfilter.$ost_name.no_precreate=0
+       [[ -z "$p" ]] && restore_lustre_params < $p || true
        sleep_maxage
 
        new_status=$(ost_dev_status $ost_idx)
        [[ ! "$new_status" =~ "D" && ! "$new_status" =~ "N" ]] ||
                error "$ost_name status is '$new_status', has 'D' and/or 'N'"
+       # can't check 'f' as devices may actually be on flash
 }
 run_test 56c "check 'lfs df' showing device status"
 
+test_56d() {
+       local mdts=$($LFS df -v $MOUNT | grep -c MDT)
+       local osts=$($LFS df -v $MOUNT | grep -c OST)
+
+       $LFS df $MOUNT
+
+       (( mdts == MDSCOUNT )) ||
+               error "lfs df -v showed $mdts MDTs, not $MDSCOUNT"
+       (( osts == OSTCOUNT )) ||
+               error "lfs df -v showed $osts OSTs, not $OSTCOUNT"
+}
+run_test 56d "'lfs df -v' prints only configured devices"
+
 NUMFILES=3
 NUMDIRS=3
 setup_56() {
@@ -5747,7 +5942,7 @@ test_56ob() {
        cmd="$LFS find $dir -ctime +1s -type f"
        nums=$($cmd | wc -l)
        (( $nums == $count * 2 + 1)) ||
-               error "'$cmd' wrong: found $nums, expected $((expected*2+1))"
+               error "'$cmd' wrong: found $nums, expected $((count * 2 + 1))"
 }
 run_test 56ob "check lfs find -atime -mtime -ctime with units"
 
@@ -5759,18 +5954,26 @@ test_newerXY_base() {
        local negref
 
        if [ $y == "t" ]; then
-               ref="\"$(date +"%Y-%m-%d %H:%M:%S")\""
+               if [ $x == "b" ]; then
+                       ref="\"$(do_facet mds1 date +"%Y-%m-%d\ %H:%M:%S")\""
+               else
+                       ref="\"$(date +"%Y-%m-%d %H:%M:%S")\""
+               fi
        else
-               ref=$DIR/$tfile.newer
+               ref=$DIR/$tfile.newer.$x$y
                touch $ref || error "touch $ref failed"
        fi
        sleep 2
        setup_56 $dir $NUMFILES $NUMDIRS "-i0 -c1" "-i0 -c1"
        sleep 2
        if [ $y == "t" ]; then
-               negref="\"$(date +"%Y-%m-%d %H:%M:%S")\""
+               if [ $x == "b" ]; then
+                       negref="\"$(do_facet mds1 date +"%Y-%m-%d\ %H:%M:%S")\""
+               else
+                       negref="\"$(date +"%Y-%m-%d %H:%M:%S")\""
+               fi
        else
-               negref=$DIR/$tfile.newerneg
+               negref=$DIR/$tfile.negnewer.$x$y
                touch $negref || error "touch $negref failed"
        fi
 
@@ -5795,6 +5998,7 @@ test_newerXY_base() {
 }
 
 test_56oc() {
+       test_newerXY_base "b" "t"
        test_newerXY_base "a" "a"
        test_newerXY_base "a" "m"
        test_newerXY_base "a" "c"
@@ -5804,12 +6008,96 @@ test_56oc() {
        test_newerXY_base "c" "a"
        test_newerXY_base "c" "m"
        test_newerXY_base "c" "c"
+       test_newerXY_base "b" "b"
        test_newerXY_base "a" "t"
        test_newerXY_base "m" "t"
        test_newerXY_base "c" "t"
+       test_newerXY_base "b" "t"
 }
 run_test 56oc "check lfs find -newerXY work"
 
+btime_supported() {
+       local dir=$DIR/$tdir
+       local rc
+
+       mkdir -p $dir
+       touch $dir/$tfile
+       $LFS find $dir -btime -1d -type f
+       rc=$?
+       rm -rf $dir
+       return $rc
+}
+
+test_56od() {
+       [ $MDS1_VERSION -lt $(version_code 2.13.53) ] &&
+               ! btime_supported && skip "btime unsupported on MDS"
+
+       [ $CLIENT_VERSION -lt $(version_code 2.13.53) ] &&
+               ! btime_supported && skip "btime unsupported on clients"
+
+       local dir=$DIR/$tdir
+       local ref=$DIR/$tfile.ref
+       local negref=$DIR/$tfile.negref
+
+       mkdir $dir || error "mkdir $dir failed"
+       touch $dir/$tfile.n1 || error "touch $dir/$tfile.n1 failed"
+       touch $dir/$tfile.n2 || error "touch $dir/$tfile.n2 failed"
+       mkdir $dir/$tdir.n1 || error "mkdir $dir/$tdir.n1 failed"
+       mkdir $dir/$tdir.n2 || error "mkdir $dir/$tdir.n2 failed"
+       touch $ref || error "touch $ref failed"
+       # sleep 3 seconds at least
+       sleep 3
+
+       local before=$(do_facet mds1 date +%s)
+       local skew=$(($(date +%s) - before + 1))
+
+       if (( skew < 0 && skew > -5 )); then
+               sleep $((0 - skew + 1))
+               skew=0
+       fi
+
+       # Set the dir stripe params to limit files all on MDT0,
+       # otherwise we need to calc the max clock skew between
+       # the client and MDTs.
+       setup_56 $dir/d.btime $NUMFILES $NUMDIRS "-i0 -c1" "-i0 -c1"
+       sleep 2
+       touch $negref || error "touch $negref failed"
+
+       local cmd="$LFS find $dir -newerbb $ref ! -newerbb $negref -type f"
+       local nums=$($cmd | wc -l)
+       local expected=$(((NUMFILES + 1) * NUMDIRS))
+
+       [ $nums -eq $expected ] ||
+               error "'$cmd' wrong: found $nums, expected $expected"
+
+       cmd="$LFS find $dir -newerbb $ref ! -newerbb $negref -type d"
+       nums=$($cmd | wc -l)
+       expected=$((NUMFILES + 1))
+       [ $nums -eq $expected ] ||
+               error "'$cmd' wrong: found $nums, expected $expected"
+
+       [ $skew -lt 0 ] && return
+
+       local after=$(do_facet mds1 date +%s)
+       local age=$((after - before + 1 + skew))
+
+       cmd="$LFS find $dir -btime -${age}s -type f"
+       nums=$($cmd | wc -l)
+       expected=$(((NUMFILES + 1) * NUMDIRS))
+
+       echo "Clock skew between client and server: $skew, age:$age"
+       [ $nums -eq $expected ] ||
+               error "'$cmd' wrong: found $nums, expected $expected"
+
+       expected=$(($NUMDIRS + 1))
+       cmd="$LFS find $dir -btime -${age}s -type d"
+       nums=$($cmd | wc -l)
+       [ $nums -eq $expected ] ||
+               error "'$cmd' wrong: found $nums, expected $expected"
+       rm -f $ref $negref || error "Failed to remove $ref $negref"
+}
+run_test 56od "check lfs find -btime with units"
+
 test_56p() {
        [ $RUNAS_ID -eq $UID ] &&
                skip_env "RUNAS_ID = UID = $UID -- skipping"
@@ -5938,156 +6226,90 @@ test_56r() {
 }
 run_test 56r "check lfs find -size works"
 
-test_56ra() {
-       [[ $MDS1_VERSION -gt $(version_code 2.12.58) ]] ||
-               skip "MDS < 2.12.58 doesn't return LSOM data"
-       local dir=$DIR/$tdir
-
-       [[ $OSC == "mdc" ]] && skip "DoM files" && return
-
-       setup_56 $dir $NUMFILES $NUMDIRS "-c 1"
+test_56ra_sub() {
+       local expected=$1
+       local glimpses=$2
+       local cmd="$3"
 
        cancel_lru_locks $OSC
 
        local rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       local expected=12
-       local cmd="$LFS find -size 0 -type f -lazy $dir"
        local nums=$($cmd | wc -l)
 
        [ $nums -eq $expected ] ||
                error "'$cmd' wrong: found $nums, expected $expected"
 
        local rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       [ $rpcs_before -eq $rpcs_after ] ||
-               error "'$cmd' should not send glimpse RPCs to OST"
-       cmd="$LFS find -size 0 -type f $dir"
-       nums=$($cmd | wc -l)
-       [ $nums -eq $expected ] ||
-               error "'$cmd' wrong: found $nums, expected $expected"
-       rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
-       $LCTL get_param osc.*.stats
-       [ $rpcs_after -eq $((rpcs_before + 12)) ] ||
-               error "'$cmd' should send 12 glimpse RPCs to OST"
 
+       if (( rpcs_before + glimpses != rpcs_after )); then
+               echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
+               $LCTL get_param osc.*.stats | grep ldlm_glimpse_enqueue
+
+               if [[ $glimpses == 0 ]]; then
+                       error "'$cmd' should not send glimpse RPCs to OST"
+               else
+                       error "'$cmd' should send $glimpses glimpse RPCs to OST"
+               fi
+       fi
+}
+
+test_56ra() {
+       [[ $MDS1_VERSION -gt $(version_code 2.12.58) ]] ||
+               skip "MDS < 2.12.58 doesn't return LSOM data"
+       local dir=$DIR/$tdir
+
+       [[ $OSC == "mdc" ]] && skip "DoM files" && return
+
+       setup_56 $dir $NUMFILES $NUMDIRS "-c 1"
+       # open and close all files to ensure LSOM is updated
        cancel_lru_locks $OSC
-       rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       expected=0
-       cmd="$LFS find ! -size 0 -type f -lazy $dir"
-       nums=$($cmd | wc -l)
-       [ $nums -eq $expected ] ||
-               error "'$cmd' wrong: found $nums, expected $expected"
-       rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       $LCTL get_param mdc.*.stats
-       [ $rpcs_before -eq $rpcs_after ] ||
-               error "'$cmd' should not send glimpse RPCs to OST"
-       cmd="$LFS find ! -size 0 -type f $dir"
-       nums=$($cmd | wc -l)
-       [ $nums -eq $expected ] ||
-               error "'$cmd' wrong: found $nums, expected $expected"
-       rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
-       [ $rpcs_after -eq $((rpcs_before + 12)) ] ||
-               error "'$cmd' should send 12 glimpse RPCs to OST"
+       find $dir -type f | xargs cat > /dev/null
+
+       #   expect_found  glimpse_rpcs  command_to_run
+       test_56ra_sub 12  0 "$LFS find -size 0 -type f -lazy $dir"
+       test_56ra_sub 12 12 "$LFS find -size 0 -type f $dir"
+       test_56ra_sub  0  0 "$LFS find ! -size 0 -type f -lazy $dir"
+       test_56ra_sub  0 12 "$LFS find ! -size 0 -type f $dir"
 
        echo "test" > $dir/$tfile
        echo "test2" > $dir/$tfile.2 && sync
        cancel_lru_locks $OSC
-       rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       expected=1
-       cmd="$LFS find -size 5 -type f -lazy $dir"
-       nums=$($cmd | wc -l)
-       [ $nums -eq $expected ] ||
-               error "'$cmd' wrong: found $nums, expected $expected"
-       rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       [ $rpcs_before -eq $rpcs_after ] ||
-               error "'$cmd' should not send glimpse RPCs to OST"
-       cmd="$LFS find -size 5 -type f $dir"
-       nums=$($cmd | wc -l)
-       [ $nums -eq $expected ] ||
-               error "'$cmd' wrong: found $nums, expected $expected"
-       rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
-       [ $rpcs_after -eq $((rpcs_before + 14)) ] ||
-               error "'$cmd' should send 14 glimpse RPCs to OST"
+       cat $dir/$tfile $dir/$tfile.2 > /dev/null
 
-       cancel_lru_locks $OSC
-       rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       expected=1
-       cmd="$LFS find -size +5 -type f -lazy $dir"
-       nums=$($cmd | wc -l)
-       [ $nums -eq $expected ] ||
-               error "'$cmd' wrong: found $nums, expected $expected"
-       rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       [ $rpcs_before -eq $rpcs_after ] ||
-               error "'$cmd' should not send glimpse RPCs to OST"
-       cmd="$LFS find -size +5 -type f $dir"
-       nums=$($cmd | wc -l)
-       [ $nums -eq $expected ] ||
-               error "'$cmd' wrong: found $nums, expected $expected"
-       rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
-       [ $rpcs_after -eq $((rpcs_before + 14)) ] ||
-               error "'$cmd' should send 14 glimpse RPCs to OST"
+       test_56ra_sub  1  0 "$LFS find -size 5 -type f -lazy $dir"
+       test_56ra_sub  1 14 "$LFS find -size 5 -type f $dir"
+       test_56ra_sub  1  0 "$LFS find -size +5 -type f -lazy $dir"
+       test_56ra_sub  1 14 "$LFS find -size +5 -type f $dir"
 
-       cancel_lru_locks $OSC
-       rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       expected=2
-       cmd="$LFS find -size +0 -type f -lazy $dir"
-       nums=$($cmd | wc -l)
-       [ $nums -eq $expected ] ||
-               error "'$cmd' wrong: found $nums, expected $expected"
-       rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       [ $rpcs_before -eq $rpcs_after ] ||
-               error "'$cmd' should not send glimpse RPCs to OST"
-       cmd="$LFS find -size +0 -type f $dir"
-       nums=$($cmd | wc -l)
-       [ $nums -eq $expected ] ||
-               error "'$cmd' wrong: found $nums, expected $expected"
-       rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
-       [ $rpcs_after -eq $((rpcs_before + 14)) ] ||
-               error "'$cmd' should send 14 glimpse RPCs to OST"
+       test_56ra_sub  2  0 "$LFS find -size +0 -type f -lazy $dir"
+       test_56ra_sub  2 14 "$LFS find -size +0 -type f $dir"
+       test_56ra_sub  2  0 "$LFS find ! -size -5 -type f -lazy $dir"
+       test_56ra_sub  2 14 "$LFS find ! -size -5 -type f $dir"
+       test_56ra_sub 12  0 "$LFS find -size -5 -type f -lazy $dir"
+       test_56ra_sub 12 14 "$LFS find -size -5 -type f $dir"
+}
+run_test 56ra "check lfs find -size -lazy works for data on OSTs"
 
-       cancel_lru_locks $OSC
-       rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       expected=2
-       cmd="$LFS find ! -size -5 -type f -lazy $dir"
-       nums=$($cmd | wc -l)
-       [ $nums -eq $expected ] ||
-               error "'$cmd' wrong: found $nums, expected $expected"
-       rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       [ $rpcs_before -eq $rpcs_after ] ||
-               error "'$cmd' should not send glimpse RPCs to OST"
-       cmd="$LFS find ! -size -5 -type f $dir"
-       nums=$($cmd | wc -l)
-       [ $nums -eq $expected ] ||
-               error "'$cmd' wrong: found $nums, expected $expected"
-       rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
-       [ $rpcs_after -eq $((rpcs_before + 14)) ] ||
-               error "'$cmd' should send 14 glimpse RPCs to OST"
+test_56rb() {
+       local dir=$DIR/$tdir
+       local tmp=$TMP/$tfile.log
+       local mdt_idx;
 
-       cancel_lru_locks $OSC
-       rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       expected=12
-       cmd="$LFS find -size -5 -type f -lazy $dir"
-       nums=$($cmd | wc -l)
-       [ $nums -eq $expected ] ||
-               error "'$cmd' wrong: found $nums, expected $expected"
-       rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       [ $rpcs_before -eq $rpcs_after ] ||
-               error "'$cmd' should not send glimpse RPCs to OST"
-       cmd="$LFS find -size -5 -type f $dir"
-       nums=$($cmd | wc -l)
-       [ $nums -eq $expected ] ||
-               error "'$cmd' wrong: found $nums, expected $expected"
-       rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
-       echo "Before: $rpcs_before After: $rpcs_after $NUMFILES"
-       [ $rpcs_after -eq $((rpcs_before + 14)) ] ||
-               error "'$cmd' should send 14 glimpse RPCs to OST"
+       test_mkdir -p $dir || error "failed to mkdir $dir"
+       $LFS setstripe -c 1 -i 0 $dir/$tfile ||
+               error "failed to setstripe $dir/$tfile"
+       mdt_idx=$($LFS getdirstripe -i $dir)
+       dd if=/dev/zero of=$dir/$tfile bs=1M count=1
+
+       stack_trap "rm -f $tmp" EXIT
+       $LFS find --size +100K --ost 0 $dir |& tee $tmp
+       ! grep -q obd_uuid $tmp ||
+               error "failed to find --size +100K --ost 0 $dir"
+       $LFS find --size +100K --mdt $mdt_idx $dir |& tee $tmp
+       ! grep -q obd_uuid $tmp ||
+               error "failed to find --size +100K --mdt $mdt_idx $dir"
 }
-run_test 56ra "check lfs find -size -lazy works for data on OSTs"
+run_test 56rb "check lfs find --size --ost/--mdt works"
 
 test_56s() { # LU-611 #LU-9369
        [[ $OSTCOUNT -lt 2 ]] && skip_env "need at least 2 OSTs"
@@ -6438,7 +6660,9 @@ test_56wb() {
        echo "done."
 
        echo -n "Removing test file from pool '$pool'..."
-       $LFS migrate $file1 &> /dev/null ||
+       # "lfs migrate $file" won't remove the file from the pool
+       # until some striping information is changed.
+       $LFS migrate -c 1 $file1 &> /dev/null ||
                error "cannot remove from pool"
        [ "$($LFS getstripe -p $file1)" ] &&
                error "pool still set"
@@ -6460,19 +6684,23 @@ run_test 56wb "check lfs_migrate pool support"
 
 test_56wc() {
        local file1="$DIR/$tdir/file1"
+       local parent_ssize
+       local parent_scount
+       local cur_ssize
+       local cur_scount
+       local orig_ssize
 
        echo -n "Creating test dir..."
        test_mkdir $DIR/$tdir &> /dev/null || error "cannot create dir"
-       local def_stripe_size=$($LFS getstripe -S $DIR/$tdir 2>/dev/null)
        $LFS setstripe -S 1M -c 1 "$DIR/$tdir" &> /dev/null ||
-               error "cannot set stripe"
+               error "cannot set stripe by '-S 1M -c 1'"
        echo "done"
 
        echo -n "Setting initial stripe for test file..."
        $LFS setstripe -S 512K -c 1 "$file1" &> /dev/null ||
                error "cannot set stripe"
-       [ $($LFS getstripe -S "$file1") -eq 524288 ] ||
-               error "stripe size not set"
+       cur_ssize=$($LFS getstripe -S "$file1")
+       [ $cur_ssize -eq 524288 ] || error "setstripe -S $cur_ssize != 524288"
        echo "done."
 
        # File currently set to -S 512K -c 1
@@ -6489,8 +6717,8 @@ test_56wc() {
        echo -n "Verifying -S option is passed through to lfs migrate..."
        $LFS_MIGRATE -y -S 1M "$file1" &> /dev/null ||
                error "migration failed"
-       [ $($LFS getstripe -S "$file1") -eq 1048576 ] ||
-               error "file was not restriped"
+       cur_ssize=$($LFS getstripe -S "$file1")
+       [ $cur_ssize -eq 1048576 ] || error "migrate -S $cur_ssize != 1048576"
        echo "done."
 
        # File currently set to -S 1M -c 1
@@ -6501,8 +6729,9 @@ test_56wc() {
                error "long option without argument not supported"
        $LFS_MIGRATE -y --stripe-size 512K "$file1" &> /dev/null ||
                error "long option with argument not supported"
-       [ $($LFS getstripe -S "$file1") -eq 524288 ] ||
-               error "file not restriped with --stripe-size option"
+       cur_ssize=$($LFS getstripe -S "$file1")
+       [ $cur_ssize -eq 524288 ] ||
+               error "migrate --stripe-size $cur_ssize != 524288"
        echo "done."
 
        # File currently set to -S 512K -c 1
@@ -6511,8 +6740,8 @@ test_56wc() {
                echo -n "Verifying explicit stripe count can be set..."
                $LFS_MIGRATE -y -c 2 "$file1" &> /dev/null ||
                        error "migrate failed"
-               [ $($LFS getstripe -c "$file1") -eq 2 ] ||
-                       error "file not restriped to explicit count"
+               cur_scount=$($LFS getstripe -c "$file1")
+               [ $cur_scount -eq 2 ] || error "migrate -c $cur_scount != 2"
                echo "done."
        fi
 
@@ -6521,17 +6750,21 @@ test_56wc() {
        # Ensure parent striping is used if -R is set, and no stripe
        # count or size is specified
        echo -n "Setting stripe for parent directory..."
-       $LFS setstripe -S 1M -c 1 "$DIR/$tdir" &> /dev/null ||
-               error "cannot set stripe"
+       $LFS setstripe -S 2M -c 1 "$DIR/$tdir" &> /dev/null ||
+               error "cannot set stripe '-S 2M -c 1'"
        echo "done."
 
        echo -n "Verifying restripe option uses parent stripe settings..."
+       parent_ssize=$($LFS getstripe -S $DIR/$tdir 2>/dev/null)
+       parent_scount=$($LFS getstripe -c $DIR/$tdir 2>/dev/null)
        $LFS_MIGRATE -y -R "$file1" &> /dev/null ||
                error "migrate failed"
-       [ $($LFS getstripe -S "$file1") -eq $def_stripe_size ] ||
-               error "file not restriped to parent settings"
-       [ $($LFS getstripe -c "$file1") -eq 1 ] ||
-               error "file not restriped to parent settings"
+       cur_ssize=$($LFS getstripe -S "$file1")
+       [ $cur_ssize -eq $parent_ssize ] ||
+               error "migrate -R stripe_size $cur_ssize != $parent_ssize"
+       cur_scount=$($LFS getstripe -c "$file1")
+       [ $cur_scount -eq $parent_scount ] ||
+               error "migrate -R stripe_count $cur_scount != $parent_scount"
        echo "done."
 
        # File currently set to -S 1M -c 1
@@ -6539,13 +6772,14 @@ test_56wc() {
        # Ensure striping is preserved if -R is not set, and no stripe
        # count or size is specified
        echo -n "Verifying striping size preserved when not specified..."
-       local orig_stripe_size=$($LFS getstripe -S "$file1" 2>/dev/null)
+       orig_ssize=$($LFS getstripe -S "$file1" 2>/dev/null)
        $LFS setstripe -S 2M -c 1 "$DIR/$tdir" &> /dev/null ||
                error "cannot set stripe on parent directory"
        $LFS_MIGRATE -y "$file1" &> /dev/null ||
                error "migrate failed"
-       [ $($LFS getstripe -S "$file1") -eq $orig_stripe_size ] ||
-               error "file was restriped"
+       cur_ssize=$($LFS getstripe -S "$file1")
+       [ $cur_ssize -eq $orig_ssize ] ||
+               error "migrate by default $cur_ssize != $orig_ssize"
        echo "done."
 
        # Ensure file name properly detected when final option has no argument
@@ -6598,6 +6832,24 @@ test_56wd() {
 }
 run_test 56wd "check lfs_migrate --rsync and --no-rsync work"
 
+test_56we() {
+       local td=$DIR/$tdir
+       local tf=$td/$tfile
+
+       test_mkdir $td || error "cannot create $td"
+       touch $tf || error "cannot touch $tf"
+
+       echo -n "Make sure --non-direct|-D works..."
+       $LFS_MIGRATE -y --non-direct -v $tf 2>&1 |
+               grep -q "lfs migrate --non-direct" ||
+               error "--non-direct option cannot work correctly"
+       $LFS_MIGRATE -y -D -v $tf 2>&1 |
+               grep -q "lfs migrate -D" ||
+               error "-D option cannot work correctly"
+       echo "done."
+}
+run_test 56we "check lfs_migrate --non-direct|-D support"
+
 test_56x() {
        [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
        check_swap_layouts_support
@@ -6833,6 +7085,115 @@ test_56xc() {
 }
 run_test 56xc "lfs migration autostripe"
 
+test_56xd() {
+       [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
+
+       local dir=$DIR/$tdir
+       local f_mgrt=$dir/$tfile.mgrt
+       local f_yaml=$dir/$tfile.yaml
+       local f_copy=$dir/$tfile.copy
+       local layout_yaml="-E 1M -S 512K -c 1 -E -1 -S 1M -c 2 -i 0"
+       local layout_copy="-c 2 -S 2M -i 1"
+       local yamlfile=$dir/yamlfile
+       local layout_before;
+       local layout_after;
+
+       test_mkdir "$dir" || error "cannot create dir $dir"
+       $LFS setstripe $layout_yaml $f_yaml ||
+               error "cannot setstripe $f_yaml with layout $layout_yaml"
+       $LFS getstripe --yaml $f_yaml > $yamlfile
+       $LFS setstripe $layout_copy $f_copy ||
+               error "cannot setstripe $f_copy with layout $layout_copy"
+       touch $f_mgrt
+       dd if=/dev/zero of=$f_mgrt bs=1M count=4
+
+       # 1. test option --yaml
+       $LFS_MIGRATE -y --yaml $yamlfile $f_mgrt ||
+               error "cannot migrate $f_mgrt with --yaml $yamlfile"
+       layout_before=$(get_layout_param $f_yaml)
+       layout_after=$(get_layout_param $f_mgrt)
+       [ "$layout_after" == "$layout_before" ] ||
+               error "lfs_migrate --yaml: $layout_after != $layout_before"
+
+       # 2. test option --copy
+       $LFS_MIGRATE -y --copy $f_copy $f_mgrt ||
+               error "cannot migrate $f_mgrt with --copy $f_copy"
+       layout_before=$(get_layout_param $f_copy)
+       layout_after=$(get_layout_param $f_mgrt)
+       [ "$layout_after" == "$layout_before" ] ||
+               error "lfs_migrate --copy: $layout_after != $layout_before"
+}
+run_test 56xd "check lfs_migrate --yaml and --copy support"
+
+test_56xe() {
+       [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
+
+       local dir=$DIR/$tdir
+       local f_comp=$dir/$tfile
+       local layout="-E 1M -S 512K -c 1 -E -1 -S 1M -c 2 -i 0"
+       local layout_before=""
+       local layout_after=""
+
+       test_mkdir "$dir" || error "cannot create dir $dir"
+       $LFS setstripe $layout $f_comp ||
+               error "cannot setstripe $f_comp with layout $layout"
+       layout_before=$(get_layout_param $f_comp)
+       dd if=/dev/zero of=$f_comp bs=1M count=4
+
+       # 1. migrate a comp layout file by lfs_migrate
+       $LFS_MIGRATE -y $f_comp || error "cannot migrate $f_comp by lfs_migrate"
+       layout_after=$(get_layout_param $f_comp)
+       [ "$layout_before" == "$layout_after" ] ||
+               error "lfs_migrate: $layout_before != $layout_after"
+
+       # 2. migrate a comp layout file by lfs migrate
+       $LFS migrate $f_comp || error "cannot migrate $f_comp by lfs migrate"
+       layout_after=$(get_layout_param $f_comp)
+       [ "$layout_before" == "$layout_after" ] ||
+               error "lfs migrate: $layout_before != $layout_after"
+}
+run_test 56xe "migrate a composite layout file"
+
+test_56xf() {
+       [[ $OSTCOUNT -ge 2 ]] || skip_env "needs >= 2 OSTs"
+
+       [[ $MDS1_VERSION -ge $(version_code 2.13.53) ]] ||
+               skip "Need server version at least 2.13.53"
+
+       local dir=$DIR/$tdir
+       local f_comp=$dir/$tfile
+       local layout="-E 1M -c1 -E -1 -c2"
+       local fid_before=""
+       local fid_after=""
+
+       test_mkdir "$dir" || error "cannot create dir $dir"
+       $LFS setstripe $layout $f_comp ||
+               error "cannot setstripe $f_comp with layout $layout"
+       fid_before=$($LFS getstripe --fid $f_comp)
+       dd if=/dev/zero of=$f_comp bs=1M count=4
+
+       # 1. migrate a comp layout file to a comp layout
+       $LFS migrate $f_comp || error "cannot migrate $f_comp by lfs migrate"
+       fid_after=$($LFS getstripe --fid $f_comp)
+       [ "$fid_before" == "$fid_after" ] ||
+               error "comp-to-comp migrate: $fid_before != $fid_after"
+
+       # 2. migrate a comp layout file to a plain layout
+       $LFS migrate -c2 $f_comp ||
+               error "cannot migrate $f_comp by lfs migrate"
+       fid_after=$($LFS getstripe --fid $f_comp)
+       [ "$fid_before" == "$fid_after" ] ||
+               error "comp-to-plain migrate: $fid_before != $fid_after"
+
+       # 3. migrate a plain layout file to a comp layout
+       $LFS migrate $layout $f_comp ||
+               error "cannot migrate $f_comp by lfs migrate"
+       fid_after=$($LFS getstripe --fid $f_comp)
+       [ "$fid_before" == "$fid_after" ] ||
+               error "plain-to-comp migrate: $fid_before != $fid_after"
+}
+run_test 56xf "FID is not lost during migration of a composite layout file"
+
 test_56y() {
        [ $MDS1_VERSION -lt $(version_code 2.4.53) ] &&
                skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53"
@@ -7492,8 +7853,8 @@ run_test 63b "async write errors should be returned to fsync ==="
 test_64a () {
        [ $PARALLEL == "yes" ] && skip "skip parallel run"
 
-       df $DIR
-       lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
+       lfs df $DIR
+       lctl get_param osc.*[oO][sS][cC][_-]*.cur* | grep "=[1-9]"
 }
 run_test 64a "verify filter grant calculations (in kernel) ====="
 
@@ -7509,18 +7870,25 @@ test_64c() {
 }
 run_test 64c "verify grant shrink"
 
-# this does exactly what osc_request.c:osc_announce_cached() does in
-# order to calculate max amount of grants to ask from server
-want_grant() {
+import_param() {
        local tgt=$1
+       local param=$2
 
-       local nrpages=$($LCTL get_param -n osc.${tgt}.max_pages_per_rpc)
-       local rpc_in_flight=$($LCTL get_param -n osc.${tgt}.max_rpcs_in_flight)
+       $LCTL get_param osc.$tgt.import | awk "/$param/ { print \$2 }"
+}
 
-       ((rpc_in_flight ++));
+# this does exactly what osc_request.c:osc_announce_cached() does in
+# order to calculate max amount of grants to ask from server
+want_grant() {
+       local tgt=$1
+
+       local nrpages=$($LCTL get_param -n osc.$tgt.max_pages_per_rpc)
+       local rpc_in_flight=$($LCTL get_param -n osc.$tgt.max_rpcs_in_flight)
+
+       ((rpc_in_flight++));
        nrpages=$((nrpages * rpc_in_flight))
 
-       local dirty_max_pages=$($LCTL get_param -n osc.${tgt}.max_dirty_mb)
+       local dirty_max_pages=$($LCTL get_param -n osc.$tgt.max_dirty_mb)
 
        dirty_max_pages=$((dirty_max_pages * 1024 * 1024 / PAGE_SIZE))
 
@@ -7528,13 +7896,11 @@ want_grant() {
        local undirty=$((nrpages * PAGE_SIZE))
 
        local max_extent_pages
-       max_extent_pages=$($LCTL get_param osc.${tgt}.import |
-           grep grant_max_extent_size | awk '{print $2}')
+       max_extent_pages=$(import_param $tgt grant_max_extent_size)
        max_extent_pages=$((max_extent_pages / PAGE_SIZE))
        local nrextents=$(((nrpages + max_extent_pages - 1) / max_extent_pages))
        local grant_extent_tax
-       grant_extent_tax=$($LCTL get_param osc.${tgt}.import |
-           grep grant_extent_tax | awk '{print $2}')
+       grant_extent_tax=$(import_param $tgt grant_extent_tax)
 
        undirty=$((undirty + nrextents * grant_extent_tax))
 
@@ -7548,56 +7914,171 @@ grant_chunk() {
        local max_brw_size
        local grant_extent_tax
 
-       max_brw_size=$($LCTL get_param osc.${tgt}.import |
-           grep max_brw_size | awk '{print $2}')
+       max_brw_size=$(import_param $tgt max_brw_size)
 
-       grant_extent_tax=$($LCTL get_param osc.${tgt}.import |
-           grep grant_extent_tax | awk '{print $2}')
+       grant_extent_tax=$(import_param $tgt grant_extent_tax)
 
        echo $(((max_brw_size + grant_extent_tax) * 2))
 }
 
 test_64d() {
-       [ $OST1_VERSION -lt $(version_code 2.10.56) ] &&
+       [ $OST1_VERSION -ge $(version_code 2.10.56) ] ||
                skip "OST < 2.10.55 doesn't limit grants enough"
 
-       local tgt=$($LCTL dl | grep "0000-osc-[^mM]" | awk '{print $4}')
-       local file=$DIR/$tfile
+       local tgt=$($LCTL dl | awk '/OST0000-osc-[^mM]/ { print $4 }')
 
-       [[ $($LCTL get_param osc.${tgt}.import |
-            grep "connect_flags:.*grant_param") ]] ||
+       [[ "$($LCTL get_param osc.${tgt}.import)" =~ "grant_param" ]] ||
                skip "no grant_param connect flag"
 
-       local olddebug=$($LCTL get_param -n debug 2> /dev/null)
+       local olddebug="$($LCTL get_param -n debug 2> /dev/null)"
+
+       $LCTL set_param -n -n debug="$OLDDEBUG" || true
+       stack_trap "$LCTL set_param -n debug='$olddebug'" EXIT
 
-       $LCTL set_param debug="$OLDDEBUG" 2> /dev/null || true
 
        local max_cur_granted=$(($(want_grant $tgt) + $(grant_chunk $tgt)))
-       stack_trap "rm -f $file" EXIT
+       stack_trap "rm -f $DIR/$tfile && wait_delete_completed" EXIT
 
-       $LFS setstripe $file -i 0 -c 1
-       dd if=/dev/zero of=$file bs=1M count=1000 &
+       $LFS setstripe $DIR/$tfile -i 0 -c 1
+       dd if=/dev/zero of=$DIR/$tfile bs=1M count=1000 &
        ddpid=$!
 
-       while true
-       do
-               local cur_grant=$($LCTL get_param -n osc.${tgt}.cur_grant_bytes)
-               if [[ $cur_grant -gt $max_cur_granted ]]
-               then
+       while kill -0 $ddpid; do
+               local cur_grant=$($LCTL get_param -n osc.$tgt.cur_grant_bytes)
+
+               if [[ $cur_grant -gt $max_cur_granted ]]; then
                        kill $ddpid
                        error "cur_grant $cur_grant > $max_cur_granted"
                fi
-               kill -0 $ddpid
-               [[ $? -ne 0 ]] && break;
-               sleep 2
-       done
 
-       rm -f $DIR/$tfile
-       wait_delete_completed
-       $LCTL set_param debug="$olddebug" 2> /dev/null || true
+               sleep 1
+       done
 }
 run_test 64d "check grant limit exceed"
 
+check_grants() {
+       local tgt=$1
+       local expected=$2
+       local msg=$3
+       local cur_grants=$($LCTL get_param -n osc.$tgt.cur_grant_bytes)
+
+       ((cur_grants == expected)) ||
+               error "$msg: grants mismatch: $cur_grants, expected $expected"
+}
+
+round_up_p2() {
+       echo $((($1 + $2 - 1) & ~($2 - 1)))
+}
+
+test_64e() {
+       [ $PARALLEL == "yes" ] && skip "skip parallel run"
+       [ $OST1_VERSION -ge $(version_code 2.11.56) ] ||
+               skip "Need OSS version at least 2.11.56"
+
+       # Remount client to reset grant
+       remount_client $MOUNT || error "failed to remount client"
+       local osc_tgt="$FSNAME-OST0000-osc-$($LFS getname -i $DIR)"
+
+       local init_grants=$(import_param $osc_tgt initial_grant)
+
+       check_grants $osc_tgt $init_grants "init grants"
+
+       local extent_tax=$(import_param $osc_tgt grant_extent_tax)
+       local max_brw_size=$(import_param $osc_tgt max_brw_size)
+       local gbs=$(import_param $osc_tgt grant_block_size)
+
+       # write random number of bytes from max_brw_size / 4 to max_brw_size
+       local write_bytes=$(shuf -i $((max_brw_size / 4))-$max_brw_size -n 1)
+       # align for direct io
+       write_bytes=$(round_up_p2 $write_bytes PAGE_SIZE)
+       # round to grant consumption unit
+       local wb_round_up=$(round_up_p2 $write_bytes gbs)
+
+       local grants=$((wb_round_up + extent_tax))
+
+       $LFS setstripe -c 1 -i 0 $DIR/$tfile  || error "lfs setstripe failed"
+
+       # define OBD_FAIL_TGT_NO_GRANT 0x725
+       # make the server not grant more back
+       do_facet ost1 $LCTL set_param fail_loc=0x725
+       dd if=/dev/zero of=$DIR/$tfile bs=$write_bytes count=1 oflag=direct
+
+       do_facet ost1 $LCTL set_param fail_loc=0
+
+       check_grants $osc_tgt $((init_grants - grants)) "dio w/o grant alloc"
+
+       rm -f $DIR/$tfile || error "rm failed"
+
+       # Remount client to reset grant
+       remount_client $MOUNT || error "failed to remount client"
+       osc_tgt="$FSNAME-OST0000-osc-$($LFS getname -i $DIR)"
+
+       $LFS setstripe -c 1 -i 0 $DIR/$tfile || error "lfs setstripe failed"
+
+       # define OBD_FAIL_TGT_NO_GRANT 0x725
+       # make the server not grant more back
+       do_facet ost1 $LCTL set_param fail_loc=0x725
+       $MULTIOP $DIR/$tfile "oO_WRONLY:w${write_bytes}yc"
+       do_facet ost1 $LCTL set_param fail_loc=0
+
+       check_grants $osc_tgt $((init_grants - grants)) "buf io w/o grant alloc"
+}
+run_test 64e "check grant consumption (no grant allocation)"
+
+test_64f() {
+       [ $PARALLEL == "yes" ] && skip "skip parallel run"
+
+       # Remount client to reset grant
+       remount_client $MOUNT || error "failed to remount client"
+       local osc_tgt="$FSNAME-OST0000-osc-$($LFS getname -i $DIR)"
+
+       local init_grants=$(import_param $osc_tgt initial_grant)
+       local extent_tax=$(import_param $osc_tgt grant_extent_tax)
+       local max_brw_size=$(import_param $osc_tgt max_brw_size)
+       local gbs=$(import_param $osc_tgt grant_block_size)
+       local chunk=$(grant_chunk $osc_tgt)
+
+       # write random number of bytes from max_brw_size / 4 to max_brw_size
+       local write_bytes=$(shuf -i $((max_brw_size / 4))-$max_brw_size -n 1)
+       # align for direct io
+       write_bytes=$(round_up_p2 $write_bytes PAGE_SIZE)
+       # round to grant consumption unit
+       local wb_round_up=$(round_up_p2 $write_bytes gbs)
+
+       local grants=$((wb_round_up + extent_tax))
+
+       $LFS setstripe -c 1 -i 0 $DIR/$tfile || error "lfs setstripe failed"
+       dd if=/dev/zero of=$DIR/$tfile bs=$write_bytes count=1 oflag=direct ||
+               error "error writing to $DIR/$tfile"
+
+       check_grants $osc_tgt $((init_grants - grants + chunk)) \
+               "direct io with grant allocation"
+
+       rm -f $DIR/$tfile || error "rm failed"
+
+       # Remount client to reset grant
+       remount_client $MOUNT || error "failed to remount client"
+       osc_tgt="$FSNAME-OST0000-osc-$($LFS getname -i $DIR)"
+
+       $LFS setstripe -c 1 -i 0 $DIR/$tfile || error "lfs setstripe failed"
+
+       local cmd="oO_WRONLY:w${write_bytes}_yc"
+
+       $MULTIOP $DIR/$tfile $cmd &
+       MULTIPID=$!
+       sleep 1
+
+       check_grants $osc_tgt $((init_grants - grants)) \
+               "buffered io, not write rpc"
+
+       kill -USR1 $MULTIPID
+       wait
+
+       check_grants $osc_tgt $((init_grants - grants + chunk)) \
+               "buffered io, one RPC"
+}
+run_test 64f "check grant consumption (with grant allocation)"
+
 # bug 1414 - set/get directories' stripe info
 test_65a() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run"
@@ -7839,7 +8320,7 @@ run_test 65m "normal user can't set filesystem default stripe"
 
 test_65n() {
        [ -n "$FILESET" ] && skip "Not functional for FILESET set"
-       [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.12.50) ]] ||
+       [[ $MDS1_VERSION -ge $(version_code 2.12.50) ]] ||
                skip "Need MDS version at least 2.12.50"
        [[ $PARALLEL != "yes" ]] || skip "skip parallel run"
 
@@ -8149,35 +8630,45 @@ test_74c() {
 }
 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
 
-num_inodes() {
-       awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
+slab_lic=/sys/kernel/slab/lustre_inode_cache
+num_objects() {
+       [ -f $slab_lic/shrink ] && echo 1 > $slab_lic/shrink
+       [ -f $slab_lic/objects ] && awk '{ print $1 }' $slab_lic/objects ||
+               awk '/lustre_inode_cache/ { print $2; exit }' /proc/slabinfo
 }
 
-test_76() { # Now for bug 20433, added originally in bug 1443
+test_76() { # Now for b=20433, added originally in b=1443
        [ $PARALLEL == "yes" ] && skip "skip parallel run"
 
-       local CPUS=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
-
        cancel_lru_locks osc
-       BEFORE_INODES=$(num_inodes)
-       echo "before inodes: $BEFORE_INODES"
-       local COUNT=1000
-       [ "$SLOW" = "no" ] && COUNT=100
-       for i in $(seq $COUNT); do
+       # there may be some slab objects cached per core
+       local cpus=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
+       local before=$(num_objects)
+       local count=$((512 * cpus))
+       [ "$SLOW" = "no" ] && count=$((128 * cpus))
+       local margin=$((count / 10))
+       if [[ -f $slab_lic/aliases ]]; then
+               local aliases=$(cat $slab_lic/aliases)
+               (( aliases > 0 )) && margin=$((margin * aliases))
+       fi
+
+       echo "before slab objects: $before"
+       for i in $(seq $count); do
                touch $DIR/$tfile
                rm -f $DIR/$tfile
        done
        cancel_lru_locks osc
-       AFTER_INODES=$(num_inodes)
-       echo "after inodes: $AFTER_INODES"
-       local wait=0
-       while [[ $((AFTER_INODES-1*${CPUS:-1})) -gt $BEFORE_INODES ]]; do
-               sleep 2
-               AFTER_INODES=$(num_inodes)
-               wait=$((wait+2))
-               echo "wait $wait seconds inodes: $AFTER_INODES"
-               if [ $wait -gt 30 ]; then
-                       error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
+       local after=$(num_objects)
+       echo "created: $count, after slab objects: $after"
+       # shared slab counts are not very accurate, allow significant margin
+       # the main goal is that the cache growth is not permanently > $count
+       while (( after > before + margin )); do
+               sleep 1
+               after=$(num_objects)
+               wait=$((wait + 1))
+               (( wait % 5 == 0 )) && echo "wait $wait seconds objects: $after"
+               if (( wait > 60 )); then
+                       error "inode slab grew from $before+$margin to $after"
                fi
        done
 }
@@ -8440,9 +8931,8 @@ test_77k() { # LU-10906
        local i
 
        [ "$ORIG_CSUM" ] || ORIG_CSUM=$(eval $get_checksum)
-       stack_trap "wait_update $HOSTNAME '$get_checksum' $ORIG_CSUM" EXIT
-       stack_trap "do_facet mgs $LCTL set_param -P $cksum_param=$ORIG_CSUM" \
-               EXIT
+       stack_trap "wait_update $HOSTNAME '$get_checksum' $ORIG_CSUM || true"
+       stack_trap "do_facet mgs $LCTL set_param -P $cksum_param=$ORIG_CSUM"
 
        for i in 0 1; do
                do_facet mgs $LCTL set_param -P $cksum_param=$i ||
@@ -8665,28 +9155,6 @@ test_81b() { # LU-456
 }
 run_test 81b "OST should return -ENOSPC when retry still fails ======="
 
-test_82() { # LU-1031
-       dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
-       local gid1=14091995
-       local gid2=16022000
-
-       multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
-       local MULTIPID1=$!
-       multiop_bg_pause $DIR/$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 "Second grouplock blocks first one"
-       fi
-       kill -USR1 $MULTIPID1
-       wait $MULTIPID1
-       wait $MULTIPID2
-}
-run_test 82 "Basic grouplock test"
-
 test_99() {
        [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs"
 
@@ -8932,16 +9400,11 @@ test_101c() {
 }
 run_test 101c "check stripe_size aligned read-ahead ================="
 
-set_read_ahead() {
-       $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
-       $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
-}
-
 test_101d() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run"
 
        local file=$DIR/$tfile
-       local sz_MB=${FILESIZE_101d:-500}
+       local sz_MB=${FILESIZE_101d:-80}
        local ra_MB=${READAHEAD_MB:-40}
 
        local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
@@ -8956,27 +9419,35 @@ test_101d() {
        cancel_lru_locks osc
 
        echo Disable read-ahead
-       local old_READAHEAD=$(set_read_ahead 0)
+       local old_RA=$($LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1)
+       $LCTL set_param -n llite.*.max_read_ahead_mb=0
+       stack_trap "$LCTL set_param -n llite.*.max_read_ahead_mb $old_RA" EXIT
+       $LCTL get_param -n llite.*.max_read_ahead_mb
+
+       echo "Reading the test file $file with read-ahead disabled"
+       local sz_KB=$((sz_MB * 1024 / 4))
+       # 10485760 bytes transferred in 0.000938 secs (11179579337 bytes/sec)
+       # 104857600 bytes (105 MB) copied, 0.00876352 s, 12.0 GB/s
+       local raOFF=$(LANG=C dd if=$file of=/dev/null bs=4k count=$sz_KB |&
+                     sed -e '/records/d' -e 's/.* \([0-9]*\.[0-9]*\) *s.*/\1/')
 
-       echo Reading the test file $file with read-ahead disabled
-       local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
-
-       echo Cancel LRU locks on lustre client to flush the client cache
+       echo "Cancel LRU locks on lustre client to flush the client cache"
        cancel_lru_locks osc
        echo Enable read-ahead with ${ra_MB}MB
-       set_read_ahead $ra_MB
+       $LCTL set_param -n llite.*.max_read_ahead_mb=$ra_MB
 
-       echo Reading the test file $file with read-ahead enabled
-       local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
+       echo "Reading the test file $file with read-ahead enabled"
+       local raON=$(LANG=C dd if=$file of=/dev/null bs=4k count=$sz_KB |&
+                    sed -e '/records/d' -e 's/.* \([0-9]*\.[0-9]*\) *s.*/\1/')
 
        echo "read-ahead disabled time read $raOFF"
-       echo "read-ahead enabled  time read $raON"
+       echo "read-ahead enabled time read $raON"
 
-       set_read_ahead $old_READAHEAD
        rm -f $file
        wait_delete_completed
 
-       [ $raOFF -le 1 ] || [ $raON -lt $raOFF ] ||
+       # use awk for this check instead of bash because it handles decimals
+       awk "{ exit !($raOFF < 1.0 || $raOFF > $raON) }" <<<"ignore_me" ||
                error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
 }
 run_test 101d "file read with and without read-ahead enabled"
@@ -9156,6 +9627,58 @@ test_101h() {
 }
 run_test 101h "Readahead should cover current read window"
 
+test_101i() {
+       dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 ||
+               error "dd 10M file failed"
+
+       local max_per_file_mb=$($LCTL get_param -n \
+               llite.*.max_read_ahead_per_file_mb 2>/dev/null)
+       cancel_lru_locks osc
+       stack_trap "$LCTL set_param llite.*.max_read_ahead_per_file_mb=$max_per_file_mb"
+       $LCTL set_param llite.*.max_read_ahead_per_file_mb=1 ||
+               error "set max_read_ahead_per_file_mb to 1 failed"
+
+       echo "Reset readahead stats"
+       $LCTL set_param llite.*.read_ahead_stats=0
+
+       dd if=$DIR/$tfile of=/dev/null bs=2M
+
+       $LCTL get_param llite.*.read_ahead_stats
+       local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
+                    awk '/misses/ { print $2 }')
+       [ $miss -eq 5 ] || error "expected misses 5 but got $miss"
+       rm -f $DIR/$tfile
+}
+run_test 101i "allow current readahead to exceed reservation"
+
+test_101j() {
+       $LFS setstripe -i 0 -c 1 $DIR/$tfile ||
+               error "setstripe $DIR/$tfile failed"
+       local file_size=$((1048576 * 16))
+       local old_ra=$($LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1)
+       stack_trap "$LCTL set_param -n llite.*.max_read_ahead_mb $old_ra" EXIT
+
+       echo Disable read-ahead
+       $LCTL set_param -n llite.*.max_read_ahead_mb=0
+
+       dd if=/dev/zero of=$DIR/$tfile bs=1M count=$(($file_size / 1048576))
+       for blk in $PAGE_SIZE 1048576 $file_size; do
+               cancel_lru_locks osc
+               echo "Reset readahead stats"
+               $LCTL set_param -n llite.*.read_ahead_stats=0
+               local count=$(($file_size / $blk))
+               dd if=$DIR/$tfile bs=$blk count=$count of=/dev/null
+               local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
+                            get_named_value 'failed to fast read' |
+                            cut -d" " -f1 | calc_total)
+               $LCTL get_param -n llite.*.read_ahead_stats
+               [ $miss -eq $count ] || error "expected $count got $miss"
+       done
+
+       rm -f $p $DIR/$tfile
+}
+run_test 101j "A complete read block should be submitted when no RA"
+
 setup_test102() {
        test_mkdir $DIR/$tdir
        chown $RUNAS_ID $DIR/$tdir
@@ -9249,36 +9772,54 @@ test_102a() {
 }
 run_test 102a "user xattr test =================================="
 
+check_102b_layout() {
+       local layout="$*"
+       local testfile=$DIR/$tfile
+
+       echo "test layout '$layout'"
+       $LFS setstripe $layout $testfile || error "setstripe failed"
+       $LFS getstripe -y $testfile
+
+       echo "get/set/list trusted.lov xattr ..." # b=10930
+       local value=$(getfattr -n trusted.lov -e hex $testfile | grep trusted)
+       [[ "$value" =~ "trusted.lov" ]] ||
+               error "can't get trusted.lov from $testfile"
+       local stripe_count_orig=$($LFS getstripe -c $testfile) ||
+               error "getstripe failed"
+
+       $MCREATE $testfile.2 || error "mcreate $testfile.2 failed"
+
+       value=$(cut -d= -f2 <<<$value)
+       # LU-13168: truncated xattr should fail if short lov_user_md header
+       [ $CLIENT_VERSION -lt $(version_code 2.13.53) ] &&
+               lens="${#value}" || lens="$(seq 4 2 ${#value})"
+       for len in $lens; do
+               echo "setfattr $len $testfile.2"
+               setfattr -n trusted.lov -v ${value:0:$len} $testfile.2 &&
+                       [ $len -lt 66 ] && error "short xattr len=$len worked"
+       done
+       local stripe_size=$($LFS getstripe -S $testfile.2)
+       local stripe_count=$($LFS getstripe -c $testfile.2)
+       [[ $stripe_size -eq 65536 ]] ||
+               error "stripe size $stripe_size != 65536"
+       [[ $stripe_count -eq $stripe_count_orig ]] ||
+               error "stripe count $stripe_count != $stripe_count_orig"
+       rm $testfile $testfile.2
+}
+
 test_102b() {
        [ -z "$(which setfattr 2>/dev/null)" ] &&
                skip_env "could not find setfattr"
        [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
 
-       # b10930: get/set/list trusted.lov xattr
-       echo "get/set/list trusted.lov xattr ..."
-       local testfile=$DIR/$tfile
-       $LFS setstripe -S 65536 -i 1 -c $OSTCOUNT $testfile ||
-               error "setstripe failed"
-       local STRIPECOUNT=$($LFS getstripe -c $testfile) ||
-               error "getstripe failed"
-       getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
-               error "can't get trusted.lov from $testfile"
+       # check plain layout
+       check_102b_layout -S 65536 -i 1 -c $OSTCOUNT
 
-       local testfile2=${testfile}2
-       local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
-                       grep "trusted.lov" | sed -e 's/[^=]\+=//')
+       # and also check composite layout
+       check_102b_layout -E 1M -S 65536 -i 1 -c $OSTCOUNT -Eeof -S4M
 
-       $MCREATE $testfile2
-       setfattr -n trusted.lov -v $value $testfile2
-       local stripe_size=$($LFS getstripe -S $testfile2)
-       local stripe_count=$($LFS getstripe -c $testfile2)
-       [[ $stripe_size -eq 65536 ]] ||
-               error "stripe size $stripe_size != 65536"
-       [[ $stripe_count -eq $STRIPECOUNT ]] ||
-               error "stripe count $stripe_count != $STRIPECOUNT"
-       rm -f $DIR/$tfile
 }
-run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
+run_test 102b "getfattr/setfattr for trusted.lov EAs"
 
 test_102c() {
        [ -z "$(which setfattr 2>/dev/null)" ] &&
@@ -11058,8 +11599,8 @@ test_121() { #bug #10589
 }
 run_test 121 "read cancel race ========="
 
-test_123a() { # was test 123, statahead(bug 11401)
-       [ $PARALLEL == "yes" ] && skip "skip parallel run"
+test_123a_base() { # was test 123, statahead(bug 11401)
+       local lsx="$1"
 
        SLOWOK=0
        if ! grep -q "processor.*: 1" /proc/cpuinfo; then
@@ -11071,76 +11612,120 @@ test_123a() { # was test 123, statahead(bug 11401)
        test_mkdir $DIR/$tdir
        NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
        [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
-        MULT=10
-        for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
-                createmany -o $DIR/$tdir/$tfile $j $((i - j))
-
-                max=`lctl get_param -n llite.*.statahead_max | head -n 1`
-                lctl set_param -n llite.*.statahead_max 0
-                lctl get_param llite.*.statahead_max
-                cancel_lru_locks mdc
-                cancel_lru_locks osc
-                stime=`date +%s`
-                time ls -l $DIR/$tdir | wc -l
-                etime=`date +%s`
-                delta=$((etime - stime))
-                log "ls $i files without statahead: $delta sec"
-                lctl set_param llite.*.statahead_max=$max
-
-                swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
-                lctl get_param -n llite.*.statahead_max | grep '[0-9]'
-                cancel_lru_locks mdc
-                cancel_lru_locks osc
-                stime=`date +%s`
-                time ls -l $DIR/$tdir | wc -l
-                etime=`date +%s`
-                delta_sa=$((etime - stime))
-                log "ls $i files with statahead: $delta_sa sec"
-                lctl get_param -n llite.*.statahead_stats
-                ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
+       MULT=10
+       for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
+               createmany -o $DIR/$tdir/$tfile $j $((i - j))
+
+               max=$(lctl get_param -n llite.*.statahead_max | head -n 1)
+               lctl set_param -n llite.*.statahead_max 0
+               lctl get_param llite.*.statahead_max
+               cancel_lru_locks mdc
+               cancel_lru_locks osc
+               stime=$(date +%s)
+               time $lsx $DIR/$tdir | wc -l
+               etime=$(date +%s)
+               delta=$((etime - stime))
+               log "$lsx $i files without statahead: $delta sec"
+               lctl set_param llite.*.statahead_max=$max
+
+               swrong=$(lctl get_param -n llite.*.statahead_stats |
+                       grep "statahead wrong:" | awk '{print $3}')
+               lctl get_param -n llite.*.statahead_max | grep '[0-9]'
+               cancel_lru_locks mdc
+               cancel_lru_locks osc
+               stime=$(date +%s)
+               time $lsx $DIR/$tdir | wc -l
+               etime=$(date +%s)
+               delta_sa=$((etime - stime))
+               log "$lsx $i files with statahead: $delta_sa sec"
+               lctl get_param -n llite.*.statahead_stats
+               ewrong=$(lctl get_param -n llite.*.statahead_stats |
+                       grep "statahead wrong:" | awk '{print $3}')
 
                [[ $swrong -lt $ewrong ]] &&
                        log "statahead was stopped, maybe too many locks held!"
                [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
 
-                if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
-                    max=`lctl get_param -n llite.*.statahead_max | head -n 1`
-                    lctl set_param -n llite.*.statahead_max 0
-                    lctl get_param llite.*.statahead_max
-                    cancel_lru_locks mdc
-                    cancel_lru_locks osc
-                    stime=`date +%s`
-                    time ls -l $DIR/$tdir | wc -l
-                    etime=`date +%s`
-                    delta=$((etime - stime))
-                    log "ls $i files again without statahead: $delta sec"
-                    lctl set_param llite.*.statahead_max=$max
-                    if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
-                        if [  $SLOWOK -eq 0 ]; then
-                                error "ls $i files is slower with statahead!"
-                        else
-                                log "ls $i files is slower with statahead!"
-                        fi
-                        break
-                    fi
-                fi
+               if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
+                       max=$(lctl get_param -n llite.*.statahead_max |
+                               head -n 1)
+                       lctl set_param -n llite.*.statahead_max 0
+                       lctl get_param llite.*.statahead_max
+                       cancel_lru_locks mdc
+                       cancel_lru_locks osc
+                       stime=$(date +%s)
+                       time $lsx $DIR/$tdir | wc -l
+                       etime=$(date +%s)
+                       delta=$((etime - stime))
+                       log "$lsx $i files again without statahead: $delta sec"
+                       lctl set_param llite.*.statahead_max=$max
+                       if [ $((delta_sa * 100 > delta * 105 && delta_sa > delta + 2)) ]; then
+                               if [  $SLOWOK -eq 0 ]; then
+                                       error "$lsx $i files is slower with statahead!"
+                               else
+                                       log "$lsx $i files is slower with statahead!"
+                               fi
+                               break
+                       fi
+               fi
 
-                [ $delta -gt 20 ] && break
-                [ $delta -gt 8 ] && MULT=$((50 / delta))
-                [ "$SLOW" = "no" -a $delta -gt 5 ] && break
-        done
-        log "ls done"
+               [ $delta -gt 20 ] && break
+               [ $delta -gt 8 ] && MULT=$((50 / delta))
+               [ "$SLOW" = "no" -a $delta -gt 5 ] && break
+       done
+       log "$lsx done"
 
-        stime=`date +%s`
-        rm -r $DIR/$tdir
-        sync
-        etime=`date +%s`
-        delta=$((etime - stime))
-        log "rm -r $DIR/$tdir/: $delta seconds"
-        log "rm done"
-        lctl get_param -n llite.*.statahead_stats
+       stime=$(date +%s)
+       rm -r $DIR/$tdir
+       sync
+       etime=$(date +%s)
+       delta=$((etime - stime))
+       log "rm -r $DIR/$tdir/: $delta seconds"
+       log "rm done"
+       lctl get_param -n llite.*.statahead_stats
+}
+
+test_123aa() {
+       [ $PARALLEL == "yes" ] && skip "skip parallel run"
+
+       test_123a_base "ls -l"
+}
+run_test 123aa "verify statahead work"
+
+test_123ab() {
+       [ $PARALLEL == "yes" ] && skip "skip parallel run"
+
+       statx_supported || skip_env "Test must be statx() syscall supported"
+
+       test_123a_base "$STATX -l"
+}
+run_test 123ab "verify statahead work by using statx"
+
+test_123ac() {
+       [ $PARALLEL == "yes" ] && skip "skip parallel run"
+
+       statx_supported || skip_env "Test must be statx() syscall supported"
+
+       local rpcs_before
+       local rpcs_after
+       local agl_before
+       local agl_after
+
+       cancel_lru_locks $OSC
+       rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+       agl_before=$($LCTL get_param -n llite.*.statahead_stats |
+               awk '/agl.total:/ {print $3}')
+       test_123a_base "$STATX -c \"%n %i %A %h %u %g %W %X %Z\" -D"
+       test_123a_base "$STATX --cached=always -D"
+       agl_after=$($LCTL get_param -n llite.*.statahead_stats |
+               awk '/agl.total:/ {print $3}')
+       [ $agl_before -eq $agl_after ] ||
+               error "Should not trigger AGL thread - $agl_before:$agl_after"
+       rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+       [ $rpcs_after -eq $rpcs_before ] ||
+               error "$STATX should not send glimpse RPCs to $OSC"
 }
-run_test 123a "verify statahead work"
+run_test 123ac "verify statahead work by using statx without glimpse RPCs"
 
 test_123b () { # statahead(bug 15027)
        [ $PARALLEL == "yes" ] && skip "skip parallel run"
@@ -11665,7 +12250,7 @@ set_dir_limits () {
 check_mds_dmesg() {
        local facets=$(get_facets MDS)
        for facet in ${facets//,/ }; do
-               do_facet $facet "dmesg | tail -3 | grep -q $1" && return 0
+               do_facet $facet "dmesg | tail -3 | grep $1" && return 0
        done
        return 1
 }
@@ -11680,55 +12265,49 @@ test_129() {
        remote_mds_nodsh && skip "remote MDS with nodsh"
 
        local ENOSPC=28
-       local EFBIG=27
        local has_warning=false
 
        rm -rf $DIR/$tdir
        mkdir -p $DIR/$tdir
 
        # block size of mds1
-       local maxsize=$(($($LCTL get_param -n mdc.*MDT0000*.blocksize) * 5))
-       set_dir_limits $maxsize $maxsize
+       local maxsize=$(($($LCTL get_param -n mdc.*MDT0000*.blocksize) * 8))
+       set_dir_limits $maxsize $((maxsize * 6 / 8))
+       stack_trap "set_dir_limits 0 0"
+       stack_trap "unlinkmany $DIR/$tdir/file_base_ 2000 || true"
        local dirsize=$(stat -c%s "$DIR/$tdir")
        local nfiles=0
-       while [[ $dirsize -le $maxsize ]]; do
-               $MULTIOP $DIR/$tdir/file_base_$nfiles Oc
+       while (( $dirsize <= $maxsize )); do
+               $MCREATE $DIR/$tdir/file_base_$nfiles
                rc=$?
-               if ! $has_warning; then
-                       check_mds_dmesg '"is approaching"' && has_warning=true
-               fi
                # check two errors:
-               # ENOSPC for new ext4 max_dir_size (kernel commit df981d03ee)
-               # EFBIG for previous versions included in ldiskfs series
-               if [ $rc -eq $EFBIG ] || [ $rc -eq $ENOSPC ]; then
+               # ENOSPC for ext4 max_dir_size, which has been used since
+               # kernel v3.6-rc1-8-gdf981d03ee, lustre v2_4_50_0-79-gaed82035c0
+               if (( rc == ENOSPC )); then
                        set_dir_limits 0 0
-                       echo "return code $rc received as expected"
+                       echo "rc=$rc returned as expected after $nfiles files"
 
                        createmany -o $DIR/$tdir/file_extra_$nfiles. 5 ||
-                               error_exit "create failed w/o dir size limit"
-
-                       check_mds_dmesg '"has reached"' ||
-                               error_exit "reached message should be output"
+                               error "create failed w/o dir size limit"
 
-                       [ $has_warning = "false" ] &&
-                               error_exit "warning message should be output"
+                       # messages may be rate limited if test is run repeatedly
+                       check_mds_dmesg '"is approaching max"' ||
+                               echo "warning message should be output"
+                       check_mds_dmesg '"has reached max"' ||
+                               echo "reached message should be output"
 
                        dirsize=$(stat -c%s "$DIR/$tdir")
 
                        [[ $dirsize -ge $maxsize ]] && return 0
-                       error_exit "current dir size $dirsize, " \
-                                  "previous limit $maxsize"
-               elif [ $rc -ne 0 ]; then
-                       set_dir_limits 0 0
-                       error_exit "return $rc received instead of expected " \
-                                  "$EFBIG or $ENOSPC, files in dir $dirsize"
+                       error "dirsize $dirsize < $maxsize after $nfiles files"
+               elif (( rc != 0 )); then
+                       break
                fi
                nfiles=$((nfiles + 1))
                dirsize=$(stat -c%s "$DIR/$tdir")
        done
 
-       set_dir_limits 0 0
-       error "exceeded dir size limit $maxsize($MDSCOUNT) : $dirsize bytes"
+       error "rc=$rc, size=$dirsize/$maxsize, mdt=$MDSCOUNT, nfiles=$nfiles"
 }
 run_test 129 "test directory size limit ========================"
 
@@ -12455,38 +13034,21 @@ test_133e() {
 }
 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
 
-proc_regexp="/{proc,sys}/{fs,sys,kernel/debug}/{lustre,lnet}/"
-
-# Some versions of find (4.5.11, 4.5.14) included in CentOS 7.3-7.5 do
-# not honor the -ignore_readdir_race option correctly. So we call
-# error_ignore() rather than error() in these cases. See LU-11152.
-error_133() {
-       if (find --version; do_facet mds1 find --version) |
-               grep -q '\b4\.5\.1[1-4]\b'; then
-               error_ignore LU-11152 "$@"
-       else
-               error "$@"
-       fi
-}
-
 test_133f() {
-       # First without trusting modes.
-       local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
-       echo "proc_dirs='$proc_dirs'"
-       [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
-       find $proc_dirs -exec cat '{}' \; &> /dev/null
+       [[ $(lustre_version_code $facet) -ge $(version_code 2.7.65) ]] ||
+               skip "too old lustre for get_param -R ($facet_ver)"
 
-       # Second verifying readability.
+       # verifying readability.
        $LCTL get_param -R '*' &> /dev/null
 
        # Verifing writability with badarea_io.
-       find $proc_dirs \
-               -ignore_readdir_race \
-               -type f \
-               -not -name force_lbug \
-               -not -name changelog_mask \
-               -exec badarea_io '{}' \; ||
-                       error_133 "find $proc_dirs failed"
+       $LCTL list_param -FR '*' | grep '=' | tr -d = |
+               egrep -v 'force_lbug|changelog_mask' | xargs badarea_io ||
+               error "client badarea_io failed"
+
+       # remount the FS in case writes/reads /proc break the FS
+       cleanup || error "failed to unmount"
+       setup || error "failed to setup"
 }
 run_test 133f "Check reads/writes of client lustre proc files with bad area io"
 
@@ -12503,10 +13065,10 @@ test_133g() {
                        log "$facet: too old lustre for get_param -R"
                fi
                if [ $facet_ver -ge $(version_code 2.5.54) ]; then
-                       do_facet $facet "$LCTL list_param -R '*' | grep '=' |
-                               tr -d= | egrep -v 'force_lbug|changelog_mask' |
+                       do_facet $facet "$LCTL list_param -FR '*' | grep '=' |
+                               tr -d = | egrep -v 'force_lbug|changelog_mask' |
                                xargs badarea_io" ||
-                                       error_133 "$facet badarea_io failed"
+                                       error "$facet badarea_io failed"
                else
                        skip_noexit "$facet: too old lustre for get_param -R"
                fi
@@ -12515,7 +13077,6 @@ test_133g() {
        # remount the FS in case writes/reads /proc break the FS
        cleanup || error "failed to unmount"
        setup || error "failed to setup"
-       true
 }
 run_test 133g "Check reads/writes of server lustre proc files with bad area io"
 
@@ -12526,24 +13087,21 @@ test_133h() {
                skip "Need MDS version at least 2.9.54"
 
        local facet
-
        for facet in client mds1 ost1; do
-               local facet_proc_dirs=$(do_facet $facet \
-                                       \\\ls -d $proc_regexp 2> /dev/null)
-               [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
-               echo "${facet}_proc_dirs='$facet_proc_dirs'"
                # Get the list of files that are missing the terminating newline
-               local missing=($(do_facet $facet \
-                       find ${facet_proc_dirs} -type f \|              \
-                               while read F\; do                       \
-                                       awk -v FS='\v' -v RS='\v\v'     \
-                                       "'END { if(NR>0 &&              \
-                                       \\\$NF !~ /.*\\\n\$/)           \
-                                               print FILENAME}'"       \
-                                       '\$F'\;                         \
-                               done 2>/dev/null))
-               [ ${#missing[*]} -eq 0 ] ||
-                       error "files do not end with newline: ${missing[*]}"
+               local plist=$(do_facet $facet
+                       $LCTL list_param -FR '*' | grep '=' | tr -d =)
+               local ent
+               for ent in $plist; do
+                       local missing=$(do_facet $facet $LCTL get_param $ent \|\
+                               awk -v FS='\v' -v RS='\v\v' \
+                               "'END { if(NR>0 && \\\$NF !~ /.*\\\n\$/) \
+                                       print FILENAME}'" 2>/dev/null)
+                       [ -z $missing ] || {
+                               do_facet $facet $LCTL get_param $ent | od -An -tx1
+                               error "file does not end with newline: $facet-$ent"
+                       }
+               done
        done
 }
 run_test 133h "Proc files should end with newlines"
@@ -12662,7 +13220,7 @@ test_136() {
        local fname
 
        mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
-       $SETSTRIPE -c 1 -i 0 $DIR/$tdir || error "failed to set striping"
+       $LFS setstripe -c 1 -i 0 $DIR/$tdir || error "failed to set striping"
        #set only one record at plain llog
 #define OBD_FAIL_CATALOG_FULL_CHECK                0x131a
        do_facet $SINGLEMDS $LCTL set_param fail_loc=0x131a fail_val=1
@@ -12732,7 +13290,7 @@ test_140() { #bug-17379
 }
 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
 
-test_150() {
+test_150a() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run"
 
        local TF="$TMP/$tfile"
@@ -12763,7 +13321,60 @@ test_150() {
        rm -f $TF
        true
 }
-run_test 150 "truncate/append tests"
+run_test 150a "truncate/append tests"
+
+test_150b() {
+       [ "$ost1_FSTYPE" != ldiskfs ] && skip "non-ldiskfs backend"
+       [ $OST1_VERSION -lt $(version_code 2.13.50) ] &&
+               skip "Need OST version at least 2.13.53"
+       touch $DIR/$tfile
+       check_fallocate $DIR/$tfile || error "fallocate failed"
+}
+run_test 150b "Verify fallocate (prealloc) functionality"
+
+test_150c() {
+       local bytes
+       local want
+
+       [ "$ost1_FSTYPE" != ldiskfs ] && skip "non-ldiskfs backend"
+       [ $OST1_VERSION -lt $(version_code 2.13.50) ] &&
+               skip "Need OST version at least 2.13.53"
+
+       $LFS setstripe -c $OSTCOUNT -S1M $DIR/$tdir || error "setstripe failed"
+       fallocate -l ${OSTCOUNT}m $DIR/$tdir || error "fallocate failed"
+       sync; sync_all_data
+       cancel_lru_locks $OSC
+       sleep 5
+       bytes=$(($(stat -c '%b * %B' $DIR/$tdir)))
+       want=$((OSTCOUNT * 1048576))
+
+       # Must allocate all requested space, not more than 5% extra
+       (( $bytes >= $want && $bytes < $want * 105 / 100 )) ||
+               error "bytes $bytes is not $want"
+}
+run_test 150c "Verify fallocate Size and Blocks"
+
+test_150d() {
+       local bytes
+       local want
+
+       [ "$ost1_FSTYPE" != ldiskfs ] && skip "non-ldiskfs backend"
+       [ $OST1_VERSION -lt $(version_code 2.13.50) ] &&
+               skip "Need OST version at least 2.13.53"
+
+       $LFS setstripe -c $OSTCOUNT -S1M $DIR/$tdir || error "setstripe failed"
+       fallocate -o 1G -l ${OSTCOUNT}m $DIR/$tdir || error "fallocate failed"
+       sync; sync_all_data
+       cancel_lru_locks $OSC
+       sleep 5
+       bytes=$(($(stat -c '%b * %B' $DIR/$tdir)))
+       want=$((OSTCOUNT * 1048576))
+
+       # Must allocate all requested space, not more than 5% extra
+       (( $bytes >= $want && $bytes < $want * 105 / 100 )) ||
+               error "bytes $bytes is not $want"
+}
+run_test 150d "Verify fallocate Size and Blocks - Non zero start"
 
 #LU-2902 roc_hit was not able to read all values from lproc
 function roc_hit_init() {
@@ -13050,10 +13661,19 @@ test_154A() {
        [ -z "$fid" ] && error "path2fid unable to get $tf FID"
 
        # check that we get the same pathname back
-       local found=$($LFS fid2path $MOUNT "$fid")
-       [ -z "$found" ] && error "fid2path unable to get '$fid' path"
-       [ "$found" == "$tf" ] ||
-               error "fid2path($fid=path2fid($tf)) = $found != $tf"
+       local rootpath
+       local found
+       for rootpath in "$MOUNT" "$MOUNT///" "$MOUNT/$tfile"; do
+               echo "$rootpath $fid"
+               found=$($LFS fid2path $rootpath "$fid")
+               [ -z "$found" ] && error "fid2path unable to get '$fid' path"
+               [ "$found" == "$tf" ] || error "fid2path $found != $tf"
+       done
+
+       # check wrong root path format
+       rootpath=$MOUNT"_wrong"
+       found=$($LFS fid2path $rootpath "$fid")
+       [ -z "$found" ] || error "should fail ($rootpath != $MOUNT)"
 }
 run_test 154A "lfs path2fid and fid2path basic checks"
 
@@ -13875,7 +14495,9 @@ test_160f() {
        local i
 
        # generate some changelog records to accumulate on each MDT
-       test_mkdir -c $MDSCOUNT $DIR/$tdir || error "test_mkdir $tdir failed"
+       # use fnv1a because created files should be evenly distributed
+       test_mkdir -c $MDSCOUNT -H fnv_1a_64 $DIR/$tdir ||
+               error "test_mkdir $tdir failed"
        log "$(date +%s): creating first files"
        createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
                error "create $DIR/$tdir/$tfile failed"
@@ -14001,7 +14623,9 @@ test_160g() {
        local i
 
        # generate some changelog records to accumulate on each MDT
-       test_mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
+       # use fnv1a because created files should be evenly distributed
+       test_mkdir -c $MDSCOUNT -H fnv_1a_64 $DIR/$tdir ||
+               error "mkdir $tdir failed"
        createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
                error "create $DIR/$tdir/$tfile failed"
 
@@ -14115,7 +14739,9 @@ test_160h() {
        local i
 
        # generate some changelog records to accumulate on each MDT
-       test_mkdir -c $MDSCOUNT $DIR/$tdir || error "test_mkdir $tdir failed"
+       # use fnv1a because created files should be evenly distributed
+       test_mkdir -c $MDSCOUNT -H fnv_1a_64 $DIR/$tdir ||
+               error "test_mkdir $tdir failed"
        createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
                error "create $DIR/$tdir/$tfile failed"
 
@@ -14264,7 +14890,9 @@ test_160i() {
        changelog_register || error "first changelog_register failed"
 
        # generate some changelog records to accumulate on each MDT
-       test_mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
+       # use fnv1a because created files should be evenly distributed
+       test_mkdir -c $MDSCOUNT -H fnv_1a_64 $DIR/$tdir ||
+               error "mkdir $tdir failed"
        createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
                error "create $DIR/$tdir/$tfile failed"
 
@@ -14323,20 +14951,27 @@ test_160j() {
                skip "Need MDS version at least 2.12.56"
 
        mount_client $MOUNT2 || error "mount_client on $MOUNT2 failed"
+       stack_trap "umount $MOUNT2" EXIT
 
        changelog_register || error "first changelog_register failed"
+       stack_trap "changelog_deregister" EXIT
 
        # generate some changelog
-       test_mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
+       # use fnv1a because created files should be evenly distributed
+       test_mkdir -c $MDSCOUNT -H fnv_1a_64 $DIR/$tdir ||
+               error "mkdir $tdir failed"
        createmany -m $DIR/$tdir/${tfile}bis $((MDSCOUNT * 2)) ||
                error "create $DIR/$tdir/${tfile}bis failed"
 
        # open the changelog device
        exec 3>/dev/changelog-$FSNAME-MDT0000
+       stack_trap "exec 3>&-" EXIT
        exec 4</dev/changelog-$FSNAME-MDT0000
+       stack_trap "exec 4<&-" EXIT
 
        # umount the first lustre mount
        umount $MOUNT
+       stack_trap "mount_client $MOUNT" EXIT
 
        # read changelog
        cat <&4 >/dev/null || error "read changelog failed"
@@ -14347,16 +14982,6 @@ test_160j() {
                error "User $cl_user not found in changelog_users"
 
        printf 'clear:'$cl_user':0' >&3
-
-       # close
-       exec 3>&-
-       exec 4<&-
-
-       # cleanup
-       changelog_deregister || error "changelog_deregister failed"
-
-       umount $MOUNT2
-       mount_client $MOUNT || error "mount_client on $MOUNT failed"
 }
 run_test 160j "client can be umounted  while its chanangelog is being used"
 
@@ -14388,6 +15013,71 @@ test_160k() {
 }
 run_test 160k "Verify that changelog records are not lost"
 
+# Verifies that a file passed as a parameter has recently had an operation
+# performed on it that has generated an MTIME changelog which contains the
+# correct parent FID. As files might reside on a different MDT from the
+# parent directory in DNE configurations, the FIDs are translated to paths
+# before being compared, which should be identical
+compare_mtime_changelog() {
+       local file="${1}"
+       local mdtidx
+       local mtime
+       local cl_fid
+       local pdir
+       local dir
+
+       mdtidx=$($LFS getstripe --mdt-index $file)
+       mdtidx=$(printf "%04x" $mdtidx)
+
+       # Obtain the parent FID from the MTIME changelog
+       mtime=$($LFS changelog $FSNAME-MDT$mdtidx | tail -n 1 | grep MTIME)
+       [ -z "$mtime" ] && error "MTIME changelog not recorded"
+
+       cl_fid=$(sed -e 's/.* p=//' -e 's/ .*//' <<<$mtime)
+       [ -z "$cl_fid" ] && error "parent FID not present"
+
+       # Verify that the path for the parent FID is the same as the path for
+       # the test directory
+       pdir=$($LFS fid2path $MOUNT "$cl_fid")
+
+       dir=$(dirname $1)
+
+       [[ "${pdir%/}" == "$dir" ]] ||
+               error "MTIME changelog parent FID is wrong, expected $dir, got $pdir"
+}
+
+test_160l() {
+       [ $PARALLEL == "yes" ] && skip "skip parallel run"
+
+       remote_mds_nodsh && skip "remote MDS with nodsh"
+       [[ $MDS1_VERSION -ge $(version_code 2.13.55) ]] ||
+               skip "Need MDS version at least 2.13.55"
+
+       local cl_user
+
+       changelog_register || error "changelog_register failed"
+       cl_user="${CL_USERS[$SINGLEMDS]%% *}"
+
+       changelog_users $SINGLEMDS | grep -q $cl_user ||
+               error "User '$cl_user' not found in changelog_users"
+
+       # Clear some types so that MTIME changelogs are generated
+       changelog_chmask "-CREAT"
+       changelog_chmask "-CLOSE"
+
+       test_mkdir $DIR/$tdir || error "failed to mkdir $DIR/$tdir"
+
+       # Test CL_MTIME during setattr
+       touch $DIR/$tdir/$tfile
+       compare_mtime_changelog $DIR/$tdir/$tfile
+
+       # Test CL_MTIME during close
+       dd if=/dev/urandom of=$DIR/$tdir/${tfile}_2 bs=1M count=64 ||
+               error "cannot create file $DIR/$tdir/${tfile}_2"
+       compare_mtime_changelog $DIR/$tdir/${tfile}_2
+}
+run_test 160l "Verify that MTIME changelog records contain the parent FID"
+
 test_161a() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run"
 
@@ -14704,16 +15394,243 @@ test_162c() {
                        error "get fid for local directory $DIR/$lpath failed"
                check_path "$DIR/$lpath" $MOUNT $FID --link 0
 
-               rpath="$rpath/$i"
-               test_mkdir $DIR/$rpath
-               FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
-                       error "get fid for remote directory $DIR/$rpath failed"
-               check_path "$DIR/$rpath" $MOUNT $FID --link 0
-       done
+               rpath="$rpath/$i"
+               test_mkdir $DIR/$rpath
+               FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
+                       error "get fid for remote directory $DIR/$rpath failed"
+               check_path "$DIR/$rpath" $MOUNT $FID --link 0
+       done
+
+       return 0
+}
+run_test 162c "fid2path works with paths 100 or more directories deep"
+
+oalr_event_count() {
+       local event="${1}"
+       local trace="${2}"
+
+       awk -v name="${FSNAME}-OST0000" \
+           -v event="${event}" \
+           '$1 == "TRACE" && $2 == event && $3 == name' \
+           "${trace}" |
+       wc -l
+}
+
+oalr_expect_event_count() {
+       local event="${1}"
+       local trace="${2}"
+       local expect="${3}"
+       local count
+
+       count=$(oalr_event_count "${event}" "${trace}")
+       if ((count == expect)); then
+               return 0
+       fi
+
+       error_noexit "${event} event count was '${count}', expected ${expect}"
+       cat "${trace}" >&2
+       exit 1
+}
+
+cleanup_165() {
+       do_facet ost1 killall --quiet -KILL ofd_access_log_reader || true
+       stop ost1
+       start ost1 "$(ostdevname 1)" $OST_MOUNT_OPTS
+}
+
+setup_165() {
+       sync # Flush previous IOs so we can count log entries.
+       do_facet ost1 $LCTL set_param "obdfilter.${FSNAME}-OST0000.access_log_size=4096"
+       stack_trap cleanup_165 EXIT
+}
+
+test_165a() {
+       local trace="/tmp/${tfile}.trace"
+       local rc
+       local count
+
+       do_facet ost1 ofd_access_log_reader --debug=- --trace=- > "${trace}" &
+       setup_165
+       sleep 5
+
+       do_facet ost1 ofd_access_log_reader --list
+       stop ost1
+
+       do_facet ost1 killall -TERM ofd_access_log_reader
+       wait
+       rc=$?
+
+       if ((rc != 0)); then
+               error "ofd_access_log_reader exited with rc = '${rc}'"
+       fi
+
+       # Parse trace file for discovery events:
+       oalr_expect_event_count alr_log_add "${trace}" 1
+       oalr_expect_event_count alr_log_eof "${trace}" 1
+       oalr_expect_event_count alr_log_free "${trace}" 1
+}
+run_test 165a "ofd access log discovery"
+
+test_165b() {
+       local trace="/tmp/${tfile}.trace"
+       local file="${DIR}/${tfile}"
+       local pfid1
+       local pfid2
+       local -a entry
+       local rc
+       local count
+       local size
+       local flags
+
+       setup_165
+
+       lfs setstripe -c 1 -i 0 "${file}"
+       $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_WRONLY:w1048576c || error "cannot create '${file}'"
+       do_facet ost1 ofd_access_log_reader --list
+
+       do_facet ost1 ofd_access_log_reader --debug=- --trace=- > "${trace}" &
+       sleep 5
+       do_facet ost1 killall -TERM ofd_access_log_reader
+       wait
+       rc=$?
+
+       if ((rc != 0)); then
+               error "ofd_access_log_reader exited with rc = '${rc}'"
+       fi
+
+       oalr_expect_event_count alr_log_entry "${trace}" 1
+
+       pfid1=$($LFS path2fid "${file}")
+
+       # 1     2             3   4    5     6   7    8    9     10
+       # TRACE alr_log_entry OST PFID BEGIN END TIME SIZE COUNT FLAGS
+       entry=( - $(awk -v pfid="${pfid}" '$1 == "TRACE" && $2 == "alr_log_entry"' "${trace}" ) )
+
+       echo "entry = '${entry[*]}'" >&2
+
+       pfid2=${entry[4]}
+       if [[ "${pfid1}" != "${pfid2}" ]]; then
+               error "entry '${entry[*]}' has invalid PFID '${pfid2}', expected ${pfid1}"
+       fi
+
+       size=${entry[8]}
+       if ((size != 1048576)); then
+               error "entry '${entry[*]}' has invalid io size '${size}', expected 1048576"
+       fi
+
+       flags=${entry[10]}
+       if [[ "${flags}" != "w" ]]; then
+               error "entry '${entry[*]}' has invalid io flags '${flags}', expected 'w'"
+       fi
+
+       do_facet ost1 ofd_access_log_reader --debug=- --trace=- > "${trace}" &
+       $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_RDONLY:r524288c || error "cannot read '${file}'"
+       sleep 5
+       do_facet ost1 killall -TERM ofd_access_log_reader
+       wait
+       rc=$?
+
+       if ((rc != 0)); then
+               error "ofd_access_log_reader exited with rc = '${rc}'"
+       fi
+
+       oalr_expect_event_count alr_log_entry "${trace}" 1
+
+       entry=( - $(awk -v pfid="${pfid}" '$1 == "TRACE" && $2 == "alr_log_entry"' "${trace}" ) )
+       echo "entry = '${entry[*]}'" >&2
+
+       pfid2=${entry[4]}
+       if [[ "${pfid1}" != "${pfid2}" ]]; then
+               error "entry '${entry[*]}' has invalid PFID '${pfid2}', expected ${pfid1}"
+       fi
+
+       size=${entry[8]}
+       if ((size != 524288)); then
+               error "entry '${entry[*]}' has invalid io size '${size}', 524288"
+       fi
+
+       flags=${entry[10]}
+       if [[ "${flags}" != "r" ]]; then
+               error "entry '${entry[*]}' has invalid io flags '${flags}', expected 'r'"
+       fi
+}
+run_test 165b "ofd access log entries are produced and consumed"
+
+test_165c() {
+       local file="${DIR}/${tdir}/${tfile}"
+       test_mkdir "${DIR}/${tdir}"
+
+       setup_165
+
+       lfs setstripe -c 1 -i 0 "${DIR}/${tdir}"
+
+       # 4096 / 64 = 64. Create twice as many entries.
+       for ((i = 0; i < 128; i++)); do
+               $MULTIOP "${file}-${i}" oO_CREAT:O_WRONLY:w512c || error "cannot create file"
+       done
+
+       sync
+       do_facet ost1 ofd_access_log_reader --list
+       unlinkmany  "${file}-%d" 128
+}
+run_test 165c "full ofd access logs do not block IOs"
+
+oal_peek_entry_count() {
+       do_facet ost1 ofd_access_log_reader --list | awk '$1 == "_entry_count:" { print $2; }'
+}
+
+oal_expect_entry_count() {
+       local entry_count=$(oal_peek_entry_count)
+       local expect="$1"
+
+       if ((entry_count == expect)); then
+               return 0
+       fi
+
+       error_noexit "bad entry count, got ${entry_count}, expected ${expect}"
+       do_facet ost1 ofd_access_log_reader --list >&2
+       exit 1
+}
+
+test_165d() {
+       local trace="/tmp/${tfile}.trace"
+       local file="${DIR}/${tdir}/${tfile}"
+       local param="obdfilter.${FSNAME}-OST0000.access_log_mask"
+       local entry_count
+       test_mkdir "${DIR}/${tdir}"
+
+       setup_165
+       lfs setstripe -c 1 -i 0 "${file}"
+
+       do_facet ost1 lctl set_param "${param}=rw"
+       $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_WRONLY:w1048576c || error "cannot create '${file}'"
+       oal_expect_entry_count 1
+
+       $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_RDONLY:r1048576c || error "cannot read '${file}'"
+       oal_expect_entry_count 2
 
-       return 0
+       do_facet ost1 lctl set_param "${param}=r"
+       $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_WRONLY:w1048576c || error "cannot create '${file}'"
+       oal_expect_entry_count 2
+
+       $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_RDONLY:r1048576c || error "cannot read '${file}'"
+       oal_expect_entry_count 3
+
+       do_facet ost1 lctl set_param "${param}=w"
+       $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_WRONLY:w1048576c || error "cannot create '${file}'"
+       oal_expect_entry_count 4
+
+       $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_RDONLY:r1048576c || error "cannot read '${file}'"
+       oal_expect_entry_count 4
+
+       do_facet ost1 lctl set_param "${param}=0"
+       $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_WRONLY:w1048576c || error "cannot create '${file}'"
+       oal_expect_entry_count 4
+
+       $MULTIOP "${file}" oO_CREAT:O_DIRECT:O_RDONLY:r1048576c || error "cannot read '${file}'"
+       oal_expect_entry_count 4
 }
-run_test 162c "fid2path works with paths 100 or more directories deep"
+run_test 165d "ofd_access_log mask works"
 
 test_169() {
        # do directio so as not to populate the page cache
@@ -14870,7 +15787,8 @@ obdecho_test() {
 test_180a() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run"
 
-       if ! module_loaded obdecho; then
+       if ! [ -d /sys/fs/lustre/echo_client ] &&
+          ! module_loaded obdecho; then
                load_module obdecho/obdecho &&
                        stack_trap "rmmod obdecho" EXIT ||
                        error "unable to load obdecho on client"
@@ -15081,6 +15999,7 @@ test_184c() {
        local cmpn_arg=$(cmp -n 2>&1 | grep "invalid option")
        [ -n "$cmpn_arg" ] && skip_env "cmp does not support -n"
        check_swap_layouts_support
+       check_swap_layout_no_dom $DIR
 
        local dir0=$DIR/$tdir/$testnum
        mkdir -p $dir0 || error "creating dir $dir0"
@@ -15128,6 +16047,7 @@ run_test 184c "Concurrent write and layout swap"
 
 test_184d() {
        check_swap_layouts_support
+       check_swap_layout_no_dom $DIR
        [ -z "$(which getfattr 2>/dev/null)" ] &&
                skip_env "no getfattr command"
 
@@ -15164,6 +16084,7 @@ test_184e() {
        [[ $MDS1_VERSION -ge $(version_code 2.6.94) ]] ||
                skip "Need MDS version at least 2.6.94"
        check_swap_layouts_support
+       check_swap_layout_no_dom $DIR
        [ -z "$(which getfattr 2>/dev/null)" ] &&
                skip_env "no getfattr command"
 
@@ -15654,16 +16575,31 @@ test_205a() { # Job stats
 }
 run_test 205a "Verify job stats"
 
-# LU-13117
+# LU-13117, LU-13597
 test_205b() {
+       job_stats="mdt.*.job_stats"
+       $LCTL set_param $job_stats=clear
        $LCTL set_param jobid_var=USER jobid_name="%e.%u"
        env -i USERTESTJOBSTATS=foolish touch $DIR/$tfile.1
-       do_facet $SINGLEMDS $LCTL get_param mdt.*.job_stats |
-               grep job_id: | grep foolish &&
+       do_facet $SINGLEMDS $LCTL get_param $job_stats |
+               grep "job_id:.*foolish" &&
                        error "Unexpected jobid found"
-       true
+       do_facet $SINGLEMDS $LCTL get_param $job_stats |
+               grep "open:.*min.*max.*sum" ||
+                       error "wrong job_stats format found"
+}
+run_test 205b "Verify job stats jobid and output format"
+
+# LU-13733
+test_205c() {
+       $LCTL set_param llite.*.stats=0
+       dd if=/dev/zero of=$DIR/$tfile.1 bs=4k count=1
+       $LCTL get_param llite.*.stats
+       $LCTL get_param llite.*.stats | grep \
+               "write_bytes *1 samples \[bytes\] 4096 4096 4096 16777216" ||
+                       error "wrong client stats format found"
 }
-run_test 205b "Verify job stats jobid parsing"
+run_test 205c "Verify client stats format"
 
 # LU-1480, LU-1773 and LU-1657
 test_206() {
@@ -15771,6 +16707,8 @@ test_209() {
        sync; sleep 5; sync;
 
        echo 3 > /proc/sys/vm/drop_caches
+       [ -f /sys/kernel/slab/ptlrpc_cache/shrink ] &&
+               echo 1 > /sys/kernel/slab/ptlrpc_cache/shrink
        req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
 
        # open/close 500 times
@@ -15779,6 +16717,8 @@ test_209() {
        done
 
        echo 3 > /proc/sys/vm/drop_caches
+       [ -f /sys/kernel/slab/ptlrpc_cache/shrink ] &&
+               echo 1 > /sys/kernel/slab/ptlrpc_cache/shrink
        req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
 
        echo "before: $req_before, after: $req_after"
@@ -15788,6 +16728,27 @@ test_209() {
 }
 run_test 209 "read-only open/close requests should be freed promptly"
 
+test_210() {
+       local pid
+
+       $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eW_E+eUc &
+       pid=$!
+       sleep 1
+
+       $LFS getstripe $DIR/$tfile
+       kill -USR1 $pid
+       wait $pid || error "multiop failed"
+
+       $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
+       pid=$!
+       sleep 1
+
+       $LFS getstripe $DIR/$tfile
+       kill -USR1 $pid
+       wait $pid || error "multiop failed"
+}
+run_test 210 "lfs getstripe does not break leases"
+
 test_212() {
        size=`date +%s`
        size=$((size % 8192 + 1))
@@ -16200,8 +17161,7 @@ test_224c() { # LU-6441
        save_writethrough $p
        set_cache writethrough on
 
-       local pages_per_rpc=$($LCTL get_param \
-                               osc.*.max_pages_per_rpc)
+       local pages_per_rpc=$($LCTL get_param osc.*.max_pages_per_rpc)
        local at_max=$($LCTL get_param -n at_max)
        local timeout=$($LCTL get_param -n timeout)
        local test_at="at_max"
@@ -16352,6 +17312,34 @@ test_226b () {
 }
 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
 
+test_226c () {
+       [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
+       [[ $MDS1_VERSION -ge $(version_code 2.13.55) ]] ||
+               skip "Need MDS version at least 2.13.55"
+
+       local submnt=/mnt/submnt
+       local srcfile=/etc/passwd
+       local dstfile=$submnt/passwd
+       local path
+       local fid
+
+       rm -rf $DIR/$tdir
+       rm -rf $submnt
+       $LFS setdirstripe -c -1 -i 1 $DIR/$tdir ||
+               error "create remote directory failed"
+       mkdir -p $submnt || error "create $submnt failed"
+       $MOUNT_CMD $MGSNID:/$FSNAME/$tdir $submnt ||
+               error "mount $submnt failed"
+       stack_trap "umount $submnt" EXIT
+
+       cp $srcfile $dstfile
+       fid=$($LFS path2fid $dstfile)
+       path=$($LFS fid2path $submnt "$fid")
+       [ "$path" = "$dstfile" ] ||
+               error "fid2path $submnt $fid failed ($path != $dstfile)"
+}
+run_test 226c "call path2fid and fid2path under remote dir with subdir mount"
+
 # LU-1299 Executing or running ldd on a truncated executable does not
 # cause an out-of-memory condition.
 test_227() {
@@ -16610,6 +17598,27 @@ test_230b() {
        ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
        ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
 
+       local len
+       local lnktgt
+
+       # inline symlink
+       for len in 58 59 60; do
+               lnktgt=$(str_repeat 'l' $len)
+               touch $migrate_dir/$lnktgt
+               ln -s $lnktgt $migrate_dir/${len}char_ln
+       done
+
+       # PATH_MAX
+       for len in 4094 4095; do
+               lnktgt=$(str_repeat 'l' $len)
+               ln -s $lnktgt $migrate_dir/${len}char_ln
+       done
+
+       # NAME_MAX
+       for len in 254 255; do
+               touch $migrate_dir/$(str_repeat 'l' $len)
+       done
+
        $LFS migrate -m $MDTIDX $migrate_dir ||
                error "fails on migrating remote dir to MDT1"
 
@@ -16617,7 +17626,8 @@ test_230b() {
        for ((i = 0; i < 10; i++)); do
                for file in $(find $migrate_dir/dir_${i}); do
                        mdt_index=$($LFS getstripe -m $file)
-                       [ $mdt_index == $MDTIDX ] ||
+                       # broken symlink getstripe will fail
+                       [ $mdt_index -ne $MDTIDX ] && stat -L $file &&
                                error "$file is not on MDT${MDTIDX}"
                done
        done
@@ -16681,7 +17691,7 @@ test_230b() {
        echo "migrate back to MDT0, checking.."
        for file in $(find $migrate_dir); do
                mdt_index=$($LFS getstripe -m $file)
-               [ $mdt_index == $MDTIDX ] ||
+               [ $mdt_index -ne $MDTIDX ] && stat -L $file &&
                        error "$file is not on MDT${MDTIDX}"
        done
 
@@ -16835,7 +17845,7 @@ test_230d() {
        old_count=$((MDSCOUNT - old_index))
        new_index=$((RANDOM % MDSCOUNT))
        new_count=$((MDSCOUNT - new_index))
-       new_hash="all_char"
+       new_hash=1 # for all_char
 
        [ $old_count -gt 1 ] && old_count=$((old_count - RANDOM % old_count))
        [ $new_count -gt 1 ] && new_count=$((new_count - RANDOM % new_count))
@@ -17027,7 +18037,7 @@ run_test 230i "lfs migrate -m tolerates trailing slashes"
 
 test_230j() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
-       [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
+       [ $MDS1_VERSION -lt $(version_code 2.13.52) ] &&
                skip "Need MDS version at least 2.11.52"
 
        $LFS mkdir -m 0 -c 1 $DIR/$tdir || error "mkdir $tdir failed"
@@ -17035,7 +18045,7 @@ test_230j() {
                error "create $tfile failed"
        cat /etc/passwd > $DIR/$tdir/$tfile
 
-       $LFS migrate -m 1 $DIR/$tdir
+       $LFS migrate -m 1 $DIR/$tdir || error "migrate failed"
 
        cmp /etc/passwd $DIR/$tdir/$tfile ||
                error "DoM file mismatch after migration"
@@ -17159,6 +18169,212 @@ test_230m() {
 }
 run_test 230m "xattrs not changed after dir migration"
 
+test_230n() {
+       [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
+       [[ $MDS1_VERSION -ge $(version_code 2.13.53) ]] ||
+               skip "Need MDS version at least 2.13.53"
+
+       $LFS mkdir -i 0 $DIR/$tdir || error "mkdir $tdir failed"
+       cat /etc/hosts > $DIR/$tdir/$tfile
+       $LFS mirror extend -N1 $DIR/$tdir/$tfile || error "Mirroring failed"
+       $LFS migrate -m 1 $DIR/$tdir || error "Migration failed"
+
+       cmp /etc/hosts $DIR/$tdir/$tfile ||
+               error "File data mismatch after migration"
+}
+run_test 230n "Dir migration with mirrored file"
+
+test_230o() {
+       [ $MDSCOUNT -ge 2 ] || skip "needs >= 2 MDTs"
+       [ $MDS1_VERSION -ge $(version_code 2.13.52) ] ||
+               skip "Need MDS version at least 2.13.52"
+
+       local mdts=$(comma_list $(mdts_nodes))
+       local timeout=100
+
+       local restripe_status
+       local delta
+       local i
+       local j
+
+       [[ $(facet_fstype mds1) == zfs ]] && timeout=300
+
+       # in case "crush" hash type is not set
+       do_nodes $mdts "$LCTL set_param lod.*.mdt_hash=crush"
+
+       restripe_status=$(do_facet mds1 $LCTL get_param -n \
+                          mdt.*MDT0000.enable_dir_restripe)
+       do_nodes $mdts "$LCTL set_param mdt.*.enable_dir_restripe=1"
+       stack_trap "do_nodes $mdts $LCTL set_param \
+                   mdt.*.enable_dir_restripe=$restripe_status"
+
+       mkdir $DIR/$tdir
+       createmany -m $DIR/$tdir/f 100 ||
+               error "create files under remote dir failed $i"
+       createmany -d $DIR/$tdir/d 100 ||
+               error "create dirs under remote dir failed $i"
+
+       for i in $(seq 2 $MDSCOUNT); do
+               do_nodes $mdts "$LCTL set_param mdt.*.md_stats=clear > /dev/null"
+               $LFS setdirstripe -c $i $DIR/$tdir ||
+                       error "split -c $i $tdir failed"
+               wait_update $HOSTNAME \
+                       "$LFS getdirstripe -H $DIR/$tdir" "crush" $timeout ||
+                       error "dir split not finished"
+               delta=$(do_nodes $mdts "lctl get_param -n mdt.*MDT*.md_stats" |
+                       awk '/migrate/ {sum += $2} END { print sum }')
+               echo "$delta files migrated when dir split from $((i - 1)) to $i stripes"
+               # delta is around total_files/stripe_count
+               [ $delta -lt $((200 /(i - 1))) ] ||
+                       error "$delta files migrated"
+       done
+}
+run_test 230o "dir split"
+
+test_230p() {
+       [ $MDSCOUNT -ge 2 ] || skip "needs >= 2 MDTs"
+       [ $MDS1_VERSION -ge $(version_code 2.13.52) ] ||
+               skip "Need MDS version at least 2.13.52"
+
+       local mdts=$(comma_list $(mdts_nodes))
+       local timeout=100
+
+       local restripe_status
+       local delta
+       local i
+       local j
+
+       [[ $(facet_fstype mds1) == zfs ]] && timeout=300
+
+       do_nodes $mdts "$LCTL set_param lod.*.mdt_hash=crush"
+
+       restripe_status=$(do_facet mds1 $LCTL get_param -n \
+                          mdt.*MDT0000.enable_dir_restripe)
+       do_nodes $mdts "$LCTL set_param mdt.*.enable_dir_restripe=1"
+       stack_trap "do_nodes $mdts $LCTL set_param \
+                   mdt.*.enable_dir_restripe=$restripe_status"
+
+       test_mkdir -c $MDSCOUNT -H crush $DIR/$tdir
+       createmany -m $DIR/$tdir/f 100 ||
+               error "create files under remote dir failed $i"
+       createmany -d $DIR/$tdir/d 100 ||
+               error "create dirs under remote dir failed $i"
+
+       for i in $(seq $((MDSCOUNT - 1)) -1 1); do
+               local mdt_hash="crush"
+
+               do_nodes $mdts "$LCTL set_param mdt.*.md_stats=clear > /dev/null"
+               $LFS setdirstripe -c $i $DIR/$tdir ||
+                       error "split -c $i $tdir failed"
+               [ $i -eq 1 ] && mdt_hash="none"
+               wait_update $HOSTNAME \
+                       "$LFS getdirstripe -H $DIR/$tdir" $mdt_hash $timeout ||
+                       error "dir merge not finished"
+               delta=$(do_nodes $mdts "lctl get_param -n mdt.*MDT*.md_stats" |
+                       awk '/migrate/ {sum += $2} END { print sum }')
+               echo "$delta files migrated when dir merge from $((i + 1)) to $i stripes"
+               # delta is around total_files/stripe_count
+               [ $delta -lt $((200 / i)) ] ||
+                       error "$delta files migrated"
+       done
+}
+run_test 230p "dir merge"
+
+test_230q() {
+       [ $MDSCOUNT -ge 2 ] || skip "needs >= 2 MDTs"
+       [ $MDS1_VERSION -ge $(version_code 2.13.52) ] ||
+               skip "Need MDS version at least 2.13.52"
+
+       local mdts=$(comma_list $(mdts_nodes))
+       local saved_threshold=$(do_facet mds1 \
+                       $LCTL get_param -n mdt.*-MDT0000.dir_split_count)
+       local saved_delta=$(do_facet mds1 \
+                       $LCTL get_param -n mdt.*-MDT0000.dir_split_delta)
+       local threshold=100
+       local delta=2
+       local total=0
+       local stripe_count=0
+       local stripe_index
+       local nr_files
+
+       stack_trap "do_nodes $mdts $LCTL set_param \
+                   mdt.*.dir_split_count=$saved_threshold"
+       stack_trap "do_nodes $mdts $LCTL set_param \
+                   mdt.*.dir_split_delta=$saved_delta"
+       stack_trap "do_nodes $mdts $LCTL set_param mdt.*.dir_restripe_nsonly=1"
+       do_nodes $mdts "$LCTL set_param mdt.*.enable_dir_auto_split=1"
+       do_nodes $mdts "$LCTL set_param mdt.*.dir_split_count=$threshold"
+       do_nodes $mdts "$LCTL set_param mdt.*.dir_split_delta=$delta"
+       do_nodes $mdts "$LCTL set_param mdt.*.dir_restripe_nsonly=0"
+       do_nodes $mdts "$LCTL set_param lod.*.mdt_hash=crush"
+
+       $LFS mkdir -i -1 -c 1 $DIR/$tdir || error "mkdir $tdir failed"
+       stripe_index=$($LFS getdirstripe -i $DIR/$tdir)
+
+       while [ $stripe_count -lt $MDSCOUNT ]; do
+               createmany -m $DIR/$tdir/f $total $((threshold * 3 / 2)) ||
+                       error "create sub files failed"
+               stat $DIR/$tdir > /dev/null
+               total=$((total + threshold * 3 / 2))
+               stripe_count=$((stripe_count + delta))
+               [ $stripe_count -gt $MDSCOUNT ] && stripe_count=$MDSCOUNT
+
+               wait_update $HOSTNAME \
+                       "$LFS getdirstripe -c $DIR/$tdir" "$stripe_count" 40 ||
+                       error "stripe count $($LFS getdirstripe -c $DIR/$tdir) != $stripe_count"
+
+               wait_update $HOSTNAME \
+                       "$LFS getdirstripe -H $DIR/$tdir" "crush" 200 ||
+                       error "stripe hash $($LFS getdirstripe -H $DIR/$tdir) != crush"
+
+               nr_files=$($LFS getstripe -m $DIR/$tdir/* |
+                          grep -w $stripe_index | wc -l)
+               echo "$nr_files files on MDT$stripe_index after split"
+               [ $nr_files -lt $((total / (stripe_count - 1))) ] ||
+                       error "$nr_files files on MDT$stripe_index after split"
+
+               nr_files=$(ls $DIR/$tdir | wc -w)
+               [ $nr_files -eq $total ] ||
+                       error "total sub files $nr_files != $total"
+       done
+}
+run_test 230q "dir auto split"
+
+test_230r() {
+       [[ $PARALLEL != "yes" ]] || skip "skip parallel run"
+       [[ $MDSCOUNT -ge 2 ]] || skip_env "needs >= 2 MDTs"
+       [[ $MDS1_VERSION -ge $(version_code 2.13.54) ]] ||
+               skip "Need MDS version at least 2.13.54"
+
+       # maximum amount of local locks:
+       # parent striped dir - 2 locks
+       # new stripe in parent to migrate to - 1 lock
+       # source and target - 2 locks
+       # Total 5 locks for regular file
+       mkdir -p $DIR/$tdir
+       $LFS mkdir -i1 -c2 $DIR/$tdir/dir1
+       touch $DIR/$tdir/dir1/eee
+
+       # create 4 hardlink for 4 more locks
+       # Total: 9 locks > RS_MAX_LOCKS (8)
+       $LFS mkdir -i1 -c1 $DIR/$tdir/dir2
+       $LFS mkdir -i1 -c1 $DIR/$tdir/dir3
+       $LFS mkdir -i1 -c1 $DIR/$tdir/dir4
+       $LFS mkdir -i1 -c1 $DIR/$tdir/dir5
+       ln $DIR/$tdir/dir1/eee $DIR/$tdir/dir2/eee
+       ln $DIR/$tdir/dir1/eee $DIR/$tdir/dir3/eee
+       ln $DIR/$tdir/dir1/eee $DIR/$tdir/dir4/eee
+       ln $DIR/$tdir/dir1/eee $DIR/$tdir/dir5/eee
+
+       cancel_lru_locks mdc
+
+       $LFS migrate -m1 -c1 $DIR/$tdir/dir1 ||
+               error "migrate dir fails"
+
+       rm -rf $DIR/$tdir || error "rm dir failed after migration"
+}
+run_test 230r "migrate with too many local locks"
+
 test_231a()
 {
        # For simplicity this test assumes that max_pages_per_rpc
@@ -17620,7 +18836,7 @@ test_247c() {
        $LFS fid2path $submount $fid && error "fid2path should fail"
        cleanup_247 $submount
 }
-run_test 247c "running fid2path outside root"
+run_test 247c "running fid2path outside subdirectory root"
 
 test_247d() {
        lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
@@ -17633,11 +18849,28 @@ test_247d() {
        FILESET="$FILESET/$tdir" mount_client $submount ||
                error "mount $submount failed"
        trap "cleanup_247 $submount" EXIT
-       local fid=$($LFS path2fid $submount/dir1)
-       $LFS fid2path $submount $fid || error "fid2path should succeed"
+
+       local td=$submount/dir1
+       local fid=$($LFS path2fid $td)
+       [ -z "$fid" ] && error "path2fid unable to get $td FID"
+
+       # check that we get the same pathname back
+       local rootpath
+       local found
+       for rootpath in "$submount" "$submount///" "$submount/dir1"; do
+               echo "$rootpath $fid"
+               found=$($LFS fid2path $rootpath "$fid")
+               [ -n "found" ] || error "fid2path should succeed"
+               [ "$found" == "$td" ] || error "fid2path $found != $td"
+       done
+       # check wrong root path format
+       rootpath=$submount"_wrong"
+       found=$($LFS fid2path $rootpath "$fid")
+       [ -z "$found" ] || error "fid2path should fail ($rootpath != $submount)"
+
        cleanup_247 $submount
 }
-run_test 247d "running fid2path inside root"
+run_test 247d "running fid2path inside subdirectory root"
 
 # LU-8037
 test_247e() {
@@ -17655,6 +18888,38 @@ test_247e() {
 }
 run_test 247e "mount .. as fileset"
 
+test_247f() {
+       [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
+       [ $MDS1_VERSION -lt $(version_code 2.13.52) ] &&
+               skip "Need at least version 2.13.52"
+       lctl get_param -n mdc.$FSNAME-MDT0000*.import |
+               grep -q subtree ||
+               skip "Fileset feature is not supported"
+
+       mkdir $DIR/$tdir || error "mkdir $tdir failed"
+       $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/$tdir/remote ||
+               error "mkdir remote failed"
+       mkdir $DIR/$tdir/remote/subdir || error "mkdir remote/subdir failed"
+       $LFS mkdir -c $MDSCOUNT $DIR/$tdir/striped ||
+               error "mkdir striped failed"
+       mkdir $DIR/$tdir/striped/subdir || error "mkdir striped/subdir failed"
+
+       local submount=${MOUNT}_$tdir
+
+       mkdir -p $submount || error "mkdir $submount failed"
+
+       local dir
+       local fileset=$FILESET
+
+       for dir in $tdir/remote $tdir/remote/subdir \
+                  $tdir/striped $tdir/striped/subdir $tdir/striped/. ; do
+               FILESET="$fileset/$dir" mount_client $submount ||
+                       error "mount $dir failed"
+               umount_client $submount
+       done
+}
+run_test 247f "mount striped or remote directory as fileset"
+
 test_248a() {
        local fast_read_sav=$($LCTL get_param -n llite.*.fast_read 2>/dev/null)
        [ -z "$fast_read_sav" ] && skip "no fast read support"
@@ -18809,6 +20074,101 @@ test_270f() {
 }
 run_test 270f "DoM: maximum DoM stripe size checks"
 
+test_270g() {
+       [ $MDS1_VERSION -ge $(version_code 2.13.52) ] ||
+               skip "Need MDS version at least 2.13.52"
+       local dom=$DIR/$tdir/$tfile
+
+       $LFS mkdir -i 0 -c 1 $DIR/$tdir
+       local lodname=${FSNAME}-MDT0000-mdtlov
+
+       local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
+       save_lustre_params mds1 "lod.${lodname}.dom_stripesize_max_kb" > $save
+       save_lustre_params mds1 "lod.${lodname}.dom_threshold_free_mb" >> $save
+       stack_trap "restore_lustre_params < $save; rm -f $save" EXIT
+
+       local dom_limit=1024
+       local dom_threshold="50%"
+
+       $LFS setstripe -d $DIR/$tdir
+       $LFS setstripe -E ${dom_limit}K -L mdt $DIR/$tdir ||
+               error "Can't set directory default striping"
+
+       do_facet mds1 $LCTL set_param -n \
+                               lod.${lodname}.dom_stripesize_max_kb=$dom_limit
+       # set 0 threshold and create DOM file to change tunable stripesize
+       do_facet mds1 $LCTL set_param -n lod.${lodname}.dom_threshold_free_mb=0
+       $LFS setstripe -E ${dom_limit}K -L mdt -E -1 $dom ||
+               error "Failed to create $dom file"
+       # now tunable dom_cur_stripesize should reach maximum
+       local dom_current=$(do_facet mds1 $LCTL get_param -n \
+                                       lod.${lodname}.dom_stripesize_cur_kb)
+       [[ $dom_current == $dom_limit ]] ||
+               error "Current DOM stripesize is not maximum"
+       rm $dom
+
+       # set threshold for further tests
+       do_facet mds1 $LCTL set_param -n \
+                       lod.${lodname}.dom_threshold_free_mb=$dom_threshold
+       echo "DOM threshold is $dom_threshold free space"
+       local dom_def
+       local dom_set
+       # Spoof bfree to exceed threshold
+       #define OBD_FAIL_MDS_STATFS_SPOOF   0x168
+       do_facet mds1 $LCTL set_param -n fail_loc=0x0168
+       for spfree in 40 20 0 15 30 55; do
+               do_facet mds1 $LCTL set_param -n fail_val=$spfree
+               $LFS setstripe -E ${dom_limit}K -L mdt -E -1 $dom ||
+                       error "Failed to create $dom file"
+               dom_def=$(do_facet mds1 $LCTL get_param -n \
+                                       lod.${lodname}.dom_stripesize_cur_kb)
+               echo "Free space: ${spfree}%, default DOM stripe: ${dom_def}K"
+               [[ $dom_def != $dom_current ]] ||
+                       error "Default stripe size was not changed"
+               if [[ $spfree > 0 ]] ; then
+                       dom_set=$($LFS getstripe -S $dom)
+                       [[ $dom_set == $((dom_def * 1024)) ]] ||
+                               error "DOM component size is still old"
+               else
+                       [[ $($LFS getstripe -L $dom) != "mdt" ]] ||
+                               error "DoM component is set with no free space"
+               fi
+               rm $dom
+               dom_current=$dom_def
+       done
+}
+run_test 270g "DoM: default DoM stripe size depends on free space"
+
+test_270h() {
+       [[ $MDS1_VERSION -ge $(version_code 2.13.53) ]] ||
+               skip "Need MDS version at least 2.13.53"
+
+       local mdtname=${FSNAME}-MDT0000-mdtlov
+       local dom=$DIR/$tdir/$tfile
+       local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
+
+       save_lustre_params mds1 "lod.*.dom_stripesize" > $save
+       stack_trap "restore_lustre_params < $save; rm -f $save" EXIT
+
+       $LFS mkdir -i 0 -c 1 $DIR/$tdir
+       $LFS setstripe -E 1M -c1  -E -1 -c2 ${dom}_1 ||
+               error "can't create OST file"
+       # mirrored file with DOM entry in the second mirror
+       $LFS mirror extend -N -E 1M -L mdt -E eof -c2 ${dom}_1 ||
+               error "can't create mirror with DoM component"
+
+       do_facet mds1 $LCTL set_param -n lod.$mdtname.dom_stripesize=0
+
+       # DOM component in the middle and has other enries in the same mirror,
+       # should succeed but lost DoM component
+       $LFS setstripe --copy=${dom}_1 $dom ||
+               error "Can't create file from OST|DOM mirror layout"
+       # check new file has no DoM layout after all
+       [[ $($LFS getstripe -L $dom) != "mdt" ]] ||
+               error "File has DoM component while DoM is disabled"
+}
+run_test 270h "DoM: DoM stripe removal when disabled on server"
+
 test_271a() {
        [ $MDS1_VERSION -lt $(version_code 2.10.55) ] &&
                skip "Need MDS version at least 2.10.55"
@@ -19394,6 +20754,25 @@ test_278() {
 }
 run_test 278 "Race starting MDS between MDTs stop/start"
 
+test_280() {
+       [ $MGS_VERSION -lt $(version_code 2.13.52) ] &&
+               skip "Need MGS version at least 2.13.52"
+       [ $PARALLEL == "yes" ] && skip "skip parallel run"
+       combined_mgs_mds || skip "needs combined MGS/MDT"
+
+       umount_client $MOUNT
+#define OBD_FAIL_MDS_LLOG_UMOUNT_RACE   0x15e
+       do_facet mgs $LCTL set_param fail_loc=0x8000015e fail_val=0
+
+       mount_client $MOUNT &
+       sleep 1
+       stop mgs || error "stop mgs failed"
+       #for a race mgs would crash
+       start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
+       mount_client $MOUNT || error "mount client failed"
+}
+run_test 280 "Race between MGS umount and client llog processing"
+
 cleanup_test_300() {
        trap 0
        umask $SAVE_UMASK
@@ -19547,12 +20926,22 @@ test_300d() {
        #local striped directory
        $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
                error "set striped dir error"
+        #look at the directories for debug purposes
+       ls -l $DIR/$tdir
+       $LFS getdirstripe $DIR/$tdir
+       ls -l $DIR/$tdir/striped_dir
+       $LFS getdirstripe $DIR/$tdir/striped_dir
        createmany -o $DIR/$tdir/striped_dir/f 10 ||
                error "create 10 files failed"
 
        #remote striped directory
        $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
                error "set striped dir error"
+        #look at the directories for debug purposes
+       ls -l $DIR/$tdir
+       $LFS getdirstripe $DIR/$tdir
+       ls -l $DIR/$tdir/remote_striped_dir
+       $LFS getdirstripe $DIR/$tdir/remote_striped_dir
        createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
                error "create 10 files failed"
 
@@ -20086,7 +21475,7 @@ test_300q() {
 run_test 300q "create remote directory under orphan directory"
 
 test_300r() {
-       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
+       [ $MDS1_VERSION -lt $(version_code 2.7.55) ] &&
                skip "Need MDS version at least 2.7.55" && return
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
 
@@ -20401,7 +21790,7 @@ test_316() {
        chown nobody $DIR/$tdir/d
        touch $DIR/$tdir/d/file
 
-       $LFS mv -M1 $DIR/$tdir/d || error "lfs mv failed"
+       $LFS mv -m1 $DIR/$tdir/d || error "lfs mv failed"
 }
 run_test 316 "lfs mv"
 
@@ -20483,9 +21872,8 @@ test_318() {
                           llite.*.max_read_ahead_async_active 2>/dev/null)
        [ $max_active -ne 256 ] && error "expected 256 but got $max_active"
 
-       # currently reset to 0 is unsupported, leave it 512 for now.
-       $LCTL set_param llite.*.max_read_ahead_async_active=0 &&
-               error "set max_read_ahead_async_active should fail"
+       $LCTL set_param llite.*.max_read_ahead_async_active=0 ||
+               error "set max_read_ahead_async_active should succeed"
 
        $LCTL set_param llite.*.max_read_ahead_async_active=512
        max_active=$($LCTL get_param -n \
@@ -20544,6 +21932,126 @@ test_319() {
 }
 run_test 319 "lost lease lock on migrate error"
 
+test_398a() { # LU-4198
+       $LFS setstripe -c 1 -i 0 $DIR/$tfile
+       $LCTL set_param ldlm.namespaces.*.lru_size=clear
+
+       # request a new lock on client
+       dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
+
+       dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=direct conv=notrunc
+       local lock_count=$($LCTL get_param -n \
+                          ldlm.namespaces.*-OST0000-osc-ffff*.lru_size)
+       [[ $lock_count -eq 0 ]] || error "lock should be cancelled by direct IO"
+
+       $LCTL set_param ldlm.namespaces.*-OST0000-osc-ffff*.lru_size=clear
+
+       # no lock cached, should use lockless IO and not enqueue new lock
+       dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=direct conv=notrunc
+       lock_count=$($LCTL get_param -n \
+                    ldlm.namespaces.*-OST0000-osc-ffff*.lru_size)
+       [[ $lock_count -eq 0 ]] || error "no lock should be held by direct IO"
+}
+run_test 398a "direct IO should cancel lock otherwise lockless"
+
+test_398b() { # LU-4198
+       which fio || skip_env "no fio installed"
+       $LFS setstripe -c -1 $DIR/$tfile
+
+       local size=12
+       dd if=/dev/zero of=$DIR/$tfile bs=1M count=$size
+
+       local njobs=4
+       echo "mix direct rw ${size}M to OST0 by fio with $njobs jobs..."
+       fio --name=rand-rw --rw=randrw --bs=$PAGE_SIZE --direct=1 \
+               --numjobs=$njobs --fallocate=none \
+               --iodepth=16 --allow_file_create=0 --size=$((size/njobs))M \
+               --filename=$DIR/$tfile &
+       bg_pid=$!
+
+       echo "mix buffer rw ${size}M to OST0 by fio with $njobs jobs..."
+       fio --name=rand-rw --rw=randrw --bs=$PAGE_SIZE \
+               --numjobs=$njobs --fallocate=none \
+               --iodepth=16 --allow_file_create=0 --size=$((size/njobs))M \
+               --filename=$DIR/$tfile || true
+       wait $bg_pid
+
+       rm -rf $DIR/$tfile
+}
+run_test 398b "DIO and buffer IO race"
+
+test_398c() { # LU-4198
+       which fio || skip_env "no fio installed"
+
+       saved_debug=$($LCTL get_param -n debug)
+       $LCTL set_param debug=0
+
+       local size=$(lctl get_param -n osc.$FSNAME-OST0000*.kbytesavail | head -1)
+       ((size /= 1024)) # by megabytes
+       ((size /= 2)) # write half of the OST at most
+       [ $size -gt 40 ] && size=40 #reduce test time anyway
+
+       $LFS setstripe -c 1 $DIR/$tfile
+
+       # it seems like ldiskfs reserves more space than necessary if the
+       # writing blocks are not mapped, so it extends the file firstly
+       dd if=/dev/zero of=$DIR/$tfile bs=1M count=$size && sync
+       cancel_lru_locks osc
+
+       # clear and verify rpc_stats later
+       $LCTL set_param osc.${FSNAME}-OST0000-osc-ffff*.rpc_stats=clear
+
+       local njobs=4
+       echo "writing ${size}M to OST0 by fio with $njobs jobs..."
+       fio --name=rand-write --rw=randwrite --bs=$PAGE_SIZE --direct=1 \
+               --numjobs=$njobs --fallocate=none --ioengine=libaio \
+               --iodepth=16 --allow_file_create=0 --size=$((size/njobs))M \
+               --filename=$DIR/$tfile
+       [ $? -eq 0 ] || error "fio write error"
+
+       [ $($LCTL get_param -n \
+        ldlm.namespaces.${FSNAME}-OST0000-osc-ffff*.lock_count) -eq 0 ] ||
+               error "Locks were requested while doing AIO"
+
+       # get the percentage of 1-page I/O
+       pct=$($LCTL get_param osc.${FSNAME}-OST0000-osc-ffff*.rpc_stats |
+               grep -A 1 'pages per rpc' | grep -v 'pages per rpc' |
+               awk '{print $7}')
+       [ $pct -le 50 ] || error "$pct% of I/O are 1-page"
+
+       echo "mix rw ${size}M to OST0 by fio with $njobs jobs..."
+       fio --name=rand-rw --rw=randrw --bs=$PAGE_SIZE --direct=1 \
+               --numjobs=$njobs --fallocate=none --ioengine=libaio \
+               --iodepth=16 --allow_file_create=0 --size=$((size/njobs))M \
+               --filename=$DIR/$tfile
+       [ $? -eq 0 ] || error "fio mixed read write error"
+
+       echo "AIO with large block size ${size}M"
+       fio --name=rand-rw --rw=randrw --bs=${size}M --direct=1 \
+               --numjobs=1 --fallocate=none --ioengine=libaio \
+               --iodepth=16 --allow_file_create=0 --size=${size}M \
+               --filename=$DIR/$tfile
+       [ $? -eq 0 ] || error "fio large block size failed"
+
+       rm -rf $DIR/$tfile
+       $LCTL set_param debug="$saved_debug"
+}
+run_test 398c "run fio to test AIO"
+
+test_398d() { #  LU-13846
+       test -f aiocp || skip_env "no aiocp installed"
+       local aio_file=$DIR/aio_file
+
+       $LFS setstripe -c -1 -S 1M $DIR/$tfile $aio_file
+
+       dd if=/dev/urandom of=$DIR/$tfile bs=1M count=64
+       aiocp -a $PAGE_SIZE -b 64M -s 64M -f O_DIRECT $DIR/$tfile $aio_file
+
+       diff $DIR/$tfile $aio_file || "file diff after aiocp"
+       rm -rf $DIR/$tfile $aio_file
+}
+run_test 398d "run aiocp to verify block size > stripe size"
+
 test_fake_rw() {
        local read_write=$1
        if [ "$read_write" = "write" ]; then
@@ -20629,6 +22137,10 @@ test_400a() { # LU-1606, was conf-sanity test_74
        local prefix=/usr/include/lustre
        local prog
 
+       # Oleg removes c files in his test rig so test if any c files exist
+       [ -z "$(ls -A $LUSTRE_TESTS_API_DIR)" ] && \
+               skip_env "Needed c test files are missing"
+
        if ! [[ -d $prefix ]]; then
                # Assume we're running in tree and fixup the include path.
                extra_flags+=" -I$LUSTRE/../lnet/include/uapi -I$LUSTRE/include/uapi -I$LUSTRE/include"
@@ -20636,7 +22148,7 @@ test_400a() { # LU-1606, was conf-sanity test_74
        fi
 
        for prog in $LUSTRE_TESTS_API_DIR/*.c; do
-               $CC -Wall -Werror $extra_flags -o $out $prog -llustreapi ||
+               $CC -Wall -Werror -std=c99 $extra_flags -o $out $prog -llustreapi ||
                        error "client api broken"
        done
        rm -f $out
@@ -20668,7 +22180,7 @@ test_400b() { # LU-1606, LU-5011
                        continue # lustre_ioctl.h is internal header
                fi
 
-               $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
+               $CC -Wall -Werror -std=c99 -include $header -c -x c /dev/null -o $out ||
                        error "cannot compile '$header'"
        done
        rm -f $out
@@ -20682,6 +22194,7 @@ test_401a() { #LU-7437
        #count the number of parameters by "list_param -R"
        local params=$($LCTL list_param -R '*' 2>/dev/null | wc -l)
        #count the number of parameters by listing proc files
+       local proc_regexp="/{proc,sys}/{fs,sys,kernel/debug}/{lustre,lnet}/"
        local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
        echo "proc_dirs='$proc_dirs'"
        [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
@@ -20853,6 +22366,7 @@ test_405() {
                        skip "Layout swap lock is not supported"
 
        check_swap_layouts_support
+       check_swap_layout_no_dom $DIR
 
        test_mkdir $DIR/$tdir
        swap_lock_test -d $DIR/$tdir ||
@@ -21003,6 +22517,8 @@ test_410()
 {
        [[ $CLIENT_VERSION -lt $(version_code 2.9.59) ]] &&
                skip "Need client version at least 2.9.59"
+       [ -f $LUSTRE/tests/kernel/kinode.ko ] ||
+               skip "Need MODULES build"
 
        # Create a file, and stat it from the kernel
        local testfile=$DIR/$tfile
@@ -21057,7 +22573,7 @@ run_test 411 "Slab allocation error with cgroup does not LBUG"
 
 test_412() {
        [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs"
-       if [ $(lustre_version_code mds1) -lt $(version_code 2.10.55) ]; then
+       if [ $MDS1_VERSION -lt $(version_code 2.10.55) ]; then
                skip "Need server version at least 2.10.55"
        fi
 
@@ -21325,7 +22841,7 @@ run_test 414 "simulate ENOMEM in ptlrpc_register_bulk()"
 
 test_415() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run"
-       [ $(lustre_version_code mds1) -lt $(version_code 2.11.52) ] &&
+       [ $MDS1_VERSION -lt $(version_code 2.11.52) ] &&
                skip "Need server version at least 2.11.52"
 
        # LU-11102
@@ -21367,7 +22883,7 @@ test_415() {
 run_test 415 "lock revoke is not missing"
 
 test_416() {
-       [ $(lustre_version_code mds1) -lt $(version_code 2.11.55) ] &&
+       [ $MDS1_VERSION -lt $(version_code 2.11.55) ] &&
                skip "Need server version at least 2.11.55"
 
        # define OBD_FAIL_OSD_TXN_START    0x19a
@@ -21821,8 +23337,37 @@ test_422() {
 }
 run_test 422 "kill a process with RPC in progress"
 
+stat_test() {
+    df -h $MOUNT &
+    df -h $MOUNT &
+    df -h $MOUNT &
+    df -h $MOUNT &
+    df -h $MOUNT &
+    df -h $MOUNT &
+}
+
+test_423() {
+    local _stats
+    # ensure statfs cache is expired
+    sleep 2;
+
+    _stats=$(stat_test | grep $MOUNT | sort -u | wc -l)
+    [[ ${_stats} -ne 1 ]] && error "statfs wrong"
+
+    return 0
+}
+run_test 423 "statfs should return a right data"
+
+test_424() {
+#define OBD_FAIL_PTLRPC_BULK_REPLY_ATTACH      0x522 | OBD_FAIL_ONCE
+       $LCTL set_param fail_loc=0x80000522
+       dd if=/dev/zero of=$DIR/$tfile bs=2M count=1 oflag=sync
+       rm -f $DIR/$tfile
+}
+run_test 424 "simulate ENOMEM in ptl_send_rpc bulk reply ME attach"
+
 prep_801() {
-       [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
+       [[ $MDS1_VERSION -lt $(version_code 2.9.55) ]] ||
        [[ $OST1_VERSION -lt $(version_code 2.9.55) ]] &&
                skip "Need server version at least 2.9.55"
 
@@ -22053,7 +23598,7 @@ cleanup_802a() {
 
 test_802a() {
        [[ $mds1_FSTYPE = zfs ]] || skip "ZFS specific test"
-       [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
+       [[ $MDS1_VERSION -lt $(version_code 2.9.55) ]] ||
        [[ $OST1_VERSION -lt $(version_code 2.9.55) ]] &&
                skip "Need server version at least 2.9.55"
 
@@ -22298,7 +23843,8 @@ test_805() {
        do_facet $SINGLEMDS zfs set quota=$(((usedkb+freekb)*1024)) $fsset
        trap cleanup_805 EXIT
        mkdir $DIR/$tdir
-       $LFS setstripe -E 1M -L mdt $DIR/$tdir || error "DoM not working"
+       $LFS setstripe -E 1M -c2 -E 4M -c2 -E -1 -c2 $DIR/$tdir ||
+               error "Can't set PFL layout"
        createmany -m $DIR/$tdir/f- 1000000 && error "ENOSPC wasn't met"
        rm -rf $DIR/$tdir || error "not able to remove"
        do_facet $SINGLEMDS zfs set quota=$old $fsset
@@ -22450,7 +23996,7 @@ test_807() {
                error "truncate $tdir/trunc failed"
 
        local bs=1048576
-       dd if=/dev/zero of=$DIR/$tdir/single_dd bs=$bs count=1 ||
+       dd if=/dev/zero of=$DIR/$tdir/single_dd bs=$bs count=1 conv=fsync ||
                error "write $tfile failed"
 
        # multi-client wirtes
@@ -22471,7 +24017,8 @@ test_807() {
                wait ${pids[$i]}
        done
 
-       sleep 5
+       do_rpc_nodes "$CLIENTS" cancel_lru_locks osc
+       do_nodes "$CLIENTS" "sync ; sleep 5 ; sync"
        $LSOM_SYNC -u $cl_user -m $FSNAME-MDT0000 $MOUNT
        check_lsom_data $DIR/$tdir/trunc
        check_lsom_data $DIR/$tdir/single_dd
@@ -22571,23 +24118,6 @@ test_810() {
 }
 run_test 810 "partial page writes on ZFS (LU-11663)"
 
-test_811() {
-       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ] &&
-               skip "Need MDS version at least 2.11.56"
-
-       #define OBD_FAIL_MDS_ORPHAN_DELETE      0x165
-       do_facet mds1 $LCTL set_param fail_loc=0x165
-       $MULTIOP $DIR/$tfile Ouc || error "multiop failed"
-
-       stop mds1
-       start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
-
-       sleep 5
-       [[ $(do_facet mds1 pgrep orph_.*-MDD | wc -l) -eq 0 ]] ||
-               error "MDD orphan cleanup thread not quit"
-}
-run_test 811 "orphan name stub can be cleaned up in startup"
-
 test_812a() {
        [ $OST1_VERSION -lt $(version_code 2.12.51) ] &&
                skip "OST < 2.12.51 doesn't support this fail_loc"
@@ -22903,6 +24433,42 @@ test_819b() {
 }
 run_test 819b "too big niobuf in write"
 
+
+function test_820_start_ost() {
+       sleep 5
+
+       for num in $(seq $OSTCOUNT); do
+               start ost$num $(ostdevname $num) $OST_MOUNT_OPTS
+       done
+}
+
+test_820() {
+       [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
+
+       mkdir $DIR/$tdir
+       umount_client $MOUNT || error "umount failed"
+       for num in $(seq $OSTCOUNT); do
+               stop ost$num
+       done
+
+       # mount client with no active OSTs
+       # so that the client can't initialize max LOV EA size
+       # from OSC notifications
+       mount_client $MOUNT || error "mount failed"
+       # delay OST starting to keep this 0 max EA size for a while
+       test_820_start_ost &
+
+       # create a directory on MDS2
+       test_mkdir -i 1 -c1 $DIR/$tdir/mds2 ||
+               error "Failed to create directory"
+       # open intent should update default EA size
+       # see mdc_update_max_ea_from_body()
+       # notice this is the very first RPC to MDS2
+       cp /etc/services $DIR/$tdir/mds2 ||
+               error "Failed to copy files to mds$n"
+}
+run_test 820 "update max EA from open intent"
+
 #
 # tests that do cleanup/setup should be run at the end
 #
@@ -22946,6 +24512,18 @@ test_901() {
 }
 run_test 901 "don't leak a mgc lock on client umount"
 
+# LU-13377
+test_902() {
+       [ $CLIENT_VERSION -lt $(version_code 2.13.52) ] &&
+               skip "client does not have LU-13377 fix"
+       #define OBD_FAIL_LLITE_SHORT_COMMIT 0x1415
+       $LCTL set_param fail_loc=0x1415
+       dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
+       cancel_lru_locks osc
+       rm -f $DIR/$tfile
+}
+run_test 902 "test short write doesn't hang lustre"
+
 complete $SECONDS
 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
 check_and_cleanup_lustre