@@ -1596,6 +1596,13 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
1596
1596
1597
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
1607
* if we have trouble faulting in the pages, fall
1601
1608
* back to one page at a time
@@ -1605,6 +1612,7 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
1605
1612
1606
1613
if (copied == 0 ) {
1607
1614
force_page_uptodate = true;
1615
+ dirty_sectors = 0 ;
1608
1616
dirty_pages = 0 ;
1609
1617
} else {
1610
1618
force_page_uptodate = false;
@@ -1615,20 +1623,19 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
1615
1623
/*
1616
1624
* If we had a short copy we need to release the excess delaloc
1617
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
1628
* we still have an outstanding extent for the chunk we actually
1620
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
1631
if (num_sectors > dirty_sectors ) {
1630
- release_bytes = (write_bytes - copied )
1631
- & ~((u64 )root -> sectorsize - 1 );
1632
+ /*
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
1639
if (copied > 0 ) {
1633
1640
spin_lock (& BTRFS_I (inode )-> lock );
1634
1641
BTRFS_I (inode )-> outstanding_extents ++ ;
0 commit comments