aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/btrfs/file.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 1933e8b07ed7..159a93450e26 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1596,6 +1596,13 @@ again:
1596 1596
1597 copied = btrfs_copy_from_user(pos, write_bytes, pages, i); 1597 copied = btrfs_copy_from_user(pos, write_bytes, pages, i);
1598 1598
1599 num_sectors = BTRFS_BYTES_TO_BLKS(root->fs_info,
1600 reserve_bytes);
1601 dirty_sectors = round_up(copied + sector_offset,
1602 root->sectorsize);
1603 dirty_sectors = BTRFS_BYTES_TO_BLKS(root->fs_info,
1604 dirty_sectors);
1605
1599 /* 1606 /*
1600 * if we have trouble faulting in the pages, fall 1607 * if we have trouble faulting in the pages, fall
1601 * back to one page at a time 1608 * back to one page at a time
@@ -1605,6 +1612,7 @@ again:
1605 1612
1606 if (copied == 0) { 1613 if (copied == 0) {
1607 force_page_uptodate = true; 1614 force_page_uptodate = true;
1615 dirty_sectors = 0;
1608 dirty_pages = 0; 1616 dirty_pages = 0;
1609 } else { 1617 } else {
1610 force_page_uptodate = false; 1618 force_page_uptodate = false;
@@ -1615,20 +1623,19 @@ again:
1615 /* 1623 /*
1616 * If we had a short copy we need to release the excess delaloc 1624 * If we had a short copy we need to release the excess delaloc
1617 * bytes we reserved. We need to increment outstanding_extents 1625 * bytes we reserved. We need to increment outstanding_extents
1618 * because btrfs_delalloc_release_space will decrement it, but 1626 * because btrfs_delalloc_release_space and
1627 * btrfs_delalloc_release_metadata will decrement it, but
1619 * we still have an outstanding extent for the chunk we actually 1628 * we still have an outstanding extent for the chunk we actually
1620 * managed to copy. 1629 * managed to copy.
1621 */ 1630 */
1622 num_sectors = BTRFS_BYTES_TO_BLKS(root->fs_info,
1623 reserve_bytes);
1624 dirty_sectors = round_up(copied + sector_offset,
1625 root->sectorsize);
1626 dirty_sectors = BTRFS_BYTES_TO_BLKS(root->fs_info,
1627 dirty_sectors);
1628
1629 if (num_sectors > dirty_sectors) { 1631 if (num_sectors > dirty_sectors) {
1630 release_bytes = (write_bytes - copied) 1632 /*
1631 & ~((u64)root->sectorsize - 1); 1633 * we round down because we don't want to count
1634 * any partial blocks actually sent through the
1635 * IO machines
1636 */
1637 release_bytes = round_down(release_bytes - copied,
1638 root->sectorsize);
1632 if (copied > 0) { 1639 if (copied > 0) {
1633 spin_lock(&BTRFS_I(inode)->lock); 1640 spin_lock(&BTRFS_I(inode)->lock);
1634 BTRFS_I(inode)->outstanding_extents++; 1641 BTRFS_I(inode)->outstanding_extents++;