Lines Matching refs:cache

118 void btrfs_get_block_group(struct btrfs_block_group *cache)  in btrfs_get_block_group()  argument
120 refcount_inc(&cache->refs); in btrfs_get_block_group()
123 void btrfs_put_block_group(struct btrfs_block_group *cache) in btrfs_put_block_group() argument
125 if (refcount_dec_and_test(&cache->refs)) { in btrfs_put_block_group()
126 WARN_ON(cache->pinned > 0); in btrfs_put_block_group()
134 if (!(cache->flags & BTRFS_BLOCK_GROUP_METADATA) || in btrfs_put_block_group()
135 !BTRFS_FS_LOG_CLEANUP_ERROR(cache->fs_info)) in btrfs_put_block_group()
136 WARN_ON(cache->reserved > 0); in btrfs_put_block_group()
143 if (WARN_ON(!list_empty(&cache->discard_list))) in btrfs_put_block_group()
144 btrfs_discard_cancel_work(&cache->fs_info->discard_ctl, in btrfs_put_block_group()
145 cache); in btrfs_put_block_group()
155 WARN_ON(!RB_EMPTY_ROOT(&cache->full_stripe_locks_root.root)); in btrfs_put_block_group()
156 kfree(cache->free_space_ctl); in btrfs_put_block_group()
157 kfree(cache->physical_map); in btrfs_put_block_group()
158 kfree(cache); in btrfs_put_block_group()
170 struct btrfs_block_group *cache; in btrfs_add_block_group_cache() local
180 cache = rb_entry(parent, struct btrfs_block_group, cache_node); in btrfs_add_block_group_cache()
181 if (block_group->start < cache->start) { in btrfs_add_block_group_cache()
183 } else if (block_group->start > cache->start) { in btrfs_add_block_group_cache()
208 struct btrfs_block_group *cache, *ret = NULL; in block_group_cache_tree_search() local
216 cache = rb_entry(n, struct btrfs_block_group, cache_node); in block_group_cache_tree_search()
217 end = cache->start + cache->length - 1; in block_group_cache_tree_search()
218 start = cache->start; in block_group_cache_tree_search()
222 ret = cache; in block_group_cache_tree_search()
226 ret = cache; in block_group_cache_tree_search()
231 ret = cache; in block_group_cache_tree_search()
261 struct btrfs_block_group *cache) in btrfs_next_block_group() argument
263 struct btrfs_fs_info *fs_info = cache->fs_info; in btrfs_next_block_group()
269 if (RB_EMPTY_NODE(&cache->cache_node)) { in btrfs_next_block_group()
270 const u64 next_bytenr = cache->start + cache->length; in btrfs_next_block_group()
273 btrfs_put_block_group(cache); in btrfs_next_block_group()
276 node = rb_next(&cache->cache_node); in btrfs_next_block_group()
277 btrfs_put_block_group(cache); in btrfs_next_block_group()
279 cache = rb_entry(node, struct btrfs_block_group, cache_node); in btrfs_next_block_group()
280 btrfs_get_block_group(cache); in btrfs_next_block_group()
282 cache = NULL; in btrfs_next_block_group()
284 return cache; in btrfs_next_block_group()
393 struct btrfs_block_group *cache) in btrfs_get_caching_control() argument
397 spin_lock(&cache->lock); in btrfs_get_caching_control()
398 if (!cache->caching_ctl) { in btrfs_get_caching_control()
399 spin_unlock(&cache->lock); in btrfs_get_caching_control()
403 ctl = cache->caching_ctl; in btrfs_get_caching_control()
405 spin_unlock(&cache->lock); in btrfs_get_caching_control()
428 void btrfs_wait_block_group_cache_progress(struct btrfs_block_group *cache, in btrfs_wait_block_group_cache_progress() argument
433 caching_ctl = btrfs_get_caching_control(cache); in btrfs_wait_block_group_cache_progress()
437 wait_event(caching_ctl->wait, btrfs_block_group_done(cache) || in btrfs_wait_block_group_cache_progress()
438 (cache->free_space_ctl->free_space >= num_bytes)); in btrfs_wait_block_group_cache_progress()
443 static int btrfs_caching_ctl_wait_done(struct btrfs_block_group *cache, in btrfs_caching_ctl_wait_done() argument
446 wait_event(caching_ctl->wait, btrfs_block_group_done(cache)); in btrfs_caching_ctl_wait_done()
447 return cache->cached == BTRFS_CACHE_ERROR ? -EIO : 0; in btrfs_caching_ctl_wait_done()
450 static int btrfs_wait_block_group_cache_done(struct btrfs_block_group *cache) in btrfs_wait_block_group_cache_done() argument
455 caching_ctl = btrfs_get_caching_control(cache); in btrfs_wait_block_group_cache_done()
457 return (cache->cached == BTRFS_CACHE_ERROR) ? -EIO : 0; in btrfs_wait_block_group_cache_done()
458 ret = btrfs_caching_ctl_wait_done(cache, caching_ctl); in btrfs_wait_block_group_cache_done()
732 int btrfs_cache_block_group(struct btrfs_block_group *cache, bool wait) in btrfs_cache_block_group() argument
734 struct btrfs_fs_info *fs_info = cache->fs_info; in btrfs_cache_block_group()
749 caching_ctl->block_group = cache; in btrfs_cache_block_group()
753 spin_lock(&cache->lock); in btrfs_cache_block_group()
754 if (cache->cached != BTRFS_CACHE_NO) { in btrfs_cache_block_group()
757 caching_ctl = cache->caching_ctl; in btrfs_cache_block_group()
760 spin_unlock(&cache->lock); in btrfs_cache_block_group()
763 WARN_ON(cache->caching_ctl); in btrfs_cache_block_group()
764 cache->caching_ctl = caching_ctl; in btrfs_cache_block_group()
765 cache->cached = BTRFS_CACHE_STARTED; in btrfs_cache_block_group()
766 spin_unlock(&cache->lock); in btrfs_cache_block_group()
773 btrfs_get_block_group(cache); in btrfs_cache_block_group()
778 ret = btrfs_caching_ctl_wait_done(cache, caching_ctl); in btrfs_cache_block_group()
1166 static int inc_block_group_ro(struct btrfs_block_group *cache, int force) in inc_block_group_ro() argument
1168 struct btrfs_space_info *sinfo = cache->space_info; in inc_block_group_ro()
1173 spin_lock(&cache->lock); in inc_block_group_ro()
1175 if (cache->swap_extents) { in inc_block_group_ro()
1180 if (cache->ro) { in inc_block_group_ro()
1181 cache->ro++; in inc_block_group_ro()
1186 num_bytes = cache->length - cache->reserved - cache->pinned - in inc_block_group_ro()
1187 cache->bytes_super - cache->zone_unusable - cache->used; in inc_block_group_ro()
1211 if (btrfs_can_overcommit(cache->fs_info, sinfo, num_bytes, in inc_block_group_ro()
1218 if (btrfs_is_zoned(cache->fs_info)) { in inc_block_group_ro()
1220 sinfo->bytes_readonly += cache->zone_unusable; in inc_block_group_ro()
1221 sinfo->bytes_zone_unusable -= cache->zone_unusable; in inc_block_group_ro()
1222 cache->zone_unusable = 0; in inc_block_group_ro()
1224 cache->ro++; in inc_block_group_ro()
1225 list_add_tail(&cache->ro_list, &sinfo->ro_bgs); in inc_block_group_ro()
1228 spin_unlock(&cache->lock); in inc_block_group_ro()
1230 if (ret == -ENOSPC && btrfs_test_opt(cache->fs_info, ENOSPC_DEBUG)) { in inc_block_group_ro()
1231 btrfs_info(cache->fs_info, in inc_block_group_ro()
1232 "unable to make block group %llu ro", cache->start); in inc_block_group_ro()
1233 btrfs_dump_space_info(cache->fs_info, cache->space_info, 0, 0); in inc_block_group_ro()
1839 static int exclude_super_stripes(struct btrfs_block_group *cache) in exclude_super_stripes() argument
1841 struct btrfs_fs_info *fs_info = cache->fs_info; in exclude_super_stripes()
1848 if (cache->start < BTRFS_SUPER_INFO_OFFSET) { in exclude_super_stripes()
1849 stripe_len = BTRFS_SUPER_INFO_OFFSET - cache->start; in exclude_super_stripes()
1850 cache->bytes_super += stripe_len; in exclude_super_stripes()
1851 ret = btrfs_add_excluded_extent(fs_info, cache->start, in exclude_super_stripes()
1859 ret = btrfs_rmap_block(fs_info, cache->start, NULL, in exclude_super_stripes()
1868 cache->start); in exclude_super_stripes()
1874 cache->start + cache->length - logical[nr]); in exclude_super_stripes()
1876 cache->bytes_super += len; in exclude_super_stripes()
1893 struct btrfs_block_group *cache; in btrfs_create_block_group_cache() local
1895 cache = kzalloc(sizeof(*cache), GFP_NOFS); in btrfs_create_block_group_cache()
1896 if (!cache) in btrfs_create_block_group_cache()
1899 cache->free_space_ctl = kzalloc(sizeof(*cache->free_space_ctl), in btrfs_create_block_group_cache()
1901 if (!cache->free_space_ctl) { in btrfs_create_block_group_cache()
1902 kfree(cache); in btrfs_create_block_group_cache()
1906 cache->start = start; in btrfs_create_block_group_cache()
1908 cache->fs_info = fs_info; in btrfs_create_block_group_cache()
1909 cache->full_stripe_len = btrfs_full_stripe_len(fs_info, start); in btrfs_create_block_group_cache()
1911 cache->discard_index = BTRFS_DISCARD_INDEX_UNUSED; in btrfs_create_block_group_cache()
1913 refcount_set(&cache->refs, 1); in btrfs_create_block_group_cache()
1914 spin_lock_init(&cache->lock); in btrfs_create_block_group_cache()
1915 init_rwsem(&cache->data_rwsem); in btrfs_create_block_group_cache()
1916 INIT_LIST_HEAD(&cache->list); in btrfs_create_block_group_cache()
1917 INIT_LIST_HEAD(&cache->cluster_list); in btrfs_create_block_group_cache()
1918 INIT_LIST_HEAD(&cache->bg_list); in btrfs_create_block_group_cache()
1919 INIT_LIST_HEAD(&cache->ro_list); in btrfs_create_block_group_cache()
1920 INIT_LIST_HEAD(&cache->discard_list); in btrfs_create_block_group_cache()
1921 INIT_LIST_HEAD(&cache->dirty_list); in btrfs_create_block_group_cache()
1922 INIT_LIST_HEAD(&cache->io_list); in btrfs_create_block_group_cache()
1923 INIT_LIST_HEAD(&cache->active_bg_list); in btrfs_create_block_group_cache()
1924 btrfs_init_free_space_ctl(cache, cache->free_space_ctl); in btrfs_create_block_group_cache()
1925 atomic_set(&cache->frozen, 0); in btrfs_create_block_group_cache()
1926 mutex_init(&cache->free_space_lock); in btrfs_create_block_group_cache()
1927 cache->full_stripe_locks_root.root = RB_ROOT; in btrfs_create_block_group_cache()
1928 mutex_init(&cache->full_stripe_locks_root.lock); in btrfs_create_block_group_cache()
1930 return cache; in btrfs_create_block_group_cache()
1992 struct btrfs_block_group *cache; in read_one_block_group() local
1998 cache = btrfs_create_block_group_cache(info, key->objectid); in read_one_block_group()
1999 if (!cache) in read_one_block_group()
2002 cache->length = key->offset; in read_one_block_group()
2003 cache->used = btrfs_stack_block_group_used(bgi); in read_one_block_group()
2004 cache->flags = btrfs_stack_block_group_flags(bgi); in read_one_block_group()
2005 cache->global_root_id = btrfs_stack_block_group_chunk_objectid(bgi); in read_one_block_group()
2007 set_free_space_tree_thresholds(cache); in read_one_block_group()
2021 cache->disk_cache_state = BTRFS_DC_CLEAR; in read_one_block_group()
2023 if (!mixed && ((cache->flags & BTRFS_BLOCK_GROUP_METADATA) && in read_one_block_group()
2024 (cache->flags & BTRFS_BLOCK_GROUP_DATA))) { in read_one_block_group()
2027 cache->start); in read_one_block_group()
2032 ret = btrfs_load_block_group_zone_info(cache, false); in read_one_block_group()
2035 cache->start); in read_one_block_group()
2044 ret = exclude_super_stripes(cache); in read_one_block_group()
2047 btrfs_free_excluded_extents(cache); in read_one_block_group()
2064 btrfs_calc_zone_unusable(cache); in read_one_block_group()
2066 btrfs_free_excluded_extents(cache); in read_one_block_group()
2067 } else if (cache->length == cache->used) { in read_one_block_group()
2068 cache->cached = BTRFS_CACHE_FINISHED; in read_one_block_group()
2069 btrfs_free_excluded_extents(cache); in read_one_block_group()
2070 } else if (cache->used == 0) { in read_one_block_group()
2071 cache->cached = BTRFS_CACHE_FINISHED; in read_one_block_group()
2072 add_new_free_space(cache, cache->start, in read_one_block_group()
2073 cache->start + cache->length); in read_one_block_group()
2074 btrfs_free_excluded_extents(cache); in read_one_block_group()
2077 ret = btrfs_add_block_group_cache(info, cache); in read_one_block_group()
2079 btrfs_remove_free_space_cache(cache); in read_one_block_group()
2082 trace_btrfs_add_block_group(info, cache, 0); in read_one_block_group()
2083 btrfs_add_bg_to_space_info(info, cache); in read_one_block_group()
2085 set_avail_alloc_bits(info, cache->flags); in read_one_block_group()
2086 if (btrfs_chunk_writeable(info, cache->start)) { in read_one_block_group()
2087 if (cache->used == 0) { in read_one_block_group()
2088 ASSERT(list_empty(&cache->bg_list)); in read_one_block_group()
2090 btrfs_discard_queue_work(&info->discard_ctl, cache); in read_one_block_group()
2092 btrfs_mark_bg_unused(cache); in read_one_block_group()
2095 inc_block_group_ro(cache, 1); in read_one_block_group()
2100 btrfs_put_block_group(cache); in read_one_block_group()
2160 struct btrfs_block_group *cache; in btrfs_read_block_groups() local
2225 cache = list_first_entry(&space_info->block_groups[i], in btrfs_read_block_groups()
2228 btrfs_sysfs_add_block_group_type(cache); in btrfs_read_block_groups()
2241 list_for_each_entry(cache, in btrfs_read_block_groups()
2244 inc_block_group_ro(cache, 1); in btrfs_read_block_groups()
2245 list_for_each_entry(cache, in btrfs_read_block_groups()
2248 inc_block_group_ro(cache, 1); in btrfs_read_block_groups()
2467 struct btrfs_block_group *cache; in btrfs_make_block_group() local
2472 cache = btrfs_create_block_group_cache(fs_info, chunk_offset); in btrfs_make_block_group()
2473 if (!cache) in btrfs_make_block_group()
2476 cache->length = size; in btrfs_make_block_group()
2477 set_free_space_tree_thresholds(cache); in btrfs_make_block_group()
2478 cache->used = bytes_used; in btrfs_make_block_group()
2479 cache->flags = type; in btrfs_make_block_group()
2480 cache->cached = BTRFS_CACHE_FINISHED; in btrfs_make_block_group()
2481 cache->global_root_id = calculate_global_root_id(fs_info, cache->start); in btrfs_make_block_group()
2484 cache->needs_free_space = 1; in btrfs_make_block_group()
2486 ret = btrfs_load_block_group_zone_info(cache, true); in btrfs_make_block_group()
2488 btrfs_put_block_group(cache); in btrfs_make_block_group()
2492 ret = exclude_super_stripes(cache); in btrfs_make_block_group()
2495 btrfs_free_excluded_extents(cache); in btrfs_make_block_group()
2496 btrfs_put_block_group(cache); in btrfs_make_block_group()
2500 add_new_free_space(cache, chunk_offset, chunk_offset + size); in btrfs_make_block_group()
2502 btrfs_free_excluded_extents(cache); in btrfs_make_block_group()
2509 cache->space_info = btrfs_find_space_info(fs_info, cache->flags); in btrfs_make_block_group()
2510 ASSERT(cache->space_info); in btrfs_make_block_group()
2512 ret = btrfs_add_block_group_cache(fs_info, cache); in btrfs_make_block_group()
2514 btrfs_remove_free_space_cache(cache); in btrfs_make_block_group()
2515 btrfs_put_block_group(cache); in btrfs_make_block_group()
2523 trace_btrfs_add_block_group(fs_info, cache, 1); in btrfs_make_block_group()
2524 btrfs_add_bg_to_space_info(fs_info, cache); in btrfs_make_block_group()
2528 if (btrfs_should_fragment_free_space(cache)) { in btrfs_make_block_group()
2531 cache->space_info->bytes_used += new_bytes_used >> 1; in btrfs_make_block_group()
2532 fragment_free_space(cache); in btrfs_make_block_group()
2536 list_add_tail(&cache->bg_list, &trans->new_bgs); in btrfs_make_block_group()
2541 return cache; in btrfs_make_block_group()
2553 int btrfs_inc_block_group_ro(struct btrfs_block_group *cache, in btrfs_inc_block_group_ro() argument
2556 struct btrfs_fs_info *fs_info = cache->fs_info; in btrfs_inc_block_group_ro()
2571 ret = inc_block_group_ro(cache, 0); in btrfs_inc_block_group_ro()
2607 alloc_flags = btrfs_get_alloc_profile(fs_info, cache->flags); in btrfs_inc_block_group_ro()
2608 if (alloc_flags != cache->flags) { in btrfs_inc_block_group_ro()
2622 ret = inc_block_group_ro(cache, 0); in btrfs_inc_block_group_ro()
2627 alloc_flags = btrfs_get_alloc_profile(fs_info, cache->space_info->flags); in btrfs_inc_block_group_ro()
2635 ret = btrfs_zoned_activate_one_bg(fs_info, cache->space_info, true); in btrfs_inc_block_group_ro()
2639 ret = inc_block_group_ro(cache, 0); in btrfs_inc_block_group_ro()
2643 if (cache->flags & BTRFS_BLOCK_GROUP_SYSTEM) { in btrfs_inc_block_group_ro()
2644 alloc_flags = btrfs_get_alloc_profile(fs_info, cache->flags); in btrfs_inc_block_group_ro()
2656 void btrfs_dec_block_group_ro(struct btrfs_block_group *cache) in btrfs_dec_block_group_ro() argument
2658 struct btrfs_space_info *sinfo = cache->space_info; in btrfs_dec_block_group_ro()
2661 BUG_ON(!cache->ro); in btrfs_dec_block_group_ro()
2664 spin_lock(&cache->lock); in btrfs_dec_block_group_ro()
2665 if (!--cache->ro) { in btrfs_dec_block_group_ro()
2666 if (btrfs_is_zoned(cache->fs_info)) { in btrfs_dec_block_group_ro()
2668 cache->zone_unusable = in btrfs_dec_block_group_ro()
2669 (cache->alloc_offset - cache->used) + in btrfs_dec_block_group_ro()
2670 (cache->length - cache->zone_capacity); in btrfs_dec_block_group_ro()
2671 sinfo->bytes_zone_unusable += cache->zone_unusable; in btrfs_dec_block_group_ro()
2672 sinfo->bytes_readonly -= cache->zone_unusable; in btrfs_dec_block_group_ro()
2674 num_bytes = cache->length - cache->reserved - in btrfs_dec_block_group_ro()
2675 cache->pinned - cache->bytes_super - in btrfs_dec_block_group_ro()
2676 cache->zone_unusable - cache->used; in btrfs_dec_block_group_ro()
2678 list_del_init(&cache->ro_list); in btrfs_dec_block_group_ro()
2680 spin_unlock(&cache->lock); in btrfs_dec_block_group_ro()
2686 struct btrfs_block_group *cache) in update_block_group_item() argument
2696 key.objectid = cache->start; in update_block_group_item()
2698 key.offset = cache->length; in update_block_group_item()
2709 btrfs_set_stack_block_group_used(&bgi, cache->used); in update_block_group_item()
2711 cache->global_root_id); in update_block_group_item()
2712 btrfs_set_stack_block_group_flags(&bgi, cache->flags); in update_block_group_item()
2889 struct btrfs_block_group *cache, *tmp; in btrfs_setup_space_cache() local
2902 list_for_each_entry_safe(cache, tmp, &cur_trans->dirty_bgs, in btrfs_setup_space_cache()
2904 if (cache->disk_cache_state == BTRFS_DC_CLEAR) in btrfs_setup_space_cache()
2905 cache_save_setup(cache, trans, path); in btrfs_setup_space_cache()
2927 struct btrfs_block_group *cache; in btrfs_start_dirty_block_groups() local
2965 cache = list_first_entry(&dirty, struct btrfs_block_group, in btrfs_start_dirty_block_groups()
2972 if (!list_empty(&cache->io_list)) { in btrfs_start_dirty_block_groups()
2973 list_del_init(&cache->io_list); in btrfs_start_dirty_block_groups()
2974 btrfs_wait_cache_io(trans, cache, path); in btrfs_start_dirty_block_groups()
2975 btrfs_put_block_group(cache); in btrfs_start_dirty_block_groups()
2988 list_del_init(&cache->dirty_list); in btrfs_start_dirty_block_groups()
2993 cache_save_setup(cache, trans, path); in btrfs_start_dirty_block_groups()
2995 if (cache->disk_cache_state == BTRFS_DC_SETUP) { in btrfs_start_dirty_block_groups()
2996 cache->io_ctl.inode = NULL; in btrfs_start_dirty_block_groups()
2997 ret = btrfs_write_out_cache(trans, cache, path); in btrfs_start_dirty_block_groups()
2998 if (ret == 0 && cache->io_ctl.inode) { in btrfs_start_dirty_block_groups()
3006 list_add_tail(&cache->io_list, io); in btrfs_start_dirty_block_groups()
3016 ret = update_block_group_item(trans, path, cache); in btrfs_start_dirty_block_groups()
3029 if (list_empty(&cache->dirty_list)) { in btrfs_start_dirty_block_groups()
3030 list_add_tail(&cache->dirty_list, in btrfs_start_dirty_block_groups()
3032 btrfs_get_block_group(cache); in btrfs_start_dirty_block_groups()
3043 btrfs_put_block_group(cache); in btrfs_start_dirty_block_groups()
3093 struct btrfs_block_group *cache; in btrfs_write_dirty_block_groups() local
3121 cache = list_first_entry(&cur_trans->dirty_bgs, in btrfs_write_dirty_block_groups()
3130 if (!list_empty(&cache->io_list)) { in btrfs_write_dirty_block_groups()
3132 list_del_init(&cache->io_list); in btrfs_write_dirty_block_groups()
3133 btrfs_wait_cache_io(trans, cache, path); in btrfs_write_dirty_block_groups()
3134 btrfs_put_block_group(cache); in btrfs_write_dirty_block_groups()
3142 list_del_init(&cache->dirty_list); in btrfs_write_dirty_block_groups()
3146 cache_save_setup(cache, trans, path); in btrfs_write_dirty_block_groups()
3152 if (!ret && cache->disk_cache_state == BTRFS_DC_SETUP) { in btrfs_write_dirty_block_groups()
3153 cache->io_ctl.inode = NULL; in btrfs_write_dirty_block_groups()
3154 ret = btrfs_write_out_cache(trans, cache, path); in btrfs_write_dirty_block_groups()
3155 if (ret == 0 && cache->io_ctl.inode) { in btrfs_write_dirty_block_groups()
3157 list_add_tail(&cache->io_list, io); in btrfs_write_dirty_block_groups()
3167 ret = update_block_group_item(trans, path, cache); in btrfs_write_dirty_block_groups()
3184 ret = update_block_group_item(trans, path, cache); in btrfs_write_dirty_block_groups()
3192 btrfs_put_block_group(cache); in btrfs_write_dirty_block_groups()
3203 cache = list_first_entry(io, struct btrfs_block_group, in btrfs_write_dirty_block_groups()
3205 list_del_init(&cache->io_list); in btrfs_write_dirty_block_groups()
3206 btrfs_wait_cache_io(trans, cache, path); in btrfs_write_dirty_block_groups()
3207 btrfs_put_block_group(cache); in btrfs_write_dirty_block_groups()
3243 struct btrfs_block_group *cache = NULL; in btrfs_update_block_group() local
3263 cache = btrfs_lookup_block_group(info, bytenr); in btrfs_update_block_group()
3264 if (!cache) { in btrfs_update_block_group()
3268 factor = btrfs_bg_type_to_factor(cache->flags); in btrfs_update_block_group()
3276 if (!alloc && !btrfs_block_group_done(cache)) in btrfs_update_block_group()
3277 btrfs_cache_block_group(cache, true); in btrfs_update_block_group()
3279 byte_in_group = bytenr - cache->start; in btrfs_update_block_group()
3280 WARN_ON(byte_in_group > cache->length); in btrfs_update_block_group()
3282 spin_lock(&cache->space_info->lock); in btrfs_update_block_group()
3283 spin_lock(&cache->lock); in btrfs_update_block_group()
3286 cache->disk_cache_state < BTRFS_DC_CLEAR) in btrfs_update_block_group()
3287 cache->disk_cache_state = BTRFS_DC_CLEAR; in btrfs_update_block_group()
3289 old_val = cache->used; in btrfs_update_block_group()
3290 num_bytes = min(total, cache->length - byte_in_group); in btrfs_update_block_group()
3293 cache->used = old_val; in btrfs_update_block_group()
3294 cache->reserved -= num_bytes; in btrfs_update_block_group()
3295 cache->space_info->bytes_reserved -= num_bytes; in btrfs_update_block_group()
3296 cache->space_info->bytes_used += num_bytes; in btrfs_update_block_group()
3297 cache->space_info->disk_used += num_bytes * factor; in btrfs_update_block_group()
3298 spin_unlock(&cache->lock); in btrfs_update_block_group()
3299 spin_unlock(&cache->space_info->lock); in btrfs_update_block_group()
3302 cache->used = old_val; in btrfs_update_block_group()
3303 cache->pinned += num_bytes; in btrfs_update_block_group()
3305 cache->space_info, num_bytes); in btrfs_update_block_group()
3306 cache->space_info->bytes_used -= num_bytes; in btrfs_update_block_group()
3307 cache->space_info->disk_used -= num_bytes * factor; in btrfs_update_block_group()
3309 reclaim = should_reclaim_block_group(cache, num_bytes); in btrfs_update_block_group()
3310 spin_unlock(&cache->lock); in btrfs_update_block_group()
3311 spin_unlock(&cache->space_info->lock); in btrfs_update_block_group()
3319 if (list_empty(&cache->dirty_list)) { in btrfs_update_block_group()
3320 list_add_tail(&cache->dirty_list, in btrfs_update_block_group()
3323 btrfs_get_block_group(cache); in btrfs_update_block_group()
3335 btrfs_mark_bg_unused(cache); in btrfs_update_block_group()
3337 btrfs_mark_bg_to_reclaim(cache); in btrfs_update_block_group()
3340 btrfs_put_block_group(cache); in btrfs_update_block_group()
3362 int btrfs_add_reserved_bytes(struct btrfs_block_group *cache, in btrfs_add_reserved_bytes() argument
3365 struct btrfs_space_info *space_info = cache->space_info; in btrfs_add_reserved_bytes()
3369 spin_lock(&cache->lock); in btrfs_add_reserved_bytes()
3370 if (cache->ro) { in btrfs_add_reserved_bytes()
3373 cache->reserved += num_bytes; in btrfs_add_reserved_bytes()
3375 trace_btrfs_space_reservation(cache->fs_info, "space_info", in btrfs_add_reserved_bytes()
3377 btrfs_space_info_update_bytes_may_use(cache->fs_info, in btrfs_add_reserved_bytes()
3380 cache->delalloc_bytes += num_bytes; in btrfs_add_reserved_bytes()
3387 btrfs_try_granting_tickets(cache->fs_info, space_info); in btrfs_add_reserved_bytes()
3389 spin_unlock(&cache->lock); in btrfs_add_reserved_bytes()
3405 void btrfs_free_reserved_bytes(struct btrfs_block_group *cache, in btrfs_free_reserved_bytes() argument
3408 struct btrfs_space_info *space_info = cache->space_info; in btrfs_free_reserved_bytes()
3411 spin_lock(&cache->lock); in btrfs_free_reserved_bytes()
3412 if (cache->ro) in btrfs_free_reserved_bytes()
3414 cache->reserved -= num_bytes; in btrfs_free_reserved_bytes()
3419 cache->delalloc_bytes -= num_bytes; in btrfs_free_reserved_bytes()
3420 spin_unlock(&cache->lock); in btrfs_free_reserved_bytes()
3422 btrfs_try_granting_tickets(cache->fs_info, space_info); in btrfs_free_reserved_bytes()
4086 void btrfs_freeze_block_group(struct btrfs_block_group *cache) in btrfs_freeze_block_group() argument
4088 atomic_inc(&cache->frozen); in btrfs_freeze_block_group()