Commit 55a61d1d authored by Josef Bacik's avatar Josef Bacik Committed by Chris Mason

Btrfs: fix typo in fallocate to make it honor actual size

There is a typo in __btrfs_prealloc_file_range() where we set the i_size to
actual_len/cur_offset, and then just set it to cur_offset again, and do the same
with btrfs_ordered_update_i_size().  This fixes it back to keeping i_size in a
local variable and then updating i_size properly.  Tested this with

xfs_io -F -f -c "falloc 0 1" -c "pwrite 0 1" foo

stat'ing foo gives us a size of 1 instead of 4096 like it was.  Thanks,
Signed-off-by: default avatarJosef Bacik <josef@redhat.com>
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 45f49bce
...@@ -7002,6 +7002,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode, ...@@ -7002,6 +7002,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_root *root = BTRFS_I(inode)->root;
struct btrfs_key ins; struct btrfs_key ins;
u64 cur_offset = start; u64 cur_offset = start;
u64 i_size;
int ret = 0; int ret = 0;
bool own_trans = true; bool own_trans = true;
...@@ -7043,11 +7044,11 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode, ...@@ -7043,11 +7044,11 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
(actual_len > inode->i_size) && (actual_len > inode->i_size) &&
(cur_offset > inode->i_size)) { (cur_offset > inode->i_size)) {
if (cur_offset > actual_len) if (cur_offset > actual_len)
i_size_write(inode, actual_len); i_size = actual_len;
else else
i_size_write(inode, cur_offset); i_size = cur_offset;
i_size_write(inode, cur_offset); i_size_write(inode, i_size);
btrfs_ordered_update_i_size(inode, cur_offset, NULL); btrfs_ordered_update_i_size(inode, i_size, NULL);
} }
ret = btrfs_update_inode(trans, root, inode); ret = btrfs_update_inode(trans, root, inode);
......
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