diff options
Diffstat (limited to 'fs/btrfs/file.c')
-rw-r--r-- | fs/btrfs/file.c | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 859ba2dd8890..e8d06b6b9194 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -1605,6 +1605,14 @@ static long btrfs_fallocate(struct file *file, int mode, | |||
1605 | return -EOPNOTSUPP; | 1605 | return -EOPNOTSUPP; |
1606 | 1606 | ||
1607 | /* | 1607 | /* |
1608 | * Make sure we have enough space before we do the | ||
1609 | * allocation. | ||
1610 | */ | ||
1611 | ret = btrfs_check_data_free_space(inode, len); | ||
1612 | if (ret) | ||
1613 | return ret; | ||
1614 | |||
1615 | /* | ||
1608 | * wait for ordered IO before we have any locks. We'll loop again | 1616 | * wait for ordered IO before we have any locks. We'll loop again |
1609 | * below with the locks held. | 1617 | * below with the locks held. |
1610 | */ | 1618 | */ |
@@ -1667,27 +1675,12 @@ static long btrfs_fallocate(struct file *file, int mode, | |||
1667 | if (em->block_start == EXTENT_MAP_HOLE || | 1675 | if (em->block_start == EXTENT_MAP_HOLE || |
1668 | (cur_offset >= inode->i_size && | 1676 | (cur_offset >= inode->i_size && |
1669 | !test_bit(EXTENT_FLAG_PREALLOC, &em->flags))) { | 1677 | !test_bit(EXTENT_FLAG_PREALLOC, &em->flags))) { |
1670 | |||
1671 | /* | ||
1672 | * Make sure we have enough space before we do the | ||
1673 | * allocation. | ||
1674 | */ | ||
1675 | ret = btrfs_check_data_free_space(inode, last_byte - | ||
1676 | cur_offset); | ||
1677 | if (ret) { | ||
1678 | free_extent_map(em); | ||
1679 | break; | ||
1680 | } | ||
1681 | |||
1682 | ret = btrfs_prealloc_file_range(inode, mode, cur_offset, | 1678 | ret = btrfs_prealloc_file_range(inode, mode, cur_offset, |
1683 | last_byte - cur_offset, | 1679 | last_byte - cur_offset, |
1684 | 1 << inode->i_blkbits, | 1680 | 1 << inode->i_blkbits, |
1685 | offset + len, | 1681 | offset + len, |
1686 | &alloc_hint); | 1682 | &alloc_hint); |
1687 | 1683 | ||
1688 | /* Let go of our reservation. */ | ||
1689 | btrfs_free_reserved_data_space(inode, last_byte - | ||
1690 | cur_offset); | ||
1691 | if (ret < 0) { | 1684 | if (ret < 0) { |
1692 | free_extent_map(em); | 1685 | free_extent_map(em); |
1693 | break; | 1686 | break; |
@@ -1715,6 +1708,8 @@ static long btrfs_fallocate(struct file *file, int mode, | |||
1715 | &cached_state, GFP_NOFS); | 1708 | &cached_state, GFP_NOFS); |
1716 | out: | 1709 | out: |
1717 | mutex_unlock(&inode->i_mutex); | 1710 | mutex_unlock(&inode->i_mutex); |
1711 | /* Let go of our reservation. */ | ||
1712 | btrfs_free_reserved_data_space(inode, len); | ||
1718 | return ret; | 1713 | return ret; |
1719 | } | 1714 | } |
1720 | 1715 | ||
@@ -1761,7 +1756,7 @@ static int find_desired_extent(struct inode *inode, loff_t *offset, int origin) | |||
1761 | start - root->sectorsize, | 1756 | start - root->sectorsize, |
1762 | root->sectorsize, 0); | 1757 | root->sectorsize, 0); |
1763 | if (IS_ERR(em)) { | 1758 | if (IS_ERR(em)) { |
1764 | ret = -ENXIO; | 1759 | ret = PTR_ERR(em); |
1765 | goto out; | 1760 | goto out; |
1766 | } | 1761 | } |
1767 | last_end = em->start + em->len; | 1762 | last_end = em->start + em->len; |
@@ -1773,7 +1768,7 @@ static int find_desired_extent(struct inode *inode, loff_t *offset, int origin) | |||
1773 | while (1) { | 1768 | while (1) { |
1774 | em = btrfs_get_extent_fiemap(inode, NULL, 0, start, len, 0); | 1769 | em = btrfs_get_extent_fiemap(inode, NULL, 0, start, len, 0); |
1775 | if (IS_ERR(em)) { | 1770 | if (IS_ERR(em)) { |
1776 | ret = -ENXIO; | 1771 | ret = PTR_ERR(em); |
1777 | break; | 1772 | break; |
1778 | } | 1773 | } |
1779 | 1774 | ||