aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent-tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r--fs/btrfs/extent-tree.c51
1 files changed, 48 insertions, 3 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 28c4809851a5..cb7626646bba 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -4344,6 +4344,34 @@ int btrfs_pin_extent(struct btrfs_root *root,
4344 return 0; 4344 return 0;
4345} 4345}
4346 4346
4347/*
4348 * this function must be called within transaction
4349 */
4350int btrfs_pin_extent_for_log_replay(struct btrfs_trans_handle *trans,
4351 struct btrfs_root *root,
4352 u64 bytenr, u64 num_bytes)
4353{
4354 struct btrfs_block_group_cache *cache;
4355
4356 cache = btrfs_lookup_block_group(root->fs_info, bytenr);
4357 BUG_ON(!cache);
4358
4359 /*
4360 * pull in the free space cache (if any) so that our pin
4361 * removes the free space from the cache. We have load_only set
4362 * to one because the slow code to read in the free extents does check
4363 * the pinned extents.
4364 */
4365 cache_block_group(cache, trans, root, 1);
4366
4367 pin_down_extent(root, cache, bytenr, num_bytes, 0);
4368
4369 /* remove us from the free space cache (if we're there at all) */
4370 btrfs_remove_free_space(cache, bytenr, num_bytes);
4371 btrfs_put_block_group(cache);
4372 return 0;
4373}
4374
4347/** 4375/**
4348 * btrfs_update_reserved_bytes - update the block_group and space info counters 4376 * btrfs_update_reserved_bytes - update the block_group and space info counters
4349 * @cache: The cache we are manipulating 4377 * @cache: The cache we are manipulating
@@ -5487,7 +5515,8 @@ again:
5487 return ret; 5515 return ret;
5488} 5516}
5489 5517
5490int btrfs_free_reserved_extent(struct btrfs_root *root, u64 start, u64 len) 5518static int __btrfs_free_reserved_extent(struct btrfs_root *root,
5519 u64 start, u64 len, int pin)
5491{ 5520{
5492 struct btrfs_block_group_cache *cache; 5521 struct btrfs_block_group_cache *cache;
5493 int ret = 0; 5522 int ret = 0;
@@ -5502,8 +5531,12 @@ int btrfs_free_reserved_extent(struct btrfs_root *root, u64 start, u64 len)
5502 if (btrfs_test_opt(root, DISCARD)) 5531 if (btrfs_test_opt(root, DISCARD))
5503 ret = btrfs_discard_extent(root, start, len, NULL); 5532 ret = btrfs_discard_extent(root, start, len, NULL);
5504 5533
5505 btrfs_add_free_space(cache, start, len); 5534 if (pin)
5506 btrfs_update_reserved_bytes(cache, len, RESERVE_FREE); 5535 pin_down_extent(root, cache, start, len, 1);
5536 else {
5537 btrfs_add_free_space(cache, start, len);
5538 btrfs_update_reserved_bytes(cache, len, RESERVE_FREE);
5539 }
5507 btrfs_put_block_group(cache); 5540 btrfs_put_block_group(cache);
5508 5541
5509 trace_btrfs_reserved_extent_free(root, start, len); 5542 trace_btrfs_reserved_extent_free(root, start, len);
@@ -5511,6 +5544,18 @@ int btrfs_free_reserved_extent(struct btrfs_root *root, u64 start, u64 len)
5511 return ret; 5544 return ret;
5512} 5545}
5513 5546
5547int btrfs_free_reserved_extent(struct btrfs_root *root,
5548 u64 start, u64 len)
5549{
5550 return __btrfs_free_reserved_extent(root, start, len, 0);
5551}
5552
5553int btrfs_free_and_pin_reserved_extent(struct btrfs_root *root,
5554 u64 start, u64 len)
5555{
5556 return __btrfs_free_reserved_extent(root, start, len, 1);
5557}
5558
5514static int alloc_reserved_file_extent(struct btrfs_trans_handle *trans, 5559static int alloc_reserved_file_extent(struct btrfs_trans_handle *trans,
5515 struct btrfs_root *root, 5560 struct btrfs_root *root,
5516 u64 parent, u64 root_objectid, 5561 u64 parent, u64 root_objectid,