aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent-tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r--fs/btrfs/extent-tree.c82
1 files changed, 38 insertions, 44 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 075854e7a044..aaee2b7fee78 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -4721,6 +4721,8 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
4721 enum btrfs_reserve_flush_enum flush = BTRFS_RESERVE_FLUSH_ALL; 4721 enum btrfs_reserve_flush_enum flush = BTRFS_RESERVE_FLUSH_ALL;
4722 int ret = 0; 4722 int ret = 0;
4723 bool delalloc_lock = true; 4723 bool delalloc_lock = true;
4724 u64 to_free = 0;
4725 unsigned dropped;
4724 4726
4725 /* If we are a free space inode we need to not flush since we will be in 4727 /* If we are a free space inode we need to not flush since we will be in
4726 * the middle of a transaction commit. We also don't need the delalloc 4728 * the middle of a transaction commit. We also don't need the delalloc
@@ -4764,55 +4766,19 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
4764 csum_bytes = BTRFS_I(inode)->csum_bytes; 4766 csum_bytes = BTRFS_I(inode)->csum_bytes;
4765 spin_unlock(&BTRFS_I(inode)->lock); 4767 spin_unlock(&BTRFS_I(inode)->lock);
4766 4768
4767 if (root->fs_info->quota_enabled) 4769 if (root->fs_info->quota_enabled) {
4768 ret = btrfs_qgroup_reserve(root, num_bytes + 4770 ret = btrfs_qgroup_reserve(root, num_bytes +
4769 nr_extents * root->leafsize); 4771 nr_extents * root->leafsize);
4772 if (ret)
4773 goto out_fail;
4774 }
4770 4775
4771 /* 4776 ret = reserve_metadata_bytes(root, block_rsv, to_reserve, flush);
4772 * ret != 0 here means the qgroup reservation failed, we go straight to 4777 if (unlikely(ret)) {
4773 * the shared error handling then. 4778 if (root->fs_info->quota_enabled)
4774 */
4775 if (ret == 0) {
4776 ret = reserve_metadata_bytes(root, block_rsv,
4777 to_reserve, flush);
4778 if (ret && root->fs_info->quota_enabled) {
4779 btrfs_qgroup_free(root, num_bytes + 4779 btrfs_qgroup_free(root, num_bytes +
4780 nr_extents * root->leafsize); 4780 nr_extents * root->leafsize);
4781 } 4781 goto out_fail;
4782 }
4783
4784 if (ret) {
4785 u64 to_free = 0;
4786 unsigned dropped;
4787
4788 spin_lock(&BTRFS_I(inode)->lock);
4789 dropped = drop_outstanding_extent(inode);
4790 /*
4791 * If the inodes csum_bytes is the same as the original
4792 * csum_bytes then we know we haven't raced with any free()ers
4793 * so we can just reduce our inodes csum bytes and carry on.
4794 * Otherwise we have to do the normal free thing to account for
4795 * the case that the free side didn't free up its reserve
4796 * because of this outstanding reservation.
4797 */
4798 if (BTRFS_I(inode)->csum_bytes == csum_bytes)
4799 calc_csum_metadata_size(inode, num_bytes, 0);
4800 else
4801 to_free = calc_csum_metadata_size(inode, num_bytes, 0);
4802 spin_unlock(&BTRFS_I(inode)->lock);
4803 if (dropped)
4804 to_free += btrfs_calc_trans_metadata_size(root, dropped);
4805
4806 if (to_free) {
4807 btrfs_block_rsv_release(root, block_rsv, to_free);
4808 trace_btrfs_space_reservation(root->fs_info,
4809 "delalloc",
4810 btrfs_ino(inode),
4811 to_free, 0);
4812 }
4813 if (delalloc_lock)
4814 mutex_unlock(&BTRFS_I(inode)->delalloc_mutex);
4815 return ret;
4816 } 4782 }
4817 4783
4818 spin_lock(&BTRFS_I(inode)->lock); 4784 spin_lock(&BTRFS_I(inode)->lock);
@@ -4833,6 +4799,34 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
4833 block_rsv_add_bytes(block_rsv, to_reserve, 1); 4799 block_rsv_add_bytes(block_rsv, to_reserve, 1);
4834 4800
4835 return 0; 4801 return 0;
4802
4803out_fail:
4804 spin_lock(&BTRFS_I(inode)->lock);
4805 dropped = drop_outstanding_extent(inode);
4806 /*
4807 * If the inodes csum_bytes is the same as the original
4808 * csum_bytes then we know we haven't raced with any free()ers
4809 * so we can just reduce our inodes csum bytes and carry on.
4810 * Otherwise we have to do the normal free thing to account for
4811 * the case that the free side didn't free up its reserve
4812 * because of this outstanding reservation.
4813 */
4814 if (BTRFS_I(inode)->csum_bytes == csum_bytes)
4815 calc_csum_metadata_size(inode, num_bytes, 0);
4816 else
4817 to_free = calc_csum_metadata_size(inode, num_bytes, 0);
4818 spin_unlock(&BTRFS_I(inode)->lock);
4819 if (dropped)
4820 to_free += btrfs_calc_trans_metadata_size(root, dropped);
4821
4822 if (to_free) {
4823 btrfs_block_rsv_release(root, block_rsv, to_free);
4824 trace_btrfs_space_reservation(root->fs_info, "delalloc",
4825 btrfs_ino(inode), to_free, 0);
4826 }
4827 if (delalloc_lock)
4828 mutex_unlock(&BTRFS_I(inode)->delalloc_mutex);
4829 return ret;
4836} 4830}
4837 4831
4838/** 4832/**