+# LU-1512 try to reuse idle OI blocks
+test_228a() {
+ [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+ [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
+ skip "non-ldiskfs backend" && return
+
+ local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
+ local myDIR=$DIR/$tdir
+
+ mkdir -p $myDIR
+ #define OBD_FAIL_SEQ_EXHAUST 0x1002
+ $LCTL set_param fail_loc=0x80001002
+ createmany -o $myDIR/t- 10000
+ $LCTL set_param fail_loc=0
+ # The guard is current the largest FID holder
+ touch $myDIR/guard
+ local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
+ tr -d '[')
+ local IDX=$(($SEQ % 64))
+
+ do_facet $SINGLEMDS sync
+ # Make sure journal flushed.
+ sleep 6
+ local blk1=$(do_facet $SINGLEMDS \
+ "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
+ grep Blockcount | awk '{print $4}')
+
+ # Remove old files, some OI blocks will become idle.
+ unlinkmany $myDIR/t- 10000
+ # Create new files, idle OI blocks should be reused.
+ createmany -o $myDIR/t- 2000
+ do_facet $SINGLEMDS sync
+ # Make sure journal flushed.
+ sleep 6
+ local blk2=$(do_facet $SINGLEMDS \
+ "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
+ grep Blockcount | awk '{print $4}')
+
+ [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
+}
+run_test 228a "try to reuse idle OI blocks"
+
+test_228b() {
+ [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+ [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
+ skip "non-ldiskfs backend" && return
+
+ local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
+ local myDIR=$DIR/$tdir
+
+ mkdir -p $myDIR
+ #define OBD_FAIL_SEQ_EXHAUST 0x1002
+ $LCTL set_param fail_loc=0x80001002
+ createmany -o $myDIR/t- 10000
+ $LCTL set_param fail_loc=0
+ # The guard is current the largest FID holder
+ touch $myDIR/guard
+ local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
+ tr -d '[')
+ local IDX=$(($SEQ % 64))
+
+ do_facet $SINGLEMDS sync
+ # Make sure journal flushed.
+ sleep 6
+ local blk1=$(do_facet $SINGLEMDS \
+ "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
+ grep Blockcount | awk '{print $4}')
+
+ # Remove old files, some OI blocks will become idle.
+ unlinkmany $myDIR/t- 10000
+
+ # stop the MDT
+ stop $SINGLEMDS || error "Fail to stop MDT."
+ # remount the MDT
+ start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
+
+ df $MOUNT || error "Fail to df."
+ # Create new files, idle OI blocks should be reused.
+ createmany -o $myDIR/t- 2000
+ do_facet $SINGLEMDS sync
+ # Make sure journal flushed.
+ sleep 6
+ local blk2=$(do_facet $SINGLEMDS \
+ "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
+ grep Blockcount | awk '{print $4}')
+
+ [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
+}
+run_test 228b "idle OI blocks can be reused after MDT restart"
+
+#LU-1881
+test_228c() {
+ [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+ [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
+ skip "non-ldiskfs backend" && return
+
+ local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
+ local myDIR=$DIR/$tdir
+
+ mkdir -p $myDIR
+ #define OBD_FAIL_SEQ_EXHAUST 0x1002
+ $LCTL set_param fail_loc=0x80001002
+ # 20000 files can guarantee there are index nodes in the OI file
+ createmany -o $myDIR/t- 20000
+ $LCTL set_param fail_loc=0
+ # The guard is current the largest FID holder
+ touch $myDIR/guard
+ local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
+ tr -d '[')
+ local IDX=$(($SEQ % 64))
+
+ do_facet $SINGLEMDS sync
+ # Make sure journal flushed.
+ sleep 6
+ local blk1=$(do_facet $SINGLEMDS \
+ "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
+ grep Blockcount | awk '{print $4}')
+
+ # Remove old files, some OI blocks will become idle.
+ unlinkmany $myDIR/t- 20000
+ rm -f $myDIR/guard
+ # The OI file should become empty now
+
+ # Create new files, idle OI blocks should be reused.
+ createmany -o $myDIR/t- 2000
+ do_facet $SINGLEMDS sync
+ # Make sure journal flushed.
+ sleep 6
+ local blk2=$(do_facet $SINGLEMDS \
+ "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
+ grep Blockcount | awk '{print $4}')
+
+ [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
+}
+run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
+
+test_230a() {
+ [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+ [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+ local MDTIDX=1
+
+ mkdir -p $DIR/$tdir/test_230_local
+ local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
+ [ $mdt_idx -ne 0 ] &&
+ error "create local directory on wrong MDT $mdt_idx"
+
+ $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
+ error "create remote directory failed"
+ local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
+ [ $mdt_idx -ne $MDTIDX ] &&
+ error "create remote directory on wrong MDT $mdt_idx"
+
+ createmany -o $DIR/$tdir/test_230/t- 10 ||
+ error "create files on remote directory failed"
+ mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
+ [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
+ rm -r $DIR/$tdir || error "unlink remote directory failed"
+}
+run_test 230a "Create remote directory and files under the remote directory"
+
+test_230b() {
+ [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+ [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+ local MDTIDX=1
+ local remote_dir=$DIR/$tdir/remote_dir
+ local rc=0
+
+ mkdir -p $DIR/$tdir
+ $LFS mkdir -i $MDTIDX $remote_dir ||
+ error "create remote directory failed"
+
+ $LFS mkdir -i 0 $remote_dir/new_dir &&
+ error "nested remote directory create succeed!"
+
+ do_facet mds$((MDTIDX + 1)) lctl set_param mdt.*.enable_remote_dir=1
+ $LFS mkdir -i 0 $remote_dir/new_dir || rc=$?
+ do_facet mds$((MDTIDX + 1)) lctl set_param mdt.*.enable_remote_dir=0
+
+ [ $rc -ne 0 ] &&
+ error "create remote directory failed after set enable_remote_dir"
+
+ rm -rf $remote_dir || error "first unlink remote directory failed"
+
+ $RUNAS -G$RUNAS_GID $LFS mkdir -i $MDTIDX $DIR/$tfile &&
+ error "chown worked"
+
+ do_facet mds$MDTIDX lctl set_param \
+ mdt.*.enable_remote_dir_gid=$RUNAS_GID
+ $LFS mkdir -i $MDTIDX $remote_dir || rc=$?
+ do_facet mds$MDTIDX lctl set_param mdt.*.enable_remote_dir_gid=0
+
+ [ $rc -ne 0 ] &&
+ error "create remote dir failed after set enable_remote_dir_gid"
+
+ rm -r $DIR/$tdir || error "second unlink remote directory failed"
+}
+run_test 230b "nested remote directory should be failed"
+
+test_231a()
+{
+ # For simplicity this test assumes that max_pages_per_rpc
+ # is the same across all OSCs
+ local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -1)
+ local bulk_size=$((max_pages * 4096))
+
+ mkdir -p $DIR/$tdir
+
+ # clear the OSC stats
+ $LCTL set_param osc.*.stats=0 &>/dev/null
+
+ # Client writes $bulk_size - there must be 1 rpc for $max_pages.
+ dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
+ oflag=direct &>/dev/null || error "dd failed"
+
+ local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
+ if [ x$nrpcs != "x1" ]; then
+ error "found $nrpc ost_write RPCs, not 1 as expected"
+ fi
+
+ # Drop the OSC cache, otherwise we will read from it
+ cancel_lru_locks osc
+
+ # clear the OSC stats
+ $LCTL set_param osc.*.stats=0 &>/dev/null
+
+ # Client reads $bulk_size.
+ dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
+ iflag=direct &>/dev/null || error "dd failed"
+
+ nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
+ if [ x$nrpcs != "x1" ]; then
+ error "found $nrpc ost_read RPCs, not 1 as expected"
+ fi
+}
+run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
+
+test_231b() {
+ mkdir -p $DIR/$tdir
+ local i
+ for i in {0..1023}; do
+ dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
+ seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
+ error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
+ done
+ sync
+}
+run_test 231b "must not assert on fully utilized OST request buffer"
+
+test_232() {
+ mkdir -p $DIR/$tdir
+ #define OBD_FAIL_LDLM_OST_LVB 0x31c
+ $LCTL set_param fail_loc=0x31c
+
+ # ignore dd failure
+ dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
+
+ $LCTL set_param fail_loc=0
+ umount_client $MOUNT || error "umount failed"
+ mount_client $MOUNT || error "mount failed"
+}
+run_test 232 "failed lock should not block umount"
+