Skip to content

Commit

Permalink
Btrfs: fix delalloc accounting after copy_from_user faults
Browse files Browse the repository at this point in the history
Commit 56244ef was almost but not quite enough to fix the
reservation math after btrfs_copy_from_user returned partial copies.

Some users are still seeing warnings in btrfs_destroy_inode, and with a
long enough test run I'm able to trigger them as well.

This patch fixes the accounting math again, bringing it much closer to
the way it was before the sectorsize conversion Chandan did.  The
problem is accounting for the offset into the page/sector when we do a
partial copy.  This one just uses the dirty_sectors variable which
should already be updated properly.

Signed-off-by: Chris Mason <clm@fb.com>
cc: stable@vger.kernel.org # v4.6+
  • Loading branch information
Chris Mason committed Jul 21, 2016
1 parent bac357d commit 8b8b08c
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions fs/btrfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1629,13 +1629,11 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
* managed to copy.
*/
if (num_sectors > dirty_sectors) {
/*
* we round down because we don't want to count
* any partial blocks actually sent through the
* IO machines
*/
release_bytes = round_down(release_bytes - copied,
root->sectorsize);

/* release everything except the sectors we dirtied */
release_bytes -= dirty_sectors <<
root->fs_info->sb->s_blocksize_bits;

if (copied > 0) {
spin_lock(&BTRFS_I(inode)->lock);
BTRFS_I(inode)->outstanding_extents++;
Expand Down

0 comments on commit 8b8b08c

Please sign in to comment.