Lines Matching refs:block_group
129 struct inode *lookup_free_space_inode(struct btrfs_block_group *block_group,
132 struct btrfs_fs_info *fs_info = block_group->fs_info;
136 spin_lock(&block_group->lock);
137 if (block_group->inode)
138 inode = igrab(block_group->inode);
139 spin_unlock(&block_group->lock);
144 block_group->start);
148 spin_lock(&block_group->lock);
153 block_group->disk_cache_state = BTRFS_DC_CLEAR;
156 if (!test_and_set_bit(BLOCK_GROUP_FLAG_IREF, &block_group->runtime_flags))
157 block_group->inode = igrab(inode);
158 spin_unlock(&block_group->lock);
223 struct btrfs_block_group *block_group,
234 ino, block_group->start);
244 struct btrfs_block_group *block_group)
255 inode = lookup_free_space_inode(block_group, path);
268 spin_lock(&block_group->lock);
269 if (test_and_clear_bit(BLOCK_GROUP_FLAG_IREF, &block_group->runtime_flags)) {
270 block_group->inode = NULL;
271 spin_unlock(&block_group->lock);
274 spin_unlock(&block_group->lock);
281 key.offset = block_group->start;
296 struct btrfs_block_group *block_group,
312 if (block_group) {
321 if (!list_empty(&block_group->io_list)) {
322 list_del_init(&block_group->io_list);
324 btrfs_wait_cache_io(trans, block_group, path);
325 btrfs_put_block_group(block_group);
332 spin_lock(&block_group->lock);
333 block_group->disk_cache_state = BTRFS_DC_CLEAR;
334 spin_unlock(&block_group->lock);
691 struct btrfs_block_group *block_group = ctl->block_group;
695 u64 size = block_group->length;
702 btrfs_err(block_group->fs_info,
704 block_group->start, block_group->length,
897 static int copy_free_space_cache(struct btrfs_block_group *block_group,
913 ret = btrfs_add_free_space(block_group, offset, bytes);
923 ret = btrfs_add_free_space(block_group, offset,
938 int load_free_space_cache(struct btrfs_block_group *block_group)
940 struct btrfs_fs_info *fs_info = block_group->fs_info;
941 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
947 u64 used = block_group->used;
954 btrfs_init_free_space_ctl(block_group, &tmp_ctl);
960 spin_lock(&block_group->lock);
961 if (block_group->disk_cache_state != BTRFS_DC_WRITTEN) {
962 spin_unlock(&block_group->lock);
965 spin_unlock(&block_group->lock);
992 inode = lookup_free_space_inode(block_group, path);
999 spin_lock(&block_group->lock);
1000 if (block_group->disk_cache_state != BTRFS_DC_WRITTEN) {
1001 spin_unlock(&block_group->lock);
1005 spin_unlock(&block_group->lock);
1016 path, block_group->start);
1021 matched = (tmp_ctl.free_space == (block_group->length - used -
1022 block_group->bytes_super));
1026 ret = copy_free_space_cache(block_group, &tmp_ctl);
1044 block_group->start);
1050 spin_lock(&block_group->lock);
1051 block_group->disk_cache_state = BTRFS_DC_CLEAR;
1052 spin_unlock(&block_group->lock);
1057 block_group->start);
1061 btrfs_discard_update_discardable(block_group);
1070 struct btrfs_block_group *block_group,
1080 /* Get the cluster for this block_group if it exists */
1081 if (block_group && !list_empty(&block_group->cluster_list)) {
1082 cluster = list_entry(block_group->cluster_list.next,
1199 struct btrfs_block_group *block_group,
1207 if (!block_group)
1219 start = block_group->start;
1221 while (start < block_group->start + block_group->length) {
1228 if (extent_start >= block_group->start + block_group->length)
1232 extent_end = min(block_group->start + block_group->length,
1297 struct btrfs_block_group *block_group,
1319 if (block_group)
1322 block_group->start, ret);
1326 if (block_group) {
1331 spin_lock(&block_group->lock);
1338 if (!ret && list_empty(&block_group->dirty_list))
1339 block_group->disk_cache_state = BTRFS_DC_WRITTEN;
1341 block_group->disk_cache_state = BTRFS_DC_ERROR;
1343 spin_unlock(&block_group->lock);
1354 struct btrfs_block_group *block_group,
1357 return __btrfs_wait_cache_io(block_group->fs_info->tree_root, trans,
1358 block_group, &block_group->io_ctl,
1359 path, block_group->start);
1368 * @block_group: block_group for this cache if it belongs to a block_group
1378 struct btrfs_block_group *block_group,
1397 if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA)) {
1398 down_write(&block_group->data_rwsem);
1399 spin_lock(&block_group->lock);
1400 if (block_group->delalloc_bytes) {
1401 block_group->disk_cache_state = BTRFS_DC_WRITTEN;
1402 spin_unlock(&block_group->lock);
1403 up_write(&block_group->data_rwsem);
1409 spin_unlock(&block_group->lock);
1426 block_group, &entries, &bitmaps,
1439 ret = write_pinned_extent_entries(trans, block_group, io_ctl, &entries);
1464 if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA))
1465 up_write(&block_group->data_rwsem);
1499 if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA))
1500 up_write(&block_group->data_rwsem);
1516 struct btrfs_block_group *block_group,
1520 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
1524 spin_lock(&block_group->lock);
1525 if (block_group->disk_cache_state < BTRFS_DC_SETUP) {
1526 spin_unlock(&block_group->lock);
1529 spin_unlock(&block_group->lock);
1531 inode = lookup_free_space_inode(block_group, path);
1536 block_group, &block_group->io_ctl, trans);
1540 block_group->start, ret);
1541 spin_lock(&block_group->lock);
1542 block_group->disk_cache_state = BTRFS_DC_ERROR;
1543 spin_unlock(&block_group->lock);
1545 block_group->io_ctl.inode = NULL;
2259 struct btrfs_block_group *block_group = ctl->block_group;
2260 struct btrfs_fs_info *fs_info = block_group->fs_info;
2264 if (btrfs_should_fragment_free_space(block_group))
2300 if (((BITS_PER_BITMAP * ctl->unit) >> 1) > block_group->length)
2314 struct btrfs_block_group *block_group = NULL;
2328 block_group = ctl->block_group;
2335 if (block_group && !list_empty(&block_group->cluster_list)) {
2340 cluster = list_entry(block_group->cluster_list.next,
2620 int __btrfs_add_free_space(struct btrfs_block_group *block_group,
2624 struct btrfs_fs_info *fs_info = block_group->fs_info;
2625 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
2674 btrfs_discard_update_discardable(block_group);
2683 btrfs_discard_check_filter(block_group, filter_bytes);
2684 btrfs_discard_queue_work(&fs_info->discard_ctl, block_group);
2690 static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group,
2693 struct btrfs_space_info *sinfo = block_group->space_info;
2694 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
2695 u64 offset = bytenr - block_group->start;
2698 bool initial = (size == block_group->length);
2701 WARN_ON(!initial && offset + size > block_group->zone_capacity);
2710 to_free = block_group->zone_capacity;
2711 else if (offset >= block_group->alloc_offset)
2713 else if (offset + size <= block_group->alloc_offset)
2716 to_free = offset + size - block_group->alloc_offset;
2724 if (!block_group->ro)
2725 block_group->zone_unusable += to_unusable;
2728 spin_lock(&block_group->lock);
2729 block_group->alloc_offset -= size;
2730 spin_unlock(&block_group->lock);
2733 reclaimable_unusable = block_group->zone_unusable -
2734 (block_group->length - block_group->zone_capacity);
2736 if (block_group->zone_unusable == block_group->length) {
2737 btrfs_mark_bg_unused(block_group);
2740 mult_perc(block_group->zone_capacity, bg_reclaim_threshold)) {
2741 btrfs_mark_bg_to_reclaim(block_group);
2747 int btrfs_add_free_space(struct btrfs_block_group *block_group,
2752 if (btrfs_is_zoned(block_group->fs_info))
2753 return __btrfs_add_free_space_zoned(block_group, bytenr, size,
2756 if (btrfs_test_opt(block_group->fs_info, DISCARD_SYNC))
2759 return __btrfs_add_free_space(block_group, bytenr, size, trim_state);
2762 int btrfs_add_free_space_unused(struct btrfs_block_group *block_group,
2765 if (btrfs_is_zoned(block_group->fs_info))
2766 return __btrfs_add_free_space_zoned(block_group, bytenr, size,
2769 return btrfs_add_free_space(block_group, bytenr, size);
2777 int btrfs_add_free_space_async_trimmed(struct btrfs_block_group *block_group,
2782 if (btrfs_is_zoned(block_group->fs_info))
2783 return __btrfs_add_free_space_zoned(block_group, bytenr, size,
2786 if (btrfs_test_opt(block_group->fs_info, DISCARD_SYNC) ||
2787 btrfs_test_opt(block_group->fs_info, DISCARD_ASYNC))
2790 return __btrfs_add_free_space(block_group, bytenr, size, trim_state);
2793 int btrfs_remove_free_space(struct btrfs_block_group *block_group,
2796 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
2801 if (btrfs_is_zoned(block_group->fs_info)) {
2813 if (block_group->start + block_group->alloc_offset <
2815 block_group->alloc_offset =
2816 offset + bytes - block_group->start;
2885 ret = __btrfs_add_free_space(block_group,
2900 btrfs_discard_update_discardable(block_group);
2906 void btrfs_dump_free_space(struct btrfs_block_group *block_group,
2909 struct btrfs_fs_info *fs_info = block_group->fs_info;
2910 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
2921 block_group->zone_capacity - block_group->alloc_offset,
2923 &block_group->runtime_flags));
2930 if (info->bytes >= bytes && !block_group->ro)
2938 list_empty(&block_group->cluster_list) ? "no" : "yes");
2944 void btrfs_init_free_space_ctl(struct btrfs_block_group *block_group,
2947 struct btrfs_fs_info *fs_info = block_group->fs_info;
2951 ctl->start = block_group->start;
2952 ctl->block_group = block_group;
2973 struct btrfs_block_group *block_group,
2976 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
2982 if (cluster->block_group != block_group) {
2987 cluster->block_group = NULL;
3024 btrfs_put_block_group(block_group);
3027 void btrfs_remove_free_space_cache(struct btrfs_block_group *block_group)
3029 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
3034 while ((head = block_group->cluster_list.next) !=
3035 &block_group->cluster_list) {
3039 WARN_ON(cluster->block_group != block_group);
3040 __btrfs_return_cluster_to_free_space(block_group, cluster);
3045 btrfs_discard_update_discardable(block_group);
3051 * Walk @block_group's free space rb_tree to determine if everything is trimmed.
3053 bool btrfs_is_free_space_trimmed(struct btrfs_block_group *block_group)
3055 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
3078 u64 btrfs_find_space_for_alloc(struct btrfs_block_group *block_group,
3082 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
3084 &block_group->fs_info->discard_ctl;
3091 bool use_bytes_index = (offset == block_group->start);
3093 ASSERT(!btrfs_is_zoned(block_group->fs_info));
3097 block_group->full_stripe_len, max_extent_size,
3130 btrfs_discard_update_discardable(block_group);
3134 __btrfs_add_free_space(block_group, align_gap, align_gap_len,
3148 struct btrfs_block_group *block_group,
3155 if (!block_group) {
3156 block_group = cluster->block_group;
3157 if (!block_group) {
3161 } else if (cluster->block_group != block_group) {
3166 btrfs_get_block_group(block_group);
3169 ctl = block_group->free_space_ctl;
3173 __btrfs_return_cluster_to_free_space(block_group, cluster);
3176 btrfs_discard_queue_work(&block_group->fs_info->discard_ctl, block_group);
3179 btrfs_put_block_group(block_group);
3182 static u64 btrfs_alloc_from_bitmap(struct btrfs_block_group *block_group,
3188 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
3215 u64 btrfs_alloc_from_cluster(struct btrfs_block_group *block_group,
3219 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
3221 &block_group->fs_info->discard_ctl;
3226 ASSERT(!btrfs_is_zoned(block_group->fs_info));
3232 if (cluster->block_group != block_group)
3256 ret = btrfs_alloc_from_bitmap(block_group,
3314 static int btrfs_bitmap_cluster(struct btrfs_block_group *block_group,
3320 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
3397 trace_btrfs_setup_cluster(block_group, cluster,
3408 setup_cluster_no_bitmap(struct btrfs_block_group *block_group,
3413 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
3492 trace_btrfs_setup_cluster(block_group, cluster, total_size, 0);
3501 setup_cluster_bitmap(struct btrfs_block_group *block_group,
3506 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
3530 ret = btrfs_bitmap_cluster(block_group, entry, cluster, offset,
3551 int btrfs_find_space_cluster(struct btrfs_block_group *block_group,
3555 struct btrfs_fs_info *fs_info = block_group->fs_info;
3556 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
3572 } else if (block_group->flags & BTRFS_BLOCK_GROUP_METADATA) {
3594 if (cluster->block_group) {
3599 trace_btrfs_find_cluster(block_group, offset, bytes, empty_size,
3602 ret = setup_cluster_no_bitmap(block_group, cluster, &bitmaps, offset,
3606 ret = setup_cluster_bitmap(block_group, cluster, &bitmaps,
3615 btrfs_get_block_group(block_group);
3617 &block_group->cluster_list);
3618 cluster->block_group = block_group;
3620 trace_btrfs_failed_cluster_setup(block_group);
3640 cluster->block_group = NULL;
3643 static int do_trimming(struct btrfs_block_group *block_group,
3649 struct btrfs_space_info *space_info = block_group->space_info;
3650 struct btrfs_fs_info *fs_info = block_group->fs_info;
3651 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
3660 spin_lock(&block_group->lock);
3661 if (!block_group->ro) {
3662 block_group->reserved += reserved_bytes;
3666 spin_unlock(&block_group->lock);
3677 __btrfs_add_free_space(block_group, reserved_start,
3681 __btrfs_add_free_space(block_group, end, reserved_end - end,
3683 __btrfs_add_free_space(block_group, start, bytes, trim_state);
3689 spin_lock(&block_group->lock);
3690 if (block_group->ro)
3692 block_group->reserved -= reserved_bytes;
3694 spin_unlock(&block_group->lock);
3704 static int trim_no_bitmap(struct btrfs_block_group *block_group,
3709 &block_group->fs_info->discard_ctl;
3710 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
3793 ret = do_trimming(block_group, total_trimmed, start, bytes,
3797 block_group->discard_cursor = start + bytes;
3802 block_group->discard_cursor = start;
3817 block_group->discard_cursor = btrfs_block_group_end(block_group);
3870 static int trim_bitmaps(struct btrfs_block_group *block_group,
3875 &block_group->fs_info->discard_ctl;
3876 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
3892 block_group->discard_cursor =
3893 btrfs_block_group_end(block_group);
3980 ret = do_trimming(block_group, total_trimmed, start, bytes,
3984 block_group->discard_cursor =
3985 btrfs_block_group_end(block_group);
3995 block_group->discard_cursor = start;
4008 block_group->discard_cursor = end;
4014 int btrfs_trim_block_group(struct btrfs_block_group *block_group,
4017 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
4021 ASSERT(!btrfs_is_zoned(block_group->fs_info));
4025 spin_lock(&block_group->lock);
4026 if (test_bit(BLOCK_GROUP_FLAG_REMOVED, &block_group->runtime_flags)) {
4027 spin_unlock(&block_group->lock);
4030 btrfs_freeze_block_group(block_group);
4031 spin_unlock(&block_group->lock);
4033 ret = trim_no_bitmap(block_group, trimmed, start, end, minlen, false);
4037 ret = trim_bitmaps(block_group, trimmed, start, end, minlen, 0, false);
4043 btrfs_unfreeze_block_group(block_group);
4047 int btrfs_trim_block_group_extents(struct btrfs_block_group *block_group,
4055 spin_lock(&block_group->lock);
4056 if (test_bit(BLOCK_GROUP_FLAG_REMOVED, &block_group->runtime_flags)) {
4057 spin_unlock(&block_group->lock);
4060 btrfs_freeze_block_group(block_group);
4061 spin_unlock(&block_group->lock);
4063 ret = trim_no_bitmap(block_group, trimmed, start, end, minlen, async);
4064 btrfs_unfreeze_block_group(block_group);
4069 int btrfs_trim_block_group_bitmaps(struct btrfs_block_group *block_group,
4077 spin_lock(&block_group->lock);
4078 if (test_bit(BLOCK_GROUP_FLAG_REMOVED, &block_group->runtime_flags)) {
4079 spin_unlock(&block_group->lock);
4082 btrfs_freeze_block_group(block_group);
4083 spin_unlock(&block_group->lock);
4085 ret = trim_bitmaps(block_group, trimmed, start, end, minlen, maxlen,
4088 btrfs_unfreeze_block_group(block_group);
4101 struct btrfs_block_group *block_group;
4109 block_group = rb_entry(node, struct btrfs_block_group, cache_node);
4110 ret = btrfs_remove_free_space_inode(trans, NULL, block_group);