| @@ -1605,7 +1605,7 @@ static void btrfs_split_extent_hook(struct inode *inode, · 1604 unmodified lines |
| 1605 | | 1605 | |
| 1606 | size = orig->end - orig->start + 1; | 1606 | size = orig->end - orig->start + 1; |
| 1607 | if (size > BTRFS_MAX_EXTENT_SIZE) { | 1607 | if (size > BTRFS_MAX_EXTENT_SIZE) { |
| 1608 | u64 num_extents; | 1608 | u32 num_extents; |
| 1609 | u64 new_size; | 1609 | u64 new_size; |
| 1610 | | 1610 | |
| 1611 | /* | 1611 | /* |
| @@ -1613,13 +1613,10 @@ static void btrfs_split_extent_hook(struct inode *inode, · 1 unmodified line |
| 1613 | * applies here, just in reverse. | 1613 | * applies here, just in reverse. |
| 1614 | */ | 1614 | */ |
| 1615 | new_size = orig->end - split + 1; | 1615 | new_size = orig->end - split + 1; |
| 1616 | num_extents = div64_u64(new_size + BTRFS_MAX_EXTENT_SIZE - 1, | 1616 | num_extents = count_max_extents(new_size); |
| 1617 | BTRFS_MAX_EXTENT_SIZE); | | |
| 1618 | new_size = split - orig->start; | 1617 | new_size = split - orig->start; |
| 1619 | num_extents += div64_u64(new_size + BTRFS_MAX_EXTENT_SIZE - 1, | 1618 | num_extents += count_max_extents(new_size); |
| 1620 | BTRFS_MAX_EXTENT_SIZE); | 1619 | if (count_max_extents(size) >= num_extents) |
| 1621 | if (div64_u64(size + BTRFS_MAX_EXTENT_SIZE - 1, | | |
| 1622 | BTRFS_MAX_EXTENT_SIZE) >= num_extents) | | |
| 1623 | return; | 1620 | return; |
| 1624 | } | 1621 | } |
| 1625 | | 1622 | |
| @@ -1639,7 +1636,7 @@ static void btrfs_merge_extent_hook(struct inode *inode, · 13 unmodified lines |
| 1639 | struct extent_state *other) | 1636 | struct extent_state *other) |
| 1640 | { | 1637 | { |
| 1641 | u64 new_size, old_size; | 1638 | u64 new_size, old_size; |
| 1642 | u64 num_extents; | 1639 | u32 num_extents; |
| 1643 | | 1640 | |
| 1644 | /* not delalloc, ignore it */ | 1641 | /* not delalloc, ignore it */ |
| 1645 | if (!(other->state & EXTENT_DELALLOC)) | 1642 | if (!(other->state & EXTENT_DELALLOC)) |
| @@ -1677,14 +1674,10 @@ static void btrfs_merge_extent_hook(struct inode *inode, · 31 unmodified lines |
| 1677 | * this case. | 1674 | * this case. |
| 1678 | */ | 1675 | */ |
| 1679 | old_size = other->end - other->start + 1; | 1676 | old_size = other->end - other->start + 1; |
| 1680 | num_extents = div64_u64(old_size + BTRFS_MAX_EXTENT_SIZE - 1, | 1677 | num_extents = count_max_extents(old_size); |
| 1681 | BTRFS_MAX_EXTENT_SIZE); | | |
| 1682 | old_size = new->end - new->start + 1; | 1678 | old_size = new->end - new->start + 1; |
| 1683 | num_extents += div64_u64(old_size + BTRFS_MAX_EXTENT_SIZE - 1, | 1679 | num_extents += count_max_extents(old_size); |
| 1684 | BTRFS_MAX_EXTENT_SIZE); | 1680 | if (count_max_extents(new_size) >= num_extents) |
| 1685 | | | |
| 1686 | if (div64_u64(new_size + BTRFS_MAX_EXTENT_SIZE - 1, | | |
| 1687 | BTRFS_MAX_EXTENT_SIZE) >= num_extents) | | |
| 1688 | return; | 1681 | return; |
| 1689 | | 1682 | |
| 1690 | spin_lock(&BTRFS_I(inode)->lock); | 1683 | spin_lock(&BTRFS_I(inode)->lock); |
| @@ -1793,8 +1786,7 @@ static void btrfs_clear_bit_hook(struct inode *inode, · 102 unmodified lines |
| 1793 | { | 1786 | { |
| 1794 | struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); | 1787 | struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); |
| 1795 | u64 len = state->end + 1 - state->start; | 1788 | u64 len = state->end + 1 - state->start; |
| 1796 | u64 num_extents = div64_u64(len + BTRFS_MAX_EXTENT_SIZE -1, | 1789 | u32 num_extents = count_max_extents(len); |
| 1797 | BTRFS_MAX_EXTENT_SIZE); | | |
| 1798 | | 1790 | |
| 1799 | spin_lock(&BTRFS_I(inode)->lock); | 1791 | spin_lock(&BTRFS_I(inode)->lock); |
| 1800 | if ((state->state & EXTENT_DEFRAG) && (*bits & EXTENT_DEFRAG)) | 1792 | if ((state->state & EXTENT_DEFRAG) && (*bits & EXTENT_DEFRAG)) |
| @@ -7617,10 +7609,8 @@ static void adjust_dio_outstanding_extents(struct inode *inode, · 5816 unmodified lines |
| 7617 | struct btrfs_dio_data *dio_data, | 7609 | struct btrfs_dio_data *dio_data, |
| 7618 | const u64 len) | 7610 | const u64 len) |
| 7619 | { | 7611 | { |
| 7620 | unsigned num_extents; | 7612 | unsigned num_extents = count_max_extents(len); |
| 7621 | | 7613 | |
| 7622 | num_extents = (unsigned) div64_u64(len + BTRFS_MAX_EXTENT_SIZE - 1, | | |
| 7623 | BTRFS_MAX_EXTENT_SIZE); | | |
| 7624 | /* | 7614 | /* |
| 7625 | * If we have an outstanding_extents count still set then we're | 7615 | * If we have an outstanding_extents count still set then we're |
| 7626 | * within our reservation, otherwise we need to adjust our inode | 7616 | * within our reservation, otherwise we need to adjust our inode |
| @@ -8681,9 +8671,7 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) · 1054 unmodified lines |
| 8681 | ret = btrfs_delalloc_reserve_space(inode, offset, count); | 8671 | ret = btrfs_delalloc_reserve_space(inode, offset, count); |
| 8682 | if (ret) | 8672 | if (ret) |
| 8683 | goto out; | 8673 | goto out; |
| 8684 | dio_data.outstanding_extents = div64_u64(count + | 8674 | dio_data.outstanding_extents = count_max_extents(count); |
| 8685 | BTRFS_MAX_EXTENT_SIZE - 1, | | |
| 8686 | BTRFS_MAX_EXTENT_SIZE); | | |
| 8687 | | 8675 | |
| 8688 | /* | 8676 | /* |
| 8689 | * We need to know how many extents we reserved so that we can | 8677 | * We need to know how many extents we reserved so that we can |