btrfs: discard before adding to the free space cache
PATCH 1/1 btrfs: discard before adding to the free space cache
Returning free space to the free space cache lets it immediately be reused. So discard before returning the free space otherwise we can race here.
Fixes 55e734b728c0 ("btrfs: Don't discard unwritten extents")
Cc Nikolay Borisov <[email protected]>
Cc Omar Sandoval <[email protected]>
Signed-off-by Dennis Zhou <[email protected]>
--- fs/btrfs/inode.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/btrfs/inode.c +4 -3
@@ -3250,13 +3250,14 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) clear_reserved_extent && !test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) && !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) { -btrfs_free_reserved_extent (fs_info, - ordered_extent->start, - ordered_extent->disk_len,1 );if (ret &&btrfs_test_opt (fs_info,DISCARD ))btrfs_discard_extent (fs_info, ordered_extent->start, ordered_extent->disk_len,NULL ); + +btrfs_free_reserved_extent (fs_info, + ordered_extent->start, + ordered_extent->disk_len,1 ); } }
Signature · 1 line
2.17.1
Quoted 8 lines · Dennis Zhou
Returning free space to the free space cache lets it immediately be reused. So discard before returning the free space otherwise we can race here.
Fixes 55e734b728c0 ("btrfs: Don't discard unwritten extents")Cc Nikolay Borisov <[email protected]>Cc Omar Sandoval <[email protected]>Signed-off-by Dennis Zhou <[email protected]>
Fair point.
Reviewed-by Nikolay Borisov <[email protected]>
Quoted 27 lines
--- fs/btrfs/inode.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)fs/btrfs/inode.c +4
-3@@ -3250,13 +3250,14 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) clear_reserved_extent && !test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) && !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) { -btrfs_free_reserved_extent (fs_info, - ordered_extent->start, - ordered_extent->disk_len,1 );if (ret &&btrfs_test_opt (fs_info,DISCARD ))btrfs_discard_extent (fs_info, ordered_extent->start, ordered_extent->disk_len,NULL ); + +btrfs_free_reserved_extent (fs_info, + ordered_extent->start, + ordered_extent->disk_len,1 ); } }
Looks good,
Reviewed-by Johannes Thumshirn <[email protected]>
Signature · 9 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Quoted 5 lines · Dennis Zhou
Returning free space to the free space cache lets it immediately be reused. So discard before returning the free space otherwise we can race here.
Fixes 55e734b728c0 ("btrfs: Don't discard unwritten extents")
Unstable commit id as the patch is still in misc-next, so I'm going to fold the fix to the original patch. Thanks.