Lines Matching refs:block_group
98 struct inode *lookup_free_space_inode(struct btrfs_block_group *block_group,
101 struct btrfs_fs_info *fs_info = block_group->fs_info;
105 spin_lock(&block_group->lock);
106 if (block_group->inode)
107 inode = igrab(block_group->inode);
108 spin_unlock(&block_group->lock);
113 block_group->start);
117 spin_lock(&block_group->lock);
122 block_group->disk_cache_state = BTRFS_DC_CLEAR;
125 if (!block_group->iref) {
126 block_group->inode = igrab(inode);
127 block_group->iref = 1;
129 spin_unlock(&block_group->lock);
196 struct btrfs_block_group *block_group,
207 ino, block_group->start);
230 struct btrfs_block_group *block_group,
237 if (block_group) {
246 if (!list_empty(&block_group->io_list)) {
247 list_del_init(&block_group->io_list);
249 btrfs_wait_cache_io(trans, block_group, path);
250 btrfs_put_block_group(block_group);
257 spin_lock(&block_group->lock);
258 block_group->disk_cache_state = BTRFS_DC_CLEAR;
259 spin_unlock(&block_group->lock);
845 int load_free_space_cache(struct btrfs_block_group *block_group)
847 struct btrfs_fs_info *fs_info = block_group->fs_info;
848 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
853 u64 used = block_group->used;
859 spin_lock(&block_group->lock);
860 if (block_group->disk_cache_state != BTRFS_DC_WRITTEN) {
861 spin_unlock(&block_group->lock);
864 spin_unlock(&block_group->lock);
891 inode = lookup_free_space_inode(block_group, path);
898 spin_lock(&block_group->lock);
899 if (block_group->disk_cache_state != BTRFS_DC_WRITTEN) {
900 spin_unlock(&block_group->lock);
904 spin_unlock(&block_group->lock);
907 path, block_group->start);
913 matched = (ctl->free_space == (block_group->length - used -
914 block_group->bytes_super));
921 block_group->start);
927 spin_lock(&block_group->lock);
928 block_group->disk_cache_state = BTRFS_DC_CLEAR;
929 spin_unlock(&block_group->lock);
934 block_group->start);
944 struct btrfs_block_group *block_group,
954 /* Get the cluster for this block_group if it exists */
955 if (block_group && !list_empty(&block_group->cluster_list)) {
956 cluster = list_entry(block_group->cluster_list.next,
1073 struct btrfs_block_group *block_group,
1081 if (!block_group)
1093 start = block_group->start;
1095 while (start < block_group->start + block_group->length) {
1103 if (extent_start >= block_group->start + block_group->length)
1107 extent_end = min(block_group->start + block_group->length,
1172 struct btrfs_block_group *block_group,
1194 if (block_group)
1197 block_group->start, ret);
1201 if (block_group) {
1206 spin_lock(&block_group->lock);
1213 if (!ret && list_empty(&block_group->dirty_list))
1214 block_group->disk_cache_state = BTRFS_DC_WRITTEN;
1216 block_group->disk_cache_state = BTRFS_DC_ERROR;
1218 spin_unlock(&block_group->lock);
1237 struct btrfs_block_group *block_group,
1240 return __btrfs_wait_cache_io(block_group->fs_info->tree_root, trans,
1241 block_group, &block_group->io_ctl,
1242 path, block_group->start);
1249 * @block_group - the block_group for this cache if it belongs to a block_group
1258 struct btrfs_block_group *block_group,
1277 if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA)) {
1278 down_write(&block_group->data_rwsem);
1279 spin_lock(&block_group->lock);
1280 if (block_group->delalloc_bytes) {
1281 block_group->disk_cache_state = BTRFS_DC_WRITTEN;
1282 spin_unlock(&block_group->lock);
1283 up_write(&block_group->data_rwsem);
1289 spin_unlock(&block_group->lock);
1306 block_group, &entries, &bitmaps,
1319 ret = write_pinned_extent_entries(trans, block_group, io_ctl, &entries);
1344 if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA))
1345 up_write(&block_group->data_rwsem);
1379 if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA))
1380 up_write(&block_group->data_rwsem);
1396 struct btrfs_block_group *block_group,
1400 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
1404 spin_lock(&block_group->lock);
1405 if (block_group->disk_cache_state < BTRFS_DC_SETUP) {
1406 spin_unlock(&block_group->lock);
1409 spin_unlock(&block_group->lock);
1411 inode = lookup_free_space_inode(block_group, path);
1416 block_group, &block_group->io_ctl, trans);
1420 block_group->start, ret);
1421 spin_lock(&block_group->lock);
1422 block_group->disk_cache_state = BTRFS_DC_ERROR;
1423 spin_unlock(&block_group->lock);
1425 block_group->io_ctl.inode = NULL;
1682 struct btrfs_block_group *block_group = ctl->private;
1686 u64 size = block_group->length;
1923 struct btrfs_block_group *block_group = ctl->private;
1928 if (!block_group || !bytes)
2094 struct btrfs_block_group *block_group = ctl->private;
2095 struct btrfs_fs_info *fs_info = block_group->fs_info;
2099 if (btrfs_should_fragment_free_space(block_group))
2135 if (((BITS_PER_BITMAP * ctl->unit) >> 1) > block_group->length)
2150 struct btrfs_block_group *block_group = NULL;
2164 block_group = ctl->private;
2171 if (block_group && !list_empty(&block_group->cluster_list)) {
2176 cluster = list_entry(block_group->cluster_list.next,
2470 struct btrfs_block_group *block_group = ctl->private;
2516 btrfs_discard_update_discardable(block_group, ctl);
2525 btrfs_discard_check_filter(block_group, filter_bytes);
2526 btrfs_discard_queue_work(&fs_info->discard_ctl, block_group);
2532 int btrfs_add_free_space(struct btrfs_block_group *block_group,
2537 if (btrfs_test_opt(block_group->fs_info, DISCARD_SYNC))
2540 return __btrfs_add_free_space(block_group->fs_info,
2541 block_group->free_space_ctl,
2550 int btrfs_add_free_space_async_trimmed(struct btrfs_block_group *block_group,
2555 if (btrfs_test_opt(block_group->fs_info, DISCARD_SYNC) ||
2556 btrfs_test_opt(block_group->fs_info, DISCARD_ASYNC))
2559 return __btrfs_add_free_space(block_group->fs_info,
2560 block_group->free_space_ctl,
2564 int btrfs_remove_free_space(struct btrfs_block_group *block_group,
2567 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
2636 ret = __btrfs_add_free_space(block_group->fs_info, ctl,
2651 btrfs_discard_update_discardable(block_group, ctl);
2657 void btrfs_dump_free_space(struct btrfs_block_group *block_group,
2660 struct btrfs_fs_info *fs_info = block_group->fs_info;
2661 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
2669 if (info->bytes >= bytes && !block_group->ro)
2677 list_empty(&block_group->cluster_list) ? "no" : "yes");
2682 void btrfs_init_free_space_ctl(struct btrfs_block_group *block_group)
2684 struct btrfs_fs_info *fs_info = block_group->fs_info;
2685 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
2689 ctl->start = block_group->start;
2690 ctl->private = block_group;
2710 struct btrfs_block_group *block_group,
2713 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
2718 if (cluster->block_group != block_group) {
2723 cluster->block_group = NULL;
2760 btrfs_put_block_group(block_group);
2791 void btrfs_remove_free_space_cache(struct btrfs_block_group *block_group)
2793 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
2798 while ((head = block_group->cluster_list.next) !=
2799 &block_group->cluster_list) {
2803 WARN_ON(cluster->block_group != block_group);
2804 __btrfs_return_cluster_to_free_space(block_group, cluster);
2809 btrfs_discard_update_discardable(block_group, ctl);
2816 * @block_group: block_group of interest
2818 * Walk @block_group's free space rb_tree to determine if everything is trimmed.
2820 bool btrfs_is_free_space_trimmed(struct btrfs_block_group *block_group)
2822 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
2845 u64 btrfs_find_space_for_alloc(struct btrfs_block_group *block_group,
2849 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
2851 &block_group->fs_info->discard_ctl;
2861 block_group->full_stripe_len, max_extent_size);
2893 btrfs_discard_update_discardable(block_group, ctl);
2897 __btrfs_add_free_space(block_group->fs_info, ctl,
2912 struct btrfs_block_group *block_group,
2919 if (!block_group) {
2920 block_group = cluster->block_group;
2921 if (!block_group) {
2925 } else if (cluster->block_group != block_group) {
2930 btrfs_get_block_group(block_group);
2933 ctl = block_group->free_space_ctl;
2937 __btrfs_return_cluster_to_free_space(block_group, cluster);
2940 btrfs_discard_queue_work(&block_group->fs_info->discard_ctl, block_group);
2943 btrfs_put_block_group(block_group);
2946 static u64 btrfs_alloc_from_bitmap(struct btrfs_block_group *block_group,
2952 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
2979 u64 btrfs_alloc_from_cluster(struct btrfs_block_group *block_group,
2983 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
2985 &block_group->fs_info->discard_ctl;
2994 if (cluster->block_group != block_group)
3018 ret = btrfs_alloc_from_bitmap(block_group,
3076 static int btrfs_bitmap_cluster(struct btrfs_block_group *block_group,
3082 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
3147 trace_btrfs_setup_cluster(block_group, cluster,
3158 setup_cluster_no_bitmap(struct btrfs_block_group *block_group,
3163 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
3240 trace_btrfs_setup_cluster(block_group, cluster, total_size, 0);
3249 setup_cluster_bitmap(struct btrfs_block_group *block_group,
3254 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
3278 ret = btrfs_bitmap_cluster(block_group, entry, cluster, offset,
3299 int btrfs_find_space_cluster(struct btrfs_block_group *block_group,
3303 struct btrfs_fs_info *fs_info = block_group->fs_info;
3304 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
3319 } else if (block_group->flags & BTRFS_BLOCK_GROUP_METADATA) {
3341 if (cluster->block_group) {
3346 trace_btrfs_find_cluster(block_group, offset, bytes, empty_size,
3349 ret = setup_cluster_no_bitmap(block_group, cluster, &bitmaps, offset,
3353 ret = setup_cluster_bitmap(block_group, cluster, &bitmaps,
3362 btrfs_get_block_group(block_group);
3364 &block_group->cluster_list);
3365 cluster->block_group = block_group;
3367 trace_btrfs_failed_cluster_setup(block_group);
3387 cluster->block_group = NULL;
3390 static int do_trimming(struct btrfs_block_group *block_group,
3396 struct btrfs_space_info *space_info = block_group->space_info;
3397 struct btrfs_fs_info *fs_info = block_group->fs_info;
3398 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
3407 spin_lock(&block_group->lock);
3408 if (!block_group->ro) {
3409 block_group->reserved += reserved_bytes;
3413 spin_unlock(&block_group->lock);
3436 spin_lock(&block_group->lock);
3437 if (block_group->ro)
3439 block_group->reserved -= reserved_bytes;
3441 spin_unlock(&block_group->lock);
3451 static int trim_no_bitmap(struct btrfs_block_group *block_group,
3456 &block_group->fs_info->discard_ctl;
3457 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
3540 ret = do_trimming(block_group, total_trimmed, start, bytes,
3544 block_group->discard_cursor = start + bytes;
3549 block_group->discard_cursor = start;
3564 block_group->discard_cursor = btrfs_block_group_end(block_group);
3617 static int trim_bitmaps(struct btrfs_block_group *block_group,
3622 &block_group->fs_info->discard_ctl;
3623 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
3639 block_group->discard_cursor =
3640 btrfs_block_group_end(block_group);
3727 ret = do_trimming(block_group, total_trimmed, start, bytes,
3731 block_group->discard_cursor =
3732 btrfs_block_group_end(block_group);
3742 block_group->discard_cursor = start;
3755 block_group->discard_cursor = end;
3761 int btrfs_trim_block_group(struct btrfs_block_group *block_group,
3764 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
3770 spin_lock(&block_group->lock);
3771 if (block_group->removed) {
3772 spin_unlock(&block_group->lock);
3775 btrfs_freeze_block_group(block_group);
3776 spin_unlock(&block_group->lock);
3778 ret = trim_no_bitmap(block_group, trimmed, start, end, minlen, false);
3782 ret = trim_bitmaps(block_group, trimmed, start, end, minlen, 0, false);
3788 btrfs_unfreeze_block_group(block_group);
3792 int btrfs_trim_block_group_extents(struct btrfs_block_group *block_group,
3800 spin_lock(&block_group->lock);
3801 if (block_group->removed) {
3802 spin_unlock(&block_group->lock);
3805 btrfs_freeze_block_group(block_group);
3806 spin_unlock(&block_group->lock);
3808 ret = trim_no_bitmap(block_group, trimmed, start, end, minlen, async);
3809 btrfs_unfreeze_block_group(block_group);
3814 int btrfs_trim_block_group_bitmaps(struct btrfs_block_group *block_group,
3822 spin_lock(&block_group->lock);
3823 if (block_group->removed) {
3824 spin_unlock(&block_group->lock);
3827 btrfs_freeze_block_group(block_group);
3828 spin_unlock(&block_group->lock);
3830 ret = trim_bitmaps(block_group, trimmed, start, end, minlen, maxlen,
3833 btrfs_unfreeze_block_group(block_group);