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()
678 int btrfs_cache_block_group(struct btrfs_block_group *cache, int load_cache_only) in btrfs_cache_block_group() argument
681 struct btrfs_fs_info *fs_info = cache->fs_info; in btrfs_cache_block_group()
692 caching_ctl->block_group = cache; in btrfs_cache_block_group()
693 caching_ctl->progress = cache->start; in btrfs_cache_block_group()
697 spin_lock(&cache->lock); in btrfs_cache_block_group()
710 while (cache->cached == BTRFS_CACHE_FAST) { in btrfs_cache_block_group()
713 ctl = cache->caching_ctl; in btrfs_cache_block_group()
716 spin_unlock(&cache->lock); in btrfs_cache_block_group()
722 spin_lock(&cache->lock); in btrfs_cache_block_group()
725 if (cache->cached != BTRFS_CACHE_NO) { in btrfs_cache_block_group()
726 spin_unlock(&cache->lock); in btrfs_cache_block_group()
730 WARN_ON(cache->caching_ctl); in btrfs_cache_block_group()
731 cache->caching_ctl = caching_ctl; in btrfs_cache_block_group()
732 cache->cached = BTRFS_CACHE_FAST; in btrfs_cache_block_group()
733 spin_unlock(&cache->lock); in btrfs_cache_block_group()
737 ret = load_free_space_cache(cache); in btrfs_cache_block_group()
739 spin_lock(&cache->lock); in btrfs_cache_block_group()
741 cache->caching_ctl = NULL; in btrfs_cache_block_group()
742 cache->cached = BTRFS_CACHE_FINISHED; in btrfs_cache_block_group()
743 cache->last_byte_to_unpin = (u64)-1; in btrfs_cache_block_group()
747 cache->caching_ctl = NULL; in btrfs_cache_block_group()
748 cache->cached = BTRFS_CACHE_NO; in btrfs_cache_block_group()
750 cache->cached = BTRFS_CACHE_STARTED; in btrfs_cache_block_group()
751 cache->has_caching_ctl = 1; in btrfs_cache_block_group()
754 spin_unlock(&cache->lock); in btrfs_cache_block_group()
757 btrfs_should_fragment_free_space(cache)) { in btrfs_cache_block_group()
760 spin_lock(&cache->space_info->lock); in btrfs_cache_block_group()
761 spin_lock(&cache->lock); in btrfs_cache_block_group()
762 bytes_used = cache->length - cache->used; in btrfs_cache_block_group()
763 cache->space_info->bytes_used += bytes_used >> 1; in btrfs_cache_block_group()
764 spin_unlock(&cache->lock); in btrfs_cache_block_group()
765 spin_unlock(&cache->space_info->lock); in btrfs_cache_block_group()
766 fragment_free_space(cache); in btrfs_cache_block_group()
774 btrfs_free_excluded_extents(cache); in btrfs_cache_block_group()
782 spin_lock(&cache->lock); in btrfs_cache_block_group()
784 cache->caching_ctl = NULL; in btrfs_cache_block_group()
785 cache->cached = BTRFS_CACHE_NO; in btrfs_cache_block_group()
787 cache->cached = BTRFS_CACHE_STARTED; in btrfs_cache_block_group()
788 cache->has_caching_ctl = 1; in btrfs_cache_block_group()
790 spin_unlock(&cache->lock); in btrfs_cache_block_group()
804 btrfs_get_block_group(cache); in btrfs_cache_block_group()
1215 static int inc_block_group_ro(struct btrfs_block_group *cache, int force) in inc_block_group_ro() argument
1217 struct btrfs_space_info *sinfo = cache->space_info; in inc_block_group_ro()
1222 spin_lock(&cache->lock); in inc_block_group_ro()
1224 if (cache->ro) { in inc_block_group_ro()
1225 cache->ro++; in inc_block_group_ro()
1230 num_bytes = cache->length - cache->reserved - cache->pinned - in inc_block_group_ro()
1231 cache->bytes_super - cache->used; in inc_block_group_ro()
1255 if (btrfs_can_overcommit(cache->fs_info, sinfo, num_bytes, in inc_block_group_ro()
1262 cache->ro++; in inc_block_group_ro()
1263 list_add_tail(&cache->ro_list, &sinfo->ro_bgs); in inc_block_group_ro()
1266 spin_unlock(&cache->lock); in inc_block_group_ro()
1268 if (ret == -ENOSPC && btrfs_test_opt(cache->fs_info, ENOSPC_DEBUG)) { in inc_block_group_ro()
1269 btrfs_info(cache->fs_info, in inc_block_group_ro()
1270 "unable to make block group %llu ro", cache->start); in inc_block_group_ro()
1271 btrfs_dump_space_info(cache->fs_info, cache->space_info, 0, 0); in inc_block_group_ro()
1723 static int exclude_super_stripes(struct btrfs_block_group *cache) in exclude_super_stripes() argument
1725 struct btrfs_fs_info *fs_info = cache->fs_info; in exclude_super_stripes()
1731 if (cache->start < BTRFS_SUPER_INFO_OFFSET) { in exclude_super_stripes()
1732 stripe_len = BTRFS_SUPER_INFO_OFFSET - cache->start; in exclude_super_stripes()
1733 cache->bytes_super += stripe_len; in exclude_super_stripes()
1734 ret = btrfs_add_excluded_extent(fs_info, cache->start, in exclude_super_stripes()
1742 ret = btrfs_rmap_block(fs_info, cache->start, in exclude_super_stripes()
1749 cache->start + cache->length - logical[nr]); in exclude_super_stripes()
1751 cache->bytes_super += len; in exclude_super_stripes()
1765 static void link_block_group(struct btrfs_block_group *cache) in link_block_group() argument
1767 struct btrfs_space_info *space_info = cache->space_info; in link_block_group()
1768 int index = btrfs_bg_flags_to_raid_index(cache->flags); in link_block_group()
1771 list_add_tail(&cache->list, &space_info->block_groups[index]); in link_block_group()
1778 struct btrfs_block_group *cache; in btrfs_create_block_group_cache() local
1780 cache = kzalloc(sizeof(*cache), GFP_NOFS); in btrfs_create_block_group_cache()
1781 if (!cache) in btrfs_create_block_group_cache()
1784 cache->free_space_ctl = kzalloc(sizeof(*cache->free_space_ctl), in btrfs_create_block_group_cache()
1786 if (!cache->free_space_ctl) { in btrfs_create_block_group_cache()
1787 kfree(cache); in btrfs_create_block_group_cache()
1791 cache->start = start; in btrfs_create_block_group_cache()
1793 cache->fs_info = fs_info; in btrfs_create_block_group_cache()
1794 cache->full_stripe_len = btrfs_full_stripe_len(fs_info, start); in btrfs_create_block_group_cache()
1796 cache->discard_index = BTRFS_DISCARD_INDEX_UNUSED; in btrfs_create_block_group_cache()
1798 refcount_set(&cache->refs, 1); in btrfs_create_block_group_cache()
1799 spin_lock_init(&cache->lock); in btrfs_create_block_group_cache()
1800 init_rwsem(&cache->data_rwsem); in btrfs_create_block_group_cache()
1801 INIT_LIST_HEAD(&cache->list); in btrfs_create_block_group_cache()
1802 INIT_LIST_HEAD(&cache->cluster_list); in btrfs_create_block_group_cache()
1803 INIT_LIST_HEAD(&cache->bg_list); in btrfs_create_block_group_cache()
1804 INIT_LIST_HEAD(&cache->ro_list); in btrfs_create_block_group_cache()
1805 INIT_LIST_HEAD(&cache->discard_list); in btrfs_create_block_group_cache()
1806 INIT_LIST_HEAD(&cache->dirty_list); in btrfs_create_block_group_cache()
1807 INIT_LIST_HEAD(&cache->io_list); in btrfs_create_block_group_cache()
1808 btrfs_init_free_space_ctl(cache); in btrfs_create_block_group_cache()
1809 atomic_set(&cache->frozen, 0); in btrfs_create_block_group_cache()
1810 mutex_init(&cache->free_space_lock); in btrfs_create_block_group_cache()
1811 btrfs_init_full_stripe_locks_tree(&cache->full_stripe_locks_root); in btrfs_create_block_group_cache()
1813 return cache; in btrfs_create_block_group_cache()
1870 static void read_block_group_item(struct btrfs_block_group *cache, in read_block_group_item() argument
1878 cache->length = key->offset; in read_block_group_item()
1882 cache->used = btrfs_stack_block_group_used(&bgi); in read_block_group_item()
1883 cache->flags = btrfs_stack_block_group_flags(&bgi); in read_block_group_item()
1891 struct btrfs_block_group *cache; in read_one_block_group() local
1898 cache = btrfs_create_block_group_cache(info, key->objectid); in read_one_block_group()
1899 if (!cache) in read_one_block_group()
1902 read_block_group_item(cache, path, key); in read_one_block_group()
1904 set_free_space_tree_thresholds(cache); in read_one_block_group()
1918 cache->disk_cache_state = BTRFS_DC_CLEAR; in read_one_block_group()
1920 if (!mixed && ((cache->flags & BTRFS_BLOCK_GROUP_METADATA) && in read_one_block_group()
1921 (cache->flags & BTRFS_BLOCK_GROUP_DATA))) { in read_one_block_group()
1924 cache->start); in read_one_block_group()
1934 ret = exclude_super_stripes(cache); in read_one_block_group()
1937 btrfs_free_excluded_extents(cache); in read_one_block_group()
1947 if (cache->length == cache->used) { in read_one_block_group()
1948 cache->last_byte_to_unpin = (u64)-1; in read_one_block_group()
1949 cache->cached = BTRFS_CACHE_FINISHED; in read_one_block_group()
1950 btrfs_free_excluded_extents(cache); in read_one_block_group()
1951 } else if (cache->used == 0) { in read_one_block_group()
1952 cache->last_byte_to_unpin = (u64)-1; in read_one_block_group()
1953 cache->cached = BTRFS_CACHE_FINISHED; in read_one_block_group()
1954 add_new_free_space(cache, cache->start, in read_one_block_group()
1955 cache->start + cache->length); in read_one_block_group()
1956 btrfs_free_excluded_extents(cache); in read_one_block_group()
1959 ret = btrfs_add_block_group_cache(info, cache); in read_one_block_group()
1961 btrfs_remove_free_space_cache(cache); in read_one_block_group()
1964 trace_btrfs_add_block_group(info, cache, 0); in read_one_block_group()
1965 btrfs_update_space_info(info, cache->flags, cache->length, in read_one_block_group()
1966 cache->used, cache->bytes_super, &space_info); in read_one_block_group()
1968 cache->space_info = space_info; in read_one_block_group()
1970 link_block_group(cache); in read_one_block_group()
1972 set_avail_alloc_bits(info, cache->flags); in read_one_block_group()
1973 if (btrfs_chunk_readonly(info, cache->start)) { in read_one_block_group()
1974 inc_block_group_ro(cache, 1); in read_one_block_group()
1975 } else if (cache->used == 0) { in read_one_block_group()
1976 ASSERT(list_empty(&cache->bg_list)); in read_one_block_group()
1978 btrfs_discard_queue_work(&info->discard_ctl, cache); in read_one_block_group()
1980 btrfs_mark_bg_unused(cache); in read_one_block_group()
1984 btrfs_put_block_group(cache); in read_one_block_group()
1992 struct btrfs_block_group *cache; in btrfs_read_block_groups() local
2035 cache = list_first_entry(&space_info->block_groups[i], in btrfs_read_block_groups()
2038 btrfs_sysfs_add_block_group_type(cache); in btrfs_read_block_groups()
2051 list_for_each_entry(cache, in btrfs_read_block_groups()
2054 inc_block_group_ro(cache, 1); in btrfs_read_block_groups()
2055 list_for_each_entry(cache, in btrfs_read_block_groups()
2058 inc_block_group_ro(cache, 1); in btrfs_read_block_groups()
2140 struct btrfs_block_group *cache; in btrfs_make_block_group() local
2145 cache = btrfs_create_block_group_cache(fs_info, chunk_offset); in btrfs_make_block_group()
2146 if (!cache) in btrfs_make_block_group()
2149 cache->length = size; in btrfs_make_block_group()
2150 set_free_space_tree_thresholds(cache); in btrfs_make_block_group()
2151 cache->used = bytes_used; in btrfs_make_block_group()
2152 cache->flags = type; in btrfs_make_block_group()
2153 cache->last_byte_to_unpin = (u64)-1; in btrfs_make_block_group()
2154 cache->cached = BTRFS_CACHE_FINISHED; in btrfs_make_block_group()
2155 cache->needs_free_space = 1; in btrfs_make_block_group()
2156 ret = exclude_super_stripes(cache); in btrfs_make_block_group()
2159 btrfs_free_excluded_extents(cache); in btrfs_make_block_group()
2160 btrfs_put_block_group(cache); in btrfs_make_block_group()
2164 add_new_free_space(cache, chunk_offset, chunk_offset + size); in btrfs_make_block_group()
2166 btrfs_free_excluded_extents(cache); in btrfs_make_block_group()
2169 if (btrfs_should_fragment_free_space(cache)) { in btrfs_make_block_group()
2173 fragment_free_space(cache); in btrfs_make_block_group()
2181 cache->space_info = btrfs_find_space_info(fs_info, cache->flags); in btrfs_make_block_group()
2182 ASSERT(cache->space_info); in btrfs_make_block_group()
2184 ret = btrfs_add_block_group_cache(fs_info, cache); in btrfs_make_block_group()
2186 btrfs_remove_free_space_cache(cache); in btrfs_make_block_group()
2187 btrfs_put_block_group(cache); in btrfs_make_block_group()
2195 trace_btrfs_add_block_group(fs_info, cache, 1); in btrfs_make_block_group()
2196 btrfs_update_space_info(fs_info, cache->flags, size, bytes_used, in btrfs_make_block_group()
2197 cache->bytes_super, &cache->space_info); in btrfs_make_block_group()
2200 link_block_group(cache); in btrfs_make_block_group()
2202 list_add_tail(&cache->bg_list, &trans->new_bgs); in btrfs_make_block_group()
2219 int btrfs_inc_block_group_ro(struct btrfs_block_group *cache, in btrfs_inc_block_group_ro() argument
2222 struct btrfs_fs_info *fs_info = cache->fs_info; in btrfs_inc_block_group_ro()
2255 alloc_flags = btrfs_get_alloc_profile(fs_info, cache->flags); in btrfs_inc_block_group_ro()
2256 if (alloc_flags != cache->flags) { in btrfs_inc_block_group_ro()
2270 ret = inc_block_group_ro(cache, 0); in btrfs_inc_block_group_ro()
2275 alloc_flags = btrfs_get_alloc_profile(fs_info, cache->space_info->flags); in btrfs_inc_block_group_ro()
2279 ret = inc_block_group_ro(cache, 0); in btrfs_inc_block_group_ro()
2281 if (cache->flags & BTRFS_BLOCK_GROUP_SYSTEM) { in btrfs_inc_block_group_ro()
2282 alloc_flags = btrfs_get_alloc_profile(fs_info, cache->flags); in btrfs_inc_block_group_ro()
2294 void btrfs_dec_block_group_ro(struct btrfs_block_group *cache) in btrfs_dec_block_group_ro() argument
2296 struct btrfs_space_info *sinfo = cache->space_info; in btrfs_dec_block_group_ro()
2299 BUG_ON(!cache->ro); in btrfs_dec_block_group_ro()
2302 spin_lock(&cache->lock); in btrfs_dec_block_group_ro()
2303 if (!--cache->ro) { in btrfs_dec_block_group_ro()
2304 num_bytes = cache->length - cache->reserved - in btrfs_dec_block_group_ro()
2305 cache->pinned - cache->bytes_super - cache->used; in btrfs_dec_block_group_ro()
2307 list_del_init(&cache->ro_list); in btrfs_dec_block_group_ro()
2309 spin_unlock(&cache->lock); in btrfs_dec_block_group_ro()
2315 struct btrfs_block_group *cache) in update_block_group_item() argument
2325 key.objectid = cache->start; in update_block_group_item()
2327 key.offset = cache->length; in update_block_group_item()
2338 btrfs_set_stack_block_group_used(&bgi, cache->used); in update_block_group_item()
2341 btrfs_set_stack_block_group_flags(&bgi, cache->flags); in update_block_group_item()
2515 struct btrfs_block_group *cache, *tmp; in btrfs_setup_space_cache() local
2528 list_for_each_entry_safe(cache, tmp, &cur_trans->dirty_bgs, in btrfs_setup_space_cache()
2530 if (cache->disk_cache_state == BTRFS_DC_CLEAR) in btrfs_setup_space_cache()
2531 cache_save_setup(cache, trans, path); in btrfs_setup_space_cache()
2553 struct btrfs_block_group *cache; in btrfs_start_dirty_block_groups() local
2590 cache = list_first_entry(&dirty, struct btrfs_block_group, in btrfs_start_dirty_block_groups()
2597 if (!list_empty(&cache->io_list)) { in btrfs_start_dirty_block_groups()
2598 list_del_init(&cache->io_list); in btrfs_start_dirty_block_groups()
2599 btrfs_wait_cache_io(trans, cache, path); in btrfs_start_dirty_block_groups()
2600 btrfs_put_block_group(cache); in btrfs_start_dirty_block_groups()
2613 list_del_init(&cache->dirty_list); in btrfs_start_dirty_block_groups()
2618 cache_save_setup(cache, trans, path); in btrfs_start_dirty_block_groups()
2620 if (cache->disk_cache_state == BTRFS_DC_SETUP) { in btrfs_start_dirty_block_groups()
2621 cache->io_ctl.inode = NULL; in btrfs_start_dirty_block_groups()
2622 ret = btrfs_write_out_cache(trans, cache, path); in btrfs_start_dirty_block_groups()
2623 if (ret == 0 && cache->io_ctl.inode) { in btrfs_start_dirty_block_groups()
2632 list_add_tail(&cache->io_list, io); in btrfs_start_dirty_block_groups()
2642 ret = update_block_group_item(trans, path, cache); in btrfs_start_dirty_block_groups()
2655 if (list_empty(&cache->dirty_list)) { in btrfs_start_dirty_block_groups()
2656 list_add_tail(&cache->dirty_list, in btrfs_start_dirty_block_groups()
2658 btrfs_get_block_group(cache); in btrfs_start_dirty_block_groups()
2669 btrfs_put_block_group(cache); in btrfs_start_dirty_block_groups()
2715 struct btrfs_block_group *cache; in btrfs_write_dirty_block_groups() local
2744 cache = list_first_entry(&cur_trans->dirty_bgs, in btrfs_write_dirty_block_groups()
2753 if (!list_empty(&cache->io_list)) { in btrfs_write_dirty_block_groups()
2755 list_del_init(&cache->io_list); in btrfs_write_dirty_block_groups()
2756 btrfs_wait_cache_io(trans, cache, path); in btrfs_write_dirty_block_groups()
2757 btrfs_put_block_group(cache); in btrfs_write_dirty_block_groups()
2765 list_del_init(&cache->dirty_list); in btrfs_write_dirty_block_groups()
2769 cache_save_setup(cache, trans, path); in btrfs_write_dirty_block_groups()
2775 if (!ret && cache->disk_cache_state == BTRFS_DC_SETUP) { in btrfs_write_dirty_block_groups()
2776 cache->io_ctl.inode = NULL; in btrfs_write_dirty_block_groups()
2777 ret = btrfs_write_out_cache(trans, cache, path); in btrfs_write_dirty_block_groups()
2778 if (ret == 0 && cache->io_ctl.inode) { in btrfs_write_dirty_block_groups()
2781 list_add_tail(&cache->io_list, io); in btrfs_write_dirty_block_groups()
2791 ret = update_block_group_item(trans, path, cache); in btrfs_write_dirty_block_groups()
2808 ret = update_block_group_item(trans, path, cache); in btrfs_write_dirty_block_groups()
2816 btrfs_put_block_group(cache); in btrfs_write_dirty_block_groups()
2827 cache = list_first_entry(io, struct btrfs_block_group, in btrfs_write_dirty_block_groups()
2829 list_del_init(&cache->io_list); in btrfs_write_dirty_block_groups()
2830 btrfs_wait_cache_io(trans, cache, path); in btrfs_write_dirty_block_groups()
2831 btrfs_put_block_group(cache); in btrfs_write_dirty_block_groups()
2842 struct btrfs_block_group *cache = NULL; in btrfs_update_block_group() local
2860 cache = btrfs_lookup_block_group(info, bytenr); in btrfs_update_block_group()
2861 if (!cache) { in btrfs_update_block_group()
2865 factor = btrfs_bg_type_to_factor(cache->flags); in btrfs_update_block_group()
2873 if (!alloc && !btrfs_block_group_done(cache)) in btrfs_update_block_group()
2874 btrfs_cache_block_group(cache, 1); in btrfs_update_block_group()
2876 byte_in_group = bytenr - cache->start; in btrfs_update_block_group()
2877 WARN_ON(byte_in_group > cache->length); in btrfs_update_block_group()
2879 spin_lock(&cache->space_info->lock); in btrfs_update_block_group()
2880 spin_lock(&cache->lock); in btrfs_update_block_group()
2883 cache->disk_cache_state < BTRFS_DC_CLEAR) in btrfs_update_block_group()
2884 cache->disk_cache_state = BTRFS_DC_CLEAR; in btrfs_update_block_group()
2886 old_val = cache->used; in btrfs_update_block_group()
2887 num_bytes = min(total, cache->length - byte_in_group); in btrfs_update_block_group()
2890 cache->used = old_val; in btrfs_update_block_group()
2891 cache->reserved -= num_bytes; in btrfs_update_block_group()
2892 cache->space_info->bytes_reserved -= num_bytes; in btrfs_update_block_group()
2893 cache->space_info->bytes_used += num_bytes; in btrfs_update_block_group()
2894 cache->space_info->disk_used += num_bytes * factor; in btrfs_update_block_group()
2895 spin_unlock(&cache->lock); in btrfs_update_block_group()
2896 spin_unlock(&cache->space_info->lock); in btrfs_update_block_group()
2899 cache->used = old_val; in btrfs_update_block_group()
2900 cache->pinned += num_bytes; in btrfs_update_block_group()
2902 cache->space_info, num_bytes); in btrfs_update_block_group()
2903 cache->space_info->bytes_used -= num_bytes; in btrfs_update_block_group()
2904 cache->space_info->disk_used -= num_bytes * factor; in btrfs_update_block_group()
2905 spin_unlock(&cache->lock); in btrfs_update_block_group()
2906 spin_unlock(&cache->space_info->lock); in btrfs_update_block_group()
2909 &cache->space_info->total_bytes_pinned, in btrfs_update_block_group()
2918 if (list_empty(&cache->dirty_list)) { in btrfs_update_block_group()
2919 list_add_tail(&cache->dirty_list, in btrfs_update_block_group()
2922 btrfs_get_block_group(cache); in btrfs_update_block_group()
2934 btrfs_mark_bg_unused(cache); in btrfs_update_block_group()
2937 btrfs_put_block_group(cache); in btrfs_update_block_group()
2959 int btrfs_add_reserved_bytes(struct btrfs_block_group *cache, in btrfs_add_reserved_bytes() argument
2962 struct btrfs_space_info *space_info = cache->space_info; in btrfs_add_reserved_bytes()
2966 spin_lock(&cache->lock); in btrfs_add_reserved_bytes()
2967 if (cache->ro) { in btrfs_add_reserved_bytes()
2970 cache->reserved += num_bytes; in btrfs_add_reserved_bytes()
2972 trace_btrfs_space_reservation(cache->fs_info, "space_info", in btrfs_add_reserved_bytes()
2974 btrfs_space_info_update_bytes_may_use(cache->fs_info, in btrfs_add_reserved_bytes()
2977 cache->delalloc_bytes += num_bytes; in btrfs_add_reserved_bytes()
2984 btrfs_try_granting_tickets(cache->fs_info, space_info); in btrfs_add_reserved_bytes()
2986 spin_unlock(&cache->lock); in btrfs_add_reserved_bytes()
3002 void btrfs_free_reserved_bytes(struct btrfs_block_group *cache, in btrfs_free_reserved_bytes() argument
3005 struct btrfs_space_info *space_info = cache->space_info; in btrfs_free_reserved_bytes()
3008 spin_lock(&cache->lock); in btrfs_free_reserved_bytes()
3009 if (cache->ro) in btrfs_free_reserved_bytes()
3011 cache->reserved -= num_bytes; in btrfs_free_reserved_bytes()
3016 cache->delalloc_bytes -= num_bytes; in btrfs_free_reserved_bytes()
3017 spin_unlock(&cache->lock); in btrfs_free_reserved_bytes()
3019 btrfs_try_granting_tickets(cache->fs_info, space_info); in btrfs_free_reserved_bytes()
3384 void btrfs_freeze_block_group(struct btrfs_block_group *cache) in btrfs_freeze_block_group() argument
3386 atomic_inc(&cache->frozen); in btrfs_freeze_block_group()