Whamcloud - gitweb
LU-8856 osd: mark specific transactions netfree
[fs/lustre-release.git] / lustre / tests / sanity.sh
index be29031..e99e0ed 100755 (executable)
@@ -12,30 +12,12 @@ ONLY=${ONLY:-"$*"}
 ALWAYS_EXCEPT="$SANITY_EXCEPT  42a     42b     42c"
 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
 
-# skipped tests: LU-8411 LU-9096 LU-9054
-ALWAYS_EXCEPT="  407     253     312     $ALWAYS_EXCEPT"
+# skipped tests: LU-8411 LU-9096 LU-9054 LU-10680 ..
+ALWAYS_EXCEPT="  407     253     312     160f  160g    $ALWAYS_EXCEPT"
 
 # Check Grants after these tests
 GRANT_CHECK_LIST="$GRANT_CHECK_LIST 42a 42b 42c 42d 42e 63a 63b 64a 64b 64c"
 
-is_sles11()                                            # LU-4341
-{
-       if [ -r /etc/SuSE-release ]
-       then
-               local vers=$(grep VERSION /etc/SuSE-release | awk '{print $3}')
-               local patchlev=$(grep PATCHLEVEL /etc/SuSE-release |
-                       awk '{ print $3 }')
-               if [ $vers -eq 11 ] && [ $patchlev -ge 3 ]; then
-                       return 0
-               fi
-       fi
-       return 1
-}
-
-if is_sles11; then                                     # LU-4341
-       ALWAYS_EXCEPT="$ALWAYS_EXCEPT 170"
-fi
-
 SRCDIR=$(cd $(dirname $0); echo $PWD)
 export PATH=$PATH:/sbin
 
@@ -58,7 +40,7 @@ SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
 MEMHOG=${MEMHOG:-memhog}
 DIRECTIO=${DIRECTIO:-directio}
 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
-STRIPES_PER_OBJ=-1
+DEF_STRIPE_COUNT=-1
 CHECK_GRANT=${CHECK_GRANT:-"yes"}
 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
 export PARALLEL=${PARALLEL:-"no"}
@@ -87,6 +69,30 @@ if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
        [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b"
 fi
 
+# Get the SLES version so we can make decisions on if a test should be run
+#
+# Returns a version string that should only be used in comparing
+# strings returned by version_code()
+
+sles_version_code()
+{
+       local version=$(grep VERSION_ID /etc/os-release | cut -d'"' -f2)
+
+       # All SuSE Linux versions have one decimal. version_code expects two
+       local sles_version=$version.0
+       version_code $sles_version
+}
+
+if [ -r /etc/SuSE-release ]; then
+       sles_version=$(sles_version_code)
+       [ $sles_version -lt $(version_code 11.4.0) ] &&
+               # bug number for skipped test: LU-4341
+               ALWAYS_EXCEPT="$ALWAYS_EXCEPT  170"
+       [ $sles_version -lt $(version_code 12.0.0) ] &&
+               # bug number for skipped test: LU-3703
+               ALWAYS_EXCEPT="$ALWAYS_EXCEPT  234"
+fi
+
 FAIL_ON_ERROR=false
 
 cleanup() {
@@ -112,8 +118,6 @@ check_and_setup_lustre
 DIR=${DIR:-$MOUNT}
 assert_DIR
 
-MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
-       awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
 
 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
@@ -164,6 +168,45 @@ test_0c() {
 }
 run_test 0c "check import proc"
 
+test_0d() { # LU-3397
+       [ $(lustre_version_code mgs) -lt $(version_code 2.10.57) ] &&
+               skip "proc exports not supported before 2.10.57" && return
+
+       local mgs_exp="mgs.MGS.exports"
+       local client_uuid=$($LCTL get_param -n mgc.*.uuid)
+       local exp_client_nid
+       local exp_client_version
+       local exp_val
+       local imp_val
+       local temp_imp=$DIR/$tfile.import
+       local temp_exp=$DIR/$tfile.export
+
+       # save mgc import file to $temp_imp
+       $LCTL get_param mgc.*.import | tee $temp_imp
+       # Check if client uuid is found in MGS export
+       for exp_client_nid in $(do_facet mgs $LCTL get_param -N $mgs_exp.*); do
+               [ $(do_facet mgs $LCTL get_param $exp_client_nid.uuid) == \
+                       $client_uuid ] &&
+                       break;
+       done
+       # save mgs export file to $temp_exp
+       do_facet mgs $LCTL get_param $exp_client_nid.export | tee $temp_exp
+
+       # Compare the value of field "connect_flags"
+       imp_val=$(grep "connect_flags" $temp_imp)
+       exp_val=$(grep "connect_flags" $temp_exp)
+       [ "$exp_val" == "$imp_val" ] ||
+               error "export flags '$exp_val' != import flags '$imp_val'"
+
+       # Compare the value of client version
+       exp_client_version=$(awk '/target_version:/ { print $2 }' $temp_exp)
+       exp_val=$(version_code $exp_client_version)
+       imp_val=$(lustre_version_code client)
+       [ "$exp_val" == "$imp_val" ] ||
+               error "export client version '$exp_val' != '$imp_val'"
+}
+run_test 0d "check export proc ============================="
+
 test_1() {
        test_mkdir $DIR/$tdir
        test_mkdir $DIR/$tdir/d2
@@ -498,11 +541,7 @@ test_17h() { #bug 17378
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        local mdt_idx
        test_mkdir $DIR/$tdir
-       if [[ $MDSCOUNT -gt 1 ]]; then
-               mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
-       else
-               mdt_idx=0
-       fi
+       mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
        $LFS setstripe -c -1 $DIR/$tdir
        #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
        do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
@@ -516,18 +555,14 @@ test_17i() { #bug 20018
        test_mkdir -c1 $DIR/$tdir
        local foo=$DIR/$tdir/$tfile
        local mdt_idx
-       if [[ $MDSCOUNT -gt 1 ]]; then
-               mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
-       else
-               mdt_idx=0
-       fi
+       mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
        ln -s $foo $foo || error "create symlink failed"
 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
        do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
        ls -l $foo && error "error not detected"
        return 0
 }
-run_test 17i "don't panic on short symlink"
+run_test 17i "don't panic on short symlink (should return error)"
 
 test_17k() { #bug 22301
        [[ -z "$(which rsync 2>/dev/null)" ]] &&
@@ -813,6 +848,38 @@ test_23b() { # bug 18988
 }
 run_test 23b "O_APPEND check"
 
+# LU-9409, size with O_APPEND and tiny writes
+test_23c() {
+       local file=$DIR/$tfile
+
+       # single dd
+       dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=800
+       $CHECKSTAT -s 6400 $file || error "wrong size, expected 6400"
+       rm -f $file
+
+       # racing tiny writes
+       dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=800 &
+       dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=800 &
+       wait
+       $CHECKSTAT -s 12800 $file || error "wrong size, expected 12800"
+       rm -f $file
+
+       #racing tiny & normal writes
+       dd conv=notrunc oflag=append if=/dev/zero of=$file bs=4096 count=4 &
+       dd conv=notrunc oflag=append if=/dev/zero of=$file bs=8 count=100 &
+       wait
+       $CHECKSTAT -s 17184 $file || error "wrong size, expected 17184"
+       rm -f $file
+
+       #racing tiny & normal writes 2, ugly numbers
+       dd conv=notrunc oflag=append if=/dev/zero of=$file bs=4099 count=11 &
+       dd conv=notrunc oflag=append if=/dev/zero of=$file bs=17 count=173 &
+       wait
+       $CHECKSTAT -s 48030 $file || error "wrong size, expected 48030"
+       rm -f $file
+}
+run_test 23c "O_APPEND size checks for tiny writes"
+
 # rename sanity
 test_24a() {
        echo '-- same directory rename'
@@ -857,8 +924,8 @@ test_24e() {
        test_mkdir $DIR/R5b
        touch $DIR/R5a/f
        mv $DIR/R5a/f $DIR/R5b/g
-       $CHECKSTAT -a $DIR/R5a/f || error
-       $CHECKSTAT -t file $DIR/R5b/g || error
+       $CHECKSTAT -a $DIR/R5a/f || error "$DIR/R5a/f exists"
+       $CHECKSTAT -t file $DIR/R5b/g || error "$DIR/R5b/g not file type"
 }
 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
 
@@ -867,8 +934,8 @@ test_24f() {
        test_mkdir $DIR/R6b
        touch $DIR/R6a/f $DIR/R6b/g
        mv $DIR/R6a/f $DIR/R6b/g
-       $CHECKSTAT -a $DIR/R6a/f || error
-       $CHECKSTAT -t file $DIR/R6b/g || error
+       $CHECKSTAT -a $DIR/R6a/f || error "$DIR/R6a/f exists"
+       $CHECKSTAT -t file $DIR/R6b/g || error "$DIR/R6b/g not file type"
 }
 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
 
@@ -877,8 +944,8 @@ test_24g() {
        test_mkdir $DIR/R7b
        test_mkdir $DIR/R7a/d
        mv $DIR/R7a/d $DIR/R7b/e
-       $CHECKSTAT -a $DIR/R7a/d || error
-       $CHECKSTAT -t dir $DIR/R7b/e || error
+       $CHECKSTAT -a $DIR/R7a/d || error "$DIR/R7a/d exists"
+       $CHECKSTAT -t dir $DIR/R7b/e || error "$DIR/R7b/e not dir type"
 }
 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
 
@@ -888,8 +955,8 @@ test_24h() {
        test_mkdir -c1 $DIR/R8a/d
        test_mkdir -c1 $DIR/R8b/e
        mrename $DIR/R8a/d $DIR/R8b/e
-       $CHECKSTAT -a $DIR/R8a/d || error
-       $CHECKSTAT -t dir $DIR/R8b/e || error
+       $CHECKSTAT -a $DIR/R8a/d || error "$DIR/R8a/d exists"
+       $CHECKSTAT -t dir $DIR/R8b/e || error "$DIR/R8b/e not dir type"
 }
 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
 
@@ -899,18 +966,18 @@ test_24i() {
        test_mkdir $DIR/R9/a
        touch $DIR/R9/f
        mrename $DIR/R9/f $DIR/R9/a
-       $CHECKSTAT -t file $DIR/R9/f || error
-       $CHECKSTAT -t dir  $DIR/R9/a || error
-       $CHECKSTAT -a $DIR/R9/a/f || error
+       $CHECKSTAT -t file $DIR/R9/f || error "$DIR/R9/f not file type"
+       $CHECKSTAT -t dir  $DIR/R9/a || error "$DIR/R9/a not dir type"
+       $CHECKSTAT -a $DIR/R9/a/f || error "$DIR/R9/a/f exists"
 }
 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
 
 test_24j() {
        test_mkdir $DIR/R10
        mrename $DIR/R10/f $DIR/R10/g
-       $CHECKSTAT -t dir $DIR/R10 || error
-       $CHECKSTAT -a $DIR/R10/f || error
-       $CHECKSTAT -a $DIR/R10/g || error
+       $CHECKSTAT -t dir $DIR/R10 || error "$DIR/R10 not dir type"
+       $CHECKSTAT -a $DIR/R10/f || error "$DIR/R10/f exists"
+       $CHECKSTAT -a $DIR/R10/g || error "$DIR/R10/g exists"
 }
 run_test 24j "source does not exist ============================"
 
@@ -919,15 +986,15 @@ test_24k() {
        test_mkdir $DIR/R11a/d
        touch $DIR/R11a/f
        mv $DIR/R11a/f $DIR/R11a/d
-        $CHECKSTAT -a $DIR/R11a/f || error
-        $CHECKSTAT -t file $DIR/R11a/d/f || error
+       $CHECKSTAT -a $DIR/R11a/f || error "$DIR/R11a/f exists"
+       $CHECKSTAT -t file $DIR/R11a/d/f || error "$DIR/R11a/d/f not file type"
 }
 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
 
 # bug 2429 - rename foo foo foo creates invalid file
 test_24l() {
        f="$DIR/f24l"
-       $MULTIOP $f OcNs || error
+       $MULTIOP $f OcNs || error "rename of ${f} to itself failed"
 }
 run_test 24l "Renaming a file to itself ========================"
 
@@ -945,10 +1012,10 @@ test_24n() {
     f="$DIR/f24n"
     # this stats the old file after it was renamed, so it should fail
     touch ${f}
-    $CHECKSTAT ${f}
+    $CHECKSTAT ${f} || error "${f} missing"
     mv ${f} ${f}.rename
-    $CHECKSTAT ${f}.rename
-    $CHECKSTAT -a ${f}
+    $CHECKSTAT ${f}.rename || error "${f}.rename missing"
+    $CHECKSTAT -a ${f} || error "${f} exists"
 }
 run_test 24n "Statting the old file after renaming (Posix rename 2)"
 
@@ -963,8 +1030,8 @@ test_24p() {
        test_mkdir $DIR/R12b
        DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
        mrename $DIR/R12a $DIR/R12b
-       $CHECKSTAT -a $DIR/R12a || error
-       $CHECKSTAT -t dir $DIR/R12b || error
+       $CHECKSTAT -a $DIR/R12a || error "$DIR/R12a exists"
+       $CHECKSTAT -t dir $DIR/R12b || error "$DIR/R12b not dir type"
        DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
        [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
 }
@@ -1023,7 +1090,7 @@ test_24t() {
 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
 
 test_24u() { # bug12192
-       $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
+       $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error "multiop failed"
        $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
 }
 run_test 24u "create stripe file"
@@ -1284,13 +1351,14 @@ test_25a() {
 
        test_mkdir $DIR/d25
        ln -s d25 $DIR/s25
-       touch $DIR/s25/foo || error
+       touch $DIR/s25/foo ||
+               error "File creation in symlinked directory failed"
 }
 run_test 25a "create file in symlinked directory ==============="
 
 test_25b() {
        [ ! -d $DIR/d25 ] && test_25a
-       $CHECKSTAT -t file $DIR/s25/foo || error
+       $CHECKSTAT -t file $DIR/s25/foo || error "$DIR/s25/foo not file type"
 }
 run_test 25b "lookup file in symlinked directory ==============="
 
@@ -1298,14 +1366,14 @@ test_26a() {
        test_mkdir $DIR/d26
        test_mkdir $DIR/d26/d26-2
        ln -s d26/d26-2 $DIR/s26
-       touch $DIR/s26/foo || error
+       touch $DIR/s26/foo || error "File creation failed"
 }
 run_test 26a "multiple component symlink ======================="
 
 test_26b() {
        test_mkdir -p $DIR/$tdir/d26-2
        ln -s $tdir/d26-2/foo $DIR/s26-2
-       touch $DIR/s26-2 || error
+       touch $DIR/s26-2 || error "File creation failed"
 }
 run_test 26b "multiple component symlink at end of lookup ======"
 
@@ -1354,7 +1422,7 @@ test_27a() {
        $LFS getstripe $DIR/$tdir
        $LFS setstripe -c 1 $DIR/$tdir/$tfile || error "setstripe failed"
        $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
-       cp /etc/hosts $DIR/$tdir/$tfile || error
+       cp /etc/hosts $DIR/$tdir/$tfile || error "Can't copy to one stripe file"
 }
 run_test 27a "one stripe file"
 
@@ -1479,7 +1547,7 @@ run_test 27m "create file while OST0 was full"
 
 sleep_maxage() {
        local delay=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage |
-                     head -n 1 | awk '{ print $1 * 2 }')
+                     awk '{ print $1 * 2; exit; }')
        sleep $delay
 }
 
@@ -1546,8 +1614,8 @@ test_27n() {
        reset_enospc
        rm -f $DIR/$tdir/$tfile
        exhaust_precreations 0 0x80000215
-       $LFS setstripe -c -1 $DIR/$tdir
-       touch $DIR/$tdir/$tfile || error
+       $LFS setstripe -c -1 $DIR/$tdir || error "setstripe failed"
+       touch $DIR/$tdir/$tfile || error "touch failed"
        $LFS getstripe $DIR/$tdir/$tfile
        reset_enospc
 }
@@ -1627,7 +1695,7 @@ test_27r() {
        rm -f $DIR/$tdir/$tfile
        exhaust_precreations 0 0x80000215
 
-       $LFS setstripe -i 0 -c 2 $DIR/$tdir/$tfile # && error
+       $LFS setstripe -i 0 -c 2 $DIR/$tdir/$tfile || error "setstripe failed"
 
        reset_enospc
 }
@@ -1971,19 +2039,19 @@ run_test 27z "check SEQ/OID on the MDT and OST filesystems"
 
 test_27A() { # b=19102
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
-        local restore_size=$($GETSTRIPE -S $MOUNT)
-        local restore_count=$($GETSTRIPE -c $MOUNT)
-        local restore_offset=$($GETSTRIPE -i $MOUNT)
+
+       save_layout_restore_at_exit $MOUNT
+
         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
         local default_size=$($GETSTRIPE -S $MOUNT)
         local default_offset=$($GETSTRIPE -i $MOUNT)
-        local dsize=$((1024 * 1024))
+       local dsize=$(do_facet $SINGLEMDS \
+               "$LCTL get_param -n lod.$(facet_svc $SINGLEMDS)*.stripesize")
         [ $default_size -eq $dsize ] ||
                 error "stripe size $default_size != $dsize"
         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
-        $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
 }
 run_test 27A "check filesystem-wide default LOV EA values"
 
@@ -2069,10 +2137,10 @@ test_27D() {
 
        local skip27D
        [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ] &&
-               skip27D += "-s 29"
+               skip27D+="-s 29"
        [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.55) -o \
          $(lustre_version_code client) -lt $(version_code 2.9.55) ] &&
-               skip27D += "-s 30,31"
+               skip27D+=" -s 30,31"
        llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT $skip27D ||
                error "llapi_layout_test failed"
 
@@ -2158,7 +2226,7 @@ run_test 27F "Client resend delayed layout creation with non-zero size"
 # then visible correctly (#2091)
 test_28() { # bug 2091
        test_mkdir $DIR/d28
-       $CREATETEST $DIR/d28/ct || error
+       $CREATETEST $DIR/d28/ct || error "createtest failed"
 }
 run_test 28 "create/mknod/mkdir with bad file types ============"
 
@@ -2214,7 +2282,7 @@ run_test 29 "IT_GETATTR regression  ============================"
 
 test_30a() { # was test_30
        cp $(which ls) $DIR || cp /bin/ls $DIR
-       $DIR/ls / || error
+       $DIR/ls / || error "Can't execute binary from lustre"
        rm $DIR/ls
 }
 run_test 30a "execute binary from Lustre (execve) =============="
@@ -2222,7 +2290,7 @@ run_test 30a "execute binary from Lustre (execve) =============="
 test_30b() {
        cp `which ls` $DIR || cp /bin/ls $DIR
        chmod go+rx $DIR/ls
-       $RUNAS $DIR/ls / || error
+       $RUNAS $DIR/ls / || error "Can't execute binary from lustre as non-root"
        rm $DIR/ls
 }
 run_test 30b "execute binary from Lustre as non-root ==========="
@@ -2233,29 +2301,30 @@ test_30c() { # b=22376
        chmod a-rw $DIR/ls
        cancel_lru_locks mdc
        cancel_lru_locks osc
-       $RUNAS $DIR/ls / || error
+       $RUNAS $DIR/ls / || error "Can't execute binary from lustre"
        rm -f $DIR/ls
 }
 run_test 30c "execute binary from Lustre without read perms ===="
 
 test_31a() {
-       $OPENUNLINK $DIR/f31 $DIR/f31 || error
-       $CHECKSTAT -a $DIR/f31 || error
+       $OPENUNLINK $DIR/f31 $DIR/f31 || error "openunlink failed"
+       $CHECKSTAT -a $DIR/f31 || error "$DIR/f31 exists"
 }
 run_test 31a "open-unlink file =================================="
 
 test_31b() {
-       touch $DIR/f31 || error
-       ln $DIR/f31 $DIR/f31b || error
-       $MULTIOP $DIR/f31b Ouc || error
-       $CHECKSTAT -t file $DIR/f31 || error
+       touch $DIR/f31 || error "touch $DIR/f31 failed"
+       ln $DIR/f31 $DIR/f31b || error "ln failed"
+       $MULTIOP $DIR/f31b Ouc || error "multiop failed"
+       $CHECKSTAT -t file $DIR/f31 || error "$DIR/f31 not file type"
 }
 run_test 31b "unlink file with multiple links while open ======="
 
 test_31c() {
-       touch $DIR/f31 || error
-       ln $DIR/f31 $DIR/f31c || error
-       multiop_bg_pause $DIR/f31 O_uc || return 1
+       touch $DIR/f31 || error "touch $DIR/f31 failed"
+       ln $DIR/f31 $DIR/f31c || error "ln failed"
+       multiop_bg_pause $DIR/f31 O_uc ||
+               error "multiop_bg_pause for $DIR/f31 failed"
        MULTIPID=$!
        $MULTIOP $DIR/f31c Ouc
        kill -USR1 $MULTIPID
@@ -2264,13 +2333,13 @@ test_31c() {
 run_test 31c "open-unlink file with multiple links ============="
 
 test_31d() {
-       opendirunlink $DIR/d31d $DIR/d31d || error
-       $CHECKSTAT -a $DIR/d31d || error
+       opendirunlink $DIR/d31d $DIR/d31d || error "opendirunlink failed"
+       $CHECKSTAT -a $DIR/d31d || error "$DIR/d31d exists"
 }
 run_test 31d "remove of open directory ========================="
 
 test_31e() { # bug 2904
-       openfilleddirunlink $DIR/d31e || error
+       openfilleddirunlink $DIR/d31e || error "openfilleddirunlink failed"
 }
 run_test 31e "remove of open non-empty directory ==============="
 
@@ -2431,7 +2500,7 @@ test_31p() {
 
        test_mkdir $DIR/$tdir
        $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
-       $LFS setdirstripe -D -c2 -t all_char $DIR/$tdir/striped_dir
+       $LFS setdirstripe -D -c2 -H all_char $DIR/$tdir/striped_dir
 
        opendirunlink $DIR/$tdir/striped_dir/test1 ||
                error "open unlink test1 failed"
@@ -2461,8 +2530,10 @@ test_32a() {
        [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
        trap cleanup_test32_mount EXIT
        test_mkdir -p $DIR/$tdir/ext2-mountpoint
-       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
-       $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
+       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
+               error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
+       $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. ||
+               error "$DIR/$tdir/ext2-mountpoint/.. not dir type"
        cleanup_test32_mount
 }
 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
@@ -2472,8 +2543,10 @@ test_32b() {
        [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
        trap cleanup_test32_mount EXIT
        test_mkdir -p $DIR/$tdir/ext2-mountpoint
-       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
-       ls -al $DIR/$tdir/ext2-mountpoint/.. || error
+       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
+               error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
+       ls -al $DIR/$tdir/ext2-mountpoint/.. ||
+               error "Can't list $DIR/$tdir/ext2-mountpoint/.."
        cleanup_test32_mount
 }
 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
@@ -2483,9 +2556,11 @@ test_32c() {
        [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
        trap cleanup_test32_mount EXIT
        test_mkdir -p $DIR/$tdir/ext2-mountpoint
-       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
+       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
+               error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
        test_mkdir -p $DIR/$tdir/d2/test_dir
-       $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
+       $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir ||
+               error "$DIR/$tdir/ext2-mountpoint/../d2/test_dir not dir type"
        cleanup_test32_mount
 }
 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
@@ -2495,9 +2570,11 @@ test_32d() {
        [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
        trap cleanup_test32_mount EXIT
        test_mkdir -p $DIR/$tdir/ext2-mountpoint
-       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
+       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
+               error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
        test_mkdir -p $DIR/$tdir/d2/test_dir
-       ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
+       ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir ||
+               error "Can't list $DIR/$tdir/ext2-mountpoint/../d2/test_dir"
        cleanup_test32_mount
 }
 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir"
@@ -2554,9 +2631,11 @@ test_32i() {
        [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
        trap cleanup_test32_mount EXIT
        test_mkdir -p $DIR/$tdir/ext2-mountpoint
-       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
+       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
+               error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
        touch $DIR/$tdir/test_file
-       $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
+       $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file ||
+               error "$DIR/$tdir/ext2-mountpoint/../test_file not file type"
        cleanup_test32_mount
 }
 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
@@ -2566,9 +2645,11 @@ test_32j() {
        [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
        trap cleanup_test32_mount EXIT
        test_mkdir -p $DIR/$tdir/ext2-mountpoint
-       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
+       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
+               error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
        touch $DIR/$tdir/test_file
-       cat $DIR/$tdir/ext2-mountpoint/../test_file || error
+       cat $DIR/$tdir/ext2-mountpoint/../test_file ||
+               error "Can't open $DIR/$tdir/ext2-mountpoint/../test_file"
        cleanup_test32_mount
 }
 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
@@ -2578,10 +2659,12 @@ test_32k() {
        rm -fr $DIR/$tdir
        trap cleanup_test32_mount EXIT
        test_mkdir -p $DIR/$tdir/ext2-mountpoint
-       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
+       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
+               error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
        test_mkdir -p $DIR/$tdir/d2
-       touch $DIR/$tdir/d2/test_file || error
-       $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
+       touch $DIR/$tdir/d2/test_file || error "touch failed"
+       $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file ||
+               error "$DIR/$tdir/ext2-mountpoint/../d2/test_file not file type"
        cleanup_test32_mount
 }
 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
@@ -2591,10 +2674,12 @@ test_32l() {
        rm -fr $DIR/$tdir
        trap cleanup_test32_mount EXIT
        test_mkdir -p $DIR/$tdir/ext2-mountpoint
-       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
+       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
+               error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
        test_mkdir -p $DIR/$tdir/d2
-       touch $DIR/$tdir/d2/test_file
-       cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
+       touch $DIR/$tdir/d2/test_file || error "touch failed"
+       cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file ||
+               error "Can't open $DIR/$tdir/ext2-mountpoint/../d2/test_file"
        cleanup_test32_mount
 }
 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
@@ -2605,8 +2690,10 @@ test_32m() {
        TMP_DIR=$DIR/d32m/tmp
        ln -s $DIR $TMP_DIR/symlink11
        ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
-       $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
-       $CHECKSTAT -t link $DIR/d32m/symlink01 || error
+       $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 ||
+               error "symlink11 not a link"
+       $CHECKSTAT -t link $DIR/d32m/symlink01 ||
+               error "symlink01 not a link"
 }
 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
 
@@ -2616,8 +2703,8 @@ test_32n() {
        TMP_DIR=$DIR/d32n/tmp
        ln -s $DIR $TMP_DIR/symlink11
        ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
-       ls -l $DIR/d32n/tmp/symlink11  || error
-       ls -l $DIR/d32n/symlink01 || error
+       ls -l $DIR/d32n/tmp/symlink11  || error "listing symlink11"
+       ls -l $DIR/d32n/symlink01 || error "listing symlink01"
 }
 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
 
@@ -2627,10 +2714,13 @@ test_32o() {
        TMP_DIR=$DIR/d32o/tmp
        ln -s $DIR/$tfile $TMP_DIR/symlink12
        ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
-       $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
-       $CHECKSTAT -t link $DIR/d32o/symlink02 || error
-       $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
-       $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
+       $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 ||
+               error "symlink12 not a link"
+       $CHECKSTAT -t link $DIR/d32o/symlink02 || error "symlink02 not a link"
+       $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 ||
+               error "$DIR/d32o/tmp/symlink12 not file type"
+       $CHECKSTAT -t file -f $DIR/d32o/symlink02 ||
+               error "$DIR/d32o/symlink02 not file type"
 }
 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
 
@@ -2650,9 +2740,10 @@ test_32p() {
        log 32p_7
        ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
        log 32p_8
-       cat $DIR/d32p/tmp/symlink12 || error
+       cat $DIR/d32p/tmp/symlink12 ||
+               error "Can't open $DIR/d32p/tmp/symlink12"
        log 32p_9
-       cat $DIR/d32p/symlink02 || error
+       cat $DIR/d32p/symlink02 || error "Can't open $DIR/d32p/symlink02"
        log 32p_10
 }
 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
@@ -2662,8 +2753,9 @@ test_32q() {
        [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
        trap cleanup_test32_mount EXIT
        test_mkdir -p $DIR/$tdir/ext2-mountpoint
-       touch $DIR/$tdir/ext2-mountpoint/under_the_mount
-       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
+       touch $DIR/$tdir/ext2-mountpoint/under_the_mount || error "touch failed"
+       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
+               error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
        ls $DIR/$tdir/ext2-mountpoint | grep "\<under_the_mount\>" && error
        cleanup_test32_mount
 }
@@ -2674,8 +2766,9 @@ test_32r() {
        [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
        trap cleanup_test32_mount EXIT
        test_mkdir -p $DIR/$tdir/ext2-mountpoint
-       touch $DIR/$tdir/ext2-mountpoint/under_the_mount
-       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
+       touch $DIR/$tdir/ext2-mountpoint/under_the_mount || error "touch failed"
+       mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint ||
+               error "mount failed for $EXT2_DEV $DIR/$tdir/ext2-mountpoint"
        ls $DIR/$tdir/ext2-mountpoint | grep -q under_the_mount && error || true
        cleanup_test32_mount
 }
@@ -2862,7 +2955,7 @@ test_33f() {
        do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=-1
        trap cleanup_33f EXIT
 
-       $RUNAS lfs mkdir -c$MDSCOUNT $DIR/$tdir/striped_dir ||
+       $RUNAS lfs mkdir -i 0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
                error "cannot create striped directory"
 
        $RUNAS touch $DIR/$tdir/striped_dir/{0..16} ||
@@ -2890,47 +2983,59 @@ run_test 33g "nonroot user create already existing root created file"
 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
 test_34a() {
        rm -f $DIR/f34
-       $MCREATE $DIR/f34 || error
-       $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
-       $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
-       $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
-       $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
+       $MCREATE $DIR/f34 || error "mcreate failed"
+       $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" ||
+               error "getstripe failed"
+       $TRUNCATE $DIR/f34 $TEST_34_SIZE || error "truncate failed"
+       $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" ||
+               error "getstripe failed"
+       $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
+               error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
 }
 run_test 34a "truncate file that has not been opened ==========="
 
 test_34b() {
        [ ! -f $DIR/f34 ] && test_34a
-       $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
+       $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
+               error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
        $OPENFILE -f O_RDONLY $DIR/f34
-       $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
-       $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
+       $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" ||
+               error "getstripe failed"
+       $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
+               error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
 }
 run_test 34b "O_RDONLY opening file doesn't create objects ====="
 
 test_34c() {
        [ ! -f $DIR/f34 ] && test_34a
-       $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
+       $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
+               error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
        $OPENFILE -f O_RDWR $DIR/f34
        $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
-       $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
+       $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
+               error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
 }
 run_test 34c "O_RDWR opening file-with-size works =============="
 
 test_34d() {
        [ ! -f $DIR/f34 ] && test_34a
-       dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
-       $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
+       dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 ||
+               error "dd failed"
+       $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 ||
+               error "Size of $DIR/f34 not equal to $TEST_34_SIZE bytes"
        rm $DIR/f34
 }
 run_test 34d "write to sparse file ============================="
 
 test_34e() {
        rm -f $DIR/f34e
-       $MCREATE $DIR/f34e || error
-       $TRUNCATE $DIR/f34e 1000 || error
-       $CHECKSTAT -s 1000 $DIR/f34e || error
+       $MCREATE $DIR/f34e || error "mcreate failed"
+       $TRUNCATE $DIR/f34e 1000 || error "truncate failed"
+       $CHECKSTAT -s 1000 $DIR/f34e ||
+               error "Size of $DIR/f34e not equal to 1000 bytes"
        $OPENFILE -f O_RDWR $DIR/f34e
-       $CHECKSTAT -s 1000 $DIR/f34e || error
+       $CHECKSTAT -s 1000 $DIR/f34e ||
+               error "Size of $DIR/f34e not equal to 1000 bytes"
 }
 run_test 34e "create objects, some with size and some without =="
 
@@ -2938,7 +3043,7 @@ test_34f() { # bug 6242, 6243
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        SIZE34F=48000
        rm -f $DIR/f34f
-       $MCREATE $DIR/f34f || error
+       $MCREATE $DIR/f34f || error "mcreate failed"
        $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
        dd if=$DIR/f34f of=$TMP/f34f
        $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
@@ -2951,18 +3056,20 @@ run_test 34f "read from a file with no objects until EOF ======="
 
 test_34g() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
-       dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
-       $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
-       $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
+       dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE ||
+               error "dd failed"
+       $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error "truncate failed"
+       $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile ||
+               error "Size of $DIR/$tfile not equal to $((TEST_34_SIZE / 2))"
        cancel_lru_locks osc
-       $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
+       $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile ||
                error "wrong size after lock cancel"
 
-       $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
-       $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
+       $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error "truncate failed"
+       $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile ||
                error "expanding truncate failed"
        cancel_lru_locks osc
-       $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
+       $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile ||
                error "wrong expanded size after lock cancel"
 }
 run_test 34g "truncate long file ==============================="
@@ -2972,7 +3079,7 @@ test_34h() {
        local gid=10
        local sz=1000
 
-       dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
+       dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error "dd failed"
        sync # Flush the cache so that multiop below does not block on cache
             # flush when getting the group lock
        $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
@@ -3006,13 +3113,13 @@ run_test 35a "exec file with mode 444 (should return and not leak)"
 
 test_36a() {
        rm -f $DIR/f36
-       utime $DIR/f36 || error
+       utime $DIR/f36 || error "utime failed for MDS"
 }
 run_test 36a "MDS utime check (mknod, utime)"
 
 test_36b() {
        echo "" > $DIR/f36
-       utime $DIR/f36 || error
+       utime $DIR/f36 || error "utime failed for OST"
 }
 run_test 36b "OST utime check (open, utime)"
 
@@ -3020,14 +3127,14 @@ test_36c() {
        rm -f $DIR/d36/f36
        test_mkdir $DIR/d36
        chown $RUNAS_ID $DIR/d36
-       $RUNAS utime $DIR/d36/f36 || error
+       $RUNAS utime $DIR/d36/f36 || error "utime failed for MDS as non-root"
 }
 run_test 36c "non-root MDS utime check (mknod, utime)"
 
 test_36d() {
        [ ! -d $DIR/d36 ] && test_36c
        echo "" > $DIR/d36/f36
-       $RUNAS utime $DIR/d36/f36 || error
+       $RUNAS utime $DIR/d36/f36 || error "utime failed for OST as non-root"
 }
 run_test 36d "non-root OST utime check (open, utime)"
 
@@ -4590,6 +4697,8 @@ test_56b() {
 run_test 56b "check $LFS getdirstripe"
 
 test_56c() {
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
+
        local ost_idx=0
        local ost_name=$(ostname_from_index $ost_idx)
        local old_status=$(ost_dev_status $ost_idx)
@@ -4950,11 +5059,11 @@ test_56t() { # LU-611 #LU-9369
 
        setup_56 $dir 0 $NUMDIRS
        for i in $(seq $NUMDIRS); do
-               $LFS setstripe -S 4M $dir/dir$i/$tfile
+               $LFS setstripe -S 8M $dir/dir$i/$tfile
        done
 
        local expected=$NUMDIRS
-       local cmd="$LFS find -S 4M $dir"
+       local cmd="$LFS find -S 8M $dir"
        local nums=$($cmd | wc -l)
 
        [ $nums -eq $expected ] || {
@@ -5200,9 +5309,7 @@ test_56wb() {
        echo "done."
 
        echo -n "Detecting existing pools..."
-       while IFS='' read thispool; do
-               pool_list+=("$thispool")
-       done < <($LFS pool_list $MOUNT | awk -F '.' 'NR>=2 { print $2 }')
+       pool_list=($($LFS pool_list $FSNAME | grep "$FSNAME\." | cut -d. -f2))
 
        if [ ${#pool_list[@]} -gt 0 ]; then
                echo "${pool_list[@]}"
@@ -5268,6 +5375,7 @@ test_56wc() {
 
        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"
        echo "done"
@@ -5332,7 +5440,7 @@ test_56wc() {
        echo -n "Verifying restripe option uses parent stripe settings..."
        $LFS_MIGRATE -y -R "$file1" &> /dev/null ||
                error "migrate failed"
-       [ $($LFS getstripe -S "$file1") -eq 1048576 ] ||
+       [ $($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"
@@ -5343,11 +5451,12 @@ 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)
        $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 1048576 ] ||
+       [ $($LFS getstripe -S "$file1") -eq $orig_stripe_size ] ||
                error "file was restriped"
        echo "done."
 
@@ -5532,6 +5641,9 @@ check_migrate_links() {
 }
 
 test_56xb() {
+       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
+               skip "Need MDS version at least 2.10.55" && return
+
        local dir="$DIR/$tdir"
 
        test_mkdir "$dir" || error "cannot create dir $dir"
@@ -5620,19 +5732,42 @@ test_56aa() { # LU-5937
        $LFS setdirstripe -c$MDSCOUNT $dir/striped_dir
 
        createmany -o $dir/striped_dir/${tfile}- 1024
-       local dirs=$(lfs find --size +8k $dir/)
+       local dirs=$($LFS find --size +8k $dir/)
 
        [ -n "$dirs" ] || error "lfs find --size wrong under striped dir"
 }
 run_test 56aa "lfs find --size under striped dir"
 
+test_56ab() { # LU-10705
+       test_mkdir $DIR/$tdir
+       dd if=/dev/zero of=$DIR/$tdir/$tfile.1 bs=8k count=1 seek=2k
+       dd if=/dev/zero of=$DIR/$tdir/$tfile.2 bs=4k count=1 seek=4k
+       dd if=/dev/zero of=$DIR/$tdir/$tfile.3 bs=1M count=2 seek=16
+       # Flush writes to ensure valid blocks.  Need to be more thorough for
+       # ZFS, since blocks are not allocated/returned to client immediately.
+       sync_all_data
+       wait_zfs_commit ost1 2
+       cancel_lru_locks osc
+       ls -ls $DIR/$tdir
+
+       local files=$($LFS find --size +16M $DIR/$tdir | wc -l)
+
+       [[ $files == 3 ]] || error ">16M size files $files isn't 3 as expected"
+
+       files=$($LFS find --blocks +1M $DIR/$tdir | wc -l)
+       [[ $files == 1 ]] || error ">1M blocks files $files isn't 1 as expected"
+
+       rm -f $DIR/$tdir/$tfile.[123]
+}
+run_test 56ab "lfs find --blocks"
+
 test_56ba() {
        # Create composite files with one component
        local dir=$DIR/$tdir
 
-       setup_56 $dir/1Mfiles 5 1 "--component-end 1M"
+       setup_56 $dir/1Mfiles 5 1 "-S 1M --component-end 1M"
        # Create composite files with three components
-       setup_56 $dir/2Mfiles 5 2 "-E 2M -E 4M -E 6M"
+       setup_56 $dir/2Mfiles 5 2 "-E 2M -S 1M -E 4M -E 6M"
        # Create non-composite files
        createmany -o $dir/${tfile}- 10
 
@@ -5688,6 +5823,80 @@ test_56ba() {
 }
 run_test 56ba "test lfs find --component-end, -start, -count, and -flags"
 
+test_56ca() {
+       [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.57) ]] ||
+               { skip "Need MDS version at least 2.10.57"; return 0; }
+
+       local td=$DIR/$tdir
+       local tf=$td/$tfile
+       local dir
+       local nfiles
+       local cmd
+       local i
+       local j
+
+       # create mirrored directories and mirrored files
+       mkdir $td || error "mkdir $td failed"
+       $LFS mirror create -N3 $td || error "create mirrored dir $td failed"
+       createmany -o $tf- 10 || error "create $tf- failed"
+
+       for i in $(seq 2); do
+               dir=$td/dir$i
+               mkdir $dir || error "mkdir $dir failed"
+               $LFS mirror create -N$((3 + i)) $dir ||
+                       error "create mirrored dir $dir failed"
+               createmany -o $dir/$tfile- 10 ||
+                       error "create $dir/$tfile- failed"
+       done
+
+       # change the states of some mirrored files
+       echo foo > $tf-6
+       for i in $(seq 2); do
+               dir=$td/dir$i
+               for j in $(seq 4 9); do
+                       echo foo > $dir/$tfile-$j
+               done
+       done
+
+       # find mirrored files with specific mirror count
+       cmd="$LFS find --mirror-count 3 --type f $td"
+       nfiles=$($cmd | wc -l)
+       [[ $nfiles = 10 ]] || error "$cmd: $nfiles != 10 files"
+
+       cmd="$LFS find ! --mirror-count 3 --type f $td"
+       nfiles=$($cmd | wc -l)
+       [[ $nfiles = 20 ]] || error "$cmd: $nfiles != 20 files"
+
+       cmd="$LFS find --mirror-count +2 --type f $td"
+       nfiles=$($cmd | wc -l)
+       [[ $nfiles = 30 ]] || error "$cmd: $nfiles != 30 files"
+
+       cmd="$LFS find --mirror-count -6 --type f $td"
+       nfiles=$($cmd | wc -l)
+       [[ $nfiles = 30 ]] || error "$cmd: $nfiles != 30 files"
+
+       # find mirrored files with specific file state
+       cmd="$LFS find --maxdepth 1 --mirror-state=^ro --type f $td"
+       [[ $($cmd) = $tf-6 ]] || error "$cmd: didn't return $tf-6"
+
+       cmd="$LFS find --mirror-state=ro --type f $td"
+       nfiles=$($cmd | wc -l)
+       [[ $nfiles = 17 ]] || error "$cmd: $nfiles != 17 files"
+
+       cmd="$LFS find ! --mirror-state=ro --type f $td"
+       nfiles=$($cmd | wc -l)
+       [[ $nfiles = 13 ]] || error "$cmd: $nfiles != 13 files"
+
+       cmd="$LFS find --mirror-state=wp --type f $td"
+       nfiles=$($cmd | wc -l)
+       [[ $nfiles = 13 ]] || error "$cmd: $nfiles != 13 files"
+
+       cmd="$LFS find ! --mirror-state=sp --type f $td"
+       nfiles=$($cmd | wc -l)
+       [[ $nfiles = 30 ]] || error "$cmd: $nfiles != 30 files"
+}
+run_test 56ca "check lfs find --mirror-count|-N and --mirror-state"
+
 test_57a() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        # note test will not do anything if MDS is not local
@@ -5881,6 +6090,8 @@ test_60a() {
 run_test 60a "llog_test run from kernel module and test llog_reader"
 
 test_60aa() {
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && return
+
        # test old logid format
        if [ $(lustre_version_code mgs) -le $(version_code 3.1.53) ]; then
                do_facet mgs $LCTL dl | grep MGS
@@ -6122,6 +6333,9 @@ test_64d() {
                [[ $? -ne 0 ]] && break;
                sleep 2
        done
+
+       rm -f $DIR/$tfile
+       wait_delete_completed
        $LCTL set_param debug="$olddebug" 2> /dev/null || true
 }
 run_test 64d "check grant limit exceed"
@@ -6226,44 +6440,55 @@ test_65h() {
 }
 run_test 65h "directory stripe info inherit ===================="
 
-test_65i() { # bug6367
+test_65i() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
-        $SETSTRIPE -S 65536 -c -1 $MOUNT
-}
-run_test 65i "set non-default striping on root directory (bug 6367)="
 
-test_65ia() { # bug12836
-       [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
-       $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
-}
-run_test 65ia "getstripe on -1 default directory striping"
+       save_layout_restore_at_exit $MOUNT
 
-test_65ib() { # bug12836
-       [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
-       $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
-}
-run_test 65ib "getstripe -v on -1 default directory striping"
+       # bug6367: set non-default striping on root directory
+       $LFS setstripe -S 65536 -c -1 $MOUNT || error "error setting stripe"
 
-test_65ic() { # bug12836
-       [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+       # bug12836: getstripe on -1 default directory striping
+       $LFS getstripe $MOUNT || error "getstripe $MOUNT failed"
+
+       # bug12836: getstripe -v on -1 default directory striping
+       $LFS getstripe -v $MOUNT || error "getstripe -v $MOUNT failed"
+
+       # bug12836: new find on -1 default directory striping
        $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
 }
-run_test 65ic "new find on -1 default directory striping"
+run_test 65i "various tests to set root directory striping"
 
 test_65j() { # bug6367
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
-       [ $($LFS getstripe --component-count $MOUNT) -gt 1 ] &&
-               skip "don't delete default PFL layout" && return
+
        sync; sleep 1
+
        # if we aren't already remounting for each test, do so for this test
        if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
                cleanup || error "failed to unmount"
                setup
        fi
+
+       save_layout_restore_at_exit $MOUNT
+
        $SETSTRIPE -d $MOUNT || error "setstripe failed"
 }
 run_test 65j "set default striping on root directory (bug 6367)="
 
+cleaup_65k() {
+       rm -rf $DIR/$tdir
+       wait_delete_completed
+       do_facet $SINGLEMDS "lctl set_param -n \
+               osp.$ost*MDT0000.max_create_count=$max_count"
+       do_facet $SINGLEMDS "lctl set_param -n \
+               osp.$ost*MDT0000.create_count=$count"
+       do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
+       echo $INACTIVE_OSC "is Activate"
+
+       wait_osc_import_state mds ost$ostnum FULL
+}
+
 test_65k() { # bug11679
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
@@ -6307,7 +6532,8 @@ test_65k() { # bug11679
                        [ -f $DIR/$tdir/$idx ] && continue
                        echo "$SETSTRIPE -i $idx -c 1 $DIR/$tdir/$idx"
                        $SETSTRIPE -i $idx -c 1 $DIR/$tdir/$idx ||
-                               error "setstripe $idx should succeed"
+                               { cleanup_65k;
+                                 error "setstripe $idx should succeed"; }
                        rm -f $DIR/$tdir/$idx || error "rm $idx failed"
                done
                unlinkmany $DIR/$tdir/$tfile.$ostnum. 1000
@@ -6334,7 +6560,11 @@ test_65l() { # bug 12836
 run_test 65l "lfs find on -1 stripe dir ========================"
 
 test_65m() {
-       $RUNAS $SETSTRIPE -c 2 $MOUNT && error "setstripe should fail"
+       local layout=$(save_layout $MOUNT)
+       $RUNAS $SETSTRIPE -c 2 $MOUNT && {
+               restore_layout $MOUNT $layout
+               error "setstripe should fail by non-root users"
+       }
        true
 }
 run_test 65m "normal user can't set filesystem default stripe"
@@ -6635,6 +6865,8 @@ cleanup_77c() {
 }
 
 test_77c() {
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
+
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        $GSS && skip "could not run with gss" && return
 
@@ -7376,6 +7608,8 @@ test_101g_brw_size_test() {
 }
 
 test_101g() {
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
+
        local rpcs
        local osts=$(get_facets OST)
        local list=$(comma_list $(osts_nodes))
@@ -10033,6 +10267,27 @@ test_130e() {
 }
 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
 
+test_130f() {
+       filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
+       [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
+               return
+
+       local fm_file=$DIR/$tfile
+       $MULTIOP $fm_file oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T33554432c ||
+               error "multiop create with lov_delay_create on $fm_file"
+
+       filefrag -ves $fm_file || error "filefrag $fm_file failed"
+       filefrag_extents=$(filefrag -vek $fm_file |
+                          awk '/extents? found/ { print $2 }')
+       if [[ "$filefrag_extents" != "0" ]]; then
+               error "FIEMAP on $fm_file failed; " \
+                     "returned $filefrag_extents expected 0"
+       fi
+
+       rm -f $fm_file
+}
+run_test 130f "FIEMAP (unstriped file)"
+
 # Test for writev/readv
 test_131a() {
        rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 ||
@@ -10393,8 +10648,6 @@ run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
 proc_regexp="/{proc,sys}/{fs,sys,kernel/debug}/{lustre,lnet}/"
 
 test_133f() {
-       remote_mds_nodsh && skip "remote MDS with nodsh" && return
-       remote_ost_nodsh && skip "remote OST with nodsh" && return
        # First without trusting modes.
        local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
        echo "proc_dirs='$proc_dirs'"
@@ -10404,10 +10657,27 @@ test_133f() {
        # Second verifying readability.
        $LCTL get_param -R '*' &> /dev/null || error "proc file read failed"
 
+       # 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 "find $proc_dirs failed"
+}
+run_test 133f "Check reads/writes of client lustre proc files with bad area io"
+
+test_133g() {
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
+
        # eventually, this can also be replaced with "lctl get_param -R",
        # but not until that option is always available on the server
        local facet
        for facet in mds1 ost1; do
+               [ $(lustre_version_code $facet) -le $(version_code 2.5.54) ] &&
+                       skip "Too old lustre on $facet" && continue
                local facet_proc_dirs=$(do_facet $facet \
                                        \\\ls -d $proc_regexp 2>/dev/null)
                echo "${facet}_proc_dirs='$facet_proc_dirs'"
@@ -10421,33 +10691,7 @@ test_133f() {
                        -type f \
                        -exec cat '{}' \\\; &> /dev/null ||
                                error "proc file read failed"
-       done
-}
-run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
-
-test_133g() {
-       remote_mds_nodsh && skip "remote MDS with nodsh" && return
-       remote_ost_nodsh && skip "remote OST with nodsh" && return
-       # Second verifying writability.
-       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 \
-               -ignore_readdir_race \
-               -type f \
-               -not -name force_lbug \
-               -not -name changelog_mask \
-               -exec badarea_io '{}' \; ||
-               error "find $proc_dirs failed"
 
-       local facet
-       for facet in mds1 ost1; do
-               [ $(lustre_version_code $facet) -le $(version_code 2.5.54) ] &&
-                       skip "Too old lustre on $facet" && continue
-               local facet_proc_dirs=$(do_facet $facet \
-                                       \\\ls -d $proc_regexp 2> /dev/null)
-               echo "${facet}_proc_dirs='$facet_proc_dirs'"
-               [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
                do_facet $facet find $facet_proc_dirs \
                        -ignore_readdir_race \
                        -type f \
@@ -10462,7 +10706,7 @@ test_133g() {
        setup || error "failed to setup"
        true
 }
-run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
+run_test 133g "Check reads/writes of server lustre proc files with bad area io"
 
 test_133h() {
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
@@ -10815,11 +11059,9 @@ dot_lustre_fid_permission_check() {
        rm -f $test_dir/$tfile.1
        echo "truncate fid $fid"
        $TRUNCATE $ffid 777 || error "truncate $ffid failed."
-       if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
-               echo "link fid $fid"
-               ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
-       fi
-       if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
+       echo "link fid $fid"
+       ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
+       if [[ $($LCTL get_param -n mdc.*-mdc-*.connect_flags) =~ acl ]]; then
                echo "setfacl fid $fid"
                setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
                echo "getfacl fid $fid"
@@ -10974,6 +11216,8 @@ test_154a() {
        dot_lustre_fid_permission_check "$fid" $DIR ||
                error "dot lustre permission check $fid failed"
 
+       ls -a $MOUNT | grep "\.lustre" && error ".lustre should not be listed"
+
        rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
 
        touch $MOUNT/.lustre/file &&
@@ -11491,141 +11735,122 @@ 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 $*
-       else
-               error $*
-       fi
-}
-
-changelog_chmask()
-{
-       local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
-
-       MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
-
-       if [ $MASK -eq 1 ]; then
-               do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
-       else
-               do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
-       fi
-}
-
-changelog_extract_field() {
-       local mdt=$1
-       local cltype=$2
-       local file=$3
-       local identifier=$4
-
-       $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
-               print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
-               tail -1
-}
-
 test_160a() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
                { skip "Need MDS version at least 2.2.0"; return; }
 
-       local CL_USERS="mdd.$MDT0.changelog_users"
-       local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_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"
+       changelog_register || error "changelog_register failed"
+       local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
+       changelog_users $SINGLEMDS | grep -q $cl_user ||
+               error "User $cl_user not found in changelog_users"
 
        # change something
        test_mkdir -p $DIR/$tdir/pics/2008/zachy
-       touch $DIR/$tdir/pics/2008/zachy/timestamp
-       cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
+       changelog_clear 0 || error "changelog_clear failed"
+       touch $DIR/$tdir/pics/2008/zachy/$tfile                 # open 1
+       cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg       # open 2
        mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
        ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
        ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
        rm $DIR/$tdir/pics/desktop.jpg
 
-       $LFS changelog $MDT0 | tail -5
+       changelog_dump | tail -10
 
        echo "verifying changelog mask"
-       changelog_chmask "MKDIR"
-       changelog_chmask "CLOSE"
+       changelog_chmask "-MKDIR"
+       changelog_chmask "-CLOSE"
 
-       test_mkdir -p $DIR/$tdir/pics/zach/sofia
-       echo "zzzzzz" > $DIR/$tdir/pics/zach/file
+       test_mkdir -p $DIR/$tdir/pics/zach/sofia                # not logged
+       echo "zzzzzz" > $DIR/$tdir/pics/zach/file               # not logged
 
-       changelog_chmask "MKDIR"
-       changelog_chmask "CLOSE"
+       changelog_chmask "+MKDIR"
+       changelog_chmask "+CLOSE"
 
-       test_mkdir -p $DIR/$tdir/pics/2008/sofia
-       echo "zzzzzz" > $DIR/$tdir/pics/zach/file
+       test_mkdir -p $DIR/$tdir/pics/2008/sofia                # mkdir 1
+       echo "zzzzzz" > $DIR/$tdir/pics/zach/file               # open 3
 
-       $LFS changelog $MDT0
-       MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
-       CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
-       [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
-       [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
+       changelog_dump | tail -10
+       MKDIRS=$(changelog_dump | grep -c "MKDIR")
+       CLOSES=$(changelog_dump | grep -c "CLOSE")
+       [ $MKDIRS -eq 1 ] || error "MKDIR changelog mask count $MKDIRS != 1"
+       [ $CLOSES -eq 3 ] || error "CLOSE changelog mask count $CLOSES != 3"
 
        # verify contents
        echo "verifying target fid"
-       fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
-       fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
+       local fidc=$(changelog_extract_field "CREAT" "$tfile" "t=")
+       local fidf=$($LFS path2fid $DIR/$tdir/pics/zach/$tfile)
        [ "$fidc" == "$fidf" ] ||
-               err17935 "fid in changelog $fidc != file fid $fidf"
+               error "changelog '$tfile' fid $fidc != file fid $fidf"
        echo "verifying parent fid"
-       fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
-       fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
-       [ "$fidc" == "$fidf" ] ||
-               err17935 "pfid in changelog $fidc != dir fid $fidf"
-
-       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"
-
-       MIN_REC=$($GET_CL_USERS |
-               awk 'min == "" || $2 < min {min = $2}; END {print min}')
-       FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
-       echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
-       [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
-               err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
+       # The FID returned from the Changelog may be the directory shard on
+       # a different MDT, and not the FID returned by path2fid on the parent.
+       # Instead of comparing FIDs, verify that fid2path(fidp) is correct,
+       # since this is what will matter when recreating this file in the tree.
+       local fidp=$(changelog_extract_field "CREAT" "$tfile" "p=")
+       local pathp=$($LFS fid2path $MOUNT "$fidp")
+       [ "${pathp%/}" == "$DIR/$tdir/pics/zach" ] ||
+               error "changelog fid2path($fidc) $pathp != $DIR/$tdir/pics/zach"
+
+       echo "getting records for $cl_user"
+       changelog_users $SINGLEMDS
+       local user_rec1=$(changelog_user_rec $SINGLEMDS $cl_user)
+       local nclr=3
+       __changelog_clear $SINGLEMDS $cl_user +$nclr ||
+               error "changelog_clear failed"
+       local user_rec2=$(changelog_user_rec $SINGLEMDS $cl_user)
+       echo "verifying user clear: $user_rec1 + $nclr == $user_rec2"
+       [ $user_rec2 == $((user_rec1 + nclr)) ] ||
+               error "user index expect $user_rec1 + $nclr != $user_rec2"
+
+       local min0_rec=$(changelog_users $SINGLEMDS |
+               awk 'min == "" || $2 < min { min = $2 }; END { print min }')
+       local first_rec=$($LFS changelog $(facet_svc $SINGLEMDS) |
+                         awk '{ print $1; exit; }')
+
+       changelog_dump | tail -n 5
+       echo "verifying user min purge: $min0_rec + 1 == $first_rec"
+       [ $first_rec == $((min0_rec + 1)) ] ||
+               error "first index should be $min0_rec + 1 not $first_rec"
 
        # 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 $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' ')
-       echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
-       [ $CUR_REC1 == $CUR_REC2 ] ||
-               err17935 "current index should be $CUR_REC1 is $CUR_REC2"
-
-       echo "verifying user deregister"
-       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 [ $CL_USER -eq 0 ]; then
-               LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
+       local cur_rec1=$(changelog_users $SINGLEMDS |
+                        awk '/^current.index:/ { print $NF }')
+       changelog_clear 0 ||
+               error "clear all changelog records for $cl_user failed"
+       stop $SINGLEMDS || error "Fail to stop $SINGLEMDS"
+       start $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) $MDS_MOUNT_OPTS ||
+               error "Fail to start $SINGLEMDS"
+       local cur_rec2=$(changelog_users $SINGLEMDS |
+                        awk '/^current.index:/ { print $NF }')
+       echo "verifying index survives MDT restart: $cur_rec1 == $cur_rec2"
+       [ $cur_rec1 == $cur_rec2 ] ||
+               error "current index should be $cur_rec1 not $cur_rec2"
+
+       echo "verifying users from this test are deregistered"
+       changelog_deregister || error "changelog_deregister failed"
+       changelog_users $SINGLEMDS | grep -q $cl_user &&
+               error "User '$cl_user' still in changelog_users"
+
+       # lctl get_param -n mdd.*.changelog_users
+       # current index: 144
+       # ID    index (idle seconds)
+       # cl3   144 (2)
+       if ! changelog_users $SINGLEMDS | grep "^cl"; then
+               # this is the normal case where all users were deregistered
+               # make sure no new records are added when no users are present
+               local last_rec1=$(changelog_users $SINGLEMDS |
+                                 awk '/^current.index:/ { print $NF }')
                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"
+               local last_rec2=$(changelog_users $SINGLEMDS |
+                                 awk '/^current.index:/ { print $NF }')
+               echo "verify changelogs are off: $last_rec1 == $last_rec2"
+               [ $last_rec1 == $last_rec2 ] || error "changelogs not off"
        else
-               echo "$CL_USER other changelog users; can't verify off"
+               # any changelog users must be leftovers from a previous test
+               changelog_users $SINGLEMDS
+               echo "other changelog users; can't verify off"
        fi
 }
 run_test 160a "changelog sanity"
@@ -11636,27 +11861,22 @@ test_160b() { # LU-3587
        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
                { skip "Need MDS version at least 2.2.0"; return; }
 
-       local CL_USERS="mdd.$MDT0.changelog_users"
-       local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_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"
+       changelog_register || error "changelog_register failed"
+       local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
+       changelog_users $SINGLEMDS | 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)
+       local longname1=$(str_repeat a 255)
+       local longname2=$(str_repeat b 255)
 
        cd $DIR
        echo "creating very long named file"
-       touch $LONGNAME1 || error "create of $LONGNAME1 failed"
-       echo "moving very long named file"
-       mv $LONGNAME1 $LONGNAME2
+       touch $longname1 || error "create of '$longname1' failed"
+       echo "renaming very long named file"
+       mv $longname1 $longname2
 
-       $LFS changelog $MDT0 | grep RENME
-       rm -f $LONGNAME2
-       cleanup_changelog
+       changelog_dump | grep RENME | tail -n 5
+       rm -f $longname2
 }
 run_test 160b "Verify that very long rename doesn't crash in changelog"
 
@@ -11673,24 +11893,18 @@ test_160c() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
 
        # Registration step
-       CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
-               changelog_register -n)
-       trap cleanup_changelog EXIT
+       changelog_register || error "changelog_register failed"
 
        rm -rf $DIR/$tdir
        mkdir -p $DIR/$tdir
        $MCREATE $DIR/$tdir/foo_160c
-       changelog_chmask "TRUNC"
+       changelog_chmask "-TRUNC"
        $TRUNCATE $DIR/$tdir/foo_160c 200
-       changelog_chmask "TRUNC"
+       changelog_chmask "+TRUNC"
        $TRUNCATE $DIR/$tdir/foo_160c 199
-       $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 $CL_USER 0
-
-       # Deregistration step
-       cleanup_changelog
+       changelog_dump | tail -n 5
+       local truncs=$(changelog_dump | tail -n 5 | grep -c TRUNC)
+       [ $truncs -eq 1 ] || error "TRUNC changelog mask count $truncs != 1"
 }
 run_test 160c "verify that changelog log catch the truncate event"
 
@@ -11698,30 +11912,20 @@ test_160d() {
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
 
-       local server_version=$(lustre_version_code mds1)
-       local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
-
-       [[ $server_version -ge $(version_code 2.7.60) ]] ||
+       [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.60) ]] ||
                { skip "Need MDS version at least 2.7.60+"; return; }
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
 
        # Registration step
-       CL_USER=$(do_facet mds1 $LCTL --device $MDT0 \
-               changelog_register -n)
+       changelog_register || error "changelog_register failed"
 
-       trap cleanup_changelog EXIT
        mkdir -p $DIR/$tdir/migrate_dir
-       $LFS changelog_clear $MDT0 $CL_USER 0
+       changelog_clear 0 || error "changelog_clear failed"
 
        $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 $CL_USER 0
-       [ $MIGRATES -eq 1 ] ||
-               error "MIGRATE changelog mask count $MIGRATES != 1"
-
-       # Deregistration step
-       cleanup_changelog
+       changelog_dump | tail -n 5
+       local migrates=$(changelog_dump | grep -c "MIGRT")
+       [ $migrates -eq 1 ] || error "MIGRATE changelog count $migrates != 1"
 }
 run_test 160d "verify that changelog log catch the migrate event"
 
@@ -11729,24 +11933,21 @@ test_160e() {
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
 
        # Create a user
-       CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
-               changelog_register -n)
-       echo "Registered as changelog user $CL_USER"
-       trap cleanup_changelog EXIT
+       changelog_register || error "changelog_register failed"
 
        # Delete a future user (expect fail)
-       do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister cl77
+       local MDT0=$(facet_svc $SINGLEMDS)
+       do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister "cl77"
        local rc=$?
 
        if [ $rc -eq 0 ]; then
                error "Deleted non-existant user cl77"
        elif [ $rc -ne 2 ]; then
-               error "changelog_deregister failed with $rc, " \
-                       "expected 2 (ENOENT)"
+               error "changelog_deregister failed with $rc, expect 2 (ENOENT)"
        fi
 
        # Clear to a bad index (1 billion should be safe)
-       $LFS changelog_clear $MDT0 $CL_USER 1000000000
+       $LFS changelog_clear $MDT0 "${CL_USERS[$SINGLEMDS]%% *}" 1000000000
        rc=$?
 
        if [ $rc -eq 0 ]; then
@@ -11755,77 +11956,58 @@ test_160e() {
                error "changelog_clear failed with $rc, expected 22 (EINVAL)"
        fi
 }
-run_test 160e "changelog negative testing"
-
-cleanup_160f() {
-       trap 0
-       do_facet $SINGLEMDS $LCTL set_param fail_loc=0 fail_val=0
-       echo "Deregistering changelog client $CL_USER"
-       do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
-       echo "Deregistering changelog client $CL_USER2"
-       do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER2
-       restore_lustre_params < $save_params
-       rm -f $save_params
-}
+run_test 160e "changelog negative testing (should return errors)"
 
 test_160f() {
-       # do_facet $SINGLEMDS $LCTL set_param mdd.$MDT0.changelog_gc=1
-       # should be set by default
-
-       local CL_USERS="mdd.$MDT0.changelog_users"
-       local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
-       local save_params="$TMP/sanity-$TESTNAME.parameters"
-
-       save_lustre_params $SINGLEMDS \
-               "mdd.$MDT0.changelog_max_idle_time" > $save_params
-       save_lustre_params $SINGLEMDS \
-               "mdd.$MDT0.changelog_min_gc_interval" >> $save_params
-       save_lustre_params $SINGLEMDS \
-               "mdd.$MDT0.changelog_min_free_cat_entries" >> $save_params
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.56) ]] ||
+               { skip "Need MDS version at least 2.10.56"; return 0; }
 
-       trap cleanup_160f EXIT
+       local mdts=$(comma_list $(mdts_nodes))
 
        # Create a user
-       CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
-               changelog_register -n)
-       echo "Registered as changelog user $CL_USER"
-       CL_USER2=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
-               changelog_register -n)
-       echo "Registered as changelog user $CL_USER2"
-       $GET_CL_USERS | grep -q $CL_USER ||
-               error "User $CL_USER not found in changelog_users"
-       $GET_CL_USERS | grep -q $CL_USER2 ||
-               error "User $CL_USER2 not found in changelog_users"
-
-       # generate some changelogs to accumulate
-       mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
-       touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
-       touch $DIR/$tdir/${tfile}2 || error "touch $DIR/$tdir/${tfile}2 failed"
-       rm -f $DIR/$tdir/$tfile || error "rm -f $tfile failed"
+       changelog_register || error "first changelog_register failed"
+       changelog_register || error "second changelog_register failed"
+       local cl_users=(${CL_USERS[$SINGLEMDS]})
+       local cl_user1="${cl_users[0]}"
+       local cl_user2="${cl_users[1]}"
+
+       # generate some changelog records to accumulate on each MDT
+       test_mkdir -c $MDSCOUNT $DIR/$tdir || error "test_mkdir $tdir failed"
+       createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
+               error "create $DIR/$tdir/$tfile failed"
 
        # check changelogs have been generated
-       nbcl=$($LFS changelog $MDT0 | wc -l)
+       nbcl=$(changelog_dump | wc -l)
        [[ $nbcl -eq 0 ]] && error "no changelogs found"
 
-       do_facet $SINGLEMDS $LCTL set_param \
-               mdd.$MDT0.changelog_max_idle_time=10
-       do_facet $SINGLEMDS $LCTL set_param \
-               mdd.$MDT0.changelog_min_gc_interval=2
-       do_facet $SINGLEMDS $LCTL set_param \
-               mdd.$MDT0.changelog_min_free_cat_entries=3
+       # changelog_gc=1 should be set by default
+       for param in "changelog_max_idle_time=10" \
+                    "changelog_min_gc_interval=2" \
+                    "changelog_min_free_cat_entries=3"; do
+               local MDT0=$(facet_svc $SINGLEMDS)
+               local var="${param%=*}"
+               local old=$(do_facet mds1 "$LCTL get_param -n mdd.$MDT0.$var")
+
+               stack_trap "do_nodes $mdts $LCTL set_param mdd.*.$var=$old" EXIT
+               do_nodes $mdts $LCTL set_param mdd.*.$param
+       done
 
        # simulate changelog catalog almost full
-#define OBD_FAIL_CAT_FREE_RECORDS                  0x1313
-       do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1313
-       do_facet $SINGLEMDS $LCTL set_param fail_val=3
+       #define OBD_FAIL_CAT_FREE_RECORDS       0x1313
+       do_nodes $mdts $LCTL set_param fail_loc=0x1313 fail_val=3
 
        sleep 6
-       USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$CL_USER\" {print \$2}")
-       $LFS changelog_clear $MDT0 $CL_USER $(($USER_REC1 + 2))
-       USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$CL_USER\" {print \$2}")
-       echo "verifying user clear: $(( $USER_REC1 + 2 )) == $USER_REC2"
-       [ $USER_REC2 == $(($USER_REC1 + 2)) ] ||
-               error "user index expected $(($USER_REC1 + 2)) is $USER_REC2"
+       local user_rec1=$(changelog_user_rec $SINGLEMDS $cl_user1)
+       [ -n "$user_rec1" ] ||
+               error "User $cl_user1 not found in changelog_users"
+       __changelog_clear $SINGLEMDS $cl_user1 +2
+       local user_rec2=$(changelog_user_rec $SINGLEMDS $cl_user1)
+       [ -n "$user_rec2" ] ||
+               error "User $cl_user1 not found in changelog_users"
+       echo "verifying user clear: $user_rec1 + 2 == $user_rec2"
+       [ $((user_rec1 + 2)) == $user_rec2 ] ||
+               error "user index expected $user_rec1 + 2, but is $user_rec2"
        sleep 5
 
        # generate one more changelog to trigger fail_loc
@@ -11836,82 +12018,74 @@ test_160f() {
                          "ps -e -o comm= | grep chlg_gc_thread" "" 20
 
        # check user still registered
-       $GET_CL_USERS | grep -q $CL_USER ||
-               error "User $CL_USER not found in changelog_users"
+       changelog_users $SINGLEMDS | grep -q "$cl_user1" ||
+               error "User $cl_user1 not found in changelog_users"
        # check user2 unregistered
-       $GET_CL_USERS | grep -q $CL_USER2 &&
-               error "User $CL_USER2 still found in changelog_users"
+       changelog_users $SINGLEMDS | grep -q "$cl_user2" &&
+               error "User $cl_user2 still found in changelog_users"
 
-       # check changelogs are present and starting at $USER_REC2 + 1
-       FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
-       echo "verifying min purge: $(( $USER_REC2 + 1 )) == $FIRST_REC"
-       [ $FIRST_REC == $(($USER_REC2 + 1)) ] ||
-               error "first index should be $(($USER_REC2 + 1)) is $FIRST_REC"
+       # check changelogs are present and starting at $user_rec2 + 1
+       local first_rec=$($LFS changelog $(facet_svc $SINGLEMDS) |
+                         awk '{ print $1; exit; }')
 
-       cleanup_160f
+       echo "verifying min purge: $user_rec2 + 1 == $first_rec"
+       [ $((user_rec2 + 1)) == $first_rec ] ||
+               error "first index should be $user_rec2 + 1, but is $first_rec"
 }
 run_test 160f "changelog garbage collect (timestamped users)"
 
 test_160g() {
-       # do_facet $SINGLEMDS $LCTL set_param mdd.$MDT0.changelog_gc=1
-       # should be set by default
-
-       local CL_USERS="mdd.$MDT0.changelog_users"
-       local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
-       local save_params="$TMP/sanity-$TESTNAME.parameters"
-
-       save_lustre_params $SINGLEMDS \
-               "mdd.$MDT0.changelog_max_idle_indexes" > $save_params
-       save_lustre_params $SINGLEMDS \
-               "mdd.$MDT0.changelog_min_gc_interval" >> $save_params
-       save_lustre_params $SINGLEMDS \
-               "mdd.$MDT0.changelog_min_free_cat_entries" >> $save_params
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.56) ]] ||
+               { skip "Need MDS version at least 2.10.56"; return 0; }
 
-       trap cleanup_160f EXIT
+       local mdts=$(comma_list $(mdts_nodes))
 
-#define OBD_FAIL_TIME_IN_CHLOG_USER                 0x1314
-       do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1314
+       #define OBD_FAIL_TIME_IN_CHLOG_USER     0x1314
+       do_nodes $mdts $LCTL set_param fail_loc=0x1314
 
        # Create a user
-       CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
-               changelog_register -n)
-       echo "Registered as changelog user $CL_USER"
-       CL_USER2=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
-               changelog_register -n)
-       echo "Registered as changelog user $CL_USER2"
-       $GET_CL_USERS | grep -q $CL_USER ||
-               error "User $CL_USER not found in changelog_users"
-       $GET_CL_USERS | grep -q $CL_USER2 ||
-               error "User $CL_USER2 not found in changelog_users"
-
-       # generate some changelogs to accumulate
-       mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
-       touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
-       touch $DIR/$tdir/${tfile}2 || error "touch $DIR/$tdir/${tfile}2 failed"
-       rm -f $DIR/$tdir/$tfile || error "rm -f $tfile failed"
+       changelog_register || error "first changelog_register failed"
+       changelog_register || error "second changelog_register failed"
+       local cl_users=(${CL_USERS[$SINGLEMDS]})
+       local cl_user1="${cl_users[0]}"
+       local cl_user2="${cl_users[1]}"
+
+       # generate some changelog records to accumulate on each MDT
+       test_mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
+       createmany -m $DIR/$tdir/$tfile $((MDSCOUNT * 2)) ||
+               error "create $DIR/$tdir/$tfile failed"
 
        # check changelogs have been generated
-       nbcl=$($LFS changelog $MDT0 | wc -l)
+       nbcl=$(changelog_dump | wc -l)
        [[ $nbcl -eq 0 ]] && error "no changelogs found"
 
-       do_facet $SINGLEMDS $LCTL set_param \
-               mdd.$MDT0.changelog_max_idle_indexes=$((nbcl - 1))
-       do_facet $SINGLEMDS $LCTL set_param \
-               mdd.$MDT0.changelog_min_gc_interval=2
-       do_facet $SINGLEMDS $LCTL set_param \
-               mdd.$MDT0.changelog_min_free_cat_entries=3
+       # changelog_gc=1 should be set by default
+       for param in "changelog_max_idle_indexes=$((nbcl / 2))" \
+                    "changelog_min_gc_interval=2" \
+                    "changelog_min_free_cat_entries=3"; do
+               local MDT0=$(facet_svc $SINGLEMDS)
+               local var="${param%=*}"
+               local old=$(do_facet mds1 "$LCTL get_param -n mdd.$MDT0.$var")
+
+               stack_trap "do_nodes $mdts $LCTL set_param mdd.*.$var=$old" EXIT
+               do_nodes $mdts $LCTL set_param mdd.*.$param ||
+                       error "unable to set mdd.*.$param"
+       done
 
        # simulate changelog catalog almost full
-#define OBD_FAIL_CAT_FREE_RECORDS                  0x1313
-       do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1313
-       do_facet $SINGLEMDS $LCTL set_param fail_val=3
+       #define OBD_FAIL_CAT_FREE_RECORDS       0x1313
+       do_nodes $mdts $LCTL set_param fail_loc=0x1313 fail_val=3
+
+       local user_rec1=$(changelog_user_rec $SINGLEMDS $cl_user1)
+
+       __changelog_clear $SINGLEMDS $cl_user1 +3
 
-       USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$CL_USER\" {print \$2}")
-       $LFS changelog_clear $MDT0 $CL_USER $(($USER_REC1 + 3))
-       USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$CL_USER\" {print \$2}")
-       echo "verifying user clear: $(( $USER_REC1 + 3 )) == $USER_REC2"
-       [ $USER_REC2 == $(($USER_REC1 + 3)) ] ||
-               error "user index expected $(($USER_REC1 + 3)) is $USER_REC2"
+       local user_rec2=$(changelog_user_rec $SINGLEMDS $cl_user1)
+
+       echo "verifying user clear: $user_rec1 + 3 == $user_rec2"
+       [ $((user_rec1 + 3)) == $user_rec2 ] ||
+               error "user index expected $user_rec1 + 3, but is $user_rec2"
 
        # generate one more changelog to trigger fail_loc
        rm -rf $DIR/$tdir || error "rm -rf $tdir failed"
@@ -11921,19 +12095,19 @@ test_160g() {
                          "ps -e -o comm= | grep chlg_gc_thread" "" 20
 
        # check user still registered
-       $GET_CL_USERS | grep -q $CL_USER ||
-               error "User $CL_USER not found in changelog_users"
+       [ -n "$(changelog_user_rec $SINGLEMDS $cl_user1)" ] ||
+               error "User $cl_user1 not found in changelog_users"
        # check user2 unregistered
-       $GET_CL_USERS | grep -q $CL_USER2 &&
-               error "User $CL_USER2 still found in changelog_users"
+       [ -z "$(changelog_user_rec $SINGLEMDS $cl_user2)" ] ||
+               error "User $cl_user2 still found in changelog_users"
 
-       # check changelogs are present and starting at $USER_REC2 + 1
-       FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
-       echo "verifying min purge: $(( $USER_REC2 + 1 )) == $FIRST_REC"
-       [ $FIRST_REC == $(($USER_REC2 + 1)) ] ||
-               error "first index should be $(($USER_REC2 + 1)) is $FIRST_REC"
+       # check changelogs are present and starting at $user_rec2 + 1
+       local first_rec=$($LFS changelog $(facet_svc $SINGLEMDS) |
+                         awk '{ print $1; exit; }')
 
-       cleanup_160f
+       echo "verifying min purge: $user_rec2 + 1 == $first_rec"
+       [ $((user_rec2 + 1)) == $first_rec ] ||
+               error "first index should be $user_rec2 + 1, but is $first_rec"
 }
 run_test 160g "changelog garbage collect (old users)"
 
@@ -11950,33 +12124,29 @@ test_161a() {
        local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
        if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
                $LFS fid2path $DIR $FID
-               err17935 "bad link ea"
+               error "bad link ea"
        fi
-    # middle
-    rm $DIR/$tdir/foo2/zachary
-    # last
-    rm $DIR/$tdir/foo2/thor
-    # first
-    rm $DIR/$tdir/$tfile
-    # rename
-    mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
-    if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
-       then
-       $LFS fid2path $DIR $FID
-       err17935 "bad link rename"
-    fi
-    rm $DIR/$tdir/foo2/maggie
+       # middle
+       rm $DIR/$tdir/foo2/zachary
+       # last
+       rm $DIR/$tdir/foo2/thor
+       # first
+       rm $DIR/$tdir/$tfile
+       # rename
+       mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
+       [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ] &&
+               { $LFS fid2path $DIR $FID; error "bad link rename"; }
+       rm $DIR/$tdir/foo2/maggie
 
        # overflow the EA
-       local longname=filename_avg_len_is_thirty_two_
+       local longname=$tfile.avg_len_is_thirty_two_
+       stack_trap "unlinkmany $DIR/$tdir/foo2/$longname 1000 || \
+               error_noexit 'failed to unlink many hardlinks'" EXIT
        createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
                error "failed to hardlink many files"
        links=$($LFS fid2path $DIR $FID | wc -l)
        echo -n "${links}/1000 links in link EA"
-       [[ $links -gt 60 ]] ||
-               err17935 "expected at least 60 links in link EA"
-       unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
-               error "failed to unlink many hardlinks"
+       [[ $links -gt 60 ]] || error "expected at least 60 links in link EA"
 }
 run_test 161a "link ea sanity"
 
@@ -12002,7 +12172,7 @@ test_161b() {
                     tr -d ']')
        if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
                $LFS fid2path $DIR $FID
-               err17935 "bad link ea"
+               error "bad link ea"
        fi
        # middle
        rm $remote_dir/foo2/zachary
@@ -12015,7 +12185,7 @@ test_161b() {
        local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
        if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
                $LFS fid2path $DIR $FID
-               err17935 "bad link rename"
+               error "bad link rename"
        fi
        rm $remote_dir/foo2/maggie
 
@@ -12026,7 +12196,7 @@ test_161b() {
        links=$($LFS fid2path $DIR $FID | wc -l)
        echo -n "${links}/1000 links in link EA"
        [[ ${links} -gt 60 ]] ||
-               err17935 "expected at least 60 links in link EA"
+               error "expected at least 60 links in link EA"
        unlinkmany $remote_dir/foo2/$longname 1000 ||
        error "failed to unlink many hardlinks"
 }
@@ -12040,33 +12210,29 @@ test_161c() {
 
        # define CLF_RENAME_LAST 0x0001
        # rename overwrite a target having nlink = 1 (changelog flag 0x1)
-       CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
-               changelog_register -n)
+       changelog_register || error "changelog_register failed"
 
-       trap cleanup_changelog EXIT
        rm -rf $DIR/$tdir
-       mkdir -p $DIR/$tdir
+       test_mkdir -i $((MDSCOUNT - 1)) $DIR/$tdir
        touch $DIR/$tdir/foo_161c
        touch $DIR/$tdir/bar_161c
        mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
-       $LFS changelog $MDT0 | grep RENME
-       local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
-               cut -f5 -d' ')
-       $LFS changelog_clear $MDT0 $CL_USER 0
+       changelog_dump | grep RENME | tail -n 5
+       local flags=$(changelog_dump | grep "RENME.*bar_161c" | cut -f5 -d' ')
+       changelog_clear 0 || error "changelog_clear failed"
        if [ x$flags != "x0x1" ]; then
                error "flag $flags is not 0x1"
        fi
-       echo "rename overwrite a target having nlink = 1," \
-               "changelog record has flags of $flags"
 
+       echo "rename overwrite target with nlink = 1, changelog flags=$flags"
        # rename overwrite a target having nlink > 1 (changelog flag 0x0)
        touch $DIR/$tdir/foo_161c
        touch $DIR/$tdir/bar_161c
        ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_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 $CL_USER 0
+       changelog_dump | grep RENME | tail -n 5
+       flags=$(changelog_dump | grep "RENME.*bar_161c" | cut -f5 -d' ')
+       changelog_clear 0 || error "changelog_clear failed"
        if [ x$flags != "x0x0" ]; then
                error "flag $flags is not 0x0"
        fi
@@ -12076,9 +12242,9 @@ test_161c() {
        # rename doesn't overwrite a target (changelog flag 0x0)
        touch $DIR/$tdir/foo_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 $CL_USER 0
+       changelog_dump | grep RENME | tail -n 5
+       flags=$(changelog_dump | grep RENME | tail -1 | cut -f5 -d' ')
+       changelog_clear 0 || error "changelog_clear failed"
        if [ x$flags != "x0x0" ]; then
                error "flag $flags is not 0x0"
        fi
@@ -12088,9 +12254,9 @@ test_161c() {
        # define CLF_UNLINK_LAST 0x0001
        # unlink a file having nlink = 1 (changelog flag 0x1)
        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 $CL_USER 0
+       changelog_dump | grep UNLNK | tail -n 5
+       flags=$(changelog_dump | grep UNLNK | tail -1 | cut -f5 -d' ')
+       changelog_clear 0 || error "changelog_clear failed"
        if [ x$flags != "x0x1" ]; then
                error "flag $flags is not 0x1"
        fi
@@ -12100,29 +12266,23 @@ test_161c() {
        # unlink a file having nlink > 1 (changelog flag 0x0)
        ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_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 $CL_USER 0
+       changelog_dump | grep UNLNK | tail -n 5
+       flags=$(changelog_dump | grep UNLNK | tail -1 | cut -f5 -d' ')
+       changelog_clear 0 || error "changelog_clear failed"
        if [ x$flags != "x0x0" ]; then
                error "flag $flags is not 0x0"
        fi
-       echo "unlink a file having nlink > 1," \
-               "changelog record has flags of $flags"
-       cleanup_changelog
+       echo "unlink a file having nlink > 1, changelog record flags '$flags'"
 }
 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
 
 test_161d() {
-       local user
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+
        local pid
        local fid
 
-       # cleanup previous run
-       rm -rf $DIR/$tdir/$tfile
-
-       user=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
-               changelog_register -n)
-       [[ $? -eq 0 ]] || error "changelog_register failed"
+       changelog_register || error "changelog_register failed"
 
        # work in a standalone dir to avoid locking on $DIR/$MOUNT to
        # interfer with $MOUNT/.lustre/fid/ access
@@ -12145,7 +12305,7 @@ test_161d() {
        [[ $? -eq 0 ]] || error "create should be blocked"
 
        local tempfile=$(mktemp)
-       fid=$(changelog_extract_field $MDT0 "CREAT" "$tfile" "t=")
+       fid=$(changelog_extract_field "CREAT" "$tfile" "t=")
        cat $MOUNT/.lustre/fid/$fid 2>/dev/null >$tempfile || error "cat failed"
        # some delay may occur during ChangeLog publishing and file read just
        # above, that could allow file write to happen finally
@@ -12155,35 +12315,28 @@ test_161d() {
 
        wait $pid
        [[ $? -eq 0 ]] || error "create failed"
-
-       $LFS changelog_clear $MDT0 $user 0
-       do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $user
 }
 run_test 161d "create with concurrent .lustre/fid access"
 
 check_path() {
-    local expected=$1
-    shift
-    local fid=$2
+       local expected="$1"
+       shift
+       local fid="$2"
 
-    local path=$(${LFS} fid2path $*)
-    # Remove the '//' indicating a remote directory
-    path=$(echo $path | sed 's#//#/#g')
-    RC=$?
+       local path
+       path=$($LFS fid2path "$@")
+       local rc=$?
 
-    if [ $RC -ne 0 ]; then
-       err17935 "path looked up of $expected failed. Error $RC"
-       return $RC
-    elif [ "${path}" != "${expected}" ]; then
-       err17935 "path looked up \"${path}\" instead of \"${expected}\""
-       return 2
-    fi
-    echo "fid $fid resolves to path $path (expected $expected)"
+       if [ $rc -ne 0 ]; then
+               error "path looked up of '$expected' failed: rc=$rc"
+       elif [ "$path" != "$expected" ]; then
+               error "path looked up '$path' instead of '$expected'"
+       else
+               echo "FID '$fid' resolves to path '$path' as expected"
+       fi
 }
 
 test_162a() { # was test_162
-       # Make changes to filesystem
-       [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        test_mkdir -p -c1 $DIR/$tdir/d2
        touch $DIR/$tdir/d2/$tfile
        touch $DIR/$tdir/d2/x1
@@ -12191,43 +12344,34 @@ test_162a() { # was test_162
        test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
        test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
        # regular file
-       FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
-       check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
-               error "check path $tdir/d2/$tfile failed"
+       local fid=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
+       check_path "$tdir/d2/$tfile" $FSNAME "$fid" --link 0
 
        # softlink
        ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
-       FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
-       check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
-               error "check path $tdir/d2/p/q/r/slink failed"
+       fid=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
+       check_path "$tdir/d2/p/q/r/slink" $FSNAME "$fid" --link 0
 
        # softlink to wrong file
        ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
-       FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
-       check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
-               error "check path $tdir/d2/p/q/r/slink.wrong failed"
+       fid=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
+       check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME "$fid" --link 0
 
        # hardlink
        ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
        mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
-       FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
+       fid=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
        # fid2path dir/fsname should both work
-       check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
-               error "check path $tdir/d2/a/b/c/new_file failed"
-       check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
-               error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
+       check_path "$tdir/d2/a/b/c/new_file" $FSNAME "$fid" --link 1
+       check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR "$fid" --link 0
 
        # hardlink count: check that there are 2 links
-       # Doesnt work with CMD yet: 17935
-       ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
-               err17935 "expected 2 links"
+       local nlinks=$($LFS fid2path $DIR "$fid" | wc -l)
+       [ $nlinks -eq 2 ] || error "expect 2 links, found $nlinks"
 
        # hardlink indexing: remove the first link
        rm $DIR/$tdir/d2/p/q/r/hlink
-       check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
-               error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
-
-       return 0
+       check_path "$tdir/d2/a/b/c/new_file" $FSNAME $fid --link 0
 }
 run_test 162a "path lookup sanity"
 
@@ -12236,7 +12380,7 @@ test_162b() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
 
        mkdir $DIR/$tdir
-       $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
+       $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
                                error "create striped dir failed"
 
        local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
@@ -12250,13 +12394,11 @@ test_162b() {
        for ((i=0;i<5;i++)); do
                FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
                        error "get fid for f$i failed"
-               check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
-                       error "check path $tdir/striped_dir/f$i failed"
+               check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0
 
                FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
                        error "get fid for d$i failed"
-               check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
-                       error "check path $tdir/striped_dir/d$i failed"
+               check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0
        done
 
        return 0
@@ -12277,15 +12419,13 @@ test_162c() {
                mkdir $DIR/$lpath
                FID=$($LFS path2fid $DIR/$lpath | tr -d '[]') ||
                        error "get fid for local directory $DIR/$lpath failed"
-               check_path "$DIR/$lpath" $MOUNT $FID --link 0 ||
-                       error "check path 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 ||
-                       error "check path for remote directory $DIR/$rpath failed"
+               check_path "$DIR/$rpath" $MOUNT $FID --link 0
        done
 
        return 0
@@ -12311,16 +12451,17 @@ run_test 169 "parallel read and truncate should not deadlock"
 
 test_170() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
-        $LCTL clear    # bug 18514
-        $LCTL debug_daemon start $TMP/${tfile}_log_good
-        touch $DIR/$tfile
-        $LCTL debug_daemon stop
-        sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
-               error "sed failed to read log_good"
 
-        $LCTL debug_daemon start $TMP/${tfile}_log_good
-        rm -rf $DIR/$tfile
-        $LCTL debug_daemon stop
+       $LCTL clear     # bug 18514
+       $LCTL debug_daemon start $TMP/${tfile}_log_good
+       touch $DIR/$tfile
+       $LCTL debug_daemon stop
+       sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
+               error "sed failed to read log_good"
+
+       $LCTL debug_daemon start $TMP/${tfile}_log_good
+       rm -rf $DIR/$tfile
+       $LCTL debug_daemon stop
 
         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
                error "lctl df log_bad failed"
@@ -12497,8 +12638,7 @@ test_180c() { # LU-2598
        do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
                rmmod_remote=true || error "failed to load module obdecho"
 
-       target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
-               head -n1)
+       target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4; exit; }')
        if [ -n "$target" ]; then
                obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
        else
@@ -13067,18 +13207,10 @@ verify_jobstats() {
 }
 
 jobstats_set() {
-       trap 0
-       NEW_JOBENV=${1:-$OLD_JOBENV}
-       do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
-       wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
-}
+       local new_jobenv=$1
 
-cleanup_205() {
-       trap 0
-       do_facet $SINGLEMDS \
-               $LCTL set_param mdt.*.job_cleanup_interval=$OLD_INTERVAL
-       [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
-       cleanup_changelog
+       do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$new_jobenv
+       wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $new_jobenv
 }
 
 test_205() { # Job stats
@@ -13094,20 +13226,22 @@ test_205() { # Job stats
                skip "Server doesn't support jobstats" && return 0
        [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
 
-       OLD_JOBENV=$($LCTL get_param -n jobid_var)
-       if [ $OLD_JOBENV != $JOBENV ]; then
+       local old_jobenv=$($LCTL get_param -n jobid_var)
+       if [ $old_jobenv != $JOBENV ]; then
                jobstats_set $JOBENV
-               trap cleanup_205 EXIT
+               stack_trap "do_facet mgs \
+                       $LCTL conf_param $FSNAME.sys.jobid_var=$old_jobenv" EXIT
        fi
 
-       CL_USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
-       echo "Registered as changelog user $CL_USER"
+       changelog_register
 
-       OLD_INTERVAL=$(do_facet $SINGLEMDS \
-                      lctl get_param -n mdt.*.job_cleanup_interval)
-       local interval_new=5
+       local old_interval=$(do_facet $SINGLEMDS lctl get_param -n \
+                               mdt.*.job_cleanup_interval | head -n 1)
+       local new_interval=5
        do_facet $SINGLEMDS \
-               $LCTL set_param mdt.*.job_cleanup_interval=$interval_new
+               $LCTL set_param mdt.*.job_cleanup_interval=$new_interval
+       stack_trap "do_facet $SINGLEMDS \
+               $LCTL set_param mdt.*.job_cleanup_interval=$old_interval" EXIT
        local start=$SECONDS
 
        local cmd
@@ -13149,7 +13283,7 @@ test_205() { # Job stats
        cmd="mv -f $DIR/$tfile $DIR/$tdir.rename"
        verify_jobstats "$cmd" "$SINGLEMDS"
        # jobstats expiry - sleep until old stats should be expired
-       local left=$((interval_new + 5 - (SECONDS - start)))
+       local left=$((new_interval + 5 - (SECONDS - start)))
        [ $left -ge 0 ] && wait_update_facet $SINGLEMDS \
                "lctl get_param *.*.job_stats | grep -c 'job_id.*mkdir'" \
                        "0" $left
@@ -13159,10 +13293,9 @@ test_205() { # Job stats
            grep -c "job_id.*mkdir") -gt 1 ] && error "old jobstats not expired"
 
        # Ensure that jobid are present in changelog (if supported by MDS)
-       if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ]
-       then
-               $LFS changelog $MDT0 | tail -9
-               jobids=$($LFS changelog $MDT0 | tail -9 | grep -c "j=")
+       if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ];then
+               changelog_dump | tail -10
+               jobids=$(changelog_dump | tail -9 | grep -c "j=")
                [ $jobids -eq 9 ] ||
                        error "Wrong changelog jobid count $jobids != 9"
 
@@ -13170,13 +13303,11 @@ test_205() { # Job stats
                JOBENV="disable"
                jobstats_set $JOBENV
                touch $DIR/$tfile
-               $LFS changelog $MDT0 | tail -1
-               jobids=$($LFS changelog $MDT0 | tail -1 | grep -c "j=")
+               changelog_dump | grep $tfile
+               jobids=$(changelog_dump | grep $tfile | tail -1 | grep -c "j=")
                [ $jobids -eq 0 ] ||
                        error "Unexpected jobids when jobid_var=$JOBENV"
        fi
-
-       cleanup_205
 }
 run_test 205 "Verify job stats"
 
@@ -13755,26 +13886,23 @@ test_225a () {
              skip_env "mds-survey not found" && return
        fi
 
-       [ $MDSCOUNT -ge 2 ] &&
-               skip "skipping now for more than one MDT" && return
-
-       [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
-            { skip "Need MDS version at least 2.2.51"; return; }
+       [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
+               { skip "Need MDS version at least 2.2.51"; return; }
 
-       local mds=$(facet_host $SINGLEMDS)
-       local target=$(do_nodes $mds 'lctl dl' | \
-                      awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
+       local mds=$(facet_host $SINGLEMDS)
+       local target=$(do_nodes $mds 'lctl dl' |
+                      awk '{ if ($2 == "UP" && $3 == "mdt") { print $4 }}')
 
-       local cmd1="file_count=1000 thrhi=4"
-       local cmd2="dir_count=2 layer=mdd stripe_count=0"
-       local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
-       local cmd="$cmd1 $cmd2 $cmd3"
+       local cmd1="file_count=1000 thrhi=4"
+       local cmd2="dir_count=2 layer=mdd stripe_count=0"
+       local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
+       local cmd="$cmd1 $cmd2 $cmd3"
 
-       rm -f ${TMP}/mds_survey*
-       echo + $cmd
-       eval $cmd || error "mds-survey with zero-stripe failed"
-       cat ${TMP}/mds_survey*
-       rm -f ${TMP}/mds_survey*
+       rm -f ${TMP}/mds_survey*
+       echo + $cmd
+       eval $cmd || error "mds-survey with zero-stripe failed"
+       cat ${TMP}/mds_survey*
+       rm -f ${TMP}/mds_survey*
 }
 run_test 225a "Metadata survey sanity with zero-stripe"
 
@@ -13791,20 +13919,20 @@ test_225b () {
              skip_env "Need to mount OST to test" && return
        fi
 
-       local mds=$(facet_host $SINGLEMDS)
-       local target=$(do_nodes $mds 'lctl dl' | \
-                      awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
+       local mds=$(facet_host $SINGLEMDS)
+       local target=$(do_nodes $mds 'lctl dl' |
+                      awk '{ if ($2 == "UP" && $3 == "mdt") { print $4 }}')
 
-       local cmd1="file_count=1000 thrhi=4"
-       local cmd2="dir_count=2 layer=mdd stripe_count=1"
-       local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
-       local cmd="$cmd1 $cmd2 $cmd3"
+       local cmd1="file_count=1000 thrhi=4"
+       local cmd2="dir_count=2 layer=mdd stripe_count=1"
+       local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
+       local cmd="$cmd1 $cmd2 $cmd3"
 
-       rm -f ${TMP}/mds_survey*
-       echo + $cmd
-       eval $cmd || error "mds-survey with stripe_count failed"
-       cat ${TMP}/mds_survey*
-       rm -f ${TMP}/mds_survey*
+       rm -f ${TMP}/mds_survey*
+       echo + $cmd
+       eval $cmd || error "mds-survey with stripe_count failed"
+       cat ${TMP}/mds_survey*
+       rm -f ${TMP}/mds_survey*
 }
 run_test 225b "Metadata survey sanity with stripe_count = 1"
 
@@ -14558,6 +14686,8 @@ test_232a() {
 run_test 232a "failed lock should not block umount"
 
 test_232b() {
+       [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.58) ] ||
+               { skip "Need MDS version at least 2.10.58"; return; }
        mkdir -p $DIR/$tdir
        $LFS setstripe -c1 -i0 $DIR/$tdir/$tfile
        dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1
@@ -14614,17 +14744,8 @@ test_234() {
        touch $DIR/$tdir/$tfile || error "touch failed"
        # OBD_FAIL_LLITE_XATTR_ENOMEM
        $LCTL set_param fail_loc=0x1405
-       # output of the form: attr 2 4 44 3 fc13 x86_64
-       V=($(IFS=".-" rpm -q attr))
-       if [[ ${V[1]} > 2 || ${V[2]} > 4 || ${V[3]} > 44 ||
-             ${V[1]} = 2 && ${V[2]} = 4 && ${V[3]} = 44 && ${V[4]} > 6 ]]; then
-               # attr pre-2.4.44-7 had a bug with rc
-               # LU-3703 - SLES 11 and FC13 clients have older attr
-               getfattr -n user.attr $DIR/$tdir/$tfile &&
-                       error "getfattr should have failed with ENOMEM"
-       else
-               skip "LU-3703: attr version $(getfattr --version) too old"
-       fi
+       getfattr -n user.attr $DIR/$tdir/$tfile &&
+               error "getfattr should have failed with ENOMEM"
        $LCTL set_param fail_loc=0x0
        rm -rf $DIR/$tdir
 
@@ -14714,7 +14835,7 @@ test_238() {
 }
 run_test 238 "Verify linkea consistency"
 
-test_239() {
+test_239A() { # was test_239
        [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.60) ] &&
                skip "Need MDS version at least 2.5.60" && return
        local list=$(comma_list $(mdts_nodes))
@@ -14728,7 +14849,7 @@ test_239() {
                        osp.*MDT*.sync_in_flight" | calc_sum)
        [ "$changes" -eq 0 ] || error "$changes not synced"
 }
-run_test 239 "osp_sync test"
+run_test 239A "osp_sync test"
 
 test_239a() { #LU-5297
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
@@ -15256,15 +15377,17 @@ test_254() {
 
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
-       do_facet mds1 $LCTL get_param -n mdd.$MDT0.changelog_size ||
+
+       local MDT0=$(facet_svc $SINGLEMDS)
+
+       do_facet $SINGLEMDS $LCTL get_param -n mdd.$MDT0.changelog_size ||
                { skip "MDS does not support changelog_size" && return; }
 
-       cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
-       echo "Registered as changelog user $cl_user"
+       changelog_register || error "changelog_register failed"
 
-       $LFS changelog_clear $MDT0 $cl_user 0
+       changelog_clear 0 || error "changelog_clear failed"
 
-       local size1=$(do_facet mds1 \
+       local size1=$(do_facet $SINGLEMDS \
                      $LCTL get_param -n mdd.$MDT0.changelog_size)
        echo "Changelog size $size1"
 
@@ -15279,16 +15402,12 @@ test_254() {
        ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
        rm $DIR/$tdir/pics/desktop.jpg
 
-       local size2=$(do_facet mds1 \
+       local size2=$(do_facet $SINGLEMDS \
                      $LCTL get_param -n mdd.$MDT0.changelog_size)
        echo "Changelog size after work $size2"
 
-       do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
-
-       if (( size2 <= size1 )); then
-               error "Changelog size after work should be greater than original"
-       fi
-       return 0
+       (( $size2 > $size1 )) ||
+               error "new Changelog size=$size2 less than old size=$size1"
 }
 run_test 254 "Check changelog size"
 
@@ -15493,6 +15612,8 @@ facet_meminfo() {
 }
 
 test_255b() {
+       [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
+               skip "lustre < 2.8.54 does not support ladvise " && return
        remote_ost_nodsh && skip "remote OST with nodsh" && return
 
        lfs setstripe -c 1 -i 0 $DIR/$tfile
@@ -15568,7 +15689,7 @@ test_255c() {
 
        #test 10 returns only success/failure
        i=10
-       lockahead_test -d $DIR/$tdir -t $i
+       lockahead_test -d $DIR/$tdir -t $i -f $tfile
        rc=$?
        if [ $rc -eq 255 ]; then
                error "Ladvise test${i} failed, ${rc}"
@@ -15580,7 +15701,7 @@ test_255c() {
                $LCTL get_param -n ost.OSS.ost.stats)
        count=$(echo "$count" | grep ldlm_extent_enqueue | awk '{ print $2 }')
 
-       lockahead_test -d $DIR/$tdir -t $i
+       lockahead_test -d $DIR/$tdir -t $i -f $tfile
        rc=$?
        if [ $rc -eq 255 ]; then
                error "Ladvise test${i} failed, ${rc}"
@@ -15606,7 +15727,7 @@ test_255c() {
                count=$($LCTL get_param -n \
                       ldlm.namespaces.$FSNAME-OST0000*osc-f*.lock_unused_count)
 
-               lockahead_test -d $DIR/$tdir -t $i
+               lockahead_test -d $DIR/$tdir -t $i -f $tfile
                rc=$?
                if [ $rc -eq 255 ]; then
                        error "Ladvise test ${i} failed, ${rc}"
@@ -15629,12 +15750,11 @@ test_255c() {
 
        #test 22 returns only success/failure
        i=22
-       lockahead_test -d $DIR/$tdir -t $i
+       lockahead_test -d $DIR/$tdir -t $i -f $tfile
        rc=$?
        if [ $rc -eq 255 ]; then
                error "Ladvise test${i} failed, ${rc}"
        fi
-
 }
 run_test 255c "suite of ladvise lockahead tests"
 
@@ -15645,65 +15765,51 @@ test_256() {
 
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        remote_mds_nodsh && skip "remote MDS with nodsh" && return
-       [ "$(facet_fstype mds1)" != "ldiskfs" ] &&
+       [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
                skip "ldiskfs only test" && return
 
        mdt_dev=$(mdsdevname 1)
        echo $mdt_dev
-       cl_user=$(do_facet mds1 \
-       "$LCTL get_param -n mdd.$MDT0.changelog_users | grep cl")
-       if [[ -n $cl_user ]]; then
-               skip "active changelog user"
-               return
-       fi
+       changelog_users $SINGLEMDS | grep "^cl" &&
+               skip "active changelog user" && return
 
-       cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
-       echo "Registered as changelog user $cl_user"
+       changelog_register || error "changelog_register failed"
 
        rm -rf $DIR/$tdir
        mkdir -p $DIR/$tdir
 
-       $LFS changelog_clear $MDT0 $cl_user 0
+       changelog_clear 0 || error "changelog_clear failed"
 
        # change something
        touch $DIR/$tdir/{1..10}
 
        # stop the MDT
-       stop mds1 || error "Fail to stop MDT."
+       stop $SINGLEMDS || error "Fail to stop MDT"
 
        # remount the MDT
-       start mds1 $mdt_dev $MDS_MOUNT_OPTS || error "Fail to start MDT."
+
+       start $SINGLEMDS $mdt_dev $MDS_MOUNT_OPTS || error "Fail to start MDT"
 
        #after mount new plainllog is used
        touch $DIR/$tdir/{11..19}
-       do_facet mds1 sync
-       local TEMP256FILE=$(mktemp -u TEMP256XXXXXX)
-       cat_sl=$(do_facet mds1 \
-       "$DEBUGFS -R \\\"dump changelog_catalog $TEMP256FILE\\\" $mdt_dev; \
-        llog_reader $TEMP256FILE | grep \\\"type=1064553b\\\" | wc -l")
-       do_facet mds1 rm $TEMP256FILE
-
-       if (( cat_sl != 2 )); then
-               do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
-               error "Changelog catalog has wrong number of slots $cat_sl"
-       fi
+       local tmpfile=$(mktemp -u $tfile.XXXXXX)
+       cat_sl=$(do_facet $SINGLEMDS "sync; \
+                $DEBUGFS -c -R 'dump changelog_catalog $tmpfile' $mdt_dev; \
+                llog_reader $tmpfile | grep -c type=1064553b")
+       do_facet $SINGLEMDS llog_reader $tmpfile
 
-       $LFS changelog_clear $MDT0 $cl_user 0
+       [ $cat_sl != 2 ] && error "Changelog catalog has $cat_sl != 2 slots"
 
-       do_facet mds1 sync
-       TEMP256FILE=$(mktemp -u TEMP256XXXXXX)
-       cat_sl=$(do_facet mds1 \
-       "$DEBUGFS -R \\\"dump changelog_catalog $TEMP256FILE\\\" $mdt_dev; \
-        llog_reader $TEMP256FILE | grep \\\"type=1064553b\\\" | wc -l")
-       do_facet mds1 rm $TEMP256FILE
+       changelog_clear 0 || error "changelog_clear failed"
 
-       do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
+       cat_sl=$(do_facet $SINGLEMDS "sync; \
+                $DEBUGFS -c -R 'dump changelog_catalog $tmpfile' $mdt_dev; \
+                llog_reader $tmpfile | grep -c type=1064553b; rm -f $tmpfile")
 
        if (( cat_sl == 2 )); then
                error "Empty plain llog was not deleted from changelog catalog"
-       fi
-       if (( cat_sl != 1 )); then
-               error "Active plain llog shouldn\`t be deleted from catalog"
+       elif (( cat_sl != 1 )); then
+               error "Active plain llog shouldn't be deleted from catalog"
        fi
 }
 run_test 256 "Check llog delete for empty and not full state"
@@ -16167,6 +16273,58 @@ test_271c() {
 }
 run_test 271c "DoM: IO lock at open saves enqueue RPCs"
 
+test_275() {
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
+       [ $(lustre_version_code ost1) -lt $(version_code 2.10.57) ] &&
+               skip "Need OST version >= 2.10.57" && return 0
+
+       local file=$DIR/$tfile
+       local oss
+
+       oss=$(comma_list $(osts_nodes))
+
+       dd if=/dev/urandom of=$file bs=1M count=2 ||
+               error "failed to create a file"
+       cancel_lru_locks osc
+
+       #lock 1
+       dd if=$file of=/dev/null bs=1M count=1 iflag=direct ||
+               error "failed to read a file"
+
+#define OBD_FAIL_LDLM_PAUSE_CANCEL2      0x31f
+       $LCTL set_param fail_loc=0x8000031f
+
+       cancel_lru_locks osc &
+       sleep 1
+
+#define OBD_FAIL_LDLM_PROLONG_PAUSE      0x32b
+       do_nodes $oss $LCTL set_param fail_loc=0x8000032b
+       #IO takes another lock, but matches the PENDING one
+       #and places it to the IO RPC
+       dd if=$file of=/dev/null bs=1M count=1 iflag=direct ||
+               error "failed to read a file with PENDING lock"
+}
+run_test 275 "Read on a canceled duplicate lock"
+
+test_276() {
+       remote_ost_nodsh && skip "remote OST with nodsh" && return
+       local pid
+
+       do_facet ost1 "(while true; do \
+               $LCTL get_param obdfilter.*.filesfree > /dev/null 2>&1; \
+               done) & pid=\\\$!; echo \\\$pid > $TMP/sanity_276_pid" &
+       pid=$!
+
+       for LOOP in $(seq 20); do
+               stop ost1
+               start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
+       done
+       kill -9 $pid
+       do_facet ost1 "pid=\\\$(cat $TMP/sanity_276_pid); kill -9 \\\$pid; \
+               rm $TMP/sanity_276_pid"
+}
+run_test 276 "Race between mount and obd_statfs"
+
 cleanup_test_300() {
        trap 0
        umask $SAVE_UMASK
@@ -16181,7 +16339,7 @@ test_striped_dir() {
        SAVE_UMASK=$(umask)
        trap cleanup_test_300 RETURN EXIT
 
-       $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
+       $LFS setdirstripe -i $mdt_index -c 2 -H all_char -o 755 \
                                                $DIR/$tdir/striped_dir ||
                error "set striped dir error"
 
@@ -16260,23 +16418,19 @@ test_300b() {
        local mtime2
        local mtime3
 
-       test_mkdir $DIR/$tdir
-       $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
+       test_mkdir $DIR/$tdir || error "mkdir fail"
+       $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
                error "set striped dir error"
-       for ((i=0; i<10; i++)); do
+       for i in {0..9}; do
                mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
                sleep 1
-               touch $DIR/$tdir/striped_dir/file_$i ||
-                                       error "touch error $i"
+               touch $DIR/$tdir/striped_dir/file_$i || error "touch error $i"
                mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
-               [ $mtime1 -eq $mtime2 ] &&
-                       error "mtime not change after create"
+               [ $mtime1 -eq $mtime2 ] && error "mtime unchanged after create"
                sleep 1
-               rm -f $DIR/$tdir/striped_dir/file_$i ||
-                                       error "unlink error $i"
+               rm -f $DIR/$tdir/striped_dir/file_$i || error "unlink error $i"
                mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
-               [ $mtime2 -eq $mtime3 ] &&
-                       error "mtime did not change after unlink"
+               [ $mtime2 -eq $mtime3 ] && error "mtime unchanged after unlink"
        done
        true
 }
@@ -16319,7 +16473,7 @@ test_300d() {
        $SETSTRIPE -c 2 $DIR/$tdir
 
        #local striped directory
-       $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
+       $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
                error "set striped dir error"
        createmany -o $DIR/$tdir/striped_dir/f 10 ||
                error "create 10 files failed"
@@ -16350,7 +16504,7 @@ test_300e() {
 
        mkdir -p $DIR/$tdir
 
-       $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
+       $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
                error "set striped dir error"
 
        touch $DIR/$tdir/striped_dir/a
@@ -16361,13 +16515,13 @@ test_300e() {
        mkdir $DIR/$tdir/striped_dir/dir_b
        mkdir $DIR/$tdir/striped_dir/dir_c
 
-       $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
+       $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_a ||
                error "set striped adir under striped dir error"
 
        $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_b ||
                error "set striped bdir under striped dir error"
 
-       $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
+       $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_c ||
                error "set striped cdir under striped dir error"
 
        mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b ||
@@ -16397,10 +16551,10 @@ test_300f() {
        rm -rf $DIR/$tdir
        mkdir -p $DIR/$tdir
 
-       $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
+       $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir ||
                error "set striped dir error"
 
-       $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
+       $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir1 ||
                error "set striped dir error"
 
        touch $DIR/$tdir/striped_dir/a
@@ -16534,8 +16688,7 @@ test_300h() {
        local stripe_count
 
        mkdir $DIR/$tdir
-       $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
-                                       $DIR/$tdir/striped_dir ||
+       $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
                error "set striped dir error"
 
        test_300_check_default_striped_dir striped_dir $MDSCOUNT 1
@@ -16566,7 +16719,7 @@ test_300i() {
 
        mkdir $DIR/$tdir
 
-       $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
+       $LFS setdirstripe -i 0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
                error "set striped dir error"
 
        createmany -o $DIR/$tdir/striped_dir/f- 10 ||
@@ -16622,7 +16775,7 @@ test_300j() {
 
        #define OBD_FAIL_SPLIT_UPDATE_REC       0x1702
        $LCTL set_param fail_loc=0x1702
-       $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
+       $LFS setdirstripe -i 0 -c$MDSCOUNT -H all_char $DIR/$tdir/striped_dir ||
                error "set striped dir error"
 
        createmany -o $DIR/$tdir/striped_dir/f- 10 ||
@@ -16816,8 +16969,8 @@ test_300p() {
 
        #define OBD_FAIL_OUT_ENOSPC     0x1704
        do_facet mds2 lctl set_param fail_loc=0x80001704
-       $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir > /dev/null 2>&1 &&
-                       error "create striped directory should fail"
+       $LFS setdirstripe -i 0 -c2 $DIR/$tdir/bad_striped_dir > /dev/null 2>&1 \
+                && error "create striped directory should fail"
 
        [ -e $DIR/$tdir/bad_striped_dir ] && error "striped dir exists"
 
@@ -16850,7 +17003,8 @@ prepare_remote_file() {
        mkdir $DIR/$tdir/src_dir ||
                error "create remote source failed"
 
-       cp /etc/hosts $DIR/$tdir/src_dir/a || error
+       cp /etc/hosts $DIR/$tdir/src_dir/a ||
+                error "cp to remote source failed"
        touch $DIR/$tdir/src_dir/a
 
        $LFS mkdir -i 1 $DIR/$tdir/tgt_dir ||
@@ -16881,8 +17035,9 @@ test_310a() {
        prepare_remote_file || error "prepare remote file failed"
 
        #open-unlink file
-       $OPENUNLINK $remote_file $remote_file || error
-       $CHECKSTAT -a $remote_file || error
+       $OPENUNLINK $remote_file $remote_file ||
+               error "openunlink $remote_file failed"
+       $CHECKSTAT -a $remote_file || error "$remote_file exists"
 }
 run_test 310a "open unlink remote file"
 
@@ -17118,6 +17273,19 @@ test_315() { # LU-618
 }
 run_test 315 "read should be accounted"
 
+test_316() {
+       [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
+       large_xattr_enabled || { skip "large_xattr disabled" && return; }
+
+       rm -rf $DIR/$tdir/d
+       mkdir -p $DIR/$tdir/d
+       chown nobody $DIR/$tdir/d
+       touch $DIR/$tdir/d/file
+
+       $LFS mv -M1 $DIR/$tdir/d || error "lfs mv failed"
+}
+run_test 316 "lfs mv"
+
 test_fake_rw() {
        local read_write=$1
        if [ "$read_write" = "write" ]; then
@@ -17445,10 +17613,7 @@ test_406() {
        [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.50) ] &&
                skip "Need MDS version at least 2.8.50" && return
 
-       local def_stripe_count=$($GETSTRIPE -c $MOUNT)
-       local def_stripe_size=$($GETSTRIPE -S $MOUNT)
-       local def_stripe_offset=$($GETSTRIPE -i $MOUNT)
-       local def_pool=$($GETSTRIPE -p $MOUNT)
+       local def_stripe_size=$($LFS getstripe -S $MOUNT)
        local test_pool=$TESTNAME
 
        if ! combined_mgs_mds ; then
@@ -17458,60 +17623,51 @@ test_406() {
        pool_add_targets $test_pool 0 $(($OSTCOUNT - 1)) 1 ||
                error "pool_add_targets failed"
 
+       save_layout_restore_at_exit $MOUNT
+
        # parent set default stripe count only, child will stripe from both
        # parent and fs default
-       $SETSTRIPE -c 1 -i 1 -S $((def_stripe_size * 2)) -p $test_pool $MOUNT ||
+       $LFS setstripe -c 1 -i 1 -S $((def_stripe_size * 2)) -p $test_pool $MOUNT ||
                error "setstripe $MOUNT failed"
        $LFS mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
-       $SETSTRIPE -c $OSTCOUNT $DIR/$tdir || error "setstripe $tdir failed"
+       $LFS setstripe -c $OSTCOUNT $DIR/$tdir || error "setstripe $tdir failed"
        for i in $(seq 10); do
                local f=$DIR/$tdir/$tfile.$i
                touch $f || error "touch failed"
-               local count=$($GETSTRIPE -c $f)
+               local count=$($LFS getstripe -c $f)
                [ $count -eq $OSTCOUNT ] ||
                        error "$f stripe count $count != $OSTCOUNT"
-               local offset=$($GETSTRIPE -i $f)
+               local offset=$($LFS getstripe -i $f)
                [ $offset -eq 1 ] || error "$f stripe offset $offset != 1"
-               local size=$($GETSTRIPE -S $f)
+               local size=$($LFS getstripe -S $f)
                [ $size -eq $((def_stripe_size * 2)) ] ||
                        error "$f stripe size $size != $((def_stripe_size * 2))"
-               local pool=$($GETSTRIPE -p $f)
+               local pool=$($LFS getstripe -p $f)
                [ $pool == $test_pool ] || error "$f pool $pool != $test_pool"
        done
 
        # change fs default striping, delete parent default striping, now child
        # will stripe from new fs default striping only
-       $SETSTRIPE -c 1 -S $def_stripe_size -i 0 $MOUNT ||
+       $LFS setstripe -c 1 -S $def_stripe_size -i 0 $MOUNT ||
                error "change $MOUNT default stripe failed"
-       $SETSTRIPE -c 0 $DIR/$tdir || error "delete $tdir default stripe failed"
+       $LFS setstripe -c 0 $DIR/$tdir ||
+               error "delete $tdir default stripe failed"
        for i in $(seq 11 20); do
                local f=$DIR/$tdir/$tfile.$i
                touch $f || error "touch $f failed"
-               local count=$($GETSTRIPE -c $f)
+               local count=$($LFS getstripe -c $f)
                [ $count -eq 1 ] || error "$f stripe count $count != 1"
-               local offset=$($GETSTRIPE -i $f)
+               local offset=$($LFS getstripe -i $f)
                [ $offset -eq 0 ] || error "$f stripe offset $offset != 0"
-               local size=$($GETSTRIPE -S $f)
+               local size=$($LFS getstripe -S $f)
                [ $size -eq $def_stripe_size ] ||
                        error "$f stripe size $size != $def_stripe_size"
-               local pool=$($GETSTRIPE -p $f)
-               [ "#$pool" == "#" ] || error "$f pool $pool is set"
-
+               local pool=$($LFS getstripe -p $f)
+               [ $pool == $test_pool ] || error "$f pool $pool isn't set"
        done
 
        unlinkmany $DIR/$tdir/$tfile. 1 20
 
-       # restore FS default striping
-       if [ -z $def_pool ]; then
-               $SETSTRIPE -c $def_stripe_count -S $def_stripe_size \
-                       -i $def_stripe_offset $MOUNT ||
-                       error "restore default striping failed"
-       else
-               $SETSTRIPE -c $def_stripe_count -S $def_stripe_size \
-                       -i $def_stripe_offset -p $def_pool $MOUNT ||
-                       error "restore default striping with $def_pool failed"
-       fi
-
        local f=$DIR/$tdir/$tfile
        pool_remove_all_targets $test_pool $f
        pool_remove $test_pool $f
@@ -17658,21 +17814,57 @@ test_412() {
                skip "We need at least 2 MDTs for this test" && return
 
        if [ $(lustre_version_code mds1) -lt $(version_code 2.10.55) ]; then
-               skip "Need server version at least 2.10.55" & exit 0
+               skip "Need server version at least 2.10.55" && exit 0
        fi
 
        $LFS mkdir -i $((MDSCOUNT - 1)),$((MDSCOUNT - 2)) $DIR/$tdir ||
                error "mkdir failed"
        $LFS getdirstripe $DIR/$tdir
-       stripe_index=$($LFS getdirstripe -i $DIR/$tdir)
+       local stripe_index=$($LFS getdirstripe -i $DIR/$tdir)
        [ $stripe_index -eq $((MDSCOUNT - 1)) ] ||
                error "expect $((MDSCOUT - 1)) get $stripe_index"
-       stripe_count=$($LFS getdirstripe -T $DIR/$tdir)
+       local stripe_count=$($LFS getdirstripe -T $DIR/$tdir)
        [ $stripe_count -eq 2 ] ||
                error "expect 2 get $stripe_count"
 }
 run_test 412 "mkdir on specific MDTs"
 
+test_413() {
+       [ $MDSCOUNT -lt 2 ] &&
+               skip "We need at least 2 MDTs for this test" && return
+
+       if [ $(lustre_version_code mds1) -lt $(version_code 2.10.55) ]; then
+               skip "Need server version at least 2.10.55" && exit 0
+       fi
+
+       mkdir $DIR/$tdir || error "mkdir failed"
+
+       # find MDT that is the most full
+       local max=$($LFS df | grep MDT |
+               awk 'BEGIN { a=0 }
+                       { sub("%", "", $5)
+                         if (0+$5 >= a)
+                         {
+                               a = $5
+                               b = $6
+                         }
+                       }
+                    END { split(b, c, ":")
+                          sub("]", "", c[2])
+                          print c[2]
+                        }')
+
+       for i in $(seq $((MDSCOUNT - 1))); do
+               $LFS mkdir -c $i $DIR/$tdir/d$i ||
+                       error "mkdir d$i failed"
+               $LFS getdirstripe $DIR/$tdir/d$i
+               local stripe_index=$($LFS getdirstripe -i $DIR/$tdir/d$i)
+               [ $stripe_index -ne $max ] ||
+                       error "don't expect $max"
+       done
+}
+run_test 413 "mkdir on less full MDTs"
+
 prep_801() {
        [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
        [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
@@ -17954,7 +18146,7 @@ test_803() {
                        error "Fail to create $DIR/$tdir/dir${idx}"
        done
 
-       sync; sleep 5
+       sync; sleep 3
        echo "before create:"
        $LFS df -i $MOUNT
        local before_used=$($LFS df -i | grep MDT0000_UUID | awk '{print $3}')
@@ -17964,7 +18156,7 @@ test_803() {
                        error "Fail to create $DIR/$tdir/foo$i"
        done
 
-       sync; sleep 5
+       sync; sleep 3
        echo "after create:"
        $LFS df -i $MOUNT
        local after_used=$($LFS df -i | grep MDT0000_UUID | awk '{print $3}')
@@ -17977,6 +18169,7 @@ test_803() {
                        error "Fail to remove $DIR/$tdir/foo$i"
        done
 
+       sleep 3 # avoid MDT return cached statfs
        wait_delete_completed
        echo "after unlink:"
        $LFS df -i $MOUNT
@@ -18072,6 +18265,52 @@ test_804() {
 }
 run_test 804 "verify agent entry for remote entry"
 
+cleanup_805() {
+       do_facet $SINGLEMDS zfs set quota=$old $fsset
+       unlinkmany $DIR/$tdir/f- 1000000
+       trap 0
+}
+
+test_805() {
+       local zfs_version=$(do_node $SINGLEMDS cat /sys/module/zfs/version)
+       [ "$(facet_fstype mds1)" != "zfs" ] &&
+               skip "ZFS specific test" && return
+       [ $(version_code $zfs_version) -lt $(version_code 0.7.2) ] &&
+               skip "netfree not implemented before 0.7" && return
+       [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.57) ]] ||
+               { skip "Need MDS version at least 2.10.57" && return 0; }
+
+       local fsset
+       local freekb
+       local usedkb
+       local old
+       local quota
+       local pref="osd-zfs.lustre-MDT0000."
+
+       # limit available space on MDS dataset to meet nospace issue
+       # quickly. then ZFS 0.7.2 can use reserved space if asked
+       # properly (using netfree flag in osd_declare_destroy()
+       fsset=$(do_facet $SINGLEMDS lctl get_param -n $pref.mntdev)
+       old=$(do_facet $SINGLEMDS zfs get -H quota $fsset | \
+               gawk '{print $3}')
+       freekb=$(do_facet $SINGLEMDS lctl get_param -n $pref.kbytesfree)
+       usedkb=$(do_facet $SINGLEMDS lctl get_param -n $pref.kbytestotal)
+       let "usedkb=usedkb-freekb"
+       let "freekb=freekb/2"
+       if let "freekb > 5000"; then
+               let "freekb=5000"
+       fi
+       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"
+       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
+       trap 0
+}
+run_test 805 "ZFS can remove from full fs"
+
 #
 # tests that do cleanup/setup should be run at the end
 #