Whamcloud - gitweb
LU-7803 tests: Cleanup after sanity/78
[fs/lustre-release.git] / lustre / tests / sanity.sh
index 03fb21f..6dde8ab 100755 (executable)
@@ -79,8 +79,8 @@ init_logging
 [ "$SLOW" = "no" ] && EXCEPT_SLOW="24D 27m 64b 68 71 115 300o"
 
 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
-       # bug number for skipped test: LU-4536 LU-1957 LU-2805
-       ALWAYS_EXCEPT="$ALWAYS_EXCEPT  65ic    180     184c"
+       # bug number for skipped test: LU-4536 LU-1957
+       ALWAYS_EXCEPT="$ALWAYS_EXCEPT  65ic    180"
        #                                               4   13    (min)"
        [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b 51ba"
 fi
@@ -3531,7 +3531,7 @@ test_39p() {
 run_test 39p "remote directory cached attributes updated after create ========"
 
 
-test_39p() { # LU-8041
+test_39q() { # LU-8041
        local testdir=$DIR/$tdir
        mkdir -p $testdir
        multiop_bg_pause $testdir D_c || error "multiop failed"
@@ -3541,7 +3541,7 @@ test_39p() { # LU-8041
        local atime=$(stat -c %X $testdir)
        [ "$atime" -ne 0 ] || error "atime is zero"
 }
-run_test 39p "close won't zero out atime"
+run_test 39q "close won't zero out atime"
 
 test_40() {
        dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
@@ -4459,6 +4459,26 @@ test_56a() {     # was test_56
 }
 run_test 56a "check $GETSTRIPE"
 
+test_56b() {
+       test_mkdir $DIR/$tdir
+       NUMDIRS=3
+       for i in $(seq 1 $NUMDIRS); do
+               test_mkdir $DIR/$tdir/dir$i
+       done
+
+       # test lfs getdirstripe default mode is non-recursion, which is
+       # different from lfs getstripe
+       dircnt=$($LFS getdirstripe $DIR/$tdir | grep -c lmv_stripe_count)
+       [[ $dircnt -eq 1 ]] ||
+               error "$LFS getdirstripe: found $dircnt, not 1"
+       dircnt=$($LFS getdirstripe --recursive $DIR/$tdir |
+               grep -c lmv_stripe_count)
+       [[ $dircnt -eq $((NUMDIRS + 1)) ]] ||
+               error "$LFS getdirstripe --recursive: found $dircnt, \
+                       not $((NUMDIRS + 1))"
+}
+run_test 56b "check $LFS getdirstripe"
+
 NUMFILES=3
 NUMDIRS=3
 setup_56() {
@@ -5640,6 +5660,12 @@ test_65l() { # bug 12836
 }
 run_test 65l "lfs find on -1 stripe dir ========================"
 
+test_65m() {
+       $RUNAS $SETSTRIPE -c 2 $MOUNT && error "setstripe should fail"
+       true
+}
+run_test 65m "normal user can't set filesystem default stripe"
+
 # bug 2543 - update blocks count on client
 test_66() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
@@ -6129,6 +6155,11 @@ run_test 77j "client only supporting ADLER32"
 rm -f $F77_TMP
 unset F77_TMP
 
+cleanup_test_78() {
+       trap 0
+       rm -f $DIR/$tfile
+}
+
 test_78() { # bug 10901
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        remote_ost || { skip_env "local OST" && return; }
@@ -6158,6 +6189,8 @@ test_78() { # bug 10901
        [[ $SMALLESTOST -lt 10240 ]] &&
                skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
 
+       trap cleanup_test_78 EXIT
+
        [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
                F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
 
@@ -6170,7 +6203,7 @@ test_78() { # bug 10901
                $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
        done
 
-       rm -f $DIR/$tfile
+       cleanup_test_78
 }
 run_test 78 "handle large O_DIRECT writes correctly ============"
 
@@ -8888,9 +8921,9 @@ test_129() {
                return
        fi
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
-       ENOSPC=28
-       EFBIG=27
-       has_warning=0
+       local ENOSPC=28
+       local EFBIG=27
+       local has_warning=0
 
        rm -rf $DIR/$tdir
        mkdir -p $DIR/$tdir
@@ -8922,7 +8955,7 @@ test_129() {
                        check_mds_dmesg '"has reached"' ||
                                error_exit "has reached message should be output"
 
-                       [ $has_warning ] ||
+                       [ $has_warning -eq 0 ] &&
                                error_exit "warning message should be output"
 
                        I=$(stat -c%s "$DIR/$tdir")
@@ -10599,6 +10632,12 @@ test_156() {
 run_test 156 "Verification of tunables"
 
 #Changelogs
+cleanup_changelog () {
+       trap 0
+       echo "Deregistering changelog client $CL_USER"
+       do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
+}
+
 err17935 () {
        if [[ $MDSCOUNT -gt 1 ]]; then
                error_ignore bz17935 $*
@@ -10639,10 +10678,12 @@ test_160a() {
 
        local CL_USERS="mdd.$MDT0.changelog_users"
        local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
-       USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
-       echo "Registered as changelog user $USER"
-       $GET_CL_USERS | grep -q $USER ||
-               error "User $USER not found in changelog_users"
+       CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
+               changelog_register -n)
+       echo "Registered as changelog user $CL_USER"
+       trap cleanup_changelog EXIT
+       $GET_CL_USERS | grep -q $CL_USER ||
+               error "User $CL_USER not found in changelog_users"
 
        # change something
        test_mkdir -p $DIR/$tdir/pics/2008/zachy
@@ -10686,9 +10727,9 @@ test_160a() {
        [ "$fidc" == "$fidf" ] ||
                err17935 "pfid in changelog $fidc != dir fid $fidf"
 
-       USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
-       $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
-       USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
+       USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$CL_USER\" {print \$2}")
+       $LFS changelog_clear $MDT0 $CL_USER $(($USER_REC1 + 5))
+       USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$CL_USER\" {print \$2}")
        echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
        [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
                err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
@@ -10703,7 +10744,7 @@ test_160a() {
        # LU-3446 changelog index reset on MDT restart
        local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
        CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
-       $LFS changelog_clear $MDT0 $USER 0
+       $LFS changelog_clear $MDT0 $CL_USER 0
        stop $SINGLEMDS || error "Fail to stop MDT."
        start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
        CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
@@ -10712,19 +10753,19 @@ test_160a() {
                err17935 "current index should be $CUR_REC1 is $CUR_REC2"
 
        echo "verifying user deregister"
-       do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
-       $GET_CL_USERS | grep -q $USER &&
-               error "User $USER still in changelog_users"
+       cleanup_changelog
+       $GET_CL_USERS | grep -q $CL_USER &&
+               error "User $CL_USER still in changelog_users"
 
        USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
-       if [ $USERS -eq 0 ]; then
+       if [ $CL_USER -eq 0 ]; then
                LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
                touch $DIR/$tdir/chloe
                LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
                echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
                [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
        else
-               echo "$USERS other changelog users; can't verify off"
+               echo "$CL_USER other changelog users; can't verify off"
        fi
 }
 run_test 160a "changelog sanity"
@@ -10737,10 +10778,12 @@ test_160b() { # LU-3587
 
        local CL_USERS="mdd.$MDT0.changelog_users"
        local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
-       USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
-       echo "Registered as changelog user $USER"
-       $GET_CL_USERS | grep -q $USER ||
-               error "User $USER not found in changelog_users"
+       CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
+               changelog_register -n)
+       echo "Registered as changelog user $CL_USER"
+       trap cleanup_changelog EXIT
+       $GET_CL_USERS | grep -q $CL_USER ||
+               error "User $CL_USER not found in changelog_users"
 
        local LONGNAME1=$(str_repeat a 255)
        local LONGNAME2=$(str_repeat b 255)
@@ -10752,11 +10795,8 @@ test_160b() { # LU-3587
        mv $LONGNAME1 $LONGNAME2
 
        $LFS changelog $MDT0 | grep RENME
-
-       echo "deregistering $USER"
-       do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
-
        rm -f $LONGNAME2
+       cleanup_changelog
 }
 run_test 160b "Verify that very long rename doesn't crash in changelog"
 
@@ -10773,8 +10813,9 @@ test_160c() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
 
        # Registration step
-       local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
+       CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
                changelog_register -n)
+       trap cleanup_changelog EXIT
 
        rm -rf $DIR/$tdir
        mkdir -p $DIR/$tdir
@@ -10786,11 +10827,10 @@ test_160c() {
        $LFS changelog $MDT0
        TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
        [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
-       $LFS changelog_clear $MDT0 $USER 0
+       $LFS changelog_clear $MDT0 $CL_USER 0
 
        # Deregistration step
-       echo "deregistering $USER"
-       do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
+       cleanup_changelog
 }
 run_test 160c "verify that changelog log catch the truncate event"
 
@@ -10806,21 +10846,22 @@ test_160d() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
 
        # Registration step
-       local USER=$(do_facet mds1 $LCTL --device $MDT0 \
+       CL_USER=$(do_facet mds1 $LCTL --device $MDT0 \
                changelog_register -n)
 
+       trap cleanup_changelog EXIT
        mkdir -p $DIR/$tdir/migrate_dir
-       $LFS changelog_clear $MDT0 $USER 0
+       $LFS changelog_clear $MDT0 $CL_USER 0
 
        $LFS migrate -m 1 $DIR/$tdir/migrate_dir || error "migrate fails"
        $LFS changelog $MDT0
        MIGRATES=$($LFS changelog $MDT0 | tail -5 | grep -c "MIGRT")
-       $LFS changelog_clear $MDT0 $USER 0
+       $LFS changelog_clear $MDT0 $CL_USER 0
        [ $MIGRATES -eq 1 ] ||
                error "MIGRATE changelog mask count $MIGRATES != 1"
 
        # Deregistration step
-       do_facet mds1 $LCTL --device $MDT0 changelog_deregister $USER
+       cleanup_changelog
 }
 run_test 160d "verify that changelog log catch the migrate event"
 
@@ -10927,8 +10968,10 @@ test_161c() {
 
        # define CLF_RENAME_LAST 0x0001
        # rename overwrite a target having nlink = 1 (changelog flag 0x1)
-       local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
+       CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
                changelog_register -n)
+
+       trap cleanup_changelog EXIT
        rm -rf $DIR/$tdir
        mkdir -p $DIR/$tdir
        touch $DIR/$tdir/foo_161c
@@ -10937,10 +10980,8 @@ test_161c() {
        $LFS changelog $MDT0 | grep RENME
        local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
                cut -f5 -d' ')
-       $LFS changelog_clear $MDT0 $USER 0
+       $LFS changelog_clear $MDT0 $CL_USER 0
        if [ x$flags != "x0x1" ]; then
-               do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
-                       $USER
                error "flag $flags is not 0x1"
        fi
        echo "rename overwrite a target having nlink = 1," \
@@ -10953,10 +10994,8 @@ test_161c() {
        mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
        $LFS changelog $MDT0 | grep RENME
        flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
-       $LFS changelog_clear $MDT0 $USER 0
+       $LFS changelog_clear $MDT0 $CL_USER 0
        if [ x$flags != "x0x0" ]; then
-               do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
-                       $USER
                error "flag $flags is not 0x0"
        fi
        echo "rename overwrite a target having nlink > 1," \
@@ -10967,10 +11006,8 @@ test_161c() {
        mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
        $LFS changelog $MDT0 | grep RENME
        flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
-       $LFS changelog_clear $MDT0 $USER 0
+       $LFS changelog_clear $MDT0 $CL_USER 0
        if [ x$flags != "x0x0" ]; then
-               do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
-                       $USER
                error "flag $flags is not 0x0"
        fi
        echo "rename doesn't overwrite a target," \
@@ -10981,10 +11018,8 @@ test_161c() {
        rm -f $DIR/$tdir/foo2_161c
        $LFS changelog $MDT0 | grep UNLNK
        flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
-       $LFS changelog_clear $MDT0 $USER 0
+       $LFS changelog_clear $MDT0 $CL_USER 0
        if [ x$flags != "x0x1" ]; then
-               do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
-                       $USER
                error "flag $flags is not 0x1"
        fi
        echo "unlink a file having nlink = 1," \
@@ -10995,15 +11030,13 @@ test_161c() {
        rm -f $DIR/$tdir/foobar_161c
        $LFS changelog $MDT0 | grep UNLNK
        flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
-       $LFS changelog_clear $MDT0 $USER 0
+       $LFS changelog_clear $MDT0 $CL_USER 0
        if [ x$flags != "x0x0" ]; then
-               do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
-                       $USER
                error "flag $flags is not 0x0"
        fi
        echo "unlink a file having nlink > 1," \
                "changelog record has flags of $flags"
-       do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
+       cleanup_changelog
 }
 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
 
@@ -11925,10 +11958,11 @@ jobstats_set() {
 }
 
 cleanup_205() {
+       trap 0
        do_facet $SINGLEMDS \
                $LCTL set_param mdt.*.job_cleanup_interval=$OLD_INTERVAL
        [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
-       do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
+       cleanup_changelog
 }
 
 test_205() { # Job stats
@@ -13769,33 +13803,34 @@ run_test 247e "mount .. as fileset"
 test_248() {
        local my_error=error
 
-       # This test case is time sensitive and maloo uses kvm to run auto test.
+       local fast_read_sav=$($LCTL get_param -n llite.*.fast_read 2>/dev/null)
+       [ -z "$fast_read_sav" ] && skip "no fast read support" && return
+
+       # This test case is time sensitive and Maloo uses KVM to run autotest.
        # Therefore the complete time of I/O task is unreliable and depends on
-       # the work load on the host machine when the task is running.
-       which virt-what 2> /dev/null && [ "$(virt-what)" != "kvm" ] ||
-               { echo "no virt-what installed or running in kvm; ignore error";
-                 my_error="error_ignore env=kvm"; }
+       # the workload on the host machine when the task is running.
+       local virt=$(running_in_vm)
+       [ -n "$virt" ] && echo "running in VM '$virt', ignore error" &&
+                 my_error="error_ignore env=$virt"
 
        # create a large file for fast read verification
-       dd if=/dev/zero of=$DIR/$tfile bs=128M count=1 > /dev/null 2>&1
+       dd if=/dev/zero of=$DIR/$tfile bs=1M count=128 > /dev/null 2>&1
 
        # make sure the file is created correctly
        $CHECKSTAT -s $((128*1024*1024)) $DIR/$tfile ||
                { rm -f $DIR/$tfile; skip "file creation error" && return; }
 
-       local saved_fast_read=$($LCTL get_param -n llite.*.fast_read)
-
        echo "Test 1: verify that fast read is 4 times faster on cache read"
 
        # small read with fast read enabled
        $LCTL set_param -n llite.*.fast_read=1
-       local t_fast=$(eval time -p dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
-                  awk '/real/ { print $2 }')
+       local t_fast=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
+               awk '/copied/ { print $6 }')
 
        # small read with fast read disabled
        $LCTL set_param -n llite.*.fast_read=0
-       local t_slow=$(eval time -p dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
-                  awk '/real/ { print $2 }')
+       local t_slow=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
+               awk '/copied/ { print $6 }')
 
        # verify that fast read is 4 times faster for cache read
        [ $(bc <<< "4 * $t_fast < $t_slow") -eq 1 ] ||
@@ -13806,19 +13841,19 @@ test_248() {
 
        # 1k non-cache read
        cancel_lru_locks osc
-       local t_1k=$(eval time -p dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
-            awk '/real/ { print $2 }')
+       local t_1k=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
+               awk '/copied/ { print $6 }')
 
        # 1M non-cache read
        cancel_lru_locks osc
-       local t_1m=$(eval time -p dd if=$DIR/$tfile of=/dev/null bs=1M 2>&1 |
-            awk '/real/ { print $2 }')
+       local t_1m=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
+               awk '/copied/ { print $6 }')
 
        # verify that big IO is not 4 times faster than small IO
        [ $(bc <<< "4 * $t_1k >= $t_1m") -eq 1 ] ||
                $my_error "bigger IO is way too fast: $t_1k vs $t_1m"
 
-       $LCTL set_param -n llite.*.fast_read=$saved_fast_read
+       $LCTL set_param -n llite.*.fast_read=$fast_read_sav
        rm -f $DIR/$tfile
 }
 run_test 248 "fast read verification"
@@ -13961,6 +13996,175 @@ test_254() {
 }
 run_test 254 "Check changelog size"
 
+ladvise_no_type()
+{
+       local type=$1
+       local file=$2
+
+       lfs ladvise -a invalid $file 2>&1 | grep "Valid types" |
+               awk -F: '{print $2}' | grep $type > /dev/null
+       if [ $? -ne 0 ]; then
+               return 0
+       fi
+       return 1
+}
+
+ladvise_no_ioctl()
+{
+       local file=$1
+
+       lfs ladvise -a willread $file > /dev/null 2>&1
+       if [ $? -eq 0 ]; then
+               return 1
+       fi
+
+       lfs ladvise -a willread $file 2>&1 |
+               grep "Inappropriate ioctl for device" > /dev/null
+       if [ $? -eq 0 ]; then
+               return 0
+       fi
+       return 1
+}
+
+ladvise_willread_performance()
+{
+       local repeat=10
+       local average_cache=0
+       local average_ladvise=0
+       for ((i = 1; i <= $repeat; i++)); do
+               echo "Iter $i/$repeat: reading without willread hint"
+               cancel_lru_locks osc
+               do_nodes $(comma_list $(osts_nodes)) \
+                       "echo 3 > /proc/sys/vm/drop_caches"
+               local speed_origin=$($READS -f $DIR/$tfile -s $size \
+                       -b 4096 -n $((size / 4096)) -t 60 |
+                       sed -e '/^$/d' -e 's#.*s, ##' -e 's#MB/s##')
+
+               echo "Iter $i/$repeat: Reading again without willread hint"
+               cancel_lru_locks osc
+               local speed_cache=$($READS -f $DIR/$tfile -s $size \
+                       -b 4096 -n $((size / 4096)) -t 60 |
+                       sed -e '/^$/d' -e 's#.*s, ##' -e 's#MB/s##')
+
+               echo "Iter $i/$repeat: reading with willread hint"
+               cancel_lru_locks osc
+               do_nodes $(comma_list $(osts_nodes)) \
+                       "echo 3 > /proc/sys/vm/drop_caches"
+               lfs ladvise -a willread $DIR/$tfile ||
+                       error "Ladvise failed"
+               local speed_ladvise=$($READS -f $DIR/$tfile -s $size \
+                       -b 4096 -n $((size / 4096)) -t 60 |
+                       sed -e '/^$/d' -e 's#.*s, ##' -e 's#MB/s##')
+
+               local cache_speedup=$(echo "scale=2; \
+                       ($speed_cache-$speed_origin)/$speed_origin*100" | bc)
+               cache_speedup=$(echo ${cache_speedup%.*})
+               echo "Iter $i/$repeat: cache speedup: $cache_speedup%"
+               average_cache=$((average_cache + cache_speedup))
+
+               local ladvise_speedup=$(echo "scale=2; \
+                       ($speed_ladvise-$speed_origin)/$speed_origin*100" | bc)
+               ladvise_speedup=$(echo ${ladvise_speedup%.*})
+               echo "Iter $i/$repeat: ladvise speedup: $ladvise_speedup%"
+               average_ladvise=$((average_ladvise + ladvise_speedup))
+       done
+       average_cache=$((average_cache / repeat))
+       average_ladvise=$((average_ladvise / repeat))
+
+       if [ $average_cache -lt 20 ]; then
+               echo "Speedup with cache is less than 20% ($average_cache%),"\
+                       "skipping check of speedup with willread:"\
+                       "$average_ladvise%"
+               return 0
+       fi
+
+       local lowest_speedup=$((average_cache / 2))
+       [ $average_ladvise -gt $lowest_speedup ] ||
+               error "Speedup with willread is less than $lowest_speedup%,"\
+                       "got $average_ladvise%"
+       echo "Speedup with willread ladvise: $average_ladvise%"
+       echo "Speedup with cache: $average_cache%"
+}
+
+test_255a() {
+       lfs setstripe -c -1 -i 0 $DIR/$tfile || error "$tfile failed"
+
+       ladvise_no_type willread $DIR/$tfile &&
+               skip "willread ladvise is not supported" && return
+
+       ladvise_no_ioctl $DIR/$tfile &&
+               skip "ladvise ioctl is not supported" && return
+
+       [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
+               skip "lustre < 2.8.54 does not support ladvise " && return
+
+       local size_mb=100
+       local size=$((size_mb * 1048576))
+       dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
+               error "dd to $DIR/$tfile failed"
+
+       lfs ladvise -a willread $DIR/$tfile ||
+               error "Ladvise failed with no range argument"
+
+       lfs ladvise -a willread -s 0 $DIR/$tfile ||
+               error "Ladvise failed with no -l or -e argument"
+
+       lfs ladvise -a willread -e 1 $DIR/$tfile ||
+               error "Ladvise failed with only -e argument"
+
+       lfs ladvise -a willread -l 1 $DIR/$tfile ||
+               error "Ladvise failed with only -l argument"
+
+       lfs ladvise -a willread -s 2 -e 1 $DIR/$tfile &&
+               error "End offset should not be smaller than start offset"
+
+       lfs ladvise -a willread -s 2 -e 2 $DIR/$tfile &&
+               error "End offset should not be equal to start offset"
+
+       lfs ladvise -a willread -s $size -l 1 $DIR/$tfile ||
+               error "Ladvise failed with overflowing -s argument"
+
+       lfs ladvise -a willread -s 1 -e $((size + 1)) $DIR/$tfile ||
+               error "Ladvise failed with overflowing -e argument"
+
+       lfs ladvise -a willread -s 1 -l $size $DIR/$tfile ||
+               error "Ladvise failed with overflowing -l argument"
+
+       lfs ladvise -a willread -l 1 -e 2 $DIR/$tfile &&
+               error "Ladvise succeeded with conflicting -l and -e arguments"
+
+       echo "Synchronous ladvise should wait"
+       local delay=4
+#define OBD_FAIL_OST_LADVISE_PAUSE      0x237
+       do_nodes $(comma_list $(osts_nodes)) \
+               $LCTL set_param fail_val=$delay fail_loc=0x237
+
+       local start_ts=$SECONDS
+       lfs ladvise -a willread $DIR/$tfile ||
+               error "Ladvise failed with no range argument"
+       local end_ts=$SECONDS
+       local inteval_ts=$((end_ts - start_ts))
+
+       if [ $inteval_ts -lt $(($delay - 1)) ]; then
+               error "Synchronous advice didn't wait reply"
+       fi
+
+       echo "Asynchronous ladvise shouldn't wait"
+       local start_ts=$SECONDS
+       lfs ladvise -a willread -b $DIR/$tfile ||
+               error "Ladvise failed with no range argument"
+       local end_ts=$SECONDS
+       local inteval_ts=$((end_ts - start_ts))
+
+       if [ $inteval_ts -gt $(($delay / 2)) ]; then
+               error "Asynchronous advice blocked"
+       fi
+
+       do_nodes $(comma_list $(osts_nodes)) $LCTL set_param fail_loc=0
+       ladvise_willread_performance
+}
+run_test 255a "check 'lfs ladvise -a willread'"
+
 test_256() {
        local cl_user
        local cat_sl
@@ -14790,16 +14994,114 @@ test_311() {
        local new_iused
        for i in $(seq 120); do
                new_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
-               [ $new_iused -lt $((old_iused - 900)) ] && break
+               [ $((old_iused - new_iused)) -gt 800 ] && break
                sleep 1
        done
 
        echo "waited $i sec, old Iused $old_iused, new Iused $new_iused"
-       [ $new_iused -lt $((old_iused - 900)) ] ||
+       [ $((old_iused - new_iused)) -gt 800 ] ||
                error "objs not destroyed after unlink"
 }
 run_test 311 "disable OSP precreate, and unlink should destroy objs"
 
+zfs_oid_to_objid()
+{
+       local ost=$1
+       local objid=$2
+
+       local vdevdir=$(dirname $(facet_vdevice $ost))
+       local cmd="$ZDB -e -p $vdevdir -dddd $(facet_device $ost)"
+       local zfs_zapid=$(do_facet $ost $cmd |
+                         grep -w "/O/0/d$((objid%32))" -C 5 |
+                         awk '/Object/{getline; print $1}')
+       local zfs_objid=$(do_facet $ost $cmd $zfs_zapid |
+                         awk "/$objid = /"'{printf $3}')
+
+       echo $zfs_objid
+}
+
+zfs_object_blksz() {
+       local ost=$1
+       local objid=$2
+
+       local vdevdir=$(dirname $(facet_vdevice $ost))
+       local cmd="$ZDB -e -p $vdevdir -dddd $(facet_device $ost)"
+       local blksz=$(do_facet $ost $cmd $objid |
+                     awk '/dblk/{getline; printf $4}')
+
+       case "${blksz: -1}" in
+               k|K) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024)) ;;
+               m|M) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024*1024)) ;;
+               *) ;;
+       esac
+
+       echo $blksz
+}
+
+test_312() { # LU-4856
+       [ $(facet_fstype ost1) = "zfs" ] ||
+               { skip "the test only applies to zfs" && return; }
+
+       local max_blksz=$(do_facet ost1 \
+                         $ZFS get -p recordsize $(facet_device ost1) |
+                         awk '!/VALUE/{print $3}')
+
+       # to make life a little bit easier
+       $LFS mkdir -c 1 -i 0 $DIR/$tdir
+       $LFS setstripe -c 1 -i 0 $DIR/$tdir
+
+       local tf=$DIR/$tdir/$tfile
+       touch $tf
+       local oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
+
+       # Get ZFS object id
+       local zfs_objid=$(zfs_oid_to_objid ost1 $oid)
+
+       # block size change by sequential over write
+       local blksz
+       for ((bs=4096; bs <= max_blksz; bs <<= 2)); do
+               dd if=/dev/zero of=$tf bs=$bs count=1 oflag=sync conv=notrunc
+
+               blksz=$(zfs_object_blksz ost1 $zfs_objid)
+               [ $blksz -eq $bs ] || error "blksz error: $blksz, expected: $bs"
+       done
+       rm -f $tf
+
+       # block size change by sequential append write
+       dd if=/dev/zero of=$tf bs=4K count=1 oflag=sync conv=notrunc
+       oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
+       zfs_objid=$(zfs_oid_to_objid ost1 $oid)
+
+       for ((count = 1; count < $((max_blksz / 4096)); count *= 2)); do
+               dd if=/dev/zero of=$tf bs=4K count=$count seek=$count \
+                       oflag=sync conv=notrunc
+
+               blksz=$(zfs_object_blksz ost1 $zfs_objid)
+               blksz=$((blksz / 8192)) # in 2*4K unit
+               [ $blksz -eq $count ] ||
+                       error "blksz error(in 8k): $blksz, expected: $count"
+       done
+       rm -f $tf
+
+       # random write
+       touch $tf
+       oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
+       zfs_objid=$(zfs_oid_to_objid ost1 $oid)
+
+       dd if=/dev/zero of=$tf bs=8K count=1 oflag=sync conv=notrunc
+       blksz=$(zfs_object_blksz ost1 $zfs_objid)
+       [ $blksz -eq 8192 ] || error "blksz error: $blksz, expected: 8k"
+
+       dd if=/dev/zero of=$tf bs=64K count=1 oflag=sync conv=notrunc seek=128
+       blksz=$(zfs_object_blksz ost1 $zfs_objid)
+       [ $blksz -eq 65536 ] || error "blksz error: $blksz, expected: 64k"
+
+       dd if=/dev/zero of=$tf bs=1M count=1 oflag=sync conv=notrunc
+       blksz=$(zfs_object_blksz ost1 $zfs_objid)
+       [ $blksz -eq 65536 ] || error "rewrite error: $blksz, expected: 64k"
+}
+run_test 312 "make sure ZFS adjusts its block size by write pattern"
+
 test_400a() { # LU-1606, was conf-sanity test_74
        local extra_flags=''
        local out=$TMP/$tfile
@@ -15107,6 +15409,29 @@ test_406() {
 }
 run_test 406 "DNE support fs default striping"
 
+test_407() {
+       [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+
+       [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
+               skip "Need MDS version at least 2.8.55" && return
+
+       $LFS mkdir -i 0 -c 1 $DIR/$tdir.0 ||
+               error "$LFS mkdir -i 0 -c 1 $tdir.0 failed"
+       $LFS mkdir -i 1 -c 1 $DIR/$tdir.1 ||
+               error "$LFS mkdir -i 1 -c 1 $tdir.1 failed"
+       touch $DIR/$tdir.0/$tfile.0 || error "touch $tdir.0/$tfile.0 failed"
+
+       #define OBD_FAIL_DT_TXN_STOP    0x2019
+       for idx in $(seq $MDSCOUNT); do
+               do_facet mds$idx "lctl set_param fail_loc=0x2019"
+       done
+       $LFS mkdir -c 2 $DIR/$tdir && error "$LFS mkdir -c 2 $tdir should fail"
+       mv $DIR/$tdir.0/$tfile.0 $DIR/$tdir.1/$tfile.1 &&
+               error "mv $tdir.0/$tfile.0 $tdir.1/$tfile.1 should fail"
+       true
+}
+run_test 407 "transaction fail should cause operation fail"
+
 #
 # tests that do cleanup/setup should be run at the end
 #