Lines Matching refs:bg

3941 					   struct btrfs_block_group *bg, s64 diff)  in adjust_block_group_remap_bytes()  argument
3947 spin_lock(&bg->lock); in adjust_block_group_remap_bytes()
3948 bg->remap_bytes += diff; in adjust_block_group_remap_bytes()
3949 if (bg->used == 0 && bg->remap_bytes == 0) in adjust_block_group_remap_bytes()
3951 spin_unlock(&bg->lock); in adjust_block_group_remap_bytes()
3954 btrfs_mark_bg_unused(bg); in adjust_block_group_remap_bytes()
3957 if (list_empty(&bg->dirty_list)) { in adjust_block_group_remap_bytes()
3958 list_add_tail(&bg->dirty_list, &trans->transaction->dirty_bgs); in adjust_block_group_remap_bytes()
3960 btrfs_get_block_group(bg); in adjust_block_group_remap_bytes()
4151 struct btrfs_block_group *bg, u64 new_addr, in move_existing_remap() argument
4162 const bool is_data = (bg->flags & BTRFS_BLOCK_GROUP_DATA); in move_existing_remap()
4163 struct btrfs_space_info *sinfo = bg->space_info; in move_existing_remap()
4292 adjust_block_group_remap_bytes(trans, bg, -dest_length); in move_existing_remap()
4347 struct btrfs_block_group *bg, in move_existing_remaps() argument
4357 while (bg->remap_bytes > 0) { in move_existing_remaps()
4358 key.objectid = bg->start; in move_existing_remaps()
4409 ret = move_existing_remap(fs_info, path, bg, key.objectid, in move_existing_remaps()
4415 ASSERT(bg->remap_bytes == 0); in move_existing_remaps()
4422 struct btrfs_block_group *bg) in create_remap_tree_entries() argument
4436 mutex_lock(&bg->free_space_lock); in create_remap_tree_entries()
4438 if (test_bit(BLOCK_GROUP_FLAG_NEEDS_FREE_SPACE, &bg->runtime_flags)) { in create_remap_tree_entries()
4439 mutex_unlock(&bg->free_space_lock); in create_remap_tree_entries()
4441 ret = btrfs_add_block_group_free_space(trans, bg); in create_remap_tree_entries()
4445 mutex_lock(&bg->free_space_lock); in create_remap_tree_entries()
4448 fsi = btrfs_search_free_space_info(trans, bg, path, 0); in create_remap_tree_entries()
4450 mutex_unlock(&bg->free_space_lock); in create_remap_tree_entries()
4460 mutex_unlock(&bg->free_space_lock); in create_remap_tree_entries()
4464 key.objectid = bg->start; in create_remap_tree_entries()
4468 space_root = btrfs_free_space_root(bg); in create_remap_tree_entries()
4472 mutex_unlock(&bg->free_space_lock); in create_remap_tree_entries()
4483 if (found_key.objectid >= bg->start + bg->length) in create_remap_tree_entries()
4511 mutex_unlock(&bg->free_space_lock); in create_remap_tree_entries()
4544 mutex_unlock(&bg->free_space_lock); in create_remap_tree_entries()
4556 entries[num_entries].objectid = bg->start; in create_remap_tree_entries()
4558 entries[num_entries].offset = bg->length; in create_remap_tree_entries()
4561 if (space_runs[0].start > bg->start) { in create_remap_tree_entries()
4562 entries[num_entries].objectid = bg->start; in create_remap_tree_entries()
4564 entries[num_entries].offset = space_runs[0].start - bg->start; in create_remap_tree_entries()
4576 if (space_runs[num_space_runs - 1].end < bg->start + bg->length) { in create_remap_tree_entries()
4581 bg->start + bg->length - space_runs[num_space_runs - 1].end; in create_remap_tree_entries()
4589 bg->identity_remap_count = num_entries; in create_remap_tree_entries()
4697 struct btrfs_block_group *bg) in btrfs_last_identity_remap_gone() argument
4699 struct btrfs_fs_info *fs_info = bg->fs_info; in btrfs_last_identity_remap_gone()
4714 if (bg->flags & BTRFS_BLOCK_GROUP_DUP) in btrfs_last_identity_remap_gone()
4744 btrfs_remove_bg_from_sinfo(bg); in btrfs_last_identity_remap_gone()
4746 spin_lock(&bg->lock); in btrfs_last_identity_remap_gone()
4747 clear_bit(BLOCK_GROUP_FLAG_STRIPE_REMOVAL_PENDING, &bg->runtime_flags); in btrfs_last_identity_remap_gone()
4748 spin_unlock(&bg->lock); in btrfs_last_identity_remap_gone()
4764 struct btrfs_block_group *bg, int delta) in adjust_identity_remap_count() argument
4770 WARN_ON(delta < 0 && -delta > bg->identity_remap_count); in adjust_identity_remap_count()
4772 spin_lock(&bg->lock); in adjust_identity_remap_count()
4774 bg->identity_remap_count += delta; in adjust_identity_remap_count()
4776 if (bg->identity_remap_count == 0 && in adjust_identity_remap_count()
4777 !test_bit(BLOCK_GROUP_FLAG_FULLY_REMAPPED, &bg->runtime_flags)) { in adjust_identity_remap_count()
4778 set_bit(BLOCK_GROUP_FLAG_FULLY_REMAPPED, &bg->runtime_flags); in adjust_identity_remap_count()
4782 spin_unlock(&bg->lock); in adjust_identity_remap_count()
4785 if (list_empty(&bg->dirty_list)) { in adjust_identity_remap_count()
4786 list_add_tail(&bg->dirty_list, &trans->transaction->dirty_bgs); in adjust_identity_remap_count()
4788 btrfs_get_block_group(bg); in adjust_identity_remap_count()
4797 btrfs_mark_bg_fully_remapped(bg, trans); in adjust_identity_remap_count()
5096 struct btrfs_block_group *bg) in do_remap_reloc() argument
5098 u64 last_start = bg->start; in do_remap_reloc()
5102 ret = do_remap_reloc_trans(fs_info, bg, path, &last_start); in do_remap_reloc()
5165 struct btrfs_block_group *bg) in start_block_group_remapping() argument
5171 ret = btrfs_cache_block_group(bg, true); in start_block_group_remapping()
5188 if (bg->flags & BTRFS_BLOCK_GROUP_REMAPPED) { in start_block_group_remapping()
5193 ret = create_remap_tree_entries(trans, path, bg); in start_block_group_remapping()
5199 spin_lock(&bg->lock); in start_block_group_remapping()
5200 bg->flags |= BTRFS_BLOCK_GROUP_REMAPPED; in start_block_group_remapping()
5201 spin_unlock(&bg->lock); in start_block_group_remapping()
5204 if (list_empty(&bg->dirty_list)) { in start_block_group_remapping()
5205 list_add_tail(&bg->dirty_list, &trans->transaction->dirty_bgs); in start_block_group_remapping()
5207 btrfs_get_block_group(bg); in start_block_group_remapping()
5215 ret = mark_chunk_remapped(trans, path, bg->start); in start_block_group_remapping()
5221 ret = btrfs_remove_block_group_free_space(trans, bg); in start_block_group_remapping()
5227 btrfs_remove_free_space_cache(bg); in start_block_group_remapping()
5296 struct btrfs_block_group *bg; in btrfs_relocate_block_group() local
5317 bg = btrfs_lookup_block_group(fs_info, group_start); in btrfs_relocate_block_group()
5318 if (!bg) in btrfs_relocate_block_group()
5329 if (bg->flags & BTRFS_BLOCK_GROUP_DATA) in btrfs_relocate_block_group()
5332 if (btrfs_pinned_by_swapfile(fs_info, bg)) { in btrfs_relocate_block_group()
5333 btrfs_put_block_group(bg); in btrfs_relocate_block_group()
5339 btrfs_put_block_group(bg); in btrfs_relocate_block_group()
5348 rc->block_group = bg; in btrfs_relocate_block_group()
5391 if (should_relocate_using_remap_tree(bg)) { in btrfs_relocate_block_group()
5392 if (bg->remap_bytes != 0) { in btrfs_relocate_block_group()
5393 ret = move_existing_remaps(fs_info, bg, path); in btrfs_relocate_block_group()
5397 ret = start_block_group_remapping(fs_info, path, bg); in btrfs_relocate_block_group()
5418 btrfs_put_block_group(bg); in btrfs_relocate_block_group()
5890 struct btrfs_block_group *bg, in remove_range_from_remap_tree() argument
5976 adjust_identity_remap_count(trans, bg, identity_count_delta); in remove_range_from_remap_tree()
6010 struct btrfs_block_group *bg; in btrfs_remove_extent_from_remap_tree() local
6017 bg = btrfs_lookup_block_group(fs_info, bytenr); in btrfs_remove_extent_from_remap_tree()
6018 if (!bg) in btrfs_remove_extent_from_remap_tree()
6023 if (!(bg->flags & BTRFS_BLOCK_GROUP_REMAPPED)) { in btrfs_remove_extent_from_remap_tree()
6025 btrfs_put_block_group(bg); in btrfs_remove_extent_from_remap_tree()
6060 length = remove_range_from_remap_tree(trans, path, bg, bytenr, num_bytes); in btrfs_remove_extent_from_remap_tree()
6075 btrfs_put_block_group(bg); in btrfs_remove_extent_from_remap_tree()