diff options
author | Josef Bacik <josef@toxicpanda.com> | 2020-10-23 16:58:06 +0300 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2020-12-08 17:54:02 +0300 |
commit | 2ca08c56e813323ee470f7fd8d836f30600e3960 (patch) | |
tree | 61746db82d5df67a1e90219b62a4c71c4dfb36d0 /fs/btrfs/extent-tree.c | |
parent | 27d56e62e4748c2135650c260024e9904b8c1a0a (diff) | |
download | linux-2ca08c56e813323ee470f7fd8d836f30600e3960.tar.xz |
btrfs: explicitly protect ->last_byte_to_unpin in unpin_extent_range
Currently unpin_extent_range happens in the transaction commit context,
so we are protected from ->last_byte_to_unpin changing while we're
unpinning, because any new transactions would have to wait for us to
complete before modifying ->last_byte_to_unpin.
However in the future we may want to change how this works, for instance
with async unpinning or other such TODO items. To prepare for that
future explicitly protect ->last_byte_to_unpin with the commit_root_sem
so we are sure it won't change while we're doing our work.
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r-- | fs/btrfs/extent-tree.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 27523e6b6c2d..d7a68203cda0 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2769,11 +2769,13 @@ static int unpin_extent_range(struct btrfs_fs_info *fs_info, len = cache->start + cache->length - start; len = min(len, end + 1 - start); + down_read(&fs_info->commit_root_sem); if (start < cache->last_byte_to_unpin && return_free_space) { u64 add_len = min(len, cache->last_byte_to_unpin - start); btrfs_add_free_space(cache, start, add_len); } + up_read(&fs_info->commit_root_sem); start += len; total_unpinned += len; |