aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosef Bacik <josef@toxicpanda.com>2018-10-11 15:54:21 -0400
committerDavid Sterba <dsterba@suse.com>2018-10-19 06:20:03 -0400
commit49940bdd57779c78462da7aa5a8650b2fea8c2ff (patch)
tree857e78f94bed8f2024aa9468aeaee91efaa4bca7
parentfb5c39d7a887108087de6ff93d3f326b01b4ef41 (diff)
btrfs: only free reserved extent if we didn't insert it
When we insert the file extent once the ordered extent completes we free the reserved extent reservation as it'll have been migrated to the bytes_used counter. However if we error out after this step we'll still clear the reserved extent reservation, resulting in a negative accounting of the reserved bytes for the block group and space info. Fix this by only doing the free if we didn't successfully insert a file extent for this extent. CC: stable@vger.kernel.org # 4.14+ Reviewed-by: Omar Sandoval <osandov@fb.com> Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/inode.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index f98ddd886036..28625f344952 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2941,6 +2941,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
2941 bool truncated = false; 2941 bool truncated = false;
2942 bool range_locked = false; 2942 bool range_locked = false;
2943 bool clear_new_delalloc_bytes = false; 2943 bool clear_new_delalloc_bytes = false;
2944 bool clear_reserved_extent = true;
2944 2945
2945 if (!test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) && 2946 if (!test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) &&
2946 !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags) && 2947 !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags) &&
@@ -3044,10 +3045,12 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
3044 logical_len, logical_len, 3045 logical_len, logical_len,
3045 compress_type, 0, 0, 3046 compress_type, 0, 0,
3046 BTRFS_FILE_EXTENT_REG); 3047 BTRFS_FILE_EXTENT_REG);
3047 if (!ret) 3048 if (!ret) {
3049 clear_reserved_extent = false;
3048 btrfs_release_delalloc_bytes(fs_info, 3050 btrfs_release_delalloc_bytes(fs_info,
3049 ordered_extent->start, 3051 ordered_extent->start,
3050 ordered_extent->disk_len); 3052 ordered_extent->disk_len);
3053 }
3051 } 3054 }
3052 unpin_extent_cache(&BTRFS_I(inode)->extent_tree, 3055 unpin_extent_cache(&BTRFS_I(inode)->extent_tree,
3053 ordered_extent->file_offset, ordered_extent->len, 3056 ordered_extent->file_offset, ordered_extent->len,
@@ -3108,8 +3111,13 @@ out:
3108 * wrong we need to return the space for this ordered extent 3111 * wrong we need to return the space for this ordered extent
3109 * back to the allocator. We only free the extent in the 3112 * back to the allocator. We only free the extent in the
3110 * truncated case if we didn't write out the extent at all. 3113 * truncated case if we didn't write out the extent at all.
3114 *
3115 * If we made it past insert_reserved_file_extent before we
3116 * errored out then we don't need to do this as the accounting
3117 * has already been done.
3111 */ 3118 */
3112 if ((ret || !logical_len) && 3119 if ((ret || !logical_len) &&
3120 clear_reserved_extent &&
3113 !test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) && 3121 !test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) &&
3114 !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) 3122 !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags))
3115 btrfs_free_reserved_extent(fs_info, 3123 btrfs_free_reserved_extent(fs_info,