Skip to content

Commit

Permalink
Btrfs: Improve FL_KEEP_SIZE handling in fallocate
Browse files Browse the repository at this point in the history
- We call inode_size_ok() only if FL_KEEP_SIZE isn't specified.
- As an optimisation we can skip the call if (off + len)
  isn't greater than the current size of the file. This operation
  is called under the lock so the less work we do, the better.
- If we call inode_size_ok() pass to it the correct value rather
  than a more conservative estimation.

Signed-off-by: Davide Italiano <dccitaliano@gmail.com>
Reviewed-by: Liu Bo <bo.li.liu@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
Davide Italiano authored and David Sterba committed Apr 4, 2016
1 parent 232cad8 commit 2a162ce
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions fs/btrfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2682,9 +2682,12 @@ static long btrfs_fallocate(struct file *file, int mode,
return ret;

inode_lock(inode);
ret = inode_newsize_ok(inode, alloc_end);
if (ret)
goto out;

if (!(mode & FALLOC_FL_KEEP_SIZE) && offset + len > inode->i_size) {
ret = inode_newsize_ok(inode, offset + len);
if (ret)
goto out;
}

/*
* TODO: Move these two operations after we have checked
Expand Down

0 comments on commit 2a162ce

Please sign in to comment.