Lines Matching refs:cache

116 void btrfs_get_block_group(struct btrfs_block_group *cache)  in btrfs_get_block_group()  argument
118 refcount_inc(&cache->refs); in btrfs_get_block_group()
121 void btrfs_put_block_group(struct btrfs_block_group *cache) in btrfs_put_block_group() argument
123 if (refcount_dec_and_test(&cache->refs)) { in btrfs_put_block_group()
124 WARN_ON(cache->pinned > 0); in btrfs_put_block_group()
125 WARN_ON(cache->reserved > 0); in btrfs_put_block_group()
132 if (WARN_ON(!list_empty(&cache->discard_list))) in btrfs_put_block_group()
133 btrfs_discard_cancel_work(&cache->fs_info->discard_ctl, in btrfs_put_block_group()
134 cache); in btrfs_put_block_group()
144 WARN_ON(!RB_EMPTY_ROOT(&cache->full_stripe_locks_root.root)); in btrfs_put_block_group()
145 kfree(cache->free_space_ctl); in btrfs_put_block_group()
146 kfree(cache); in btrfs_put_block_group()
158 struct btrfs_block_group *cache; in btrfs_add_block_group_cache() local
167 cache = rb_entry(parent, struct btrfs_block_group, cache_node); in btrfs_add_block_group_cache()
168 if (block_group->start < cache->start) { in btrfs_add_block_group_cache()
170 } else if (block_group->start > cache->start) { in btrfs_add_block_group_cache()
197 struct btrfs_block_group *cache, *ret = NULL; in block_group_cache_tree_search() local
205 cache = rb_entry(n, struct btrfs_block_group, cache_node); in block_group_cache_tree_search()
206 end = cache->start + cache->length - 1; in block_group_cache_tree_search()
207 start = cache->start; in block_group_cache_tree_search()
211 ret = cache; in block_group_cache_tree_search()
215 ret = cache; in block_group_cache_tree_search()
220 ret = cache; in block_group_cache_tree_search()
253 struct btrfs_block_group *cache) in btrfs_next_block_group() argument
255 struct btrfs_fs_info *fs_info = cache->fs_info; in btrfs_next_block_group()
261 if (RB_EMPTY_NODE(&cache->cache_node)) { in btrfs_next_block_group()
262 const u64 next_bytenr = cache->start + cache->length; in btrfs_next_block_group()
265 btrfs_put_block_group(cache); in btrfs_next_block_group()
266 cache = btrfs_lookup_first_block_group(fs_info, next_bytenr); return cache; in btrfs_next_block_group()
268 node = rb_next(&cache->cache_node); in btrfs_next_block_group()
269 btrfs_put_block_group(cache); in btrfs_next_block_group()
271 cache = rb_entry(node, struct btrfs_block_group, cache_node); in btrfs_next_block_group()
272 btrfs_get_block_group(cache); in btrfs_next_block_group()
274 cache = NULL; in btrfs_next_block_group()
276 return cache; in btrfs_next_block_group()
361 struct btrfs_block_group *cache) in btrfs_get_caching_control() argument
365 spin_lock(&cache->lock); in btrfs_get_caching_control()
366 if (!cache->caching_ctl) { in btrfs_get_caching_control()
367 spin_unlock(&cache->lock); in btrfs_get_caching_control()
371 ctl = cache->caching_ctl; in btrfs_get_caching_control()
373 spin_unlock(&cache->lock); in btrfs_get_caching_control()
396 void btrfs_wait_block_group_cache_progress(struct btrfs_block_group *cache, in btrfs_wait_block_group_cache_progress() argument
401 caching_ctl = btrfs_get_caching_control(cache); in btrfs_wait_block_group_cache_progress()
405 wait_event(caching_ctl->wait, btrfs_block_group_done(cache) || in btrfs_wait_block_group_cache_progress()
406 (cache->free_space_ctl->free_space >= num_bytes)); in btrfs_wait_block_group_cache_progress()
411 int btrfs_wait_block_group_cache_done(struct btrfs_block_group *cache) in btrfs_wait_block_group_cache_done() argument
416 caching_ctl = btrfs_get_caching_control(cache); in btrfs_wait_block_group_cache_done()
418 return (cache->cached == BTRFS_CACHE_ERROR) ? -EIO : 0; in btrfs_wait_block_group_cache_done()
420 wait_event(caching_ctl->wait, btrfs_block_group_done(cache)); in btrfs_wait_block_group_cache_done()
421 if (cache->cached == BTRFS_CACHE_ERROR) in btrfs_wait_block_group_cache_done()
686 int btrfs_cache_block_group(struct btrfs_block_group *cache, int load_cache_only) in btrfs_cache_block_group() argument
689 struct btrfs_fs_info *fs_info = cache->fs_info; in btrfs_cache_block_group()
700 caching_ctl->block_group = cache; in btrfs_cache_block_group()
701 caching_ctl->progress = cache->start; in btrfs_cache_block_group()
705 spin_lock(&cache->lock); in btrfs_cache_block_group()
718 while (cache->cached == BTRFS_CACHE_FAST) { in btrfs_cache_block_group()
721 ctl = cache->caching_ctl; in btrfs_cache_block_group()
724 spin_unlock(&cache->lock); in btrfs_cache_block_group()
730 spin_lock(&cache->lock); in btrfs_cache_block_group()
733 if (cache->cached != BTRFS_CACHE_NO) { in btrfs_cache_block_group()
734 spin_unlock(&cache->lock); in btrfs_cache_block_group()
738 WARN_ON(cache->caching_ctl); in btrfs_cache_block_group()
739 cache->caching_ctl = caching_ctl; in btrfs_cache_block_group()
740 cache->cached = BTRFS_CACHE_FAST; in btrfs_cache_block_group()
741 spin_unlock(&cache->lock); in btrfs_cache_block_group()
745 ret = load_free_space_cache(cache); in btrfs_cache_block_group()
747 spin_lock(&cache->lock); in btrfs_cache_block_group()
749 cache->caching_ctl = NULL; in btrfs_cache_block_group()
750 cache->cached = BTRFS_CACHE_FINISHED; in btrfs_cache_block_group()
751 cache->last_byte_to_unpin = (u64)-1; in btrfs_cache_block_group()
755 cache->caching_ctl = NULL; in btrfs_cache_block_group()
756 cache->cached = BTRFS_CACHE_NO; in btrfs_cache_block_group()
758 cache->cached = BTRFS_CACHE_STARTED; in btrfs_cache_block_group()
759 cache->has_caching_ctl = 1; in btrfs_cache_block_group()
762 spin_unlock(&cache->lock); in btrfs_cache_block_group()
765 btrfs_should_fragment_free_space(cache)) { in btrfs_cache_block_group()
768 spin_lock(&cache->space_info->lock); in btrfs_cache_block_group()
769 spin_lock(&cache->lock); in btrfs_cache_block_group()
770 bytes_used = cache->length - cache->used; in btrfs_cache_block_group()
771 cache->space_info->bytes_used += bytes_used >> 1; in btrfs_cache_block_group()
772 spin_unlock(&cache->lock); in btrfs_cache_block_group()
773 spin_unlock(&cache->space_info->lock); in btrfs_cache_block_group()
774 fragment_free_space(cache); in btrfs_cache_block_group()
782 btrfs_free_excluded_extents(cache); in btrfs_cache_block_group()
790 spin_lock(&cache->lock); in btrfs_cache_block_group()
792 cache->caching_ctl = NULL; in btrfs_cache_block_group()
793 cache->cached = BTRFS_CACHE_NO; in btrfs_cache_block_group()
795 cache->cached = BTRFS_CACHE_STARTED; in btrfs_cache_block_group()
796 cache->has_caching_ctl = 1; in btrfs_cache_block_group()
798 spin_unlock(&cache->lock); in btrfs_cache_block_group()
812 btrfs_get_block_group(cache); in btrfs_cache_block_group()
1223 static int inc_block_group_ro(struct btrfs_block_group *cache, int force) in inc_block_group_ro() argument
1225 struct btrfs_space_info *sinfo = cache->space_info; in inc_block_group_ro()
1230 spin_lock(&cache->lock); in inc_block_group_ro()
1232 if (cache->swap_extents) { in inc_block_group_ro()
1237 if (cache->ro) { in inc_block_group_ro()
1238 cache->ro++; in inc_block_group_ro()
1243 num_bytes = cache->length - cache->reserved - cache->pinned - in inc_block_group_ro()
1244 cache->bytes_super - cache->used; in inc_block_group_ro()
1268 if (btrfs_can_overcommit(cache->fs_info, sinfo, num_bytes, in inc_block_group_ro()
1275 cache->ro++; in inc_block_group_ro()
1276 list_add_tail(&cache->ro_list, &sinfo->ro_bgs); in inc_block_group_ro()
1279 spin_unlock(&cache->lock); in inc_block_group_ro()
1281 if (ret == -ENOSPC && btrfs_test_opt(cache->fs_info, ENOSPC_DEBUG)) { in inc_block_group_ro()
1282 btrfs_info(cache->fs_info, in inc_block_group_ro()
1283 "unable to make block group %llu ro", cache->start); in inc_block_group_ro()
1284 btrfs_dump_space_info(cache->fs_info, cache->space_info, 0, 0); in inc_block_group_ro()
1734 static int exclude_super_stripes(struct btrfs_block_group *cache) in exclude_super_stripes() argument
1736 struct btrfs_fs_info *fs_info = cache->fs_info; in exclude_super_stripes()
1742 if (cache->start < BTRFS_SUPER_INFO_OFFSET) { in exclude_super_stripes()
1743 stripe_len = BTRFS_SUPER_INFO_OFFSET - cache->start; in exclude_super_stripes()
1744 cache->bytes_super += stripe_len; in exclude_super_stripes()
1745 ret = btrfs_add_excluded_extent(fs_info, cache->start, in exclude_super_stripes()
1753 ret = btrfs_rmap_block(fs_info, cache->start, in exclude_super_stripes()
1760 cache->start + cache->length - logical[nr]); in exclude_super_stripes()
1762 cache->bytes_super += len; in exclude_super_stripes()
1776 static void link_block_group(struct btrfs_block_group *cache) in link_block_group() argument
1778 struct btrfs_space_info *space_info = cache->space_info; in link_block_group()
1779 int index = btrfs_bg_flags_to_raid_index(cache->flags); in link_block_group()
1782 list_add_tail(&cache->list, &space_info->block_groups[index]); in link_block_group()
1789 struct btrfs_block_group *cache; in btrfs_create_block_group_cache() local
1791 cache = kzalloc(sizeof(*cache), GFP_NOFS); in btrfs_create_block_group_cache()
1792 if (!cache) in btrfs_create_block_group_cache()
1795 cache->free_space_ctl = kzalloc(sizeof(*cache->free_space_ctl), in btrfs_create_block_group_cache()
1797 if (!cache->free_space_ctl) { in btrfs_create_block_group_cache()
1798 kfree(cache); in btrfs_create_block_group_cache()
1802 cache->start = start; in btrfs_create_block_group_cache()
1804 cache->fs_info = fs_info; in btrfs_create_block_group_cache()
1805 cache->full_stripe_len = btrfs_full_stripe_len(fs_info, start); in btrfs_create_block_group_cache()
1807 cache->discard_index = BTRFS_DISCARD_INDEX_UNUSED; in btrfs_create_block_group_cache()
1809 refcount_set(&cache->refs, 1); in btrfs_create_block_group_cache()
1810 spin_lock_init(&cache->lock); in btrfs_create_block_group_cache()
1811 init_rwsem(&cache->data_rwsem); in btrfs_create_block_group_cache()
1812 INIT_LIST_HEAD(&cache->list); in btrfs_create_block_group_cache()
1813 INIT_LIST_HEAD(&cache->cluster_list); in btrfs_create_block_group_cache()
1814 INIT_LIST_HEAD(&cache->bg_list); in btrfs_create_block_group_cache()
1815 INIT_LIST_HEAD(&cache->ro_list); in btrfs_create_block_group_cache()
1816 INIT_LIST_HEAD(&cache->discard_list); in btrfs_create_block_group_cache()
1817 INIT_LIST_HEAD(&cache->dirty_list); in btrfs_create_block_group_cache()
1818 INIT_LIST_HEAD(&cache->io_list); in btrfs_create_block_group_cache()
1819 btrfs_init_free_space_ctl(cache); in btrfs_create_block_group_cache()
1820 atomic_set(&cache->frozen, 0); in btrfs_create_block_group_cache()
1821 mutex_init(&cache->free_space_lock); in btrfs_create_block_group_cache()
1822 btrfs_init_full_stripe_locks_tree(&cache->full_stripe_locks_root); in btrfs_create_block_group_cache()
1824 return cache; in btrfs_create_block_group_cache()
1881 static void read_block_group_item(struct btrfs_block_group *cache, in read_block_group_item() argument
1889 cache->length = key->offset; in read_block_group_item()
1893 cache->used = btrfs_stack_block_group_used(&bgi); in read_block_group_item()
1894 cache->flags = btrfs_stack_block_group_flags(&bgi); in read_block_group_item()
1902 struct btrfs_block_group *cache; in read_one_block_group() local
1909 cache = btrfs_create_block_group_cache(info, key->objectid); in read_one_block_group()
1910 if (!cache) in read_one_block_group()
1913 read_block_group_item(cache, path, key); in read_one_block_group()
1915 set_free_space_tree_thresholds(cache); in read_one_block_group()
1929 cache->disk_cache_state = BTRFS_DC_CLEAR; in read_one_block_group()
1931 if (!mixed && ((cache->flags & BTRFS_BLOCK_GROUP_METADATA) && in read_one_block_group()
1932 (cache->flags & BTRFS_BLOCK_GROUP_DATA))) { in read_one_block_group()
1935 cache->start); in read_one_block_group()
1945 ret = exclude_super_stripes(cache); in read_one_block_group()
1948 btrfs_free_excluded_extents(cache); in read_one_block_group()
1958 if (cache->length == cache->used) { in read_one_block_group()
1959 cache->last_byte_to_unpin = (u64)-1; in read_one_block_group()
1960 cache->cached = BTRFS_CACHE_FINISHED; in read_one_block_group()
1961 btrfs_free_excluded_extents(cache); in read_one_block_group()
1962 } else if (cache->used == 0) { in read_one_block_group()
1963 cache->last_byte_to_unpin = (u64)-1; in read_one_block_group()
1964 cache->cached = BTRFS_CACHE_FINISHED; in read_one_block_group()
1965 add_new_free_space(cache, cache->start, in read_one_block_group()
1966 cache->start + cache->length); in read_one_block_group()
1967 btrfs_free_excluded_extents(cache); in read_one_block_group()
1970 ret = btrfs_add_block_group_cache(info, cache); in read_one_block_group()
1972 btrfs_remove_free_space_cache(cache); in read_one_block_group()
1975 trace_btrfs_add_block_group(info, cache, 0); in read_one_block_group()
1976 btrfs_update_space_info(info, cache->flags, cache->length, in read_one_block_group()
1977 cache->used, cache->bytes_super, &space_info); in read_one_block_group()
1979 cache->space_info = space_info; in read_one_block_group()
1981 link_block_group(cache); in read_one_block_group()
1983 set_avail_alloc_bits(info, cache->flags); in read_one_block_group()
1984 if (btrfs_chunk_readonly(info, cache->start)) { in read_one_block_group()
1985 inc_block_group_ro(cache, 1); in read_one_block_group()
1986 } else if (cache->used == 0) { in read_one_block_group()
1987 ASSERT(list_empty(&cache->bg_list)); in read_one_block_group()
1989 btrfs_discard_queue_work(&info->discard_ctl, cache); in read_one_block_group()
1991 btrfs_mark_bg_unused(cache); in read_one_block_group()
1995 btrfs_put_block_group(cache); in read_one_block_group()
2003 struct btrfs_block_group *cache; in btrfs_read_block_groups() local
2046 cache = list_first_entry(&space_info->block_groups[i], in btrfs_read_block_groups()
2049 btrfs_sysfs_add_block_group_type(cache); in btrfs_read_block_groups()
2062 list_for_each_entry(cache, in btrfs_read_block_groups()
2065 inc_block_group_ro(cache, 1); in btrfs_read_block_groups()
2066 list_for_each_entry(cache, in btrfs_read_block_groups()
2069 inc_block_group_ro(cache, 1); in btrfs_read_block_groups()
2151 struct btrfs_block_group *cache; in btrfs_make_block_group() local
2156 cache = btrfs_create_block_group_cache(fs_info, chunk_offset); in btrfs_make_block_group()
2157 if (!cache) in btrfs_make_block_group()
2160 cache->length = size; in btrfs_make_block_group()
2161 set_free_space_tree_thresholds(cache); in btrfs_make_block_group()
2162 cache->used = bytes_used; in btrfs_make_block_group()
2163 cache->flags = type; in btrfs_make_block_group()
2164 cache->last_byte_to_unpin = (u64)-1; in btrfs_make_block_group()
2165 cache->cached = BTRFS_CACHE_FINISHED; in btrfs_make_block_group()
2166 cache->needs_free_space = 1; in btrfs_make_block_group()
2167 ret = exclude_super_stripes(cache); in btrfs_make_block_group()
2170 btrfs_free_excluded_extents(cache); in btrfs_make_block_group()
2171 btrfs_put_block_group(cache); in btrfs_make_block_group()
2175 add_new_free_space(cache, chunk_offset, chunk_offset + size); in btrfs_make_block_group()
2177 btrfs_free_excluded_extents(cache); in btrfs_make_block_group()
2180 if (btrfs_should_fragment_free_space(cache)) { in btrfs_make_block_group()
2184 fragment_free_space(cache); in btrfs_make_block_group()
2192 cache->space_info = btrfs_find_space_info(fs_info, cache->flags); in btrfs_make_block_group()
2193 ASSERT(cache->space_info); in btrfs_make_block_group()
2195 ret = btrfs_add_block_group_cache(fs_info, cache); in btrfs_make_block_group()
2197 btrfs_remove_free_space_cache(cache); in btrfs_make_block_group()
2198 btrfs_put_block_group(cache); in btrfs_make_block_group()
2206 trace_btrfs_add_block_group(fs_info, cache, 1); in btrfs_make_block_group()
2207 btrfs_update_space_info(fs_info, cache->flags, size, bytes_used, in btrfs_make_block_group()
2208 cache->bytes_super, &cache->space_info); in btrfs_make_block_group()
2211 link_block_group(cache); in btrfs_make_block_group()
2213 list_add_tail(&cache->bg_list, &trans->new_bgs); in btrfs_make_block_group()
2230 int btrfs_inc_block_group_ro(struct btrfs_block_group *cache, in btrfs_inc_block_group_ro() argument
2233 struct btrfs_fs_info *fs_info = cache->fs_info; in btrfs_inc_block_group_ro()
2266 alloc_flags = btrfs_get_alloc_profile(fs_info, cache->flags); in btrfs_inc_block_group_ro()
2267 if (alloc_flags != cache->flags) { in btrfs_inc_block_group_ro()
2281 ret = inc_block_group_ro(cache, 0); in btrfs_inc_block_group_ro()
2286 alloc_flags = btrfs_get_alloc_profile(fs_info, cache->space_info->flags); in btrfs_inc_block_group_ro()
2290 ret = inc_block_group_ro(cache, 0); in btrfs_inc_block_group_ro()
2294 if (cache->flags & BTRFS_BLOCK_GROUP_SYSTEM) { in btrfs_inc_block_group_ro()
2295 alloc_flags = btrfs_get_alloc_profile(fs_info, cache->flags); in btrfs_inc_block_group_ro()
2307 void btrfs_dec_block_group_ro(struct btrfs_block_group *cache) in btrfs_dec_block_group_ro() argument
2309 struct btrfs_space_info *sinfo = cache->space_info; in btrfs_dec_block_group_ro()
2312 BUG_ON(!cache->ro); in btrfs_dec_block_group_ro()
2315 spin_lock(&cache->lock); in btrfs_dec_block_group_ro()
2316 if (!--cache->ro) { in btrfs_dec_block_group_ro()
2317 num_bytes = cache->length - cache->reserved - in btrfs_dec_block_group_ro()
2318 cache->pinned - cache->bytes_super - cache->used; in btrfs_dec_block_group_ro()
2320 list_del_init(&cache->ro_list); in btrfs_dec_block_group_ro()
2322 spin_unlock(&cache->lock); in btrfs_dec_block_group_ro()
2328 struct btrfs_block_group *cache) in update_block_group_item() argument
2338 key.objectid = cache->start; in update_block_group_item()
2340 key.offset = cache->length; in update_block_group_item()
2351 btrfs_set_stack_block_group_used(&bgi, cache->used); in update_block_group_item()
2354 btrfs_set_stack_block_group_flags(&bgi, cache->flags); in update_block_group_item()
2528 struct btrfs_block_group *cache, *tmp; in btrfs_setup_space_cache() local
2541 list_for_each_entry_safe(cache, tmp, &cur_trans->dirty_bgs, in btrfs_setup_space_cache()
2543 if (cache->disk_cache_state == BTRFS_DC_CLEAR) in btrfs_setup_space_cache()
2544 cache_save_setup(cache, trans, path); in btrfs_setup_space_cache()
2566 struct btrfs_block_group *cache; in btrfs_start_dirty_block_groups() local
2604 cache = list_first_entry(&dirty, struct btrfs_block_group, in btrfs_start_dirty_block_groups()
2611 if (!list_empty(&cache->io_list)) { in btrfs_start_dirty_block_groups()
2612 list_del_init(&cache->io_list); in btrfs_start_dirty_block_groups()
2613 btrfs_wait_cache_io(trans, cache, path); in btrfs_start_dirty_block_groups()
2614 btrfs_put_block_group(cache); in btrfs_start_dirty_block_groups()
2627 list_del_init(&cache->dirty_list); in btrfs_start_dirty_block_groups()
2632 cache_save_setup(cache, trans, path); in btrfs_start_dirty_block_groups()
2634 if (cache->disk_cache_state == BTRFS_DC_SETUP) { in btrfs_start_dirty_block_groups()
2635 cache->io_ctl.inode = NULL; in btrfs_start_dirty_block_groups()
2636 ret = btrfs_write_out_cache(trans, cache, path); in btrfs_start_dirty_block_groups()
2637 if (ret == 0 && cache->io_ctl.inode) { in btrfs_start_dirty_block_groups()
2645 list_add_tail(&cache->io_list, io); in btrfs_start_dirty_block_groups()
2655 ret = update_block_group_item(trans, path, cache); in btrfs_start_dirty_block_groups()
2668 if (list_empty(&cache->dirty_list)) { in btrfs_start_dirty_block_groups()
2669 list_add_tail(&cache->dirty_list, in btrfs_start_dirty_block_groups()
2671 btrfs_get_block_group(cache); in btrfs_start_dirty_block_groups()
2682 btrfs_put_block_group(cache); in btrfs_start_dirty_block_groups()
2732 struct btrfs_block_group *cache; in btrfs_write_dirty_block_groups() local
2760 cache = list_first_entry(&cur_trans->dirty_bgs, in btrfs_write_dirty_block_groups()
2769 if (!list_empty(&cache->io_list)) { in btrfs_write_dirty_block_groups()
2771 list_del_init(&cache->io_list); in btrfs_write_dirty_block_groups()
2772 btrfs_wait_cache_io(trans, cache, path); in btrfs_write_dirty_block_groups()
2773 btrfs_put_block_group(cache); in btrfs_write_dirty_block_groups()
2781 list_del_init(&cache->dirty_list); in btrfs_write_dirty_block_groups()
2785 cache_save_setup(cache, trans, path); in btrfs_write_dirty_block_groups()
2791 if (!ret && cache->disk_cache_state == BTRFS_DC_SETUP) { in btrfs_write_dirty_block_groups()
2792 cache->io_ctl.inode = NULL; in btrfs_write_dirty_block_groups()
2793 ret = btrfs_write_out_cache(trans, cache, path); in btrfs_write_dirty_block_groups()
2794 if (ret == 0 && cache->io_ctl.inode) { in btrfs_write_dirty_block_groups()
2796 list_add_tail(&cache->io_list, io); in btrfs_write_dirty_block_groups()
2806 ret = update_block_group_item(trans, path, cache); in btrfs_write_dirty_block_groups()
2823 ret = update_block_group_item(trans, path, cache); in btrfs_write_dirty_block_groups()
2831 btrfs_put_block_group(cache); in btrfs_write_dirty_block_groups()
2842 cache = list_first_entry(io, struct btrfs_block_group, in btrfs_write_dirty_block_groups()
2844 list_del_init(&cache->io_list); in btrfs_write_dirty_block_groups()
2845 btrfs_wait_cache_io(trans, cache, path); in btrfs_write_dirty_block_groups()
2846 btrfs_put_block_group(cache); in btrfs_write_dirty_block_groups()
2857 struct btrfs_block_group *cache = NULL; in btrfs_update_block_group() local
2875 cache = btrfs_lookup_block_group(info, bytenr); in btrfs_update_block_group()
2876 if (!cache) { in btrfs_update_block_group()
2880 factor = btrfs_bg_type_to_factor(cache->flags); in btrfs_update_block_group()
2888 if (!alloc && !btrfs_block_group_done(cache)) in btrfs_update_block_group()
2889 btrfs_cache_block_group(cache, 1); in btrfs_update_block_group()
2891 byte_in_group = bytenr - cache->start; in btrfs_update_block_group()
2892 WARN_ON(byte_in_group > cache->length); in btrfs_update_block_group()
2894 spin_lock(&cache->space_info->lock); in btrfs_update_block_group()
2895 spin_lock(&cache->lock); in btrfs_update_block_group()
2898 cache->disk_cache_state < BTRFS_DC_CLEAR) in btrfs_update_block_group()
2899 cache->disk_cache_state = BTRFS_DC_CLEAR; in btrfs_update_block_group()
2901 old_val = cache->used; in btrfs_update_block_group()
2902 num_bytes = min(total, cache->length - byte_in_group); in btrfs_update_block_group()
2905 cache->used = old_val; in btrfs_update_block_group()
2906 cache->reserved -= num_bytes; in btrfs_update_block_group()
2907 cache->space_info->bytes_reserved -= num_bytes; in btrfs_update_block_group()
2908 cache->space_info->bytes_used += num_bytes; in btrfs_update_block_group()
2909 cache->space_info->disk_used += num_bytes * factor; in btrfs_update_block_group()
2910 spin_unlock(&cache->lock); in btrfs_update_block_group()
2911 spin_unlock(&cache->space_info->lock); in btrfs_update_block_group()
2914 cache->used = old_val; in btrfs_update_block_group()
2915 cache->pinned += num_bytes; in btrfs_update_block_group()
2917 cache->space_info, num_bytes); in btrfs_update_block_group()
2918 cache->space_info->bytes_used -= num_bytes; in btrfs_update_block_group()
2919 cache->space_info->disk_used -= num_bytes * factor; in btrfs_update_block_group()
2920 spin_unlock(&cache->lock); in btrfs_update_block_group()
2921 spin_unlock(&cache->space_info->lock); in btrfs_update_block_group()
2923 __btrfs_mod_total_bytes_pinned(cache->space_info, in btrfs_update_block_group()
2931 if (list_empty(&cache->dirty_list)) { in btrfs_update_block_group()
2932 list_add_tail(&cache->dirty_list, in btrfs_update_block_group()
2935 btrfs_get_block_group(cache); in btrfs_update_block_group()
2947 btrfs_mark_bg_unused(cache); in btrfs_update_block_group()
2950 btrfs_put_block_group(cache); in btrfs_update_block_group()
2972 int btrfs_add_reserved_bytes(struct btrfs_block_group *cache, in btrfs_add_reserved_bytes() argument
2975 struct btrfs_space_info *space_info = cache->space_info; in btrfs_add_reserved_bytes()
2979 spin_lock(&cache->lock); in btrfs_add_reserved_bytes()
2980 if (cache->ro) { in btrfs_add_reserved_bytes()
2983 cache->reserved += num_bytes; in btrfs_add_reserved_bytes()
2985 trace_btrfs_space_reservation(cache->fs_info, "space_info", in btrfs_add_reserved_bytes()
2987 btrfs_space_info_update_bytes_may_use(cache->fs_info, in btrfs_add_reserved_bytes()
2990 cache->delalloc_bytes += num_bytes; in btrfs_add_reserved_bytes()
2997 btrfs_try_granting_tickets(cache->fs_info, space_info); in btrfs_add_reserved_bytes()
2999 spin_unlock(&cache->lock); in btrfs_add_reserved_bytes()
3015 void btrfs_free_reserved_bytes(struct btrfs_block_group *cache, in btrfs_free_reserved_bytes() argument
3018 struct btrfs_space_info *space_info = cache->space_info; in btrfs_free_reserved_bytes()
3021 spin_lock(&cache->lock); in btrfs_free_reserved_bytes()
3022 if (cache->ro) in btrfs_free_reserved_bytes()
3024 cache->reserved -= num_bytes; in btrfs_free_reserved_bytes()
3029 cache->delalloc_bytes -= num_bytes; in btrfs_free_reserved_bytes()
3030 spin_unlock(&cache->lock); in btrfs_free_reserved_bytes()
3032 btrfs_try_granting_tickets(cache->fs_info, space_info); in btrfs_free_reserved_bytes()
3399 void btrfs_freeze_block_group(struct btrfs_block_group *cache) in btrfs_freeze_block_group() argument
3401 atomic_inc(&cache->frozen); in btrfs_freeze_block_group()