Skip to content

Commit 42551ab

Browse files
josefbacikgregkh
authored andcommitted
btrfs: only free reserved extent if we didn't insert it
commit 49940bd upstream. 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: [email protected] # 4.14+ Reviewed-by: Omar Sandoval <[email protected]> Reviewed-by: Filipe Manana <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7509d4f commit 42551ab

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

fs/btrfs/inode.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2966,6 +2966,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
29662966
bool truncated = false;
29672967
bool range_locked = false;
29682968
bool clear_new_delalloc_bytes = false;
2969+
bool clear_reserved_extent = true;
29692970

29702971
if (!test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) &&
29712972
!test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags) &&
@@ -3069,10 +3070,12 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
30693070
logical_len, logical_len,
30703071
compress_type, 0, 0,
30713072
BTRFS_FILE_EXTENT_REG);
3072-
if (!ret)
3073+
if (!ret) {
3074+
clear_reserved_extent = false;
30733075
btrfs_release_delalloc_bytes(fs_info,
30743076
ordered_extent->start,
30753077
ordered_extent->disk_len);
3078+
}
30763079
}
30773080
unpin_extent_cache(&BTRFS_I(inode)->extent_tree,
30783081
ordered_extent->file_offset, ordered_extent->len,
@@ -3132,8 +3135,13 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
31323135
* wrong we need to return the space for this ordered extent
31333136
* back to the allocator. We only free the extent in the
31343137
* truncated case if we didn't write out the extent at all.
3138+
*
3139+
* If we made it past insert_reserved_file_extent before we
3140+
* errored out then we don't need to do this as the accounting
3141+
* has already been done.
31353142
*/
31363143
if ((ret || !logical_len) &&
3144+
clear_reserved_extent &&
31373145
!test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) &&
31383146
!test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags))
31393147
btrfs_free_reserved_extent(fs_info,

0 commit comments

Comments
 (0)