Lines Matching refs:cache

106 static int btrfs_update_reserved_bytes(struct btrfs_block_group_cache *cache,
115 block_group_cache_done(struct btrfs_block_group_cache *cache) in block_group_cache_done() argument
118 return cache->cached == BTRFS_CACHE_FINISHED || in block_group_cache_done()
119 cache->cached == BTRFS_CACHE_ERROR; in block_group_cache_done()
122 static int block_group_bits(struct btrfs_block_group_cache *cache, u64 bits) in block_group_bits() argument
124 return (cache->flags & bits) == bits; in block_group_bits()
127 void btrfs_get_block_group(struct btrfs_block_group_cache *cache) in btrfs_get_block_group() argument
129 atomic_inc(&cache->count); in btrfs_get_block_group()
132 void btrfs_put_block_group(struct btrfs_block_group_cache *cache) in btrfs_put_block_group() argument
134 if (atomic_dec_and_test(&cache->count)) { in btrfs_put_block_group()
135 WARN_ON(cache->pinned > 0); in btrfs_put_block_group()
136 WARN_ON(cache->reserved > 0); in btrfs_put_block_group()
137 kfree(cache->free_space_ctl); in btrfs_put_block_group()
138 kfree(cache); in btrfs_put_block_group()
151 struct btrfs_block_group_cache *cache; in btrfs_add_block_group_cache() local
158 cache = rb_entry(parent, struct btrfs_block_group_cache, in btrfs_add_block_group_cache()
160 if (block_group->key.objectid < cache->key.objectid) { in btrfs_add_block_group_cache()
162 } else if (block_group->key.objectid > cache->key.objectid) { in btrfs_add_block_group_cache()
190 struct btrfs_block_group_cache *cache, *ret = NULL; in block_group_cache_tree_search() local
198 cache = rb_entry(n, struct btrfs_block_group_cache, in block_group_cache_tree_search()
200 end = cache->key.objectid + cache->key.offset - 1; in block_group_cache_tree_search()
201 start = cache->key.objectid; in block_group_cache_tree_search()
205 ret = cache; in block_group_cache_tree_search()
209 ret = cache; in block_group_cache_tree_search()
214 ret = cache; in block_group_cache_tree_search()
240 struct btrfs_block_group_cache *cache) in free_excluded_extents() argument
244 start = cache->key.objectid; in free_excluded_extents()
245 end = start + cache->key.offset - 1; in free_excluded_extents()
254 struct btrfs_block_group_cache *cache) in exclude_super_stripes() argument
261 if (cache->key.objectid < BTRFS_SUPER_INFO_OFFSET) { in exclude_super_stripes()
262 stripe_len = BTRFS_SUPER_INFO_OFFSET - cache->key.objectid; in exclude_super_stripes()
263 cache->bytes_super += stripe_len; in exclude_super_stripes()
264 ret = add_excluded_extent(root, cache->key.objectid, in exclude_super_stripes()
273 cache->key.objectid, bytenr, in exclude_super_stripes()
281 if (logical[nr] > cache->key.objectid + in exclude_super_stripes()
282 cache->key.offset) in exclude_super_stripes()
285 if (logical[nr] + stripe_len <= cache->key.objectid) in exclude_super_stripes()
289 if (start < cache->key.objectid) { in exclude_super_stripes()
290 start = cache->key.objectid; in exclude_super_stripes()
294 cache->key.objectid + in exclude_super_stripes()
295 cache->key.offset - start); in exclude_super_stripes()
298 cache->bytes_super += len; in exclude_super_stripes()
312 get_caching_control(struct btrfs_block_group_cache *cache) in get_caching_control() argument
316 spin_lock(&cache->lock); in get_caching_control()
317 if (!cache->caching_ctl) { in get_caching_control()
318 spin_unlock(&cache->lock); in get_caching_control()
322 ctl = cache->caching_ctl; in get_caching_control()
324 spin_unlock(&cache->lock); in get_caching_control()
578 static int cache_block_group(struct btrfs_block_group_cache *cache, in cache_block_group() argument
582 struct btrfs_fs_info *fs_info = cache->fs_info; in cache_block_group()
593 caching_ctl->block_group = cache; in cache_block_group()
594 caching_ctl->progress = cache->key.objectid; in cache_block_group()
599 spin_lock(&cache->lock); in cache_block_group()
612 while (cache->cached == BTRFS_CACHE_FAST) { in cache_block_group()
615 ctl = cache->caching_ctl; in cache_block_group()
618 spin_unlock(&cache->lock); in cache_block_group()
624 spin_lock(&cache->lock); in cache_block_group()
627 if (cache->cached != BTRFS_CACHE_NO) { in cache_block_group()
628 spin_unlock(&cache->lock); in cache_block_group()
632 WARN_ON(cache->caching_ctl); in cache_block_group()
633 cache->caching_ctl = caching_ctl; in cache_block_group()
634 cache->cached = BTRFS_CACHE_FAST; in cache_block_group()
635 spin_unlock(&cache->lock); in cache_block_group()
639 ret = load_free_space_cache(fs_info, cache); in cache_block_group()
641 spin_lock(&cache->lock); in cache_block_group()
643 cache->caching_ctl = NULL; in cache_block_group()
644 cache->cached = BTRFS_CACHE_FINISHED; in cache_block_group()
645 cache->last_byte_to_unpin = (u64)-1; in cache_block_group()
649 cache->caching_ctl = NULL; in cache_block_group()
650 cache->cached = BTRFS_CACHE_NO; in cache_block_group()
652 cache->cached = BTRFS_CACHE_STARTED; in cache_block_group()
653 cache->has_caching_ctl = 1; in cache_block_group()
656 spin_unlock(&cache->lock); in cache_block_group()
660 cache)) { in cache_block_group()
663 spin_lock(&cache->space_info->lock); in cache_block_group()
664 spin_lock(&cache->lock); in cache_block_group()
665 bytes_used = cache->key.offset - in cache_block_group()
666 btrfs_block_group_used(&cache->item); in cache_block_group()
667 cache->space_info->bytes_used += bytes_used >> 1; in cache_block_group()
668 spin_unlock(&cache->lock); in cache_block_group()
669 spin_unlock(&cache->space_info->lock); in cache_block_group()
670 fragment_free_space(fs_info->extent_root, cache); in cache_block_group()
678 free_excluded_extents(fs_info->extent_root, cache); in cache_block_group()
686 spin_lock(&cache->lock); in cache_block_group()
688 cache->caching_ctl = NULL; in cache_block_group()
689 cache->cached = BTRFS_CACHE_NO; in cache_block_group()
691 cache->cached = BTRFS_CACHE_STARTED; in cache_block_group()
692 cache->has_caching_ctl = 1; in cache_block_group()
694 spin_unlock(&cache->lock); in cache_block_group()
708 btrfs_get_block_group(cache); in cache_block_group()
721 struct btrfs_block_group_cache *cache; in btrfs_lookup_first_block_group() local
723 cache = block_group_cache_tree_search(info, bytenr, 0); in btrfs_lookup_first_block_group()
725 return cache; in btrfs_lookup_first_block_group()
735 struct btrfs_block_group_cache *cache; in btrfs_lookup_block_group() local
737 cache = block_group_cache_tree_search(info, bytenr, 1); in btrfs_lookup_block_group()
739 return cache; in btrfs_lookup_block_group()
3261 struct btrfs_block_group_cache *cache) in write_one_cache_group() argument
3268 ret = btrfs_search_slot(trans, extent_root, &cache->key, path, 0, 1); in write_one_cache_group()
3277 write_extent_buffer(leaf, &cache->item, bi, sizeof(cache->item)); in write_one_cache_group()
3287 struct btrfs_block_group_cache *cache) in next_block_group() argument
3294 if (RB_EMPTY_NODE(&cache->cache_node)) { in next_block_group()
3295 const u64 next_bytenr = cache->key.objectid + cache->key.offset; in next_block_group()
3298 btrfs_put_block_group(cache); in next_block_group()
3299 cache = btrfs_lookup_first_block_group(root->fs_info, in next_block_group()
3301 return cache; in next_block_group()
3303 node = rb_next(&cache->cache_node); in next_block_group()
3304 btrfs_put_block_group(cache); in next_block_group()
3306 cache = rb_entry(node, struct btrfs_block_group_cache, in next_block_group()
3308 btrfs_get_block_group(cache); in next_block_group()
3310 cache = NULL; in next_block_group()
3312 return cache; in next_block_group()
3476 struct btrfs_block_group_cache *cache, *tmp; in btrfs_setup_space_cache() local
3489 list_for_each_entry_safe(cache, tmp, &cur_trans->dirty_bgs, in btrfs_setup_space_cache()
3491 if (cache->disk_cache_state == BTRFS_DC_CLEAR) in btrfs_setup_space_cache()
3492 cache_save_setup(cache, trans, path); in btrfs_setup_space_cache()
3514 struct btrfs_block_group_cache *cache; in btrfs_start_dirty_block_groups() local
3552 cache = list_first_entry(&dirty, in btrfs_start_dirty_block_groups()
3560 if (!list_empty(&cache->io_list)) { in btrfs_start_dirty_block_groups()
3561 list_del_init(&cache->io_list); in btrfs_start_dirty_block_groups()
3562 btrfs_wait_cache_io(root, trans, cache, in btrfs_start_dirty_block_groups()
3563 &cache->io_ctl, path, in btrfs_start_dirty_block_groups()
3564 cache->key.objectid); in btrfs_start_dirty_block_groups()
3565 btrfs_put_block_group(cache); in btrfs_start_dirty_block_groups()
3578 list_del_init(&cache->dirty_list); in btrfs_start_dirty_block_groups()
3583 cache_save_setup(cache, trans, path); in btrfs_start_dirty_block_groups()
3585 if (cache->disk_cache_state == BTRFS_DC_SETUP) { in btrfs_start_dirty_block_groups()
3586 cache->io_ctl.inode = NULL; in btrfs_start_dirty_block_groups()
3587 ret = btrfs_write_out_cache(root, trans, cache, path); in btrfs_start_dirty_block_groups()
3588 if (ret == 0 && cache->io_ctl.inode) { in btrfs_start_dirty_block_groups()
3596 list_add_tail(&cache->io_list, io); in btrfs_start_dirty_block_groups()
3606 ret = write_one_cache_group(trans, root, path, cache); in btrfs_start_dirty_block_groups()
3619 if (list_empty(&cache->dirty_list)) { in btrfs_start_dirty_block_groups()
3620 list_add_tail(&cache->dirty_list, in btrfs_start_dirty_block_groups()
3622 btrfs_get_block_group(cache); in btrfs_start_dirty_block_groups()
3632 btrfs_put_block_group(cache); in btrfs_start_dirty_block_groups()
3674 struct btrfs_block_group_cache *cache; in btrfs_write_dirty_block_groups() local
3693 cache = list_first_entry(&cur_trans->dirty_bgs, in btrfs_write_dirty_block_groups()
3702 if (!list_empty(&cache->io_list)) { in btrfs_write_dirty_block_groups()
3703 list_del_init(&cache->io_list); in btrfs_write_dirty_block_groups()
3704 btrfs_wait_cache_io(root, trans, cache, in btrfs_write_dirty_block_groups()
3705 &cache->io_ctl, path, in btrfs_write_dirty_block_groups()
3706 cache->key.objectid); in btrfs_write_dirty_block_groups()
3707 btrfs_put_block_group(cache); in btrfs_write_dirty_block_groups()
3714 list_del_init(&cache->dirty_list); in btrfs_write_dirty_block_groups()
3717 cache_save_setup(cache, trans, path); in btrfs_write_dirty_block_groups()
3722 if (!ret && cache->disk_cache_state == BTRFS_DC_SETUP) { in btrfs_write_dirty_block_groups()
3723 cache->io_ctl.inode = NULL; in btrfs_write_dirty_block_groups()
3724 ret = btrfs_write_out_cache(root, trans, cache, path); in btrfs_write_dirty_block_groups()
3725 if (ret == 0 && cache->io_ctl.inode) { in btrfs_write_dirty_block_groups()
3728 list_add_tail(&cache->io_list, io); in btrfs_write_dirty_block_groups()
3738 ret = write_one_cache_group(trans, root, path, cache); in btrfs_write_dirty_block_groups()
3745 btrfs_put_block_group(cache); in btrfs_write_dirty_block_groups()
3749 cache = list_first_entry(io, struct btrfs_block_group_cache, in btrfs_write_dirty_block_groups()
3751 list_del_init(&cache->io_list); in btrfs_write_dirty_block_groups()
3752 btrfs_wait_cache_io(root, trans, cache, in btrfs_write_dirty_block_groups()
3753 &cache->io_ctl, path, cache->key.objectid); in btrfs_write_dirty_block_groups()
3754 btrfs_put_block_group(cache); in btrfs_write_dirty_block_groups()
5851 struct btrfs_block_group_cache *cache = NULL; in update_block_group() local
5869 cache = btrfs_lookup_block_group(info, bytenr); in update_block_group()
5870 if (!cache) in update_block_group()
5872 if (cache->flags & (BTRFS_BLOCK_GROUP_DUP | in update_block_group()
5884 if (!alloc && cache->cached == BTRFS_CACHE_NO) in update_block_group()
5885 cache_block_group(cache, 1); in update_block_group()
5887 byte_in_group = bytenr - cache->key.objectid; in update_block_group()
5888 WARN_ON(byte_in_group > cache->key.offset); in update_block_group()
5890 spin_lock(&cache->space_info->lock); in update_block_group()
5891 spin_lock(&cache->lock); in update_block_group()
5894 cache->disk_cache_state < BTRFS_DC_CLEAR) in update_block_group()
5895 cache->disk_cache_state = BTRFS_DC_CLEAR; in update_block_group()
5897 old_val = btrfs_block_group_used(&cache->item); in update_block_group()
5898 num_bytes = min(total, cache->key.offset - byte_in_group); in update_block_group()
5901 btrfs_set_block_group_used(&cache->item, old_val); in update_block_group()
5902 cache->reserved -= num_bytes; in update_block_group()
5903 cache->space_info->bytes_reserved -= num_bytes; in update_block_group()
5904 cache->space_info->bytes_used += num_bytes; in update_block_group()
5905 cache->space_info->disk_used += num_bytes * factor; in update_block_group()
5906 spin_unlock(&cache->lock); in update_block_group()
5907 spin_unlock(&cache->space_info->lock); in update_block_group()
5910 btrfs_set_block_group_used(&cache->item, old_val); in update_block_group()
5911 cache->pinned += num_bytes; in update_block_group()
5912 cache->space_info->bytes_pinned += num_bytes; in update_block_group()
5913 cache->space_info->bytes_used -= num_bytes; in update_block_group()
5914 cache->space_info->disk_used -= num_bytes * factor; in update_block_group()
5915 spin_unlock(&cache->lock); in update_block_group()
5916 spin_unlock(&cache->space_info->lock); in update_block_group()
5924 if (list_empty(&cache->dirty_list)) { in update_block_group()
5925 list_add_tail(&cache->dirty_list, in update_block_group()
5928 btrfs_get_block_group(cache); in update_block_group()
5940 if (list_empty(&cache->bg_list)) { in update_block_group()
5941 btrfs_get_block_group(cache); in update_block_group()
5942 list_add_tail(&cache->bg_list, in update_block_group()
5948 btrfs_put_block_group(cache); in update_block_group()
5957 struct btrfs_block_group_cache *cache; in first_logical_byte() local
5967 cache = btrfs_lookup_first_block_group(root->fs_info, search_start); in first_logical_byte()
5968 if (!cache) in first_logical_byte()
5971 bytenr = cache->key.objectid; in first_logical_byte()
5972 btrfs_put_block_group(cache); in first_logical_byte()
5978 struct btrfs_block_group_cache *cache, in pin_down_extent() argument
5981 spin_lock(&cache->space_info->lock); in pin_down_extent()
5982 spin_lock(&cache->lock); in pin_down_extent()
5983 cache->pinned += num_bytes; in pin_down_extent()
5984 cache->space_info->bytes_pinned += num_bytes; in pin_down_extent()
5986 cache->reserved -= num_bytes; in pin_down_extent()
5987 cache->space_info->bytes_reserved -= num_bytes; in pin_down_extent()
5989 spin_unlock(&cache->lock); in pin_down_extent()
5990 spin_unlock(&cache->space_info->lock); in pin_down_extent()
6005 struct btrfs_block_group_cache *cache; in btrfs_pin_extent() local
6007 cache = btrfs_lookup_block_group(root->fs_info, bytenr); in btrfs_pin_extent()
6008 BUG_ON(!cache); /* Logic error */ in btrfs_pin_extent()
6010 pin_down_extent(root, cache, bytenr, num_bytes, reserved); in btrfs_pin_extent()
6012 btrfs_put_block_group(cache); in btrfs_pin_extent()
6022 struct btrfs_block_group_cache *cache; in btrfs_pin_extent_for_log_replay() local
6025 cache = btrfs_lookup_block_group(root->fs_info, bytenr); in btrfs_pin_extent_for_log_replay()
6026 if (!cache) in btrfs_pin_extent_for_log_replay()
6035 cache_block_group(cache, 1); in btrfs_pin_extent_for_log_replay()
6037 pin_down_extent(root, cache, bytenr, num_bytes, 0); in btrfs_pin_extent_for_log_replay()
6040 ret = btrfs_remove_free_space(cache, bytenr, num_bytes); in btrfs_pin_extent_for_log_replay()
6041 btrfs_put_block_group(cache); in btrfs_pin_extent_for_log_replay()
6142 static int btrfs_update_reserved_bytes(struct btrfs_block_group_cache *cache, in btrfs_update_reserved_bytes() argument
6145 struct btrfs_space_info *space_info = cache->space_info; in btrfs_update_reserved_bytes()
6149 spin_lock(&cache->lock); in btrfs_update_reserved_bytes()
6151 if (cache->ro) { in btrfs_update_reserved_bytes()
6154 cache->reserved += num_bytes; in btrfs_update_reserved_bytes()
6157 trace_btrfs_space_reservation(cache->fs_info, in btrfs_update_reserved_bytes()
6164 cache->delalloc_bytes += num_bytes; in btrfs_update_reserved_bytes()
6167 if (cache->ro) in btrfs_update_reserved_bytes()
6169 cache->reserved -= num_bytes; in btrfs_update_reserved_bytes()
6173 cache->delalloc_bytes -= num_bytes; in btrfs_update_reserved_bytes()
6175 spin_unlock(&cache->lock); in btrfs_update_reserved_bytes()
6186 struct btrfs_block_group_cache *cache; in btrfs_prepare_extent_commit() local
6192 cache = caching_ctl->block_group; in btrfs_prepare_extent_commit()
6193 if (block_group_cache_done(cache)) { in btrfs_prepare_extent_commit()
6194 cache->last_byte_to_unpin = (u64)-1; in btrfs_prepare_extent_commit()
6198 cache->last_byte_to_unpin = caching_ctl->progress; in btrfs_prepare_extent_commit()
6244 struct btrfs_block_group_cache *cache = NULL; in unpin_extent_range() local
6255 if (!cache || in unpin_extent_range()
6256 start >= cache->key.objectid + cache->key.offset) { in unpin_extent_range()
6257 if (cache) in unpin_extent_range()
6258 btrfs_put_block_group(cache); in unpin_extent_range()
6260 cache = btrfs_lookup_block_group(fs_info, start); in unpin_extent_range()
6261 BUG_ON(!cache); /* Logic error */ in unpin_extent_range()
6264 cache->space_info, in unpin_extent_range()
6269 len = cache->key.objectid + cache->key.offset - start; in unpin_extent_range()
6272 if (start < cache->last_byte_to_unpin) { in unpin_extent_range()
6273 len = min(len, cache->last_byte_to_unpin - start); in unpin_extent_range()
6275 btrfs_add_free_space(cache, start, len); in unpin_extent_range()
6280 space_info = cache->space_info; in unpin_extent_range()
6296 spin_lock(&cache->lock); in unpin_extent_range()
6297 cache->pinned -= len; in unpin_extent_range()
6301 if (cache->ro) { in unpin_extent_range()
6305 spin_unlock(&cache->lock); in unpin_extent_range()
6321 if (cache) in unpin_extent_range()
6322 btrfs_put_block_group(cache); in unpin_extent_range()
6773 struct btrfs_block_group_cache *cache; in btrfs_free_tree_block() local
6781 cache = btrfs_lookup_block_group(root->fs_info, buf->start); in btrfs_free_tree_block()
6784 pin_down_extent(root, cache, buf->start, buf->len, 1); in btrfs_free_tree_block()
6785 btrfs_put_block_group(cache); in btrfs_free_tree_block()
6791 btrfs_add_free_space(cache, buf->start, buf->len); in btrfs_free_tree_block()
6792 btrfs_update_reserved_bytes(cache, buf->len, RESERVE_FREE, 0); in btrfs_free_tree_block()
6793 btrfs_put_block_group(cache); in btrfs_free_tree_block()
6862 wait_block_group_cache_progress(struct btrfs_block_group_cache *cache, in wait_block_group_cache_progress() argument
6867 caching_ctl = get_caching_control(cache); in wait_block_group_cache_progress()
6871 wait_event(caching_ctl->wait, block_group_cache_done(cache) || in wait_block_group_cache_progress()
6872 (cache->free_space_ctl->free_space >= num_bytes)); in wait_block_group_cache_progress()
6878 wait_block_group_cache_done(struct btrfs_block_group_cache *cache) in wait_block_group_cache_done() argument
6883 caching_ctl = get_caching_control(cache); in wait_block_group_cache_done()
6885 return (cache->cached == BTRFS_CACHE_ERROR) ? -EIO : 0; in wait_block_group_cache_done()
6887 wait_event(caching_ctl->wait, block_group_cache_done(cache)); in wait_block_group_cache_done()
6888 if (cache->cached == BTRFS_CACHE_ERROR) in wait_block_group_cache_done()
6912 int get_block_group_index(struct btrfs_block_group_cache *cache) in get_block_group_index() argument
6914 return __get_raid_index(cache->flags); in get_block_group_index()
6943 btrfs_lock_block_group(struct btrfs_block_group_cache *cache, in btrfs_lock_block_group() argument
6947 down_read(&cache->data_rwsem); in btrfs_lock_block_group()
6951 btrfs_grab_block_group(struct btrfs_block_group_cache *cache, in btrfs_grab_block_group() argument
6954 btrfs_get_block_group(cache); in btrfs_grab_block_group()
6956 down_read(&cache->data_rwsem); in btrfs_grab_block_group()
6998 btrfs_release_block_group(struct btrfs_block_group_cache *cache, in btrfs_release_block_group() argument
7002 up_read(&cache->data_rwsem); in btrfs_release_block_group()
7003 btrfs_put_block_group(cache); in btrfs_release_block_group()
7501 struct btrfs_block_group_cache *cache; in dump_space_info() local
7522 list_for_each_entry(cache, &info->block_groups[index], list) { in dump_space_info()
7523 spin_lock(&cache->lock); in dump_space_info()
7527 cache->key.objectid, cache->key.offset, in dump_space_info()
7528 btrfs_block_group_used(&cache->item), cache->pinned, in dump_space_info()
7529 cache->reserved, cache->ro ? "[readonly]" : ""); in dump_space_info()
7530 btrfs_dump_free_space(cache, bytes); in dump_space_info()
7531 spin_unlock(&cache->lock); in dump_space_info()
7579 struct btrfs_block_group_cache *cache; in __btrfs_free_reserved_extent() local
7582 cache = btrfs_lookup_block_group(root->fs_info, start); in __btrfs_free_reserved_extent()
7583 if (!cache) { in __btrfs_free_reserved_extent()
7590 pin_down_extent(root, cache, start, len, 1); in __btrfs_free_reserved_extent()
7594 btrfs_add_free_space(cache, start, len); in __btrfs_free_reserved_extent()
7595 btrfs_update_reserved_bytes(cache, len, RESERVE_FREE, delalloc); in __btrfs_free_reserved_extent()
7598 btrfs_put_block_group(cache); in __btrfs_free_reserved_extent()
9115 static int inc_block_group_ro(struct btrfs_block_group_cache *cache, int force) in inc_block_group_ro() argument
9117 struct btrfs_space_info *sinfo = cache->space_info; in inc_block_group_ro()
9135 spin_lock(&cache->lock); in inc_block_group_ro()
9137 if (cache->ro) { in inc_block_group_ro()
9138 cache->ro++; in inc_block_group_ro()
9143 num_bytes = cache->key.offset - cache->reserved - cache->pinned - in inc_block_group_ro()
9144 cache->bytes_super - btrfs_block_group_used(&cache->item); in inc_block_group_ro()
9150 cache->ro++; in inc_block_group_ro()
9151 list_add_tail(&cache->ro_list, &sinfo->ro_bgs); in inc_block_group_ro()
9155 spin_unlock(&cache->lock); in inc_block_group_ro()
9161 struct btrfs_block_group_cache *cache) in btrfs_inc_block_group_ro() argument
9195 alloc_flags = update_block_group_flags(root, cache->flags); in btrfs_inc_block_group_ro()
9196 if (alloc_flags != cache->flags) { in btrfs_inc_block_group_ro()
9210 ret = inc_block_group_ro(cache, 0); in btrfs_inc_block_group_ro()
9213 alloc_flags = get_alloc_profile(root, cache->space_info->flags); in btrfs_inc_block_group_ro()
9218 ret = inc_block_group_ro(cache, 0); in btrfs_inc_block_group_ro()
9220 if (cache->flags & BTRFS_BLOCK_GROUP_SYSTEM) { in btrfs_inc_block_group_ro()
9221 alloc_flags = update_block_group_flags(root, cache->flags); in btrfs_inc_block_group_ro()
9282 struct btrfs_block_group_cache *cache) in btrfs_dec_block_group_ro() argument
9284 struct btrfs_space_info *sinfo = cache->space_info; in btrfs_dec_block_group_ro()
9287 BUG_ON(!cache->ro); in btrfs_dec_block_group_ro()
9290 spin_lock(&cache->lock); in btrfs_dec_block_group_ro()
9291 if (!--cache->ro) { in btrfs_dec_block_group_ro()
9292 num_bytes = cache->key.offset - cache->reserved - in btrfs_dec_block_group_ro()
9293 cache->pinned - cache->bytes_super - in btrfs_dec_block_group_ro()
9294 btrfs_block_group_used(&cache->item); in btrfs_dec_block_group_ro()
9296 list_del_init(&cache->ro_list); in btrfs_dec_block_group_ro()
9298 spin_unlock(&cache->lock); in btrfs_dec_block_group_ro()
9603 struct btrfs_block_group_cache *cache) in __link_block_group() argument
9605 int index = get_block_group_index(cache); in __link_block_group()
9611 list_add_tail(&cache->list, &space_info->block_groups[index]); in __link_block_group()
9640 struct btrfs_block_group_cache *cache; in btrfs_create_block_group_cache() local
9642 cache = kzalloc(sizeof(*cache), GFP_NOFS); in btrfs_create_block_group_cache()
9643 if (!cache) in btrfs_create_block_group_cache()
9646 cache->free_space_ctl = kzalloc(sizeof(*cache->free_space_ctl), in btrfs_create_block_group_cache()
9648 if (!cache->free_space_ctl) { in btrfs_create_block_group_cache()
9649 kfree(cache); in btrfs_create_block_group_cache()
9653 cache->key.objectid = start; in btrfs_create_block_group_cache()
9654 cache->key.offset = size; in btrfs_create_block_group_cache()
9655 cache->key.type = BTRFS_BLOCK_GROUP_ITEM_KEY; in btrfs_create_block_group_cache()
9657 cache->sectorsize = root->sectorsize; in btrfs_create_block_group_cache()
9658 cache->fs_info = root->fs_info; in btrfs_create_block_group_cache()
9659 cache->full_stripe_len = btrfs_full_stripe_len(root, in btrfs_create_block_group_cache()
9662 atomic_set(&cache->count, 1); in btrfs_create_block_group_cache()
9663 spin_lock_init(&cache->lock); in btrfs_create_block_group_cache()
9664 init_rwsem(&cache->data_rwsem); in btrfs_create_block_group_cache()
9665 INIT_LIST_HEAD(&cache->list); in btrfs_create_block_group_cache()
9666 INIT_LIST_HEAD(&cache->cluster_list); in btrfs_create_block_group_cache()
9667 INIT_LIST_HEAD(&cache->bg_list); in btrfs_create_block_group_cache()
9668 INIT_LIST_HEAD(&cache->ro_list); in btrfs_create_block_group_cache()
9669 INIT_LIST_HEAD(&cache->dirty_list); in btrfs_create_block_group_cache()
9670 INIT_LIST_HEAD(&cache->io_list); in btrfs_create_block_group_cache()
9671 btrfs_init_free_space_ctl(cache); in btrfs_create_block_group_cache()
9672 atomic_set(&cache->trimming, 0); in btrfs_create_block_group_cache()
9674 return cache; in btrfs_create_block_group_cache()
9681 struct btrfs_block_group_cache *cache; in btrfs_read_block_groups() local
9716 cache = btrfs_create_block_group_cache(root, found_key.objectid, in btrfs_read_block_groups()
9718 if (!cache) { in btrfs_read_block_groups()
9735 cache->disk_cache_state = BTRFS_DC_CLEAR; in btrfs_read_block_groups()
9738 read_extent_buffer(leaf, &cache->item, in btrfs_read_block_groups()
9740 sizeof(cache->item)); in btrfs_read_block_groups()
9741 cache->flags = btrfs_block_group_flags(&cache->item); in btrfs_read_block_groups()
9751 ret = exclude_super_stripes(root, cache); in btrfs_read_block_groups()
9757 free_excluded_extents(root, cache); in btrfs_read_block_groups()
9758 btrfs_put_block_group(cache); in btrfs_read_block_groups()
9769 if (found_key.offset == btrfs_block_group_used(&cache->item)) { in btrfs_read_block_groups()
9770 cache->last_byte_to_unpin = (u64)-1; in btrfs_read_block_groups()
9771 cache->cached = BTRFS_CACHE_FINISHED; in btrfs_read_block_groups()
9772 free_excluded_extents(root, cache); in btrfs_read_block_groups()
9773 } else if (btrfs_block_group_used(&cache->item) == 0) { in btrfs_read_block_groups()
9774 cache->last_byte_to_unpin = (u64)-1; in btrfs_read_block_groups()
9775 cache->cached = BTRFS_CACHE_FINISHED; in btrfs_read_block_groups()
9776 add_new_free_space(cache, root->fs_info, in btrfs_read_block_groups()
9780 free_excluded_extents(root, cache); in btrfs_read_block_groups()
9783 ret = btrfs_add_block_group_cache(root->fs_info, cache); in btrfs_read_block_groups()
9785 btrfs_remove_free_space_cache(cache); in btrfs_read_block_groups()
9786 btrfs_put_block_group(cache); in btrfs_read_block_groups()
9790 ret = update_space_info(info, cache->flags, found_key.offset, in btrfs_read_block_groups()
9791 btrfs_block_group_used(&cache->item), in btrfs_read_block_groups()
9794 btrfs_remove_free_space_cache(cache); in btrfs_read_block_groups()
9796 rb_erase(&cache->cache_node, in btrfs_read_block_groups()
9798 RB_CLEAR_NODE(&cache->cache_node); in btrfs_read_block_groups()
9800 btrfs_put_block_group(cache); in btrfs_read_block_groups()
9804 cache->space_info = space_info; in btrfs_read_block_groups()
9805 spin_lock(&cache->space_info->lock); in btrfs_read_block_groups()
9806 cache->space_info->bytes_readonly += cache->bytes_super; in btrfs_read_block_groups()
9807 spin_unlock(&cache->space_info->lock); in btrfs_read_block_groups()
9809 __link_block_group(space_info, cache); in btrfs_read_block_groups()
9811 set_avail_alloc_bits(root->fs_info, cache->flags); in btrfs_read_block_groups()
9812 if (btrfs_chunk_readonly(root, cache->key.objectid)) { in btrfs_read_block_groups()
9813 inc_block_group_ro(cache, 1); in btrfs_read_block_groups()
9814 } else if (btrfs_block_group_used(&cache->item) == 0) { in btrfs_read_block_groups()
9817 if (list_empty(&cache->bg_list)) { in btrfs_read_block_groups()
9818 btrfs_get_block_group(cache); in btrfs_read_block_groups()
9819 list_add_tail(&cache->bg_list, in btrfs_read_block_groups()
9838 list_for_each_entry(cache, in btrfs_read_block_groups()
9841 inc_block_group_ro(cache, 1); in btrfs_read_block_groups()
9842 list_for_each_entry(cache, in btrfs_read_block_groups()
9845 inc_block_group_ro(cache, 1); in btrfs_read_block_groups()
9896 struct btrfs_block_group_cache *cache; in btrfs_make_block_group() local
9902 cache = btrfs_create_block_group_cache(root, chunk_offset, size); in btrfs_make_block_group()
9903 if (!cache) in btrfs_make_block_group()
9906 btrfs_set_block_group_used(&cache->item, bytes_used); in btrfs_make_block_group()
9907 btrfs_set_block_group_chunk_objectid(&cache->item, chunk_objectid); in btrfs_make_block_group()
9908 btrfs_set_block_group_flags(&cache->item, type); in btrfs_make_block_group()
9910 cache->flags = type; in btrfs_make_block_group()
9911 cache->last_byte_to_unpin = (u64)-1; in btrfs_make_block_group()
9912 cache->cached = BTRFS_CACHE_FINISHED; in btrfs_make_block_group()
9913 ret = exclude_super_stripes(root, cache); in btrfs_make_block_group()
9919 free_excluded_extents(root, cache); in btrfs_make_block_group()
9920 btrfs_put_block_group(cache); in btrfs_make_block_group()
9924 add_new_free_space(cache, root->fs_info, chunk_offset, in btrfs_make_block_group()
9927 free_excluded_extents(root, cache); in btrfs_make_block_group()
9930 if (btrfs_should_fragment_free_space(root, cache)) { in btrfs_make_block_group()
9934 fragment_free_space(root, cache); in btrfs_make_block_group()
9942 ret = update_space_info(root->fs_info, cache->flags, 0, 0, in btrfs_make_block_group()
9943 &cache->space_info); in btrfs_make_block_group()
9945 btrfs_remove_free_space_cache(cache); in btrfs_make_block_group()
9946 btrfs_put_block_group(cache); in btrfs_make_block_group()
9950 ret = btrfs_add_block_group_cache(root->fs_info, cache); in btrfs_make_block_group()
9952 btrfs_remove_free_space_cache(cache); in btrfs_make_block_group()
9953 btrfs_put_block_group(cache); in btrfs_make_block_group()
9961 ret = update_space_info(root->fs_info, cache->flags, size, bytes_used, in btrfs_make_block_group()
9962 &cache->space_info); in btrfs_make_block_group()
9964 btrfs_remove_free_space_cache(cache); in btrfs_make_block_group()
9966 rb_erase(&cache->cache_node, in btrfs_make_block_group()
9968 RB_CLEAR_NODE(&cache->cache_node); in btrfs_make_block_group()
9970 btrfs_put_block_group(cache); in btrfs_make_block_group()
9975 spin_lock(&cache->space_info->lock); in btrfs_make_block_group()
9976 cache->space_info->bytes_readonly += cache->bytes_super; in btrfs_make_block_group()
9977 spin_unlock(&cache->space_info->lock); in btrfs_make_block_group()
9979 __link_block_group(cache->space_info, cache); in btrfs_make_block_group()
9981 list_add_tail(&cache->bg_list, &trans->new_bgs); in btrfs_make_block_group()
10640 struct btrfs_block_group_cache *cache = NULL; in btrfs_trim_fs() local
10654 cache = btrfs_lookup_first_block_group(fs_info, range->start); in btrfs_trim_fs()
10656 cache = btrfs_lookup_block_group(fs_info, range->start); in btrfs_trim_fs()
10658 while (cache) { in btrfs_trim_fs()
10659 if (cache->key.objectid >= (range->start + range->len)) { in btrfs_trim_fs()
10660 btrfs_put_block_group(cache); in btrfs_trim_fs()
10664 start = max(range->start, cache->key.objectid); in btrfs_trim_fs()
10666 cache->key.objectid + cache->key.offset); in btrfs_trim_fs()
10669 if (!block_group_cache_done(cache)) { in btrfs_trim_fs()
10670 ret = cache_block_group(cache, 0); in btrfs_trim_fs()
10672 btrfs_put_block_group(cache); in btrfs_trim_fs()
10675 ret = wait_block_group_cache_done(cache); in btrfs_trim_fs()
10677 btrfs_put_block_group(cache); in btrfs_trim_fs()
10681 ret = btrfs_trim_block_group(cache, in btrfs_trim_fs()
10689 btrfs_put_block_group(cache); in btrfs_trim_fs()
10694 cache = next_block_group(fs_info->tree_root, cache); in btrfs_trim_fs()