}
run_test 258b "verify i_mutex security behavior"
+test_259() {
+ local file=$DIR/$tfile
+ local before
+ local after
+
+ [ "$(facet_fstype mds1)" != "ldiskfs" ] &&
+ skip "ldiskfs only test" && return
+
+ stack_trap "rm -f $file" EXIT
+
+ wait_delete_completed
+ before=$(do_facet ost1 "$LCTL get_param -n osd-*.*OST0000.kbytesfree")
+ echo "before: $before"
+
+ $LFS setstripe -i 0 -c 1 $file
+ dd if=/dev/zero of=$file bs=1M count=10 || error "couldn't write"
+ sync_all_data
+ after=$(do_facet ost1 "$LCTL get_param -n osd-*.*OST0000.kbytesfree")
+ echo "after write: $after"
+
+#define OBD_FAIL_OSD_FAIL_AT_TRUNCATE 0x2301
+ do_facet ost1 $LCTL set_param fail_loc=0x2301
+ $TRUNCATE $file 0
+ after=$(do_facet ost1 "$LCTL get_param -n osd-*.*OST0000.kbytesfree")
+ echo "after truncate: $after"
+
+ stop ost1
+ do_facet ost1 $LCTL set_param fail_loc=0
+ start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "cannot start ost1"
+ sleep 2
+ after=$(do_facet ost1 "$LCTL get_param -n osd-*.*OST0000.kbytesfree")
+ echo "after restart: $after"
+ [ $((after - before)) -ge $(fs_log_size ost1) ] &&
+ error "missing truncate?"
+
+ return 0
+}
+run_test 259 "crash at delayed truncate"
+
test_260() {
#define OBD_FAIL_MDC_CLOSE 0x806
$LCTL set_param fail_loc=0x80000806
}
run_test 316 "lfs mv"
+test_317() {
+ local trunc_sz
+ local grant_blk_size
+
+ if [ "$(facet_fstype $facet)" == "zfs" ]; then
+ skip "LU-10370: no implementation for ZFS" && return
+ fi
+
+ stack_trap "rm -f $DIR/$tfile" EXIT
+ grant_blk_size=$($LCTL get_param osc.$FSNAME*.import |
+ awk '/grant_block_size:/ { print $2; exit; }')
+ #
+ # Create File of size 5M. Truncate it to below size's and verify
+ # blocks count.
+ #
+ dd if=/dev/zero of=$DIR/$tfile bs=5M count=1 conv=fsync ||
+ error "Create file : $DIR/$tfile"
+
+ for trunc_sz in 2097152 4097 4000 509 0; do
+ $TRUNCATE $DIR/$tfile $trunc_sz ||
+ error "truncate $tfile to $trunc_sz failed"
+ local sz=$(stat --format=%s $DIR/$tfile)
+ local blk=$(stat --format=%b $DIR/$tfile)
+ local trunc_blk=$((((trunc_sz + (grant_blk_size - 1) ) /
+ grant_blk_size) * 8))
+
+ if [[ $blk -ne $trunc_blk ]]; then
+ $(which stat) $DIR/$tfile
+ error "Expected Block $trunc_blk got $blk for $tfile"
+ fi
+
+ $CHECKSTAT -s $trunc_sz $DIR/$tfile ||
+ error "Expected Size $trunc_sz got $sz for $tfile"
+ done
+
+ #
+ # sparse file test
+ # Create file with a hole and write actual two blocks. Block count
+ # must be 16.
+ #
+ dd if=/dev/zero of=$DIR/$tfile bs=$grant_blk_size count=2 seek=5 \
+ conv=fsync || error "Create file : $DIR/$tfile"
+
+ # Calculate the final truncate size.
+ trunc_sz=$(($(stat --format=%s $DIR/$tfile) - (grant_blk_size + 1)))
+
+ #
+ # truncate to size $trunc_sz bytes. Strip the last block
+ # The block count must drop to 8
+ #
+ $TRUNCATE $DIR/$tfile $trunc_sz ||
+ error "truncate $tfile to $trunc_sz failed"
+
+ local trunc_bsz=$((grant_blk_size / $(stat --format=%B $DIR/$tfile)))
+ sz=$(stat --format=%s $DIR/$tfile)
+ blk=$(stat --format=%b $DIR/$tfile)
+
+ if [[ $blk -ne $trunc_bsz ]]; then
+ $(which stat) $DIR/$tfile
+ error "Expected Block $trunc_bsz got $blk for $tfile"
+ fi
+
+ $CHECKSTAT -s $trunc_sz $DIR/$tfile ||
+ error "Expected Size $trunc_sz got $sz for $tfile"
+}
+run_test 317 "Verify blocks get correctly update after truncate"
+
test_fake_rw() {
local read_write=$1
if [ "$read_write" = "write" ]; then