aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/inode.c
diff options
context:
space:
mode:
authorNikolay Borisov <nborisov@suse.com>2019-11-21 14:03:29 +0200
committerDavid Sterba <dsterba@suse.com>2020-01-20 16:40:50 +0100
commit4eaaec24c087a52c6b2ed75856037ae42cc6a830 (patch)
tree8f2ce4541c7afe730046ed708b3e1567c8ec5a40 /fs/btrfs/inode.c
parentbtrfs: qgroup: return ENOTCONN instead of EINVAL when quotas are not enabled (diff)
downloadlinux-dev-4eaaec24c087a52c6b2ed75856037ae42cc6a830.tar.xz
linux-dev-4eaaec24c087a52c6b2ed75856037ae42cc6a830.zip
btrfs: Don't discard unwritten extents
All callers of btrfs_free_reserved_extent (respectively __btrfs_free_reserved_extent with in set to 0) pass in extents which have only been reserved but not yet written to. Namely, * in cow_file_range that function is called only if create_io_em fails or btrfs_add_ordered_extent fail, both of which happen _before_ any IO is submitted to the newly reserved range * in submit_compressed_extents the code flow is similar - out_free_reserve can be called only before btrfs_submit_compressed_write which is where any writes to the range could occur * btrfs_new_extent_direct also calls btrfs_free_reserved_extent only if extent_map fails, before any IO is issued * __btrfs_prealloc_file_range also calls btrfs_free_reserved_extent in case insertion of the metadata fails * btrfs_alloc_tree_block again can only be called in case in-memory operations fail, before any IO is submitted * btrfs_finish_ordered_io - this is the only caller where discarding the extent could have a material effect, since it can be called for an extent which was partially written. With this change the submission of discards is optimised since discards are now not being created for extents which are known to not have been touched on disk. Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to '')
-rw-r--r--fs/btrfs/inode.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index c70baafb2a39..c1cee6a01c35 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3250,10 +3250,19 @@ out:
if ((ret || !logical_len) &&
clear_reserved_extent &&
!test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) &&
- !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags))
+ !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) {
+ /*
+ * Discard the range before returning it back to the
+ * free space pool
+ */
+ 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);
+ }
}