Whamcloud - gitweb
LU-7667 tests: Write to unique files in $TMP
[fs/lustre-release.git] / lustre / tests / conf-sanity.sh
old mode 100644 (file)
new mode 100755 (executable)
index d106839..accbf27
@@ -4,8 +4,8 @@ set -e
 
 ONLY=${ONLY:-"$*"}
 
-# bug number for skipped test:
-ALWAYS_EXCEPT="$CONF_SANITY_EXCEPT"
+# bug number for skipped test:     LU-7428
+ALWAYS_EXCEPT="$CONF_SANITY_EXCEPT 84"
 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
 
 is_sles11()                                            # LU-2181
@@ -52,7 +52,7 @@ init_test_env $@
 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
 
 # use small MDS + OST size to speed formatting time
-# do not use too small MDSSIZE/OSTSIZE, which affect the default jouranl size
+# do not use too small MDSSIZE/OSTSIZE, which affect the default journal size
 # STORED_MDSSIZE is used in test_18
 STORED_MDSSIZE=$MDSSIZE
 STORED_OSTSIZE=$OSTSIZE
@@ -213,16 +213,17 @@ remount_client() {
 }
 
 umount_client() {
-       local MOUNTPATH=$1
-       echo "umount lustre on ${MOUNTPATH}....."
-       zconf_umount $(hostname) $MOUNTPATH || return 97
+       local mountpath=$1
+       shift
+       echo "umount lustre on $mountpath....."
+       zconf_umount $HOSTNAME $mountpath $@ || return 97
 }
 
 manual_umount_client(){
        local rc
        local FORCE=$1
        echo "manual umount lustre on ${MOUNT}...."
-       do_facet client "umount -d ${FORCE} $MOUNT"
+       do_facet client "umount ${FORCE} $MOUNT"
        rc=$?
        return $rc
 }
@@ -344,7 +345,8 @@ test_4() {
        setup
        touch $DIR/$tfile || error "touch $DIR/$tfile failed"
        stop_ost || error "Unable to stop OST1"
-       cleanup
+       umount_client $MOUNT -f || error “unmount $MOUNT failed”
+       cleanup_nocli
        eno=$?
        # ok for ost to fail shutdown
        if [ 202 -ne $eno ] && [ 0 -ne $eno ]; then
@@ -363,7 +365,7 @@ test_5a() { # was test_5
        # cleanup may return an error from the failed
        # disconnects; for now I'll consider this successful
        # if all the modules have unloaded.
-       umount -d $MOUNT &
+       $UMOUNT -f $MOUNT &
        UMOUNT_PID=$!
        sleep 6
        echo "killing umount"
@@ -458,7 +460,8 @@ test_5d() {
        start_mds || error "MDS start failed"
        stop_ost || error "Unable to stop OST1"
        mount_client $MOUNT || error "mount_client $MOUNT failed"
-       cleanup || error "cleanup_nocli failed with $?"
+       umount_client $MOUNT -f || error "umount_client $MOUNT failed"
+       cleanup_nocli || error "cleanup_nocli failed with $?"
        grep " $MOUNT " /etc/mtab &&
                error "$MOUNT entry in mtab after unmount"
        pass
@@ -841,7 +844,7 @@ test_22() {
        # check_mount will block trying to contact ost
        mcreate $DIR/$tfile || error "mcreate $DIR/$tfile failed"
        rm -f $DIR/$tfile || error "remove $DIR/$tfile failed"
-       umount_client $MOUNT
+       umount_client $MOUNT -f
        pass
 
        echo "Client mount with a running ost"
@@ -1274,30 +1277,35 @@ run_test 30a "Big config llog and conf_param deletion"
 test_30b() {
        setup
 
+       local orignids=$($LCTL get_param -n \
+               osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
+
+       local orignidcount=$(echo "$orignids" | wc -w)
+
        # Make a fake nid.  Use the OST nid, and add 20 to the least significant
        # numerical part of it. Hopefully that's not already a failover address
        # for the server.
-       OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
-       ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
-       NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
-       NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
+       local OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | \
+               awk '{print $1}')
+       local ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
+       local NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
+       local NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
        echo "Using fake nid $NEW"
 
-       TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
+       local TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
                grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
        set_conf_param_and_check client "$TEST" \
                "$FSNAME-OST0000.failover.node" $NEW ||
                error "didn't add failover nid $NEW"
-       NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
+       local NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
                grep failover_nids)
        echo $NIDS
-       # The NIDS value is the failover nid strings and "[" and "]". So
-       # we need to subtract the space taken by the delimiters. This has
-       # changed from earlier version of Lustre but this test is run only
-       # locally so this change will not break interop. See LU-3386
-       NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 3))
-       echo "should have 2 failover nids: $NIDCOUNT"
-       [ $NIDCOUNT -eq 2 ] || error "Failover nid not added"
+       local NIDCOUNT=$(echo "$NIDS" | wc -w)
+       echo "should have $((orignidcount + 1)) entries \
+               in failover nids string, have $NIDCOUNT"
+       [ $NIDCOUNT -eq $((orignidcount + 1)) ] ||
+               error "Failover nid not added"
+
        do_facet mgs "$LCTL conf_param -d $FSNAME-OST0000.failover.node" ||
                error "conf_param delete failed"
        umount_client $MOUNT
@@ -1306,9 +1314,10 @@ test_30b() {
        NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
                grep failover_nids)
        echo $NIDS
-       NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 3))
-       echo "only 1 final nid should remain: $NIDCOUNT"
-       [ $NIDCOUNT -eq 1 ] || error "Failover nids not removed"
+       NIDCOUNT=$(echo "$NIDS" | wc -w)
+       echo "only $orignidcount final entries should remain \
+               in failover nids string, have $NIDCOUNT"
+       [ $NIDCOUNT -eq $orignidcount ] || error "Failover nids not removed"
 
        cleanup || error "cleanup failed with rc $?"
 }
@@ -1323,8 +1332,8 @@ run_test 31 "Connect to non-existent node (shouldn't crash)"
 
 
 T32_QID=60000
-T32_BLIMIT=20480 # Kbytes
-T32_ILIMIT=2
+T32_BLIMIT=40960 # Kbytes
+T32_ILIMIT=4
 
 #
 # This is not really a test but a tool to create new disk
@@ -1340,13 +1349,18 @@ test_32newtarball() {
        local dst=.
        local src=/etc/rc.d
        local tmp=$TMP/t32_image_create
-
-       if [ $FSNAME != t32fs -o $MDSCOUNT -ne 1 -o                                                             \
-                \( -z "$MDSDEV" -a -z "$MDSDEV1" \) -o $OSTCOUNT -ne 1 -o                      \
-                -z "$OSTDEV1" ]; then
-               error "Needs FSNAME=t32fs MDSCOUNT=1 MDSDEV1=<nonexistent_file>"        \
-                         "(or MDSDEV, in the case of b1_8) OSTCOUNT=1"                                 \
-                         "OSTDEV1=<nonexistent_file>"
+       local server_version=$(lustre_version_code $SINGLEMDS)
+       local remote_dir
+       local striped_dir
+       local pushd_dir
+
+       if [ $FSNAME != t32fs -o \( -z "$MDSDEV" -a -z "$MDSDEV1" \) -o \
+            $OSTCOUNT -ne 1 -o -z "$OSTDEV1" ]; then
+               error "Needs FSNAME=t32fs MDSCOUNT=2 "                  \
+                     "MDSDEV1=<nonexistent_file>"                      \
+                     "MDSDEV2=<nonexistent_file>"                      \
+                     "(or MDSDEV, in the case of b1_8)"                \
+                     "OSTCOUNT=1 OSTDEV1=<nonexistent_file>"
        fi
 
        mkdir $tmp || {
@@ -1357,7 +1371,7 @@ test_32newtarball() {
        mkdir $tmp/src || return 1
        tar cf - -C $src . | tar xf - -C $tmp/src
        dd if=/dev/zero of=$tmp/src/t32_qf_old bs=1M \
-               count=$(($T32_BLIMIT / 1024 / 2))
+               count=$(($T32_BLIMIT / 1024 / 4))
        chown $T32_QID.$T32_QID $tmp/src/t32_qf_old
 
        # format ost with comma-separated NIDs to verify LU-4460
@@ -1366,26 +1380,50 @@ test_32newtarball() {
 
        setupall
 
-       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ] &&
+       [[ $server_version -ge $(version_code 2.3.50) ]] ||
                $LFS quotacheck -ug /mnt/$FSNAME
        $LFS setquota -u $T32_QID -b 0 -B $T32_BLIMIT -i 0 -I $T32_ILIMIT \
                /mnt/$FSNAME
 
        tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
+
+       if [[ $MDSCOUNT -ge 2 ]]; then
+               remote_dir=/mnt/$FSNAME/remote_dir
+               $LFS mkdir -i 1 $remote_dir
+               tar cf - -C $tmp/src . | tar xf - -C $remote_dir
+
+               if [[ $server_version -ge $(version_code 2.7.0) ]]; then
+                       striped_dir=/mnt/$FSNAME/striped_dir_old
+                       $LFS mkdir -i 1 -c 2 $striped_dir
+                       tar cf - -C $tmp/src . | tar xf - -C $striped_dir
+               fi
+       fi
+
        stopall
 
        mkdir $tmp/img || return 1
 
        setupall
-       pushd /mnt/$FSNAME
+
+       pushd_dir=/mnt/$FSNAME
+       if [[ $MDSCOUNT -ge 2 ]]; then
+               pushd_dir=$remote_dir
+               if [[ $server_version -ge $(version_code 2.7.0) ]]; then
+                       pushd $striped_dir
+                       ls -Rni --time-style=+%s >$tmp/img/list2
+                       popd
+               fi
+       fi
+
+       pushd $pushd_dir
        ls -Rni --time-style=+%s >$tmp/img/list
-       find ! -name .lustre -type f -exec sha1sum {} \; |
+       find ! -name .lustre -type f -exec sha1sum {} \; |
                sort -k 2 >$tmp/img/sha1sums
        popd
        $LCTL get_param -n version | head -n 1 |
                sed -e 's/^lustre: *//' >$tmp/img/commit
 
-       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ] &&
+       [[ $server_version -ge $(version_code 2.3.50) ]] ||
                $LFS quotaon -ug /mnt/$FSNAME
        $LFS quota -u $T32_QID -v /mnt/$FSNAME
        $LFS quota -v -u $T32_QID /mnt/$FSNAME |
@@ -1396,6 +1434,8 @@ test_32newtarball() {
                awk 'BEGIN { num='5' } { if ($1 == "'/mnt/$FSNAME'") \
                { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
                | tr -d "*" > $tmp/img/ispace
+       echo $T32_BLIMIT > $tmp/img/blimit
+       echo $T32_ILIMIT > $tmp/img/ilimit
 
        stopall
 
@@ -1411,6 +1451,13 @@ test_32newtarball() {
        uname -m >$tmp/img/arch
 
        mv ${MDSDEV1:-$MDSDEV} $tmp/img
+       for num in $(seq 2 $MDSCOUNT); do
+               local devname=$(mdsdevname $num)
+               local facet=mds$num
+               [[ $(facet_fstype $facet) != zfs ]] ||
+                       devname=$(mdsvdevname $num)
+               mv $devname $tmp/img
+       done
        mv $OSTDEV1 $tmp/img
 
        version=$(sed -e 's/\(^[0-9]\+\.[0-9]\+\)\(.*$\)/\1/' $tmp/img/commit |
@@ -1454,27 +1501,34 @@ t32_check() {
 
 t32_test_cleanup() {
        local tmp=$TMP/t32
-       local fstype=$(facet_fstype $SINGLEMDS)
+       local facet=$SINGLEMDS
+       local fstype=$(facet_fstype $facet)
        local rc=$?
 
        if $shall_cleanup_lustre; then
                umount $tmp/mnt/lustre || rc=$?
        fi
        if $shall_cleanup_mdt; then
-               $r umount -d $tmp/mnt/mdt || rc=$?
+               $r $UMOUNT $tmp/mnt/mdt || rc=$?
        fi
        if $shall_cleanup_mdt1; then
-               $r umount -d $tmp/mnt/mdt1 || rc=$?
+               $r $UMOUNT $tmp/mnt/mdt1 || rc=$?
        fi
        if $shall_cleanup_ost; then
-               $r umount -d $tmp/mnt/ost || rc=$?
+               $r $UMOUNT $tmp/mnt/ost || rc=$?
        fi
 
        $r rm -rf $tmp
        rm -rf $tmp
-       if [ $fstype == "zfs" ]; then
-               $r $ZPOOL destroy t32fs-mdt1 || rc=$?
-               $r $ZPOOL destroy t32fs-ost1 || rc=$?
+       if [[ $fstype == zfs ]]; then
+               local poolname
+               local poolname_list="t32fs-mdt1 t32fs-ost1"
+
+               ! $mdt2_is_available || poolname_list+=" t32fs-mdt2"
+
+               for poolname in $poolname_list; do
+                       destroy_zpool $facet $poolname
+               done
        fi
        return $rc
 }
@@ -1564,8 +1618,8 @@ t32_verify_quota() {
                awk 'BEGIN { num='3' } { if ($1 == "'$mnt'") \
                { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
                | tr -d "*")
-       [ $qval -eq $T32_BLIMIT ] || {
-               echo "blimit, act:$qval, exp:$T32_BLIMIT"
+       [ $qval -eq $img_blimit ] || {
+               echo "blimit, act:$qval, exp:$img_blimit"
                return 1
        }
 
@@ -1573,8 +1627,8 @@ t32_verify_quota() {
                awk 'BEGIN { num='7' } { if ($1 == "'$mnt'") \
                { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
                | tr -d "*")
-       [ $qval -eq $T32_ILIMIT ] || {
-               echo "ilimit, act:$qval, exp:$T32_ILIMIT"
+       [ $qval -eq $img_ilimit ] || {
+               echo "ilimit, act:$qval, exp:$img_ilimit"
                return 1
        }
 
@@ -1596,18 +1650,18 @@ t32_verify_quota() {
 
        chmod 0777 $mnt
        runas -u $T32_QID -g $T32_QID dd if=/dev/zero of=$mnt/t32_qf_new \
-               bs=1M count=$(($T32_BLIMIT / 1024)) oflag=sync && {
+               bs=1M count=$((img_blimit / 1024)) oflag=sync && {
                echo "Write succeed, but expect -EDQUOT"
                return 1
        }
        rm -f $mnt/t32_qf_new
 
        runas -u $T32_QID -g $T32_QID createmany -m $mnt/t32_qf_ \
-               $T32_ILIMIT && {
+               $img_ilimit && {
                echo "Create succeed, but expect -EDQUOT"
                return 1
        }
-       unlinkmany $mnt/t32_qf_ $T32_ILIMIT
+       unlinkmany $mnt/t32_qf_ $img_ilimit
 
        return 0
 }
@@ -1621,6 +1675,7 @@ t32_test() {
        local shall_cleanup_mdt1=false
        local shall_cleanup_ost=false
        local shall_cleanup_lustre=false
+       local mdt2_is_available=false
        local node=$(facet_active_host $SINGLEMDS)
        local r="do_node $node"
        local node2=$(facet_active_host mds2)
@@ -1630,6 +1685,8 @@ t32_test() {
        local img_arch
        local img_bspace
        local img_ispace
+       local img_blimit
+       local img_ilimit
        local fsname=t32fs
        local nid=$($r $LCTL list_nids | head -1)
        local mopts
@@ -1639,13 +1696,17 @@ t32_test() {
        local list
        local fstype=$(facet_fstype $SINGLEMDS)
        local mdt_dev=$tmp/mdt
+       local mdt2_dev=$tmp/mdt2
        local ost_dev=$tmp/ost
+       local stripe_index
+       local stripe_count
+       local dir
 
        trap 'trap - RETURN; t32_test_cleanup' RETURN
 
        load_modules
        mkdir -p $tmp/mnt/lustre || error "mkdir $tmp/mnt/lustre failed"
-       $r mkdir -p $tmp/mnt/{mdt,ost}
+       $r mkdir -p $tmp/mnt/{mdt,mdt1,ost}
        $r tar xjvf $tarball -S -C $tmp || {
                error_noexit "Unpacking the disk image tarball"
                return 1
@@ -1655,6 +1716,14 @@ t32_test() {
        img_arch=$($r cat $tmp/arch)
        img_bspace=$($r cat $tmp/bspace)
        img_ispace=$($r cat $tmp/ispace)
+
+       # older images did not have "blimit" and "ilimit" files
+       # use old values for T32_BLIMIT and T32_ILIMIT
+       $r test -f $tmp/blimit && img_blimit=$($r cat $tmp/blimit) ||
+               img_blimit=20480
+       $r test -f $tmp/ilimit && img_ilimit=$($r cat $tmp/ilimit) ||
+               img_ilimit=2
+
        echo "Upgrading from $(basename $tarball), created with:"
        echo "  Commit: $img_commit"
        echo "  Kernel: $img_kernel"
@@ -1669,12 +1738,23 @@ t32_test() {
                $(lustre_version_code ost1) -lt $(version_code 2.5.0) ] &&
                        ff_convert="no"
 
-       if [ $fstype == "zfs" ]; then
+       ! $r test -f $mdt2_dev || mdt2_is_available=true
+
+       if [[ $fstype == zfs ]]; then
                # import pool first
-               $r $ZPOOL import -f -d $tmp t32fs-mdt1
-               $r $ZPOOL import -f -d $tmp t32fs-ost1
+               local poolname
+               local poolname_list="t32fs-mdt1 t32fs-ost1"
+
+               ! $mdt2_is_available || poolname_list+=" t32fs-mdt2"
+
+               for poolname in $poolname_list; do
+                       $r "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
+                               $ZPOOL import -f -d $tmp $poolname"
+               done
+
                mdt_dev=t32fs-mdt1/mdt1
                ost_dev=t32fs-ost1/ost1
+               ! $mdt2_is_available || mdt2_dev=t32fs-mdt2/mdt2
                wait_update_facet $SINGLEMDS "$ZPOOL list |
                        awk '/^t32fs-mdt1/ { print \\\$1 }'" "t32fs-mdt1" || {
                                error_noexit "import zfs pool failed"
@@ -1689,6 +1769,15 @@ t32_test() {
                error_noexit "tunefs.lustre before mounting the MDT"
                return 1
        }
+
+       if $mdt2_is_available; then
+               $r $TUNEFS --dryrun $mdt2_dev || {
+                       $r losetup -a
+                       error_noexit "tunefs.lustre before mounting the MDT"
+                       return 1
+               }
+       fi
+
        if [ "$writeconf" ]; then
                mopts=writeconf
                if [ $fstype == "ldiskfs" ]; then
@@ -1698,6 +1787,13 @@ t32_test() {
                                error_noexit "Enable mdt quota feature"
                                return 1
                        }
+                       if $mdt2_is_available; then
+                               $r $TUNEFS --quota $mdt2_dev || {
+                                       $r losetup -a
+                                       error_noexit "Enable mdt quota feature"
+                                       return 1
+                               }
+                       fi
                fi
        else
                if [ -n "$($LCTL list_nids | grep -v '\(tcp\|lo\)[[:digit:]]*$')" ]; then
@@ -1715,7 +1811,7 @@ t32_test() {
                        $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt
                        $r $LCTL replace_nids $fsname-OST0000 $ostnid
                        $r $LCTL replace_nids $fsname-MDT0000 $nid
-                       $r umount -d $tmp/mnt/mdt
+                       $r $UMOUNT $tmp/mnt/mdt
                fi
 
                mopts=exclude=$fsname-OST0000
@@ -1733,7 +1829,20 @@ t32_test() {
        }
        shall_cleanup_mdt=true
 
-       if [ "$dne_upgrade" != "no" ]; then
+       if $mdt2_is_available; then
+               mopts=mgsnode=$nid,$mopts
+               $r $MOUNT_CMD -o $mopts $mdt2_dev $tmp/mnt/mdt1 || {
+                       $r losetup -a
+                       error_noexit "Mounting the MDT"
+                       return 1
+               }
+
+               echo "mount new MDT....$mdt2_dev"
+               $r $LCTL set_param -n mdt.${fsname}*.enable_remote_dir=1 ||
+                       error_noexit "enable remote dir create failed"
+
+               shall_cleanup_mdt1=true
+       elif [ "$dne_upgrade" != "no" ]; then
                local fs2mdsdev=$(mdsdevname 1_2)
                local fs2mdsvdev=$(mdsvdevname 1_2)
 
@@ -1748,13 +1857,14 @@ t32_test() {
                        return 1
                }
 
+               [[ $(facet_fstype mds1) != zfs ]] || import_zpool fs2mds
+
                $r $TUNEFS --dryrun $fs2mdsdev || {
                        error_noexit "tunefs.lustre before mounting the MDT"
                        return 1
                }
 
                echo "mount new MDT....$fs2mdsdev"
-               $r mkdir -p $tmp/mnt/mdt1
                $r $MOUNT_CMD -o $mopts $fs2mdsdev $tmp/mnt/mdt1 || {
                        error_noexit "mount mdt1 failed"
                        return 1
@@ -1877,7 +1987,6 @@ t32_test() {
                        error_noexit "Setting MDT1 \"lov.stripesize\""
                        return 1
                }
-
        fi
 
        if [ "$writeconf" ]; then
@@ -1885,31 +1994,123 @@ t32_test() {
                        error_noexit "Mounting the client"
                        return 1
                }
+
                shall_cleanup_lustre=true
-               $LCTL set_param debug="$PTLDEBUG"
+               $r $LCTL set_param debug="$PTLDEBUG"
 
                t32_verify_quota $node $fsname $tmp/mnt/lustre || {
                        error_noexit "verify quota failed"
                        return 1
                }
 
+               if $r test -f $tmp/list; then
+                       #
+                       # There is not a Test Framework API to copy files to or
+                       # from a remote node.
+                       #
+                       # LU-2393 - do both sorts on same node to ensure locale
+                       # is identical
+                       local list_file=$tmp/list
+
+                       if $mdt2_is_available; then
+                               if [[ -d $tmp/mnt/lustre/striped_dir_old ]] &&
+                                  $r test -f $tmp/list2; then
+                                       list_file=$tmp/list2
+                                       pushd $tmp/mnt/lustre/striped_dir_old
+                               else
+                                       pushd $tmp/mnt/lustre/remote_dir
+                               fi
+                       else
+                               pushd $tmp/mnt/lustre
+                       fi
+                       $r cat $list_file | sort -k 6 >$tmp/list.orig
+                       ls -Rni --time-style=+%s | sort -k 6 |
+                               sed 's/\. / /' >$tmp/list || {
+                               error_noexit "ls"
+                               return 1
+                       }
+                       popd
+                       #
+                       # 32-bit and 64-bit clients use different algorithms to
+                       # convert FIDs into inode numbers.  Hence, remove the
+                       # inode numbers from the lists, if the original list was
+                       # created on an architecture with different number of
+                       # bits per "long".
+                       #
+                       if [ $(t32_bits_per_long $(uname -m)) != \
+                               $(t32_bits_per_long $img_arch) ]; then
+                               echo "Different number of bits per \"long\"" \
+                                    "from the disk image"
+                               for list in list.orig list; do
+                                       sed -i -e 's/^[0-9]\+[ \t]\+//' \
+                                                 $tmp/$list
+                               done
+                       fi
+                       if ! diff -ub $tmp/list.orig $tmp/list; then
+                               error_noexit "list verification failed"
+                               return 1
+                       fi
+               else
+                       echo "list verification skipped"
+               fi
+
                if [ "$dne_upgrade" != "no" ]; then
-                       $LFS mkdir -i 1 -c2 $tmp/mnt/lustre/remote_dir || {
-                               error_noexit "set remote dir failed"
+                       $LFS mkdir -i 1 -c2 $tmp/mnt/lustre/striped_dir || {
+                               error_noexit "set striped dir failed"
                                return 1
                        }
 
-                       $LFS setdirstripe -D -c2 $tmp/mnt/lustre/remote_dir
+                       $LFS setdirstripe -D -c2 $tmp/mnt/lustre/striped_dir
 
                        pushd $tmp/mnt/lustre
-                       tar -cf - . --exclude=./remote_dir |
-                               tar -xvf - -C remote_dir 1>/dev/null || {
-                               error_noexit "cp to remote dir failed"
+                       tar -cf - . --exclude=./striped_dir \
+                                   --exclude=./striped_dir_old \
+                                   --exclude=./remote_dir |
+                               tar -xvf - -C striped_dir 1>/dev/null || {
+                               error_noexit "cp to striped dir failed"
                                return 1
                        }
                        popd
                fi
 
+               # If it is upgrade from DNE (2.5), then rename the remote dir,
+               # which is created in 2.5 to striped dir.
+               if $mdt2_is_available && [[ "$dne_upgrade" != "no" ]]; then
+                       stripe_index=$($LFS getdirstripe -i     \
+                                      $tmp/mnt/lustre/remote_dir)
+
+                       [[ $stripe_index -eq 1 ]] || {
+                               error_noexit "get index \"$stripe_index\"" \
+                                            "from remote dir failed"
+                               return 1
+                       }
+                       mv $tmp/mnt/lustre/remote_dir   \
+                               $tmp/mnt/lustre/striped_dir/ || {
+                               error_noexit "mv remote dir failed"
+                               return 1
+                       }
+               fi
+
+               # If it is upgraded from DNE (2.7), then move the striped dir
+               # which was created in 2.7 to the new striped dir.
+               if $mdt2_is_available && [[ "$dne_upgrade" != "no" ]] &&
+                       [[ -d $tmp/mnt/lustre/striped_dir_old ]]; then
+                       stripe_count=$($LFS getdirstripe -c     \
+                                      $tmp/mnt/lustre/striped_dir_old)
+                       [[ $stripe_count -eq 2 ]] || {
+                               error_noexit "get count $stripe_count" \
+                                            "from striped dir failed"
+                               return 1
+                       }
+                       mv $tmp/mnt/lustre/striped_dir_old      \
+                               $tmp/mnt/lustre/striped_dir/ || {
+                               error_noexit "mv striped dir failed"
+                               return 1
+                       }
+               fi
+
+               sync; sleep 5; sync
+               $r $LCTL set_param -n osd*.*.force_sync=1
                dd if=/dev/zero of=$tmp/mnt/lustre/tmp_file bs=10k count=10 || {
                        error_noexit "dd failed"
                        return 1
@@ -1924,13 +2125,15 @@ t32_test() {
                        # is identical
                        $r cat $tmp/sha1sums | sort -k 2 >$tmp/sha1sums.orig
                        if [ "$dne_upgrade" != "no" ]; then
-                               pushd $tmp/mnt/lustre/remote_dir
+                               pushd $tmp/mnt/lustre/striped_dir
                        else
                                pushd $tmp/mnt/lustre
                        fi
 
-                       find ! -name .lustre -type f -exec sha1sum {} \; |
+                       find ! -path "*remote_dir*" ! -path "*striped_dir*" \
+                               ! -name .lustre -type f -exec sha1sum {} \; |
                                sort -k 2 >$tmp/sha1sums || {
+                               popd
                                error_noexit "sha1sum"
                                return 1
                        }
@@ -1939,51 +2142,79 @@ t32_test() {
                                error_noexit "sha1sum verification failed"
                                return 1
                        fi
+
+                       # if upgrade from DNE(2.5), then check remote directory
+                       # if upgrade from DNE(2.7), then check striped directory
+                       if $mdt2_is_available &&
+                          [[ "$dne_upgrade" != "no" ]]; then
+                               local new_dir="$tmp/mnt/lustre/striped_dir"
+                               local striped_dir_old="$new_dir/striped_dir_old"
+
+                               local dir_list="$new_dir/remote_dir"
+                               [[ ! -d $triped_dir_old ]] ||
+                                       dir_list+=" $striped_dir_old"
+
+                               for dir in $dir_list; do
+                                       pushd $dir
+                                       find ! -name .lustre -type f    \
+                                               -exec sha1sum {} \; |
+                                               sort -k 2 >$tmp/sha1sums || {
+                                                       popd
+                                                       error_noexit "sha1sum"
+                                                       return 1
+                                               }
+                                       popd
+                                       if ! diff -ub $tmp/sha1sums.orig \
+                                               $tmp/sha1sums; then
+                                               error_noexit "sha1sum $dir" \
+                                                            "failed"
+                                               return 1
+                                       fi
+                               done
+                       fi
                else
                        echo "sha1sum verification skipped"
                fi
 
                if [ "$dne_upgrade" != "no" ]; then
-                       rm -rf $tmp/mnt/lustre/remote_dir || {
+                       rm -rf $tmp/mnt/lustre/striped_dir || {
                                error_noexit "remove remote dir failed"
                                return 1
                        }
                fi
 
-               if $r test -f $tmp/list; then
-                       #
-                       # There is not a Test Framework API to copy files to or
-                       # from a remote node.
-                       #
-                       # LU-2393 - do both sorts on same node to ensure locale
-                       # is identical
-                       $r cat $tmp/list | sort -k 6 >$tmp/list.orig
+               # migrate files/dirs to remote MDT, then move them back
+               if [ $(lustre_version_code mds1) -ge $(version_code 2.7.50) -a \
+                    $dne_upgrade != "no" ]; then
+                       $r $LCTL set_param -n   \
+                               mdt.${fsname}*.enable_remote_dir=1 2>/dev/null
+
+                       echo "test migration"
                        pushd $tmp/mnt/lustre
-                       ls -Rni --time-style=+%s | sort -k 6 >$tmp/list || {
-                               error_noexit "ls"
-                               return 1
-                       }
+                       for dir in $(find ! -name .lustre ! -name . -type d); do
+                               mdt_index=$($LFS getdirstripe -i $dir)
+                               stripe_cnt=$($LFS getdirstripe -c $dir)
+                               if [ $mdt_index = 0 -a $stripe_cnt -le 1 ]; then
+                                       $LFS mv -M 1 $dir || {
+                                       popd
+                                       error_noexit "migrate MDT1 failed"
+                                       return 1
+                               }
+                               fi
+                       done
+
+                       for dir in $(find ! -name . ! -name .lustre -type d); do
+                               mdt_index=$($LFS getdirstripe -i $dir)
+                               stripe_cnt=$($LFS getdirstripe -c $dir)
+                               if [ $mdt_index = 1 -a $stripe_cnt -le 1 ]; then
+                                       $LFS mv -M 0 $dir || {
+                                       popd
+                                       error_noexit "migrate MDT0 failed"
+                                       return 1
+                               }
+                               fi
+                       done
                        popd
-                       #
-                       # 32-bit and 64-bit clients use different algorithms to
-                       # convert FIDs into inode numbers.  Hence, remove the inode
-                       # numbers from the lists, if the original list was created
-                       # on an architecture with different number of bits per
-                       # "long".
-                       #
-                       if [ $(t32_bits_per_long $(uname -m)) != \
-                               $(t32_bits_per_long $img_arch) ]; then
-                               echo "Different number of bits per \"long\" from the disk image"
-                               for list in list.orig list; do
-                                       sed -i -e 's/^[0-9]\+[ \t]\+//' $tmp/$list
-                               done
-                       fi
-                       if ! diff -ub $tmp/list.orig $tmp/list; then
-                               error_noexit "list verification failed"
-                               return 1
-                       fi
-               else
-                       echo "list verification skipped"
                fi
 
                #
@@ -2015,21 +2246,21 @@ t32_test() {
                }
                shall_cleanup_lustre=false
        else
-               if [ "$dne_upgrade" != "no" ]; then
-                       $r umount -d $tmp/mnt/mdt1 || {
+               if [[ "$dne_upgrade" != "no" ]] || $mdt2_is_available; then
+                       $r $UMOUNT $tmp/mnt/mdt1 || {
                                error_noexit "Unmounting the MDT2"
                                return 1
                        }
                        shall_cleanup_mdt1=false
                fi
 
-               $r umount -d $tmp/mnt/mdt || {
+               $r $UMOUNT $tmp/mnt/mdt || {
                        error_noexit "Unmounting the MDT"
                        return 1
                }
                shall_cleanup_mdt=false
 
-               $r umount -d $tmp/mnt/ost || {
+               $r $UMOUNT $tmp/mnt/ost || {
                        error_noexit "Unmounting the OST"
                        return 1
                }
@@ -2040,6 +2271,12 @@ t32_test() {
                        return 1
                }
 
+               if [[ $fstype == zfs ]]; then
+                       local poolname=t32fs-mdt1
+                       $r "$ZPOOL list -H $poolname >/dev/null 2>&1 ||
+                               $ZPOOL import -f -d $tmp $poolname"
+               fi
+
                # mount a second time to make sure we didnt leave upgrade flag on
                $r $TUNEFS --dryrun $mdt_dev || {
                        $r losetup -a
@@ -2096,6 +2333,7 @@ test_32c() {
                # Do not support 1_8 and 2_1 direct upgrade to DNE2 anymore */
                echo $tarball | grep "1_8" && continue
                echo $tarball | grep "2_1" && continue
+               load_modules
                dne_upgrade=yes t32_test $tarball writeconf || rc=$?
        done
        return $rc
@@ -2156,7 +2394,7 @@ test_33a() { # bug 12333, was test_33
        cp /etc/hosts $MOUNT2/ || error "copy /etc/hosts $MOUNT2/ failed"
        $GETSTRIPE $MOUNT2/hosts || error "$GETSTRIPE $MOUNT2/hosts failed"
 
-       umount -d $MOUNT2
+       umount $MOUNT2
        stop fs2ost -f
        stop fs2mds -f
        cleanup_nocli || error "cleanup_nocli failed with $?"
@@ -2421,7 +2659,7 @@ test_36() { # 12743
                 rc=3
        fi
 
-       umount -d $MOUNT2
+       $UMOUNT $MOUNT2
        stop fs3ost -f || error "unable to stop OST3"
        stop fs2ost -f || error "unable to stop OST2"
        stop fs2mds -f || error "unable to stop second MDS"
@@ -2459,7 +2697,7 @@ test_37() {
 
        echo mount_op=$mount_op
 
-       do_facet $SINGLEMDS "umount -d $mntpt && rm -f $mdsdev_sym"
+       do_facet $SINGLEMDS "$UMOUNT $mntpt && rm -f $mdsdev_sym"
 
        if $(echo $mount_op | grep -q "unable to set tunable"); then
                error "set tunables failed for symlink device"
@@ -2591,7 +2829,6 @@ test_41a() { #bug 14134
        stop ost1 -f || error "unable to stop OST1"
        stop_mds || error "Unable to stop MDS"
        stop_mds || error "Unable to stop MDS on second try"
-       unload_modules_conf || error "unload_modules_conf failed"
 }
 run_test 41a "mount mds with --nosvc and --nomgs"
 
@@ -2641,23 +2878,22 @@ test_41c() {
 
        cleanup
        # MDT concurrent start
-       #define OBD_FAIL_TGT_DELAY_CONNECT 0x703
-       do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x703"
+       #define OBD_FAIL_TGT_MOUNT_RACE 0x716
+       do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x716"
        start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS &
        local pid=$!
-       sleep 2
-       do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x0"
        start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS &
+       do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x0"
        local pid2=$!
        wait $pid2
        local rc2=$?
        wait $pid
        local rc=$?
-       if [ $rc == 0 ] && [ $rc2 == 114 ]; then
+       if [ $rc -eq 0 ] && [ $rc2 -ne 0 ]; then
                echo "1st MDT start succeed"
-               echo "2nd MDT start failed with EALREADY"
-       elif [ $rc2 == 0 ] && [ $rc == 114 ]; then
-               echo "1st MDT start failed with EALREADY"
+               echo "2nd MDT start failed with $rc2"
+       elif [ $rc2 -eq 0 ] && [ $rc -ne 0 ]; then
+               echo "1st MDT start failed with $rc"
                echo "2nd MDT start succeed"
        else
                stop mds1 -f
@@ -2672,23 +2908,22 @@ test_41c() {
 
        # OST concurrent start
 
-       #define OBD_FAIL_TGT_DELAY_CONNECT 0x703
-       do_facet ost1 "$LCTL set_param fail_loc=0x703"
+       #define OBD_FAIL_TGT_MOUNT_RACE 0x716
+       do_facet ost1 "$LCTL set_param fail_loc=0x716"
        start ost1 $(ostdevname 1) $OST_MOUNT_OPTS &
        pid=$!
-       sleep 2
-       do_facet ost1 "$LCTL set_param fail_loc=0x0"
        start ost1 $(ostdevname 1) $OST_MOUNT_OPTS &
+       do_facet ost1 "$LCTL set_param fail_loc=0x0"
        pid2=$!
        wait $pid2
        rc2=$?
        wait $pid
        rc=$?
-       if [ $rc == 0 ] && [ $rc2 == 114 ]; then
+       if [ $rc -eq 0 ] && [ $rc2 -ne 0 ]; then
                echo "1st OST start succeed"
-               echo "2nd OST start failed with EALREADY"
-       elif [ $rc2 == 0 ] && [ $rc == 114 ]; then
-               echo "1st OST start failed with EALREADY"
+               echo "2nd OST start failed with $rc2"
+       elif [ $rc2 -eq 0 ] && [ $rc -ne 0 ]; then
+               echo "1st OST start failed with $rc"
                echo "2nd OST start succeed"
        else
                stop_mds -f
@@ -2745,20 +2980,19 @@ test_42() { #bug 14693
 
        do_facet mgs $LCTL conf_param $FSNAME.sys.some_wrong_param=20
        cleanup || error "stopping $FSNAME failed with invalid sys param"
-       load_modules
        setup
        check_mount || error "client was not mounted with invalid sys param"
        cleanup || error "stopping $FSNAME failed with invalid sys param"
 }
 run_test 42 "allow client/server mount/unmount with invalid config param"
 
-test_43() {
+test_43a() {
        [[ $(lustre_version_code mgs) -ge $(version_code 2.5.58) ]] ||
                { skip "Need MDS version at least 2.5.58" && return 0; }
        [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
 
        ID1=${ID1:-501}
-       USER1=$(cat /etc/passwd | grep :$ID1:$ID1: | cut -d: -f1)
+       USER1=$(getent passwd | grep :$ID1:$ID1: | cut -d: -f1)
        [ -z "$USER1" ] && skip_env "missing user with uid=$ID1 gid=$ID1" &&
                return
 
@@ -2872,7 +3106,7 @@ test_43() {
        #   root should be able to access root file after that
        #
        local NIDLIST=$($LCTL list_nids all | tr '\n' ' ')
-       NIDLIST="2@elan $NIDLIST 192.168.0.[2,10]@tcp"
+       NIDLIST="2@gni $NIDLIST 192.168.0.[2,10]@tcp"
        NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
        set_conf_param_and_check mds                                    \
                "$LCTL get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"  \
@@ -2900,8 +3134,43 @@ test_43() {
        touch $DIR/$tdir-rootdir/tfile-2 ||
                error "$ST: root create permission is denied"
        echo "$ST: root create permission is granted - ok"
+       cleanup || error "cleanup failed with $?"
 }
-run_test 43 "check root_squash and nosquash_nids"
+run_test 43a "check root_squash and nosquash_nids"
+
+test_43b() { # LU-5690
+       [[ $(lustre_version_code mgs) -ge $(version_code 2.7.62) ]] ||
+               { skip "Need MGS version 2.7.62+"; return; }
+
+       if [[ -z "$fs2mds_DEV" ]]; then
+               is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
+               skip_env "mixed loopback and real device not working" && return
+       fi
+
+       local fs2mdsdev=$(mdsdevname 1_2)
+       local fs2mdsvdev=$(mdsvdevname 1_2)
+
+       # temporarily use fs2mds as fs2mgs
+       local fs2mgs=fs2mds
+       local fs2mgsdev=$fs2mdsdev
+       local fs2mgsvdev=$fs2mdsvdev
+
+       local fsname=test1234
+
+       load_module llite/lustre
+       local client_ip=$(host_nids_address $HOSTNAME $NETTYPE)
+       local host=${client_ip//*./}
+       local net=${client_ip/%$host/}
+       local nosquash_nids=$(h2$NETTYPE $net[$host,$host,$host])
+
+       add $fs2mgs $(mkfs_opts mgs $fs2mgsdev) --fsname=$fsname \
+               --param mdt.root_squash=$RUNAS_ID:$RUNAS_ID \
+               --param mdt.nosquash_nids=$nosquash_nids \
+               --reformat $fs2mgsdev $fs2mgsvdev || error "add fs2mgs failed"
+       start $fs2mgs $fs2mgsdev $MGS_MOUNT_OPTS  || error "start fs2mgs failed"
+       stop $fs2mgs -f || error "stop fs2mgs failed"
+}
+run_test 43b "parse nosquash_nids with commas in expr_list"
 
 umount_client $MOUNT
 cleanup_nocli
@@ -3309,7 +3578,7 @@ test_50f() {
            stop_ost2 || error "Unable to stop OST2"
        fi
 
-       umount_client $MOUNT || error "Unable to unmount client"
+       umount_client $MOUNT -f || error "Unable to unmount client"
        stop_ost || error "Unable to stop OST1"
        stop_mds || error "Unable to stop MDS"
        #writeconf to remove all ost2 traces for subsequent tests
@@ -3385,6 +3654,56 @@ test_50h() {
 }
 run_test 50h "LU-642: activate deactivated OST"
 
+test_50i() {
+       # prepare MDT/OST, make OSC inactive for OST1
+       [ "$MDSCOUNT" -lt "2" ] && skip_env "$MDSCOUNT < 2, skipping" && return
+
+       [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
+       do_facet mds2 "$TUNEFS --param mdc.active=0 $(mdsdevname 2)" ||
+               error "tunefs MDT2 failed"
+       start_mds  || error "Unable to start MDT"
+       start_ost  || error "Unable to start OST1"
+       start_ost2 || error "Unable to start OST2"
+       mount_client $MOUNT || error "client start failed"
+
+       mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
+
+       $LCTL conf_param ${FSNAME}-MDT0000.mdc.active=0 &&
+               error "deactive MDC0 succeeds"
+       # activate MDC for MDT2
+       local TEST="$LCTL get_param -n mdc.${FSNAME}-MDT0001-mdc-[!M]*.active"
+       set_conf_param_and_check client                                 \
+               "$TEST" "${FSNAME}-MDT0001.mdc.active" 1 ||
+               error "Unable to activate MDT2"
+
+       wait_clients_import_state ${CLIENTS:-$HOSTNAME} mds2 FULL
+       if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.60) ]
+       then
+               wait_dne_interconnect
+       fi
+       $LFS mkdir -i1 $DIR/$tdir/2 || error "mkdir $DIR/$tdir/2 failed"
+       # create some file
+       createmany -o $DIR/$tdir/2/$tfile-%d 1 || error "create files failed"
+
+       rm -rf $DIR/$tdir/2 || error "unlink dir failed"
+
+       # deactivate MDC for MDT2
+       local TEST="$LCTL get_param -n mdc.${FSNAME}-MDT0001-mdc-[!M]*.active"
+       set_conf_param_and_check client                                 \
+               "$TEST" "${FSNAME}-MDT0001.mdc.active" 0 ||
+               error "Unable to deactivate MDT2"
+
+       $LFS mkdir -i1 $DIR/$tdir/2 &&
+               error "mkdir $DIR/$tdir/2 succeeds after deactive MDT"
+
+       # cleanup
+       umount_client $MOUNT || error "Unable to umount client"
+       stop_mds
+       stop_ost
+       stop_ost 2
+}
+run_test 50i "activate deactivated MDT"
+
 test_51() {
        local LOCAL_TIMEOUT=20
 
@@ -3403,7 +3722,8 @@ test_51() {
        start_ost2 || error "Unable to start OST1"
        wait $pid
        stop_ost2 || error "Unable to stop OST1"
-       cleanup || error "cleanup failed with $?"
+       umount_client $MOUNT -f || error “unmount $MOUNT failed”
+       cleanup_nocli || error “stop server failed”
        #writeconf to remove all ost2 traces for subsequent tests
        writeconf_or_reformat
 }
@@ -3491,9 +3811,9 @@ test_52() {
        echo
 
        # backup files
-       echo backup files to $TMP/files
+       echo backup files to $TMP/$tdir
        local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
-       copy_files_xattrs $(hostname) $TMP/files $TMP/file_xattrs $files ||
+       copy_files_xattrs $(hostname) $TMP/$tdir $TMP/file_xattrs $files ||
                error "Unable to copy files"
 
        umount_client $MOUNT || error "Unable to umount client"
@@ -3520,34 +3840,23 @@ test_52() {
        do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
        [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
 
-       # recover objects dry-run
-       if [ $(lustre_version_code ost1) -ge $(version_code 2.5.56) ]; then
-               echo "ll_recover_lost_found_objs dry_run"
-               do_node $ost1node \
-                       "ll_recover_lost_found_objs -n -d $ost1mnt/O" ||
-                       error "ll_recover_lost_found_objs failed"
-       fi
-
-       # recover objects
-       echo "ll_recover_lost_found_objs fix run"
-       do_node $ost1node "ll_recover_lost_found_objs -d $ost1mnt/lost+found" ||
-                error "ll_recover_lost_found_objs failed"
-
-       # compare restored objects against saved ones
-       diff_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
-       [ $? -eq 0 ] || error "Unable to diff objects"
-
        do_node $ost1node "umount $ost1mnt" ||
                error "Unable to umount ost1 as ldiskfs"
 
        start_ost || error "Unable to start OST1"
        mount_client $MOUNT || error "Unable to mount client"
 
+       local REPAIRED=$(do_node $ost1node "$LCTL get_param \
+                        -n osd-ldiskfs.$FSNAME-OST0000.oi_scrub" |
+                        awk '/^lf_repa[ri]*ed/ { print $2 }')
+       [ $REPAIRED -gt 0 ] ||
+               error "Some entry under /lost+found should be repaired"
+
        # compare files
-       diff_files_xattrs $(hostname) $TMP/files $TMP/file_xattrs $files ||
+       diff_files_xattrs $(hostname) $TMP/$tdir $TMP/file_xattrs $files ||
                error "Unable to diff files"
 
-       rm -rf $TMP/files $TMP/file_xattrs ||
+       rm -rf $TMP/$tdir $TMP/file_xattrs ||
                error "Unable to delete temporary files"
        do_node $ost1node "rm -rf $ost1tmp" ||
                error "Unable to delete temporary files"
@@ -3648,7 +3957,6 @@ thread_sanity() {
        local newvalue="${opts}=$(expr $basethr \* $ncpts)"
        setmodopts -a $modname "$newvalue" oldvalue
 
-       load_modules
        setup
        check_mount || return 41
 
@@ -3664,7 +3972,6 @@ thread_sanity() {
                return $?
        cleanup
 
-       load_modules
        setup
 }
 
@@ -3761,8 +4068,7 @@ test_56() {
        MDSJOURNALSIZE=16
 
        for num in $(seq 1 $MDSCOUNT); do
-               add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
-                       --reformat $(mdsdevname $num) $(mdsvdevname $num)
+               reformat_mdt $num
        done
        add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=10000 --reformat \
                $(ostdevname 1) $(ostvdevname 1)
@@ -3914,20 +4220,19 @@ test_60() { # LU-471
 run_test 60 "check mkfs.lustre --mkfsoptions -E -O options setting"
 
 test_61() { # LU-80
-       local reformat=false
+       local lxattr=false
 
        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.1.53) ] ||
                { skip "Need MDS version at least 2.1.53"; return 0; }
 
        if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
-          ! large_xattr_enabled; then
-               reformat=true
-               LDISKFS_MKFS_OPTS+=" -O large_xattr"
+            ! large_xattr_enabled; then
+               lxattr=true
 
                for num in $(seq $MDSCOUNT); do
-                       add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
-                       --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
-                       error "add mds $num failed"
+                       do_facet mds${num} $TUNE2FS -O large_xattr \
+                               $(mdsdevname $num) ||
+                               error "tune2fs on mds $num failed"
                done
        fi
 
@@ -3940,45 +4245,59 @@ test_61() { # LU-80
        local large_value="$(generate_string $(max_xattr_size))"
        local small_value="bar"
 
-    local name="trusted.big"
-    log "save large xattr $name on $file"
-    setfattr -n $name -v $large_value $file ||
-        error "saving $name on $file failed"
-
-    local new_value=$(get_xattr_value $name $file)
-    [[ "$new_value" != "$large_value" ]] &&
-        error "$name different after saving"
-
-    log "shrink value of $name on $file"
-    setfattr -n $name -v $small_value $file ||
-        error "shrinking value of $name on $file failed"
-
-    new_value=$(get_xattr_value $name $file)
-    [[ "$new_value" != "$small_value" ]] &&
-        error "$name different after shrinking"
-
-    log "grow value of $name on $file"
-    setfattr -n $name -v $large_value $file ||
-        error "growing value of $name on $file failed"
-
-    new_value=$(get_xattr_value $name $file)
-    [[ "$new_value" != "$large_value" ]] &&
-        error "$name different after growing"
-
-    log "check value of $name on $file after remounting MDS"
-    fail $SINGLEMDS
-    new_value=$(get_xattr_value $name $file)
-    [[ "$new_value" != "$large_value" ]] &&
-        error "$name different after remounting MDS"
-
-    log "remove large xattr $name from $file"
-    setfattr -x $name $file || error "removing $name from $file failed"
-
-    rm -f $file
-    stopall
-       if $reformat; then
-               LDISKFS_MKFS_OPTS=${LDISKFS_MKFS_OPTS% -O large_xattr}
-               reformat
+       local name="trusted.big"
+       log "save large xattr $name on $file"
+       setfattr -n $name -v $large_value $file ||
+               error "saving $name on $file failed"
+
+       local new_value=$(get_xattr_value $name $file)
+       [[ "$new_value" != "$large_value" ]] &&
+               error "$name different after saving"
+
+       log "shrink value of $name on $file"
+       setfattr -n $name -v $small_value $file ||
+               error "shrinking value of $name on $file failed"
+
+       new_value=$(get_xattr_value $name $file)
+       [[ "$new_value" != "$small_value" ]] &&
+               error "$name different after shrinking"
+
+       log "grow value of $name on $file"
+       setfattr -n $name -v $large_value $file ||
+               error "growing value of $name on $file failed"
+
+       new_value=$(get_xattr_value $name $file)
+       [[ "$new_value" != "$large_value" ]] &&
+               error "$name different after growing"
+
+       log "check value of $name on $file after remounting MDS"
+       fail $SINGLEMDS
+       new_value=$(get_xattr_value $name $file)
+       [[ "$new_value" != "$large_value" ]] &&
+               error "$name different after remounting MDS"
+
+       log "remove large xattr $name from $file"
+       setfattr -x $name $file || error "removing $name from $file failed"
+
+       if $lxattr; then
+               stopall || error "stopping for e2fsck run"
+               for num in $(seq $MDSCOUNT); do
+                       run_e2fsck $(facet_active_host mds$num) \
+                               $(mdsdevname $num) "-y" ||
+                               error "e2fsck MDT$num failed"
+               done
+               setup_noconfig || error "remounting the filesystem failed"
+       fi
+
+       # need to delete this file to avoid problems in other tests
+       rm -f $file
+       stopall || error "stopping systems to turn off large_xattr"
+       if $lxattr; then
+               for num in $(seq $MDSCOUNT); do
+                       do_facet mds${num} $TUNE2FS -O ^large_xattr \
+                               $(mdsdevname $num) ||
+                               error "tune2fs on mds $num failed"
+               done
        fi
 }
 run_test 61 "large xattr"
@@ -3997,10 +4316,10 @@ test_62() {
                { skip "Need MDS version at least 2.2.51"; return 0; }
 
        echo "disable journal for mds"
-       do_facet mds tune2fs -O ^has_journal $mdsdev || error "tune2fs failed"
+       do_facet mds $TUNE2FS -O ^has_journal $mdsdev || error "tune2fs failed"
        start_mds && error "MDT start should fail"
        echo "disable journal for ost"
-       do_facet ost1 tune2fs -O ^has_journal $ostdev || error "tune2fs failed"
+       do_facet ost1 $TUNE2FS -O ^has_journal $ostdev || error "tune2fs failed"
        start_ost && error "OST start should fail"
        cleanup || error "cleanup failed with rc $?"
        reformat_and_config
@@ -4035,7 +4354,8 @@ test_64() {
        stop_ost2 || error "Unable to stop second ost"
        echo "$LFS df"
        $LFS df --lazy || error "lfs df failed"
-       cleanup || error "cleanup failed with $?"
+       umount_client $MOUNT -f || error “unmount $MOUNT failed”
+       cleanup_nocli || error "cleanup_nocli failed with $?"
        #writeconf to remove all ost2 traces for subsequent tests
        writeconf_or_reformat
 }
@@ -4070,7 +4390,7 @@ test_65() { # LU-2237
        do_facet $SINGLEMDS \
                "mount -t $(facet_fstype $SINGLEMDS) $opts $devname $brpt"
        do_facet $SINGLEMDS "rm -f ${brpt}/last_rcvd"
-       do_facet $SINGLEMDS "umount -d $brpt"
+       do_facet $SINGLEMDS "$UMOUNT $brpt"
 
        # restart MDS, the "last_rcvd" file should be recreated.
        start_mds || error "fail to restart the MDS"
@@ -4255,6 +4575,10 @@ test_68() {
 }
 run_test 68 "be able to reserve specific sequences in FLDB"
 
+# Test 69: is about the total number of objects ever created on an OST.
+# so that when it is reformatted the normal MDS->OST orphan recovery won't
+# just "precreate" the missing objects. In the past it might try to recreate
+# millions of objects after an OST was reformatted
 test_69() {
        local server_version=$(lustre_version_code $SINGLEMDS)
 
@@ -4266,25 +4590,50 @@ test_69() {
                skip "Need MDS version at least 2.5.0" && return
 
        setup
+       mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
 
        # use OST0000 since it probably has the most creations
        local OSTNAME=$(ostname_from_index 0)
        local mdtosc_proc1=$(get_mdtosc_proc_path mds1 $OSTNAME)
+       local last_id=$(do_facet mds1 $LCTL get_param -n \
+                       osc.$mdtosc_proc1.prealloc_last_id)
 
-       # Want to have OST LAST_ID over 1.5 * OST_MAX_PRECREATE to
-       # verify that the LAST_ID recovery is working properly.  If
+       # Want to have OST LAST_ID over 5 * OST_MAX_PRECREATE to
+       # verify that the LAST_ID recovery is working properly. If
        # not, then the OST will refuse to allow the MDS connect
        # because the LAST_ID value is too different from the MDS
        #define OST_MAX_PRECREATE=20000
-       local num_create=$((20000 * 3))
+       local ost_max_pre=20000
+       local num_create=$(( ost_max_pre * 5 + 1 - last_id))
+
+       # If the LAST_ID is already over 5 * OST_MAX_PRECREATE, we don't
+       # need to create any files. So, skip this section.
+       if [ $num_create -gt 0 ]; then
+               # Check the number of inodes available on OST0
+               local files=0
+               local ifree=$($LFS df -i $MOUNT | awk '/OST0000/ { print $4 }')
+               log "On OST0, $ifree inodes available. Want $num_create."
+
+               $SETSTRIPE -i 0 $DIR/$tdir ||
+                       error "$SETSTRIPE -i 0 $DIR/$tdir failed"
+               if [ $ifree -lt 10000 ]; then
+                       files=$(( ifree - 50 ))
+               else
+                       files=10000
+               fi
+
+               local j=$((num_create / files + 1))
+               for i in $(seq 1 $j); do
+                       createmany -o $DIR/$tdir/$tfile-$i- $files ||
+                               error "createmany fail create $files files: $?"
+                       unlinkmany $DIR/$tdir/$tfile-$i- $files ||
+                               error "unlinkmany failed unlink $files files"
+               done
+       fi
 
-       mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
-       $SETSTRIPE -i 0 $DIR/$tdir || error "$SETSTRIPE -i 0 $DIR/$tdir failed"
-       createmany -o $DIR/$tdir/$tfile- $num_create ||
-               error "createmany: failed to create $num_create files: $?"
        # delete all of the files with objects on OST0 so the
        # filesystem is not inconsistent later on
-       $LFS find $MOUNT --ost 0 | xargs rm
+       $LFS find $MOUNT --ost 0 -print0 | xargs -0 rm
 
        umount_client $MOUNT || error "umount client failed"
        stop_ost || error "OST0 stop failure"
@@ -4299,6 +4648,10 @@ test_69() {
        local idx=$($GETSTRIPE -i $DIR/$tdir/$tfile-last)
        [ $idx -ne 0 ] && error "$DIR/$tdir/$tfile-last on $idx not 0" || true
 
+       local iused=$($LFS df -i $MOUNT | awk '/OST0000/ { print $3 }')
+       log "On OST0, $iused used inodes"
+       [ $iused -ge $((ost_max_pre/2 + 1000)) ] &&
+               error "OST replacement created too many inodes; $iused"
        cleanup || error "cleanup failed with $?"
 }
 run_test 69 "replace an OST with the same index"
@@ -4400,6 +4753,59 @@ test_70d() {
 }
 run_test 70d "stop MDT1, mkdir succeed, create remote dir fail"
 
+test_70e() {
+       [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+
+       [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.62) ] ||
+               { skip "Need MDS version at least 2.7.62"; return 0; }
+
+       cleanup || error "cleanup failed with $?"
+
+       local mdsdev=$(mdsdevname 1)
+       local ostdev=$(ostdevname 1)
+       local mdsvdev=$(mdsvdevname 1)
+       local ostvdev=$(ostvdevname 1)
+       local opts_mds="$(mkfs_opts mds1 $mdsdev) --reformat $mdsdev $mdsvdev"
+       local opts_ost="$(mkfs_opts ost1 $ostdev) --reformat $ostdev $ostvdev"
+
+       add mds1 $opts_mds || error "add mds1 failed"
+       start_mdt 1 || error "start mdt1 failed"
+       add ost1 $opts_ost || error "add ost1 failed"
+       start_ost || error "start ost failed"
+       mount_client $MOUNT > /dev/null || error "mount client $MOUNT failed"
+
+       local soc=$(do_facet mds1 "$LCTL get_param -n \
+                   mdt.*MDT0000.sync_lock_cancel")
+       [ $soc == "never" ] || error "SoC enabled on single MDS"
+
+       for i in $(seq 2 $MDSCOUNT); do
+               mdsdev=$(mdsdevname $i)
+               mdsvdev=$(mdsvdevname $i)
+               opts_mds="$(mkfs_opts mds$i $mdsdev) --reformat $mdsdev \
+                         $mdsvdev"
+               add mds$i $opts_mds || error "add mds$i failed"
+               start_mdt $i || error "start mdt$i fail"
+       done
+
+       wait_dne_interconnect
+
+       for i in $(seq $MDSCOUNT); do
+               soc=$(do_facet mds$i "$LCTL get_param -n \
+                       mdt.*MDT000$((i - 1)).sync_lock_cancel")
+               [ $soc == "blocking" ] || error "SoC not enabled on DNE"
+       done
+
+       for i in $(seq 2 $MDSCOUNT); do
+               stop_mdt $i || error "stop mdt$i fail"
+       done
+       soc=$(do_facet mds1 "$LCTL get_param -n \
+               mdt.*MDT0000.sync_lock_cancel")
+       [ $soc == "never" ] || error "SoC enabled on single MDS"
+
+       cleanup || error "cleanup failed with $?"
+}
+run_test 70e "Sync-on-Cancel will be enabled by default on DNE"
+
 test_71a() {
        [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
        if combined_mgs_mds; then
@@ -4567,8 +4973,8 @@ test_72() { #LU-2634
 
        for num in $(seq $MDSCOUNT); do
                add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
-               --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
-               error "add mds $num failed"
+                       --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
+                       error "add mds $num failed"
                do_facet mds${num} "$TUNE2FS -O extents $(mdsdevname $num)" ||
                        error "$TUNE2FS failed on mds${num}"
        done
@@ -4599,7 +5005,6 @@ test_72() { #LU-2634
 run_test 72 "test fast symlink with extents flag enabled"
 
 test_73() { #LU-3006
-       load_modules
        [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
        do_facet ost1 "$TUNEFS --failnode=1.2.3.4@$NETTYPE $(ostdevname 1)" ||
                error "1st tunefs failed"
@@ -4956,7 +5361,7 @@ test_80() {
 }
 run_test 80 "mgc import reconnect race"
 
-# Save the original values of $OSTCOUNT and $OSTINDEX$i.
+#Save the original values of $OSTCOUNT and $OSTINDEX$i.
 save_ostindex() {
        local new_ostcount=$1
        saved_ostcount=$OSTCOUNT
@@ -5077,8 +5482,9 @@ test_82a() { # LU-4665
        local i
        local index
        local ost_indices
+       local LOV_V1_INSANE_STRIPE_COUNT=65532
        for i in $(seq $OSTCOUNT); do
-               index=$((RANDOM * 2))
+               index=$(((RANDOM * 2) % LOV_V1_INSANE_STRIPE_COUNT))
                ost_indices+=" $index"
        done
        ost_indices=$(comma_list $ost_indices)
@@ -5184,8 +5590,9 @@ test_82b() { # LU-4665
        local i
        local index
        local ost_indices
+       local LOV_V1_INSANE_STRIPE_COUNT=65532
        for i in $(seq $OSTCOUNT); do
-               index=$((RANDOM * 2))
+               index=$(((RANDOM * 2) % LOV_V1_INSANE_STRIPE_COUNT))
                ost_indices+=" $index"
        done
        ost_indices=$(comma_list $ost_indices)
@@ -5313,32 +5720,6 @@ test_83() {
 run_test 83 "ENOSPACE on OST doesn't cause message VFS: \
 Busy inodes after unmount ..."
 
-recovery_time_min() {
-       local CONNECTION_SWITCH_MIN=5
-       local CONNECTION_SWITCH_INC=5
-       local CONNECTION_SWITCH_MAX
-       local RECONNECT_DELAY_MAX
-       local INITIAL_CONNECT_TIMEOUT
-       local max
-       local TO_20
-
-       #CONNECTION_SWITCH_MAX=min(50, max($CONNECTION_SWITCH_MIN,$TIMEOUT)
-       (($CONNECTION_SWITCH_MIN>$TIMEOUT)) && \
-               max=$CONNECTION_SWITCH_MIN || max=$TIMEOUT
-       (($max<50)) && CONNECTION_SWITCH_MAX=$max || CONNECTION_SWITCH_MAX=50
-
-       #INITIAL_CONNECT_TIMEOUT = max(CONNECTION_SWITCH_MIN, \
-       #obd_timeout/20)
-       TO_20=$(($TIMEOUT/20))
-       (($CONNECTION_SWITCH_MIN>$TO_20)) && \
-               INITIAL_CONNECT_TIMEOUT=$CONNECTION_SWITCH_MIN || \
-               INITIAL_CONNECT_TIMEOUT=$TO_20
-
-       RECONNECT_DELAY_MAX=$(($CONNECTION_SWITCH_MAX+$CONNECTION_SWITCH_INC+ \
-                               $INITIAL_CONNECT_TIMEOUT))
-       echo $((2*$RECONNECT_DELAY_MAX))
-}
-
 test_84() {
        local facet=$SINGLEMDS
        local num=$(echo $facet | tr -d "mds")
@@ -5346,20 +5727,24 @@ test_84() {
        local time_min=$(recovery_time_min)
        local recovery_duration
        local completed_clients
+       local correct_clients
        local wrap_up=5
 
        echo "start mds service on $(facet_active_host $facet)"
-       start $facet ${dev} $MDS_MOUNT_OPTS \
-           "-o recovery_time_hard=$time_min,recovery_time_soft=$time_min" $@ ||
+       start_mds \
+       "-o recovery_time_hard=$time_min,recovery_time_soft=$time_min" $@ ||
                error "start MDS failed"
 
-       start_ost
-       start_ost2
+       start_ost || error "start OST0000 failed"
+       start_ost2 || error "start OST0001 failed"
 
        echo "recovery_time=$time_min, timeout=$TIMEOUT, wrap_up=$wrap_up"
 
-       mount_client $MOUNT1 || error "mount failed"
-       mount_client $MOUNT2 || error "mount failed"
+       mount_client $MOUNT1 || error "mount $MOUNT1 failed"
+       mount_client $MOUNT2 || error "mount $MOUNT2 failed"
+       # make sure new superblock labels are sync'd before disabling writes
+       sync_all_data
+       sleep 5
 
        replay_barrier $SINGLEMDS
        createmany -o $DIR1/$tfile-%d 1000
@@ -5369,7 +5754,7 @@ test_84() {
        #define OBD_FAIL_TGT_REPLAY_DELAY  0x709 | FAIL_SKIP
        do_facet $SINGLEMDS "lctl set_param fail_loc=0x20000709 fail_val=5"
 
-       facet_failover $SINGLEMDS || error "failover: $?"
+       facet_failover --fsck $SINGLEMDS || error "failover: $?"
        client_up
 
        echo "recovery status"
@@ -5384,8 +5769,10 @@ test_84() {
        completed_clients=$(do_facet $SINGLEMDS \
                "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status" |
                awk '/completed_clients/ { print $2 }')
-       [ "$completed_clients" = "1/2" ] ||
-               error "completed_clients != 1/2: $completed_clients"
+
+       correct_clients="$MDSCOUNT/$((MDSCOUNT+1))"
+       [ "$completed_clients" = "${correct_clients}" ] ||
+               error "$completed_clients != $correct_clients"
 
        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
        umount_client $MOUNT1
@@ -5407,6 +5794,610 @@ test_85() {
 }
 run_test 85 "osd_ost init: fail ea_fid_set"
 
+test_86() {
+       [ "$(facet_fstype ost1)" = "zfs" ] &&
+               skip "LU-6442: no such mkfs params for ZFS OSTs" && return
+
+       local OST_OPTS="$(mkfs_opts ost1 $(ostdevname 1)) \
+               --reformat $(ostdevname 1) $(ostvdevname 1)"
+
+       local NEWSIZE=1024
+       local OLDSIZE=$(do_facet ost1 "$DEBUGFS -c -R stats $(ostdevname 1)" |
+               awk '/Flex block group size: / { print $NF; exit; }')
+
+       local opts=OST_OPTS
+       if [[ ${!opts} != *mkfsoptions* ]]; then
+               eval opts=\"${!opts} \
+                       --mkfsoptions='\\\"-O flex_bg -G $NEWSIZE\\\"'\"
+       else
+               val=${!opts//--mkfsoptions=\\\"/ \
+                       --mkfsoptions=\\\"-O flex_bg -G $NEWSIZE }
+               eval opts='${val}'
+       fi
+
+       echo "params: $opts"
+
+       add ost1 $opts || error "add ost1 failed with new params"
+
+       local FOUNDSIZE=$(do_facet ost1 "$DEBUGFS -c -R stats $(ostdevname 1)" |
+               awk '/Flex block group size: / { print $NF; exit; }')
+
+       [[ $FOUNDSIZE == $NEWSIZE ]] ||
+               error "Flex block group size: $FOUNDSIZE, expected: $NEWSIZE"
+       return 0
+}
+run_test 86 "Replacing mkfs.lustre -G option"
+
+test_87() { #LU-6544
+       [[ $(lustre_version_code $SINGLEMDS1) -ge $(version_code 2.7.56) ]] ||
+               { skip "Need MDS version at least 2.7.56" && return; }
+       [[ $(facet_fstype $SINGLEMDS) != ldiskfs ]] &&
+               { skip "Only applicable to ldiskfs-based MDTs" && return; }
+       [[ $OSTCOUNT -gt 69 ]] &&
+               { skip "Ignore wide striping situation" && return; }
+
+       local mdsdev=$(mdsdevname 1)
+       local mdsvdev=$(mdsvdevname 1)
+       local file=$DIR/$tfile
+       local mntpt=$(facet_mntpt $SINGLEMDS)
+       local used_xattr_blk=0
+       local inode_size=${1:-512}
+       local left_size=0
+       local xtest="trusted.test"
+       local value
+       local orig
+       local i
+
+       #Please see LU-6544 for MDT inode size calculation
+       if [ $OSTCOUNT -gt 26 ]; then
+               inode_size=2048
+       elif [ $OSTCOUNT -gt 5 ]; then
+               inode_size=1024
+       fi
+       left_size=$(expr $inode_size - \
+                       156 - \
+                       32 - \
+                       32 - $OSTCOUNT \* 24 - 16 - 3 -  \
+                       24 - 16 - 3 - \
+                       24 - 18 - $(expr length $tfile) - 16 - 4)
+       if [ $left_size -le 0 ]; then
+               echo "No space($left_size) is expected in inode."
+               echo "Try 1-byte xattr instead to verify this."
+               left_size=1
+       else
+               echo "Estimate: at most $left_size-byte space left in inode."
+       fi
+
+       unload_modules
+       reformat
+
+       add mds1 $(mkfs_opts mds1 ${mdsdev}) --stripe-count-hint=$OSTCOUNT \
+               --reformat $mdsdev $mdsvdev || error "add mds1 failed"
+       start_mdt 1 > /dev/null || error "start mdt1 failed"
+       for i in $(seq $OSTCOUNT); do
+               start ost$i $(ostdevname $i) $OST_MOUNT_OPTS > /dev/null ||
+                       error "start ost$i failed"
+       done
+       mount_client $MOUNT > /dev/null || error "mount client $MOUNT failed"
+       check_mount || error "check client $MOUNT failed"
+
+       #set xattr
+       $SETSTRIPE -c -1 $file || error "$SETSTRIPE -c -1 $file failed"
+       $GETSTRIPE $file || error "$GETSTRIPE $file failed"
+       i=$($GETSTRIPE -c $file)
+       if [ $i -ne $OSTCOUNT ]; then
+               left_size=$(expr $left_size + $(expr $OSTCOUNT - $i) \* 24)
+               echo -n "Since only $i out $OSTCOUNT OSTs are used, "
+               echo -n "the expected left space is changed to "
+               echo "$left_size bytes at most."
+       fi
+       value=$(generate_string $left_size)
+       setfattr -n $xtest -v $value $file
+       orig=$(get_xattr_value $xtest $file)
+       [[ "$orig" != "$value" ]] && error "$xtest changed"
+
+       #Verify if inode has some expected space left
+       umount $MOUNT > /dev/null || error "umount $MOUNT failed"
+       stop_mdt 1 > /dev/null || error "stop mdt1 failed"
+       mount_ldiskfs $SINGLEMDS || error "mount -t ldiskfs $SINGLEMDS failed"
+
+       do_facet $SINGLEMDS ls -sal $mntpt/ROOT/$tfile
+       used_xattr_blk=$(do_facet $SINGLEMDS ls -s $mntpt/ROOT/$tfile |
+                       awk '{ print $1 }')
+       [[ $used_xattr_blk -eq 0 ]] &&
+               error "Please check MDS inode size calculation: \
+                      more than $left_size-byte space left in inode."
+       echo "Verified: at most $left_size-byte space left in inode."
+
+       stopall
+}
+run_test 87 "check if MDT inode can hold EAs with N stripes properly"
+
+test_88() {
+       [ "$(facet_fstype mds1)" == "zfs" ] &&
+               skip "LU-6662: no implementation for ZFS" && return
+
+       load_modules
+
+       add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) \
+               --reformat $(mdsdevname 1) || error "add mds1 failed"
+
+       do_facet mds1 "$TUNEFS $(mdsdevname 1) |
+               grep -e \".*opts:.*errors=remount-ro.*\"" ||
+               error "default mount options is missing"
+
+       add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) \
+               --mountfsoptions="user_xattr,errors=panic" \
+               --reformat $(mdsdevname 1) || error "add mds1 failed"
+
+       do_facet mds1 "$TUNEFS $(mdsdevname 1) |
+               grep -e \".*opts:.*errors=panic.*\"" ||
+               error "user can't override default mount options"
+}
+run_test 88 "check the default mount options can be overridden"
+
+# $1 test directory
+# $2 (optional) value of max_mod_rpcs_in_flight to set
+check_max_mod_rpcs_in_flight() {
+       local dir="$1"
+       local mmr="$2"
+       local idx
+       local facet
+       local tmp
+       local i
+
+       idx=$(printf "%04x" $($LFS getdirstripe -i $dir))
+       facet="mds$((0x$idx + 1))"
+
+       if [ -z "$mmr" ]; then
+               # get value of max_mod_rcps_in_flight
+               mmr=$($LCTL get_param -n \
+                       mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight) ||
+                       error "Unable to get max_mod_rpcs_in_flight"
+               echo "max_mod_rcps_in_flight is $mmr"
+       else
+               # set value of max_mod_rpcs_in_flight
+               $LCTL set_param \
+                   mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight=$mmr ||
+                       error "Unable to set max_mod_rpcs_in_flight to $mmr"
+               echo "max_mod_rpcs_in_flight set to $mmr"
+       fi
+
+       # create mmr+1 files
+       echo "creating $((mmr + 1)) files ..."
+       umask 0022
+       for i in $(seq $((mmr + 1))); do
+               touch $dir/file-$i
+       done
+
+       ### part 1 ###
+
+       # consumes mmr-1 modify RPC slots
+       #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
+       # drop requests on MDT so that RPC slots are consumed
+       # during all the request resend interval
+       do_facet $facet "$LCTL set_param fail_loc=0x159"
+       echo "launch $((mmr - 1)) chmod in parallel ..."
+       for i in $(seq $((mmr - 1))); do
+               chmod 0600 $dir/file-$i &
+       done
+       sleep 1
+
+       # send one additional modify RPC
+       do_facet $facet "$LCTL set_param fail_loc=0"
+       echo "launch 1 additional chmod in parallel ..."
+       chmod 0600 $dir/file-$mmr &
+       sleep 1
+
+       # check this additional modify RPC get a modify RPC slot
+       # and succeed its operation
+       checkstat -vp 0600 $dir/file-$mmr ||
+               error "Unable to send $mmr modify RPCs in parallel"
+       wait
+
+       ### part 2 ###
+
+       # consumes mmr modify RPC slots
+       #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
+       # drop requests on MDT so that RPC slots are consumed
+       # during all the request resend interval
+       do_facet $facet "$LCTL set_param fail_loc=0x159"
+       echo "launch $mmr chmod in parallel ..."
+       for i in $(seq $mmr); do
+               chmod 0666 $dir/file-$i &
+       done
+       sleep 1
+
+       # send one additional modify RPC
+       do_facet $facet "$LCTL set_param fail_loc=0"
+       echo "launch 1 additional chmod in parallel ..."
+       chmod 0666 $dir/file-$((mmr + 1)) &
+       sleep 1
+
+       # check this additional modify RPC blocked getting a modify RPC slot
+       checkstat -vp 0644 $dir/file-$((mmr + 1)) ||
+               error "Unexpectedly send $(($mmr + 1)) modify RPCs in parallel"
+       wait
+}
+
+test_90a() {
+       reformat
+       if ! combined_mgs_mds ; then
+               start_mgs
+       fi
+       setup
+
+       [[ $($LCTL get_param mdc.*.import |
+            grep "connect_flags:.*multi_mod_rpc") ]] ||
+               { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
+
+       # check default value
+       $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
+       check_max_mod_rpcs_in_flight $DIR/$tdir
+
+       cleanup
+}
+run_test 90a "check max_mod_rpcs_in_flight is enforced"
+
+test_90b() {
+       local idx
+       local facet
+       local tmp
+       local mmrpc
+
+       setup
+
+       [[ $($LCTL get_param mdc.*.import |
+            grep "connect_flags:.*multi_mod_rpc") ]] ||
+               { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
+
+       ### test 1.
+       # update max_mod_rpcs_in_flight
+       $LFS mkdir -c1 $DIR/${tdir}1 || error "mkdir $DIR/${tdir}1 failed"
+       check_max_mod_rpcs_in_flight $DIR/${tdir}1 1
+
+       ### test 2.
+       # check client is able to send multiple modify RPCs in paralell
+       tmp=$($LCTL get_param -n mdc.$FSNAME-MDT*-mdc-*.import |
+               grep -c "multi_mod_rpcs")
+       if [ "$tmp" -ne $MDSCOUNT ]; then
+               echo "Client not able to send multiple modify RPCs in parallel"
+               cleanup
+               return
+       fi
+
+       # update max_mod_rpcs_in_flight
+       $LFS mkdir -c1 $DIR/${tdir}2 || error "mkdir $DIR/${tdir}2 failed"
+       check_max_mod_rpcs_in_flight $DIR/${tdir}2 5
+
+       ### test 3.
+       $LFS mkdir -c1 $DIR/${tdir}3 || error "mkdir $DIR/${tdir}3 failed"
+       idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/${tdir}3))
+       facet="mds$((0x$idx + 1))"
+
+       # save MDT max_mod_rpcs_per_client
+       mmrpc=$(do_facet $facet \
+                   cat /sys/module/mdt/parameters/max_mod_rpcs_per_client)
+
+       # update max_mod_rpcs_in_flight
+       umount_client $MOUNT
+       do_facet $facet \
+               "echo 16 > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
+       mount_client $MOUNT
+       $LCTL set_param mdc.$FSNAME-MDT$idx-mdc-*.max_rpcs_in_flight=17
+       check_max_mod_rpcs_in_flight $DIR/${tdir}3 16
+
+       # restore MDT max_mod_rpcs_per_client initial value
+       do_facet $facet \
+               "echo $mmrpc > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
+
+       rm -rf $DIR/${tdir}?
+       cleanup
+}
+run_test 90b "check max_mod_rpcs_in_flight is enforced after update"
+
+test_90c() {
+       local tmp
+       local mrif
+       local mmrpc
+
+       setup
+
+       [[ $($LCTL get_param mdc.*.import |
+            grep "connect_flags:.*multi_mod_rpc") ]] ||
+               { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
+
+       # check client is able to send multiple modify RPCs in paralell
+       tmp=$($LCTL get_param -n mdc.$FSNAME-MDT*-mdc-*.import |
+               grep -c "multi_mod_rpcs")
+       if [ "$tmp" -ne $MDSCOUNT ]; then
+               skip "Client not able to send multiple modify RPCs in parallel"
+               cleanup
+               return
+       fi
+
+       # get max_rpcs_in_flight value
+       mrif=$($LCTL get_param -n mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight)
+       echo "max_rpcs_in_flight is $mrif"
+
+       # get MDT max_mod_rpcs_per_client
+       mmrpc=$(do_facet mds1 \
+                   cat /sys/module/mdt/parameters/max_mod_rpcs_per_client)
+       echo "max_mod_rpcs_per_client is $mmrpc"
+
+       # testcase 1
+       # attempt to set max_mod_rpcs_in_flight to max_rpcs_in_flight value
+       # prerequisite: set max_mod_rpcs_per_client to max_rpcs_in_flight value
+       umount_client $MOUNT
+       do_facet mds1 \
+               "echo $mrif > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
+       mount_client $MOUNT
+
+       $LCTL set_param \
+           mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$mrif &&
+           error "set max_mod_rpcs_in_flight to $mrif should fail"
+
+       umount_client $MOUNT
+       do_facet mds1 \
+               "echo $mmrpc > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
+       mount_client $MOUNT
+
+       # testcase 2
+       # attempt to set max_mod_rpcs_in_flight to max_mod_rpcs_per_client+1
+       # prerequisite: set max_rpcs_in_flight to max_mod_rpcs_per_client+2
+       $LCTL set_param \
+           mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight=$((mmrpc + 2))
+
+       $LCTL set_param \
+           mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$((mmrpc + 1)) &&
+           error "set max_mod_rpcs_in_flight to $((mmrpc + 1)) should fail"
+
+       cleanup
+}
+run_test 90c "check max_mod_rpcs_in_flight update limits"
+
+test_90d() {
+       local idx
+       local facet
+       local mmr
+       local i
+       local pid
+
+       setup
+
+       [[ $($LCTL get_param mdc.*.import |
+            grep "connect_flags:.*multi_mod_rpc") ]] ||
+               { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
+
+       $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
+       idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/$tdir))
+       facet="mds$((0x$idx + 1))"
+
+       # check client version supports multislots
+       tmp=$($LCTL get_param -N \
+               mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
+       if [ -z "$tmp" ]; then
+               skip "Client does not support multiple modify RPCs in flight"
+               cleanup
+               return
+       fi
+
+       # get current value of max_mod_rcps_in_flight
+       mmr=$($LCTL get_param -n \
+               mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
+       echo "max_mod_rcps_in_flight is $mmr"
+
+       # create mmr files
+       echo "creating $mmr files ..."
+       umask 0022
+       for i in $(seq $mmr); do
+               touch $DIR/$tdir/file-$i
+       done
+
+       # prepare for close RPC
+       multiop_bg_pause $DIR/$tdir/file-close O_c
+       pid=$!
+
+       # consumes mmr modify RPC slots
+       #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
+       # drop requests on MDT so that RPC slots are consumed
+       # during all the request resend interval
+       do_facet $facet "$LCTL set_param fail_loc=0x159"
+       echo "launch $mmr chmod in parallel ..."
+       for i in $(seq $mmr); do
+               chmod 0600 $DIR/$tdir/file-$i &
+       done
+
+       # send one additional close RPC
+       do_facet $facet "$LCTL set_param fail_loc=0"
+       echo "launch 1 additional close in parallel ..."
+       kill -USR1 $pid
+       cancel_lru_locks mdc
+       sleep 1
+
+       # check this additional close RPC get a modify RPC slot
+       # and multiop process completed
+       [ -d /proc/$pid ] &&
+               error "Unable to send the additional close RPC in parallel"
+       wait
+       rm -rf $DIR/$tdir
+       cleanup
+}
+run_test 90d "check one close RPC is allowed above max_mod_rpcs_in_flight"
+
+check_uuid_on_ost() {
+       local nid=$1
+       do_facet ost1 "$LCTL get_param obdfilter.${FSNAME}*.exports.'$nid'.uuid"
+}
+
+check_uuid_on_mdt() {
+       local nid=$1
+       do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.'$nid'.uuid"
+}
+
+test_91() {
+       local uuid
+       local nid
+       local found
+
+       [[ $(lustre_version_code ost1) -ge $(version_code 2.7.63) ]] ||
+               { skip "Need OST version at least 2.7.63" && return 0; }
+       [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.63) ]] ||
+               { skip "Need MDT version at least 2.7.63" && return 0; }
+
+       start_mds || error "MDS start failed"
+       start_ost || error "unable to start OST"
+       mount_client $MOUNT || error "client start failed"
+       check_mount || error "check_mount failed"
+
+       if remote_mds; then
+               nid=$($LCTL list_nids | head -1 | sed  "s/\./\\\./g")
+       else
+               nid="0@lo"
+       fi
+       uuid=$(get_client_uuid $MOUNT)
+
+       echo "list nids on mdt:"
+       do_facet $SINGLEMDS "$LCTL list_param mdt.${FSNAME}*.exports.*"
+       echo "uuid from $nid:"
+       do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.'$nid'.uuid"
+
+       found=$(check_uuid_on_mdt $nid | grep $uuid)
+       [ -z "$found" ] && error "can't find $uuid $nid on MDT"
+       found=$(check_uuid_on_ost $nid | grep $uuid)
+       [ -z "$found" ] && error "can't find $uuid $nid on OST"
+
+       # umount the client so it won't reconnect
+       manual_umount_client --force || error "failed to umount $?"
+       # shouldn't disappear on MDS after forced umount
+       found=$(check_uuid_on_mdt $nid | grep $uuid)
+       [ -z "$found" ] && error "can't find $uuid $nid"
+
+       echo "evict $nid"
+       do_facet $SINGLEMDS \
+               "$LCTL set_param -n mdt.${mds1_svc}.evict_client nid:$nid"
+
+       found=$(check_uuid_on_mdt $nid | grep $uuid)
+       [ -n "$found" ] && error "found $uuid $nid on MDT"
+       found=$(check_uuid_on_ost $nid | grep $uuid)
+       [ -n "$found" ] && error "found $uuid $nid on OST"
+
+       # check it didn't reconnect (being umounted)
+       sleep $((TIMEOUT+1))
+       found=$(check_uuid_on_mdt $nid | grep $uuid)
+       [ -n "$found" ] && error "found $uuid $nid on MDT"
+       found=$(check_uuid_on_ost $nid | grep $uuid)
+       [ -n "$found" ] && error "found $uuid $nid on OST"
+
+       cleanup
+}
+run_test 91 "evict-by-nid support"
+
+generate_ldev_conf() {
+       # generate an ldev.conf file
+       local ldevconfpath=$1
+       touch $ldevconfpath
+       printf "%s\t-\t%s-MGS0000\t%s\n" \
+               $mgs_HOST \
+               $FSNAME \
+               $(mgsdevname) >> $ldevconfpath
+
+       local mdsfo_host=$mdsfailover_HOST;
+       if [ -z "$mdsfo_host" ]; then
+               mdsfo_host="-"
+       fi
+
+       for num in $(seq $MDSCOUNT); do
+               printf "%s\t%s\t%s-MDT%04d\t%s\n" \
+                       $mds_HOST \
+                       $mdsfo_host \
+                       $FSNAME \
+                       $num \
+                       $(mdsdevname $num) >> $ldevconfpath
+       done
+
+       local ostfo_host=$ostfailover_HOST;
+       if [ -z "$ostfo_host" ]; then
+               ostfo_host="-"
+       fi
+
+       for num in $(seq $OSTCOUNT); do
+               printf "%s\t%s\t%s-OST%04d\t%s\n" \
+                       $ost_HOST \
+                       $ostfo_host \
+                       $FSNAME \
+                       $num \
+                       $(ostdevname $num) >> $ldevconfpath
+       done
+}
+
+generate_nids() {
+       # generate a nids file (mapping between hostname to nid)
+       # looks like we only have the MGS nid available to us
+       # so just echo that to a file
+       local nidspath=$1
+       touch $nidspath
+       echo -e "${mgs_HOST}\t${MGSNID}" >> $nidspath
+}
+
+test_92() {
+       local LDEVCONFPATH=$TMP/ldev.conf
+       local NIDSPATH=$TMP/nids
+
+       echo "Host is $(hostname)"
+
+       generate_ldev_conf $LDEVCONFPATH
+       generate_nids $NIDSPATH
+
+       echo "----- ldev.conf -----"
+       cat $LDEVCONFPATH
+       echo "--- END ldev.conf ---"
+
+       echo "----- /etc/nids -----"
+       cat $NIDSPATH
+       echo "--- END /etc/nids ---"
+
+       # ldev can be in our build tree and if we aren't in a
+       # build tree, use 'which' to try and find it
+       local LDEV=$LUSTRE/scripts/ldev
+       [ ! -f "$LDEV" ] && local LDEV=$(which ldev 2> /dev/null)
+
+       echo "ldev path is $LDEV"
+
+       if [ ! -f "$LDEV" ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "failed to find ldev!"
+       fi
+
+       # echo the mgs nid and compare it to environment variable MGSNID
+       # also, ldev.conf and nids is a server side thing, use the OSS
+       # hostname
+       local output
+       output=$(perl $LDEV -c $LDEVCONFPATH -H \
+                       $ost_HOST -n $NIDSPATH echo %m)
+
+       echo "-- START OF LDEV OUTPUT --"
+       echo -e "$output"
+       echo "--- END OF LDEV OUTPUT ---"
+
+       # ldev failed, error
+       if [ $? -ne 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev failed to execute!"
+       fi
+
+       # need to process multiple lines because of combined MGS and MDS
+       echo -e $output | awk '{ print $2 }' | while read -r line ; do
+               if [ "$line" != "$MGSNID" ]; then
+                       rm $LDEVCONFPATH $NIDSPATH
+                       error "ldev failed mgs nid '$line', expected '$MGSNID'"
+               fi
+       done
+
+       rm $LDEVCONFPATH $NIDSPATH
+}
+run_test 92 "ldev returns MGS NID correctly in command substitution"
+
 if ! combined_mgs_mds ; then
        stop mgs
 fi