Commit bab9fb03 authored by Yan's avatar Yan Committed by Chris Mason

Btrfs: truncate: don't update inode->i_blocks when extent is a hole

I think check whether extent is a hole before update 'inode->i_blocks'
is unconditional required. (original codes check it only when
del_item isn't equal to 0)
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 23223584
...@@ -595,6 +595,7 @@ static int btrfs_truncate_in_trans(struct btrfs_trans_handle *trans, ...@@ -595,6 +595,7 @@ static int btrfs_truncate_in_trans(struct btrfs_trans_handle *trans,
btrfs_file_extent_type(fi) != btrfs_file_extent_type(fi) !=
BTRFS_FILE_EXTENT_INLINE) { BTRFS_FILE_EXTENT_INLINE) {
u64 num_dec; u64 num_dec;
extent_start = btrfs_file_extent_disk_blocknr(fi);
if (!del_item) { if (!del_item) {
u64 orig_num_blocks = u64 orig_num_blocks =
btrfs_file_extent_num_blocks(fi); btrfs_file_extent_num_blocks(fi);
...@@ -604,12 +605,13 @@ static int btrfs_truncate_in_trans(struct btrfs_trans_handle *trans, ...@@ -604,12 +605,13 @@ static int btrfs_truncate_in_trans(struct btrfs_trans_handle *trans,
extent_num_blocks >>= inode->i_blkbits; extent_num_blocks >>= inode->i_blkbits;
btrfs_set_file_extent_num_blocks(fi, btrfs_set_file_extent_num_blocks(fi,
extent_num_blocks); extent_num_blocks);
inode->i_blocks -= (orig_num_blocks - num_dec = (orig_num_blocks -
extent_num_blocks) << 3; extent_num_blocks) << 3;
if (extent_start != 0) {
inode->i_blocks -= num_dec;
}
btrfs_mark_buffer_dirty(path->nodes[0]); btrfs_mark_buffer_dirty(path->nodes[0]);
} else { } else {
extent_start =
btrfs_file_extent_disk_blocknr(fi);
extent_num_blocks = extent_num_blocks =
btrfs_file_extent_disk_num_blocks(fi); btrfs_file_extent_disk_num_blocks(fi);
/* FIXME blocksize != 4096 */ /* FIXME blocksize != 4096 */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment