diff options
Diffstat (limited to 'fs/btrfs/free-space-cache.c')
-rw-r--r-- | fs/btrfs/free-space-cache.c | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 41ac927401d0..79c16a68a2bc 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c | |||
@@ -2472,9 +2472,19 @@ int btrfs_trim_block_group(struct btrfs_block_group_cache *block_group, | |||
2472 | spin_unlock(&ctl->tree_lock); | 2472 | spin_unlock(&ctl->tree_lock); |
2473 | 2473 | ||
2474 | if (bytes >= minlen) { | 2474 | if (bytes >= minlen) { |
2475 | int update_ret; | 2475 | struct btrfs_space_info *space_info; |
2476 | update_ret = btrfs_update_reserved_bytes(block_group, | 2476 | int update = 0; |
2477 | bytes, 1, 1); | 2477 | |
2478 | space_info = block_group->space_info; | ||
2479 | spin_lock(&space_info->lock); | ||
2480 | spin_lock(&block_group->lock); | ||
2481 | if (!block_group->ro) { | ||
2482 | block_group->reserved += bytes; | ||
2483 | space_info->bytes_reserved += bytes; | ||
2484 | update = 1; | ||
2485 | } | ||
2486 | spin_unlock(&block_group->lock); | ||
2487 | spin_unlock(&space_info->lock); | ||
2478 | 2488 | ||
2479 | ret = btrfs_error_discard_extent(fs_info->extent_root, | 2489 | ret = btrfs_error_discard_extent(fs_info->extent_root, |
2480 | start, | 2490 | start, |
@@ -2482,9 +2492,16 @@ int btrfs_trim_block_group(struct btrfs_block_group_cache *block_group, | |||
2482 | &actually_trimmed); | 2492 | &actually_trimmed); |
2483 | 2493 | ||
2484 | btrfs_add_free_space(block_group, start, bytes); | 2494 | btrfs_add_free_space(block_group, start, bytes); |
2485 | if (!update_ret) | 2495 | if (update) { |
2486 | btrfs_update_reserved_bytes(block_group, | 2496 | spin_lock(&space_info->lock); |
2487 | bytes, 0, 1); | 2497 | spin_lock(&block_group->lock); |
2498 | if (block_group->ro) | ||
2499 | space_info->bytes_readonly += bytes; | ||
2500 | block_group->reserved -= bytes; | ||
2501 | space_info->bytes_reserved -= bytes; | ||
2502 | spin_unlock(&space_info->lock); | ||
2503 | spin_unlock(&block_group->lock); | ||
2504 | } | ||
2488 | 2505 | ||
2489 | if (ret) | 2506 | if (ret) |
2490 | break; | 2507 | break; |