diff options
| -rw-r--r-- | fs/btrfs/ctree.h | 4 | ||||
| -rw-r--r-- | fs/btrfs/disk-io.c | 6 | ||||
| -rw-r--r-- | fs/btrfs/extent-tree.c | 23 | ||||
| -rw-r--r-- | fs/btrfs/free-space-cache.c | 12 |
4 files changed, 20 insertions, 25 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index e6fbbd74b716..7e607416755a 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
| @@ -3481,8 +3481,8 @@ void btrfs_put_block_group_cache(struct btrfs_fs_info *info); | |||
| 3481 | u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo); | 3481 | u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo); |
| 3482 | int btrfs_error_unpin_extent_range(struct btrfs_root *root, | 3482 | int btrfs_error_unpin_extent_range(struct btrfs_root *root, |
| 3483 | u64 start, u64 end); | 3483 | u64 start, u64 end); |
| 3484 | int btrfs_error_discard_extent(struct btrfs_root *root, u64 bytenr, | 3484 | int btrfs_discard_extent(struct btrfs_root *root, u64 bytenr, |
| 3485 | u64 num_bytes, u64 *actual_bytes); | 3485 | u64 num_bytes, u64 *actual_bytes); |
| 3486 | int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, | 3486 | int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, |
| 3487 | struct btrfs_root *root, u64 type); | 3487 | struct btrfs_root *root, u64 type); |
| 3488 | int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range); | 3488 | int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range); |
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 30965120772b..8c63419a7f70 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
| @@ -4121,12 +4121,6 @@ again: | |||
| 4121 | if (ret) | 4121 | if (ret) |
| 4122 | break; | 4122 | break; |
| 4123 | 4123 | ||
| 4124 | /* opt_discard */ | ||
| 4125 | if (btrfs_test_opt(root, DISCARD)) | ||
| 4126 | ret = btrfs_error_discard_extent(root, start, | ||
| 4127 | end + 1 - start, | ||
| 4128 | NULL); | ||
| 4129 | |||
| 4130 | clear_extent_dirty(unpin, start, end, GFP_NOFS); | 4124 | clear_extent_dirty(unpin, start, end, GFP_NOFS); |
| 4131 | btrfs_error_unpin_extent_range(root, start, end); | 4125 | btrfs_error_unpin_extent_range(root, start, end); |
| 4132 | cond_resched(); | 4126 | cond_resched(); |
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 222d6aea4a8a..a80b97100d90 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
| @@ -1889,8 +1889,8 @@ static int btrfs_issue_discard(struct block_device *bdev, | |||
| 1889 | return blkdev_issue_discard(bdev, start >> 9, len >> 9, GFP_NOFS, 0); | 1889 | return blkdev_issue_discard(bdev, start >> 9, len >> 9, GFP_NOFS, 0); |
| 1890 | } | 1890 | } |
| 1891 | 1891 | ||
| 1892 | static int btrfs_discard_extent(struct btrfs_root *root, u64 bytenr, | 1892 | int btrfs_discard_extent(struct btrfs_root *root, u64 bytenr, |
| 1893 | u64 num_bytes, u64 *actual_bytes) | 1893 | u64 num_bytes, u64 *actual_bytes) |
| 1894 | { | 1894 | { |
| 1895 | int ret; | 1895 | int ret; |
| 1896 | u64 discarded_bytes = 0; | 1896 | u64 discarded_bytes = 0; |
| @@ -5727,7 +5727,8 @@ void btrfs_prepare_extent_commit(struct btrfs_trans_handle *trans, | |||
| 5727 | update_global_block_rsv(fs_info); | 5727 | update_global_block_rsv(fs_info); |
| 5728 | } | 5728 | } |
| 5729 | 5729 | ||
| 5730 | static int unpin_extent_range(struct btrfs_root *root, u64 start, u64 end) | 5730 | static int unpin_extent_range(struct btrfs_root *root, u64 start, u64 end, |
| 5731 | const bool return_free_space) | ||
| 5731 | { | 5732 | { |
| 5732 | struct btrfs_fs_info *fs_info = root->fs_info; | 5733 | struct btrfs_fs_info *fs_info = root->fs_info; |
| 5733 | struct btrfs_block_group_cache *cache = NULL; | 5734 | struct btrfs_block_group_cache *cache = NULL; |
| @@ -5751,7 +5752,8 @@ static int unpin_extent_range(struct btrfs_root *root, u64 start, u64 end) | |||
| 5751 | 5752 | ||
| 5752 | if (start < cache->last_byte_to_unpin) { | 5753 | if (start < cache->last_byte_to_unpin) { |
| 5753 | len = min(len, cache->last_byte_to_unpin - start); | 5754 | len = min(len, cache->last_byte_to_unpin - start); |
| 5754 | btrfs_add_free_space(cache, start, len); | 5755 | if (return_free_space) |
| 5756 | btrfs_add_free_space(cache, start, len); | ||
| 5755 | } | 5757 | } |
| 5756 | 5758 | ||
| 5757 | start += len; | 5759 | start += len; |
| @@ -5815,7 +5817,7 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, | |||
| 5815 | end + 1 - start, NULL); | 5817 | end + 1 - start, NULL); |
| 5816 | 5818 | ||
| 5817 | clear_extent_dirty(unpin, start, end, GFP_NOFS); | 5819 | clear_extent_dirty(unpin, start, end, GFP_NOFS); |
| 5818 | unpin_extent_range(root, start, end); | 5820 | unpin_extent_range(root, start, end, true); |
| 5819 | cond_resched(); | 5821 | cond_resched(); |
| 5820 | } | 5822 | } |
| 5821 | 5823 | ||
| @@ -8872,6 +8874,7 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info) | |||
| 8872 | cache_node); | 8874 | cache_node); |
| 8873 | rb_erase(&block_group->cache_node, | 8875 | rb_erase(&block_group->cache_node, |
| 8874 | &info->block_group_cache_tree); | 8876 | &info->block_group_cache_tree); |
| 8877 | RB_CLEAR_NODE(&block_group->cache_node); | ||
| 8875 | spin_unlock(&info->block_group_cache_lock); | 8878 | spin_unlock(&info->block_group_cache_lock); |
| 8876 | 8879 | ||
| 8877 | down_write(&block_group->space_info->groups_sem); | 8880 | down_write(&block_group->space_info->groups_sem); |
| @@ -9130,6 +9133,7 @@ int btrfs_read_block_groups(struct btrfs_root *root) | |||
| 9130 | spin_lock(&info->block_group_cache_lock); | 9133 | spin_lock(&info->block_group_cache_lock); |
| 9131 | rb_erase(&cache->cache_node, | 9134 | rb_erase(&cache->cache_node, |
| 9132 | &info->block_group_cache_tree); | 9135 | &info->block_group_cache_tree); |
| 9136 | RB_CLEAR_NODE(&cache->cache_node); | ||
| 9133 | spin_unlock(&info->block_group_cache_lock); | 9137 | spin_unlock(&info->block_group_cache_lock); |
| 9134 | btrfs_put_block_group(cache); | 9138 | btrfs_put_block_group(cache); |
| 9135 | goto error; | 9139 | goto error; |
| @@ -9271,6 +9275,7 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans, | |||
| 9271 | spin_lock(&root->fs_info->block_group_cache_lock); | 9275 | spin_lock(&root->fs_info->block_group_cache_lock); |
| 9272 | rb_erase(&cache->cache_node, | 9276 | rb_erase(&cache->cache_node, |
| 9273 | &root->fs_info->block_group_cache_tree); | 9277 | &root->fs_info->block_group_cache_tree); |
| 9278 | RB_CLEAR_NODE(&cache->cache_node); | ||
| 9274 | spin_unlock(&root->fs_info->block_group_cache_lock); | 9279 | spin_unlock(&root->fs_info->block_group_cache_lock); |
| 9275 | btrfs_put_block_group(cache); | 9280 | btrfs_put_block_group(cache); |
| 9276 | return ret; | 9281 | return ret; |
| @@ -9690,13 +9695,7 @@ out: | |||
| 9690 | 9695 | ||
| 9691 | int btrfs_error_unpin_extent_range(struct btrfs_root *root, u64 start, u64 end) | 9696 | int btrfs_error_unpin_extent_range(struct btrfs_root *root, u64 start, u64 end) |
| 9692 | { | 9697 | { |
| 9693 | return unpin_extent_range(root, start, end); | 9698 | return unpin_extent_range(root, start, end, false); |
| 9694 | } | ||
| 9695 | |||
| 9696 | int btrfs_error_discard_extent(struct btrfs_root *root, u64 bytenr, | ||
| 9697 | u64 num_bytes, u64 *actual_bytes) | ||
| 9698 | { | ||
| 9699 | return btrfs_discard_extent(root, bytenr, num_bytes, actual_bytes); | ||
| 9700 | } | 9699 | } |
| 9701 | 9700 | ||
| 9702 | int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range) | 9701 | int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range) |
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 030847bf7cec..d6c03f7f136b 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c | |||
| @@ -2966,8 +2966,8 @@ static int do_trimming(struct btrfs_block_group_cache *block_group, | |||
| 2966 | spin_unlock(&block_group->lock); | 2966 | spin_unlock(&block_group->lock); |
| 2967 | spin_unlock(&space_info->lock); | 2967 | spin_unlock(&space_info->lock); |
| 2968 | 2968 | ||
| 2969 | ret = btrfs_error_discard_extent(fs_info->extent_root, | 2969 | ret = btrfs_discard_extent(fs_info->extent_root, |
| 2970 | start, bytes, &trimmed); | 2970 | start, bytes, &trimmed); |
| 2971 | if (!ret) | 2971 | if (!ret) |
| 2972 | *total_trimmed += trimmed; | 2972 | *total_trimmed += trimmed; |
| 2973 | 2973 | ||
| @@ -3185,16 +3185,18 @@ out: | |||
| 3185 | 3185 | ||
| 3186 | spin_unlock(&block_group->lock); | 3186 | spin_unlock(&block_group->lock); |
| 3187 | 3187 | ||
| 3188 | lock_chunks(block_group->fs_info->chunk_root); | ||
| 3188 | em_tree = &block_group->fs_info->mapping_tree.map_tree; | 3189 | em_tree = &block_group->fs_info->mapping_tree.map_tree; |
| 3189 | write_lock(&em_tree->lock); | 3190 | write_lock(&em_tree->lock); |
| 3190 | em = lookup_extent_mapping(em_tree, block_group->key.objectid, | 3191 | em = lookup_extent_mapping(em_tree, block_group->key.objectid, |
| 3191 | 1); | 3192 | 1); |
| 3192 | BUG_ON(!em); /* logic error, can't happen */ | 3193 | BUG_ON(!em); /* logic error, can't happen */ |
| 3194 | /* | ||
| 3195 | * remove_extent_mapping() will delete us from the pinned_chunks | ||
| 3196 | * list, which is protected by the chunk mutex. | ||
| 3197 | */ | ||
| 3193 | remove_extent_mapping(em_tree, em); | 3198 | remove_extent_mapping(em_tree, em); |
| 3194 | write_unlock(&em_tree->lock); | 3199 | write_unlock(&em_tree->lock); |
| 3195 | |||
| 3196 | lock_chunks(block_group->fs_info->chunk_root); | ||
| 3197 | list_del_init(&em->list); | ||
| 3198 | unlock_chunks(block_group->fs_info->chunk_root); | 3200 | unlock_chunks(block_group->fs_info->chunk_root); |
| 3199 | 3201 | ||
| 3200 | /* once for us and once for the tree */ | 3202 | /* once for us and once for the tree */ |
