Lines Matching refs:cache
108 static int btrfs_update_reserved_bytes(struct btrfs_block_group_cache *cache,
117 block_group_cache_done(struct btrfs_block_group_cache *cache) in block_group_cache_done() argument
120 return cache->cached == BTRFS_CACHE_FINISHED || in block_group_cache_done()
121 cache->cached == BTRFS_CACHE_ERROR; in block_group_cache_done()
124 static int block_group_bits(struct btrfs_block_group_cache *cache, u64 bits) in block_group_bits() argument
126 return (cache->flags & bits) == bits; in block_group_bits()
129 static void btrfs_get_block_group(struct btrfs_block_group_cache *cache) in btrfs_get_block_group() argument
131 atomic_inc(&cache->count); in btrfs_get_block_group()
134 void btrfs_put_block_group(struct btrfs_block_group_cache *cache) in btrfs_put_block_group() argument
136 if (atomic_dec_and_test(&cache->count)) { in btrfs_put_block_group()
137 WARN_ON(cache->pinned > 0); in btrfs_put_block_group()
138 WARN_ON(cache->reserved > 0); in btrfs_put_block_group()
139 kfree(cache->free_space_ctl); in btrfs_put_block_group()
140 kfree(cache); in btrfs_put_block_group()
153 struct btrfs_block_group_cache *cache; in btrfs_add_block_group_cache() local
160 cache = rb_entry(parent, struct btrfs_block_group_cache, in btrfs_add_block_group_cache()
162 if (block_group->key.objectid < cache->key.objectid) { in btrfs_add_block_group_cache()
164 } else if (block_group->key.objectid > cache->key.objectid) { in btrfs_add_block_group_cache()
192 struct btrfs_block_group_cache *cache, *ret = NULL; in block_group_cache_tree_search() local
200 cache = rb_entry(n, struct btrfs_block_group_cache, in block_group_cache_tree_search()
202 end = cache->key.objectid + cache->key.offset - 1; in block_group_cache_tree_search()
203 start = cache->key.objectid; in block_group_cache_tree_search()
207 ret = cache; in block_group_cache_tree_search()
211 ret = cache; in block_group_cache_tree_search()
216 ret = cache; in block_group_cache_tree_search()
242 struct btrfs_block_group_cache *cache) in free_excluded_extents() argument
246 start = cache->key.objectid; in free_excluded_extents()
247 end = start + cache->key.offset - 1; in free_excluded_extents()
256 struct btrfs_block_group_cache *cache) in exclude_super_stripes() argument
263 if (cache->key.objectid < BTRFS_SUPER_INFO_OFFSET) { in exclude_super_stripes()
264 stripe_len = BTRFS_SUPER_INFO_OFFSET - cache->key.objectid; in exclude_super_stripes()
265 cache->bytes_super += stripe_len; in exclude_super_stripes()
266 ret = add_excluded_extent(root, cache->key.objectid, in exclude_super_stripes()
275 cache->key.objectid, bytenr, in exclude_super_stripes()
283 if (logical[nr] > cache->key.objectid + in exclude_super_stripes()
284 cache->key.offset) in exclude_super_stripes()
287 if (logical[nr] + stripe_len <= cache->key.objectid) in exclude_super_stripes()
291 if (start < cache->key.objectid) { in exclude_super_stripes()
292 start = cache->key.objectid; in exclude_super_stripes()
296 cache->key.objectid + in exclude_super_stripes()
297 cache->key.offset - start); in exclude_super_stripes()
300 cache->bytes_super += len; in exclude_super_stripes()
314 get_caching_control(struct btrfs_block_group_cache *cache) in get_caching_control() argument
318 spin_lock(&cache->lock); in get_caching_control()
319 if (!cache->caching_ctl) { in get_caching_control()
320 spin_unlock(&cache->lock); in get_caching_control()
324 ctl = cache->caching_ctl; in get_caching_control()
326 spin_unlock(&cache->lock); in get_caching_control()
532 static int cache_block_group(struct btrfs_block_group_cache *cache, in cache_block_group() argument
536 struct btrfs_fs_info *fs_info = cache->fs_info; in cache_block_group()
547 caching_ctl->block_group = cache; in cache_block_group()
548 caching_ctl->progress = cache->key.objectid; in cache_block_group()
553 spin_lock(&cache->lock); in cache_block_group()
566 while (cache->cached == BTRFS_CACHE_FAST) { in cache_block_group()
569 ctl = cache->caching_ctl; in cache_block_group()
572 spin_unlock(&cache->lock); in cache_block_group()
578 spin_lock(&cache->lock); in cache_block_group()
581 if (cache->cached != BTRFS_CACHE_NO) { in cache_block_group()
582 spin_unlock(&cache->lock); in cache_block_group()
586 WARN_ON(cache->caching_ctl); in cache_block_group()
587 cache->caching_ctl = caching_ctl; in cache_block_group()
588 cache->cached = BTRFS_CACHE_FAST; in cache_block_group()
589 spin_unlock(&cache->lock); in cache_block_group()
593 ret = load_free_space_cache(fs_info, cache); in cache_block_group()
595 spin_lock(&cache->lock); in cache_block_group()
597 cache->caching_ctl = NULL; in cache_block_group()
598 cache->cached = BTRFS_CACHE_FINISHED; in cache_block_group()
599 cache->last_byte_to_unpin = (u64)-1; in cache_block_group()
603 cache->caching_ctl = NULL; in cache_block_group()
604 cache->cached = BTRFS_CACHE_NO; in cache_block_group()
606 cache->cached = BTRFS_CACHE_STARTED; in cache_block_group()
607 cache->has_caching_ctl = 1; in cache_block_group()
610 spin_unlock(&cache->lock); in cache_block_group()
616 free_excluded_extents(fs_info->extent_root, cache); in cache_block_group()
624 spin_lock(&cache->lock); in cache_block_group()
626 cache->caching_ctl = NULL; in cache_block_group()
627 cache->cached = BTRFS_CACHE_NO; in cache_block_group()
629 cache->cached = BTRFS_CACHE_STARTED; in cache_block_group()
630 cache->has_caching_ctl = 1; in cache_block_group()
632 spin_unlock(&cache->lock); in cache_block_group()
646 btrfs_get_block_group(cache); in cache_block_group()
659 struct btrfs_block_group_cache *cache; in btrfs_lookup_first_block_group() local
661 cache = block_group_cache_tree_search(info, bytenr, 0); in btrfs_lookup_first_block_group()
663 return cache; in btrfs_lookup_first_block_group()
673 struct btrfs_block_group_cache *cache; in btrfs_lookup_block_group() local
675 cache = block_group_cache_tree_search(info, bytenr, 1); in btrfs_lookup_block_group()
677 return cache; in btrfs_lookup_block_group()
3163 struct btrfs_block_group_cache *cache) in write_one_cache_group() argument
3170 ret = btrfs_search_slot(trans, extent_root, &cache->key, path, 0, 1); in write_one_cache_group()
3179 write_extent_buffer(leaf, &cache->item, bi, sizeof(cache->item)); in write_one_cache_group()
3189 struct btrfs_block_group_cache *cache) in next_block_group() argument
3196 if (RB_EMPTY_NODE(&cache->cache_node)) { in next_block_group()
3197 const u64 next_bytenr = cache->key.objectid + cache->key.offset; in next_block_group()
3200 btrfs_put_block_group(cache); in next_block_group()
3201 cache = btrfs_lookup_first_block_group(root->fs_info, in next_block_group()
3203 return cache; in next_block_group()
3205 node = rb_next(&cache->cache_node); in next_block_group()
3206 btrfs_put_block_group(cache); in next_block_group()
3208 cache = rb_entry(node, struct btrfs_block_group_cache, in next_block_group()
3210 btrfs_get_block_group(cache); in next_block_group()
3212 cache = NULL; in next_block_group()
3214 return cache; in next_block_group()
3359 struct btrfs_block_group_cache *cache, *tmp; in btrfs_setup_space_cache() local
3372 list_for_each_entry_safe(cache, tmp, &cur_trans->dirty_bgs, in btrfs_setup_space_cache()
3374 if (cache->disk_cache_state == BTRFS_DC_CLEAR) in btrfs_setup_space_cache()
3375 cache_save_setup(cache, trans, path); in btrfs_setup_space_cache()
3397 struct btrfs_block_group_cache *cache; in btrfs_start_dirty_block_groups() local
3435 cache = list_first_entry(&dirty, in btrfs_start_dirty_block_groups()
3443 if (!list_empty(&cache->io_list)) { in btrfs_start_dirty_block_groups()
3444 list_del_init(&cache->io_list); in btrfs_start_dirty_block_groups()
3445 btrfs_wait_cache_io(root, trans, cache, in btrfs_start_dirty_block_groups()
3446 &cache->io_ctl, path, in btrfs_start_dirty_block_groups()
3447 cache->key.objectid); in btrfs_start_dirty_block_groups()
3448 btrfs_put_block_group(cache); in btrfs_start_dirty_block_groups()
3461 list_del_init(&cache->dirty_list); in btrfs_start_dirty_block_groups()
3466 cache_save_setup(cache, trans, path); in btrfs_start_dirty_block_groups()
3468 if (cache->disk_cache_state == BTRFS_DC_SETUP) { in btrfs_start_dirty_block_groups()
3469 cache->io_ctl.inode = NULL; in btrfs_start_dirty_block_groups()
3470 ret = btrfs_write_out_cache(root, trans, cache, path); in btrfs_start_dirty_block_groups()
3471 if (ret == 0 && cache->io_ctl.inode) { in btrfs_start_dirty_block_groups()
3479 list_add_tail(&cache->io_list, io); in btrfs_start_dirty_block_groups()
3489 ret = write_one_cache_group(trans, root, path, cache); in btrfs_start_dirty_block_groups()
3502 if (list_empty(&cache->dirty_list)) { in btrfs_start_dirty_block_groups()
3503 list_add_tail(&cache->dirty_list, in btrfs_start_dirty_block_groups()
3505 btrfs_get_block_group(cache); in btrfs_start_dirty_block_groups()
3515 btrfs_put_block_group(cache); in btrfs_start_dirty_block_groups()
3557 struct btrfs_block_group_cache *cache; in btrfs_write_dirty_block_groups() local
3576 cache = list_first_entry(&cur_trans->dirty_bgs, in btrfs_write_dirty_block_groups()
3585 if (!list_empty(&cache->io_list)) { in btrfs_write_dirty_block_groups()
3586 list_del_init(&cache->io_list); in btrfs_write_dirty_block_groups()
3587 btrfs_wait_cache_io(root, trans, cache, in btrfs_write_dirty_block_groups()
3588 &cache->io_ctl, path, in btrfs_write_dirty_block_groups()
3589 cache->key.objectid); in btrfs_write_dirty_block_groups()
3590 btrfs_put_block_group(cache); in btrfs_write_dirty_block_groups()
3597 list_del_init(&cache->dirty_list); in btrfs_write_dirty_block_groups()
3600 cache_save_setup(cache, trans, path); in btrfs_write_dirty_block_groups()
3605 if (!ret && cache->disk_cache_state == BTRFS_DC_SETUP) { in btrfs_write_dirty_block_groups()
3606 cache->io_ctl.inode = NULL; in btrfs_write_dirty_block_groups()
3607 ret = btrfs_write_out_cache(root, trans, cache, path); in btrfs_write_dirty_block_groups()
3608 if (ret == 0 && cache->io_ctl.inode) { in btrfs_write_dirty_block_groups()
3611 list_add_tail(&cache->io_list, io); in btrfs_write_dirty_block_groups()
3621 ret = write_one_cache_group(trans, root, path, cache); in btrfs_write_dirty_block_groups()
3628 btrfs_put_block_group(cache); in btrfs_write_dirty_block_groups()
3632 cache = list_first_entry(io, struct btrfs_block_group_cache, in btrfs_write_dirty_block_groups()
3634 list_del_init(&cache->io_list); in btrfs_write_dirty_block_groups()
3635 btrfs_wait_cache_io(root, trans, cache, in btrfs_write_dirty_block_groups()
3636 &cache->io_ctl, path, cache->key.objectid); in btrfs_write_dirty_block_groups()
3637 btrfs_put_block_group(cache); in btrfs_write_dirty_block_groups()
5619 struct btrfs_block_group_cache *cache = NULL; in update_block_group() local
5637 cache = btrfs_lookup_block_group(info, bytenr); in update_block_group()
5638 if (!cache) in update_block_group()
5640 if (cache->flags & (BTRFS_BLOCK_GROUP_DUP | in update_block_group()
5652 if (!alloc && cache->cached == BTRFS_CACHE_NO) in update_block_group()
5653 cache_block_group(cache, 1); in update_block_group()
5655 byte_in_group = bytenr - cache->key.objectid; in update_block_group()
5656 WARN_ON(byte_in_group > cache->key.offset); in update_block_group()
5658 spin_lock(&cache->space_info->lock); in update_block_group()
5659 spin_lock(&cache->lock); in update_block_group()
5662 cache->disk_cache_state < BTRFS_DC_CLEAR) in update_block_group()
5663 cache->disk_cache_state = BTRFS_DC_CLEAR; in update_block_group()
5665 old_val = btrfs_block_group_used(&cache->item); in update_block_group()
5666 num_bytes = min(total, cache->key.offset - byte_in_group); in update_block_group()
5669 btrfs_set_block_group_used(&cache->item, old_val); in update_block_group()
5670 cache->reserved -= num_bytes; in update_block_group()
5671 cache->space_info->bytes_reserved -= num_bytes; in update_block_group()
5672 cache->space_info->bytes_used += num_bytes; in update_block_group()
5673 cache->space_info->disk_used += num_bytes * factor; in update_block_group()
5674 spin_unlock(&cache->lock); in update_block_group()
5675 spin_unlock(&cache->space_info->lock); in update_block_group()
5678 btrfs_set_block_group_used(&cache->item, old_val); in update_block_group()
5679 cache->pinned += num_bytes; in update_block_group()
5680 cache->space_info->bytes_pinned += num_bytes; in update_block_group()
5681 cache->space_info->bytes_used -= num_bytes; in update_block_group()
5682 cache->space_info->disk_used -= num_bytes * factor; in update_block_group()
5683 spin_unlock(&cache->lock); in update_block_group()
5684 spin_unlock(&cache->space_info->lock); in update_block_group()
5695 if (list_empty(&cache->bg_list)) { in update_block_group()
5696 btrfs_get_block_group(cache); in update_block_group()
5697 list_add_tail(&cache->bg_list, in update_block_group()
5705 if (list_empty(&cache->dirty_list)) { in update_block_group()
5706 list_add_tail(&cache->dirty_list, in update_block_group()
5709 btrfs_get_block_group(cache); in update_block_group()
5713 btrfs_put_block_group(cache); in update_block_group()
5722 struct btrfs_block_group_cache *cache; in first_logical_byte() local
5732 cache = btrfs_lookup_first_block_group(root->fs_info, search_start); in first_logical_byte()
5733 if (!cache) in first_logical_byte()
5736 bytenr = cache->key.objectid; in first_logical_byte()
5737 btrfs_put_block_group(cache); in first_logical_byte()
5743 struct btrfs_block_group_cache *cache, in pin_down_extent() argument
5746 spin_lock(&cache->space_info->lock); in pin_down_extent()
5747 spin_lock(&cache->lock); in pin_down_extent()
5748 cache->pinned += num_bytes; in pin_down_extent()
5749 cache->space_info->bytes_pinned += num_bytes; in pin_down_extent()
5751 cache->reserved -= num_bytes; in pin_down_extent()
5752 cache->space_info->bytes_reserved -= num_bytes; in pin_down_extent()
5754 spin_unlock(&cache->lock); in pin_down_extent()
5755 spin_unlock(&cache->space_info->lock); in pin_down_extent()
5770 struct btrfs_block_group_cache *cache; in btrfs_pin_extent() local
5772 cache = btrfs_lookup_block_group(root->fs_info, bytenr); in btrfs_pin_extent()
5773 BUG_ON(!cache); /* Logic error */ in btrfs_pin_extent()
5775 pin_down_extent(root, cache, bytenr, num_bytes, reserved); in btrfs_pin_extent()
5777 btrfs_put_block_group(cache); in btrfs_pin_extent()
5787 struct btrfs_block_group_cache *cache; in btrfs_pin_extent_for_log_replay() local
5790 cache = btrfs_lookup_block_group(root->fs_info, bytenr); in btrfs_pin_extent_for_log_replay()
5791 if (!cache) in btrfs_pin_extent_for_log_replay()
5800 cache_block_group(cache, 1); in btrfs_pin_extent_for_log_replay()
5802 pin_down_extent(root, cache, bytenr, num_bytes, 0); in btrfs_pin_extent_for_log_replay()
5805 ret = btrfs_remove_free_space(cache, bytenr, num_bytes); in btrfs_pin_extent_for_log_replay()
5806 btrfs_put_block_group(cache); in btrfs_pin_extent_for_log_replay()
5907 static int btrfs_update_reserved_bytes(struct btrfs_block_group_cache *cache, in btrfs_update_reserved_bytes() argument
5910 struct btrfs_space_info *space_info = cache->space_info; in btrfs_update_reserved_bytes()
5914 spin_lock(&cache->lock); in btrfs_update_reserved_bytes()
5916 if (cache->ro) { in btrfs_update_reserved_bytes()
5919 cache->reserved += num_bytes; in btrfs_update_reserved_bytes()
5922 trace_btrfs_space_reservation(cache->fs_info, in btrfs_update_reserved_bytes()
5929 cache->delalloc_bytes += num_bytes; in btrfs_update_reserved_bytes()
5932 if (cache->ro) in btrfs_update_reserved_bytes()
5934 cache->reserved -= num_bytes; in btrfs_update_reserved_bytes()
5938 cache->delalloc_bytes -= num_bytes; in btrfs_update_reserved_bytes()
5940 spin_unlock(&cache->lock); in btrfs_update_reserved_bytes()
5951 struct btrfs_block_group_cache *cache; in btrfs_prepare_extent_commit() local
5957 cache = caching_ctl->block_group; in btrfs_prepare_extent_commit()
5958 if (block_group_cache_done(cache)) { in btrfs_prepare_extent_commit()
5959 cache->last_byte_to_unpin = (u64)-1; in btrfs_prepare_extent_commit()
5963 cache->last_byte_to_unpin = caching_ctl->progress; in btrfs_prepare_extent_commit()
5981 struct btrfs_block_group_cache *cache = NULL; in unpin_extent_range() local
5989 if (!cache || in unpin_extent_range()
5990 start >= cache->key.objectid + cache->key.offset) { in unpin_extent_range()
5991 if (cache) in unpin_extent_range()
5992 btrfs_put_block_group(cache); in unpin_extent_range()
5993 cache = btrfs_lookup_block_group(fs_info, start); in unpin_extent_range()
5994 BUG_ON(!cache); /* Logic error */ in unpin_extent_range()
5997 len = cache->key.objectid + cache->key.offset - start; in unpin_extent_range()
6000 if (start < cache->last_byte_to_unpin) { in unpin_extent_range()
6001 len = min(len, cache->last_byte_to_unpin - start); in unpin_extent_range()
6003 btrfs_add_free_space(cache, start, len); in unpin_extent_range()
6007 space_info = cache->space_info; in unpin_extent_range()
6010 spin_lock(&cache->lock); in unpin_extent_range()
6011 cache->pinned -= len; in unpin_extent_range()
6014 if (cache->ro) { in unpin_extent_range()
6018 spin_unlock(&cache->lock); in unpin_extent_range()
6034 if (cache) in unpin_extent_range()
6035 btrfs_put_block_group(cache); in unpin_extent_range()
6475 struct btrfs_block_group_cache *cache; in btrfs_free_tree_block() local
6483 cache = btrfs_lookup_block_group(root->fs_info, buf->start); in btrfs_free_tree_block()
6486 pin_down_extent(root, cache, buf->start, buf->len, 1); in btrfs_free_tree_block()
6487 btrfs_put_block_group(cache); in btrfs_free_tree_block()
6493 btrfs_add_free_space(cache, buf->start, buf->len); in btrfs_free_tree_block()
6494 btrfs_update_reserved_bytes(cache, buf->len, RESERVE_FREE, 0); in btrfs_free_tree_block()
6495 btrfs_put_block_group(cache); in btrfs_free_tree_block()
6564 wait_block_group_cache_progress(struct btrfs_block_group_cache *cache, in wait_block_group_cache_progress() argument
6569 caching_ctl = get_caching_control(cache); in wait_block_group_cache_progress()
6573 wait_event(caching_ctl->wait, block_group_cache_done(cache) || in wait_block_group_cache_progress()
6574 (cache->free_space_ctl->free_space >= num_bytes)); in wait_block_group_cache_progress()
6580 wait_block_group_cache_done(struct btrfs_block_group_cache *cache) in wait_block_group_cache_done() argument
6585 caching_ctl = get_caching_control(cache); in wait_block_group_cache_done()
6587 return (cache->cached == BTRFS_CACHE_ERROR) ? -EIO : 0; in wait_block_group_cache_done()
6589 wait_event(caching_ctl->wait, block_group_cache_done(cache)); in wait_block_group_cache_done()
6590 if (cache->cached == BTRFS_CACHE_ERROR) in wait_block_group_cache_done()
6614 int get_block_group_index(struct btrfs_block_group_cache *cache) in get_block_group_index() argument
6616 return __get_raid_index(cache->flags); in get_block_group_index()
6645 btrfs_lock_block_group(struct btrfs_block_group_cache *cache, in btrfs_lock_block_group() argument
6649 down_read(&cache->data_rwsem); in btrfs_lock_block_group()
6653 btrfs_grab_block_group(struct btrfs_block_group_cache *cache, in btrfs_grab_block_group() argument
6656 btrfs_get_block_group(cache); in btrfs_grab_block_group()
6658 down_read(&cache->data_rwsem); in btrfs_grab_block_group()
6700 btrfs_release_block_group(struct btrfs_block_group_cache *cache, in btrfs_release_block_group() argument
6704 up_read(&cache->data_rwsem); in btrfs_release_block_group()
6705 btrfs_put_block_group(cache); in btrfs_release_block_group()
7135 struct btrfs_block_group_cache *cache; in dump_space_info() local
7156 list_for_each_entry(cache, &info->block_groups[index], list) { in dump_space_info()
7157 spin_lock(&cache->lock); in dump_space_info()
7161 cache->key.objectid, cache->key.offset, in dump_space_info()
7162 btrfs_block_group_used(&cache->item), cache->pinned, in dump_space_info()
7163 cache->reserved, cache->ro ? "[readonly]" : ""); in dump_space_info()
7164 btrfs_dump_free_space(cache, bytes); in dump_space_info()
7165 spin_unlock(&cache->lock); in dump_space_info()
7213 struct btrfs_block_group_cache *cache; in __btrfs_free_reserved_extent() local
7216 cache = btrfs_lookup_block_group(root->fs_info, start); in __btrfs_free_reserved_extent()
7217 if (!cache) { in __btrfs_free_reserved_extent()
7224 pin_down_extent(root, cache, start, len, 1); in __btrfs_free_reserved_extent()
7228 btrfs_add_free_space(cache, start, len); in __btrfs_free_reserved_extent()
7229 btrfs_update_reserved_bytes(cache, len, RESERVE_FREE, delalloc); in __btrfs_free_reserved_extent()
7232 btrfs_put_block_group(cache); in __btrfs_free_reserved_extent()
8760 static int set_block_group_ro(struct btrfs_block_group_cache *cache, int force) in set_block_group_ro() argument
8762 struct btrfs_space_info *sinfo = cache->space_info; in set_block_group_ro()
8781 spin_lock(&cache->lock); in set_block_group_ro()
8783 if (cache->ro) { in set_block_group_ro()
8788 num_bytes = cache->key.offset - cache->reserved - cache->pinned - in set_block_group_ro()
8789 cache->bytes_super - btrfs_block_group_used(&cache->item); in set_block_group_ro()
8795 cache->ro = 1; in set_block_group_ro()
8796 list_add_tail(&cache->ro_list, &sinfo->ro_bgs); in set_block_group_ro()
8800 spin_unlock(&cache->lock); in set_block_group_ro()
8806 struct btrfs_block_group_cache *cache) in btrfs_set_block_group_ro() argument
8813 BUG_ON(cache->ro); in btrfs_set_block_group_ro()
8842 alloc_flags = update_block_group_flags(root, cache->flags); in btrfs_set_block_group_ro()
8843 if (alloc_flags != cache->flags) { in btrfs_set_block_group_ro()
8857 ret = set_block_group_ro(cache, 0); in btrfs_set_block_group_ro()
8860 alloc_flags = get_alloc_profile(root, cache->space_info->flags); in btrfs_set_block_group_ro()
8865 ret = set_block_group_ro(cache, 0); in btrfs_set_block_group_ro()
8867 if (cache->flags & BTRFS_BLOCK_GROUP_SYSTEM) { in btrfs_set_block_group_ro()
8868 alloc_flags = update_block_group_flags(root, cache->flags); in btrfs_set_block_group_ro()
8929 struct btrfs_block_group_cache *cache) in btrfs_set_block_group_rw() argument
8931 struct btrfs_space_info *sinfo = cache->space_info; in btrfs_set_block_group_rw()
8934 BUG_ON(!cache->ro); in btrfs_set_block_group_rw()
8937 spin_lock(&cache->lock); in btrfs_set_block_group_rw()
8938 num_bytes = cache->key.offset - cache->reserved - cache->pinned - in btrfs_set_block_group_rw()
8939 cache->bytes_super - btrfs_block_group_used(&cache->item); in btrfs_set_block_group_rw()
8941 cache->ro = 0; in btrfs_set_block_group_rw()
8942 list_del_init(&cache->ro_list); in btrfs_set_block_group_rw()
8943 spin_unlock(&cache->lock); in btrfs_set_block_group_rw()
9248 struct btrfs_block_group_cache *cache) in __link_block_group() argument
9250 int index = get_block_group_index(cache); in __link_block_group()
9256 list_add_tail(&cache->list, &space_info->block_groups[index]); in __link_block_group()
9285 struct btrfs_block_group_cache *cache; in btrfs_create_block_group_cache() local
9287 cache = kzalloc(sizeof(*cache), GFP_NOFS); in btrfs_create_block_group_cache()
9288 if (!cache) in btrfs_create_block_group_cache()
9291 cache->free_space_ctl = kzalloc(sizeof(*cache->free_space_ctl), in btrfs_create_block_group_cache()
9293 if (!cache->free_space_ctl) { in btrfs_create_block_group_cache()
9294 kfree(cache); in btrfs_create_block_group_cache()
9298 cache->key.objectid = start; in btrfs_create_block_group_cache()
9299 cache->key.offset = size; in btrfs_create_block_group_cache()
9300 cache->key.type = BTRFS_BLOCK_GROUP_ITEM_KEY; in btrfs_create_block_group_cache()
9302 cache->sectorsize = root->sectorsize; in btrfs_create_block_group_cache()
9303 cache->fs_info = root->fs_info; in btrfs_create_block_group_cache()
9304 cache->full_stripe_len = btrfs_full_stripe_len(root, in btrfs_create_block_group_cache()
9307 atomic_set(&cache->count, 1); in btrfs_create_block_group_cache()
9308 spin_lock_init(&cache->lock); in btrfs_create_block_group_cache()
9309 init_rwsem(&cache->data_rwsem); in btrfs_create_block_group_cache()
9310 INIT_LIST_HEAD(&cache->list); in btrfs_create_block_group_cache()
9311 INIT_LIST_HEAD(&cache->cluster_list); in btrfs_create_block_group_cache()
9312 INIT_LIST_HEAD(&cache->bg_list); in btrfs_create_block_group_cache()
9313 INIT_LIST_HEAD(&cache->ro_list); in btrfs_create_block_group_cache()
9314 INIT_LIST_HEAD(&cache->dirty_list); in btrfs_create_block_group_cache()
9315 INIT_LIST_HEAD(&cache->io_list); in btrfs_create_block_group_cache()
9316 btrfs_init_free_space_ctl(cache); in btrfs_create_block_group_cache()
9317 atomic_set(&cache->trimming, 0); in btrfs_create_block_group_cache()
9319 return cache; in btrfs_create_block_group_cache()
9326 struct btrfs_block_group_cache *cache; in btrfs_read_block_groups() local
9361 cache = btrfs_create_block_group_cache(root, found_key.objectid, in btrfs_read_block_groups()
9363 if (!cache) { in btrfs_read_block_groups()
9380 cache->disk_cache_state = BTRFS_DC_CLEAR; in btrfs_read_block_groups()
9383 read_extent_buffer(leaf, &cache->item, in btrfs_read_block_groups()
9385 sizeof(cache->item)); in btrfs_read_block_groups()
9386 cache->flags = btrfs_block_group_flags(&cache->item); in btrfs_read_block_groups()
9396 ret = exclude_super_stripes(root, cache); in btrfs_read_block_groups()
9402 free_excluded_extents(root, cache); in btrfs_read_block_groups()
9403 btrfs_put_block_group(cache); in btrfs_read_block_groups()
9414 if (found_key.offset == btrfs_block_group_used(&cache->item)) { in btrfs_read_block_groups()
9415 cache->last_byte_to_unpin = (u64)-1; in btrfs_read_block_groups()
9416 cache->cached = BTRFS_CACHE_FINISHED; in btrfs_read_block_groups()
9417 free_excluded_extents(root, cache); in btrfs_read_block_groups()
9418 } else if (btrfs_block_group_used(&cache->item) == 0) { in btrfs_read_block_groups()
9419 cache->last_byte_to_unpin = (u64)-1; in btrfs_read_block_groups()
9420 cache->cached = BTRFS_CACHE_FINISHED; in btrfs_read_block_groups()
9421 add_new_free_space(cache, root->fs_info, in btrfs_read_block_groups()
9425 free_excluded_extents(root, cache); in btrfs_read_block_groups()
9428 ret = btrfs_add_block_group_cache(root->fs_info, cache); in btrfs_read_block_groups()
9430 btrfs_remove_free_space_cache(cache); in btrfs_read_block_groups()
9431 btrfs_put_block_group(cache); in btrfs_read_block_groups()
9435 ret = update_space_info(info, cache->flags, found_key.offset, in btrfs_read_block_groups()
9436 btrfs_block_group_used(&cache->item), in btrfs_read_block_groups()
9439 btrfs_remove_free_space_cache(cache); in btrfs_read_block_groups()
9441 rb_erase(&cache->cache_node, in btrfs_read_block_groups()
9443 RB_CLEAR_NODE(&cache->cache_node); in btrfs_read_block_groups()
9445 btrfs_put_block_group(cache); in btrfs_read_block_groups()
9449 cache->space_info = space_info; in btrfs_read_block_groups()
9450 spin_lock(&cache->space_info->lock); in btrfs_read_block_groups()
9451 cache->space_info->bytes_readonly += cache->bytes_super; in btrfs_read_block_groups()
9452 spin_unlock(&cache->space_info->lock); in btrfs_read_block_groups()
9454 __link_block_group(space_info, cache); in btrfs_read_block_groups()
9456 set_avail_alloc_bits(root->fs_info, cache->flags); in btrfs_read_block_groups()
9457 if (btrfs_chunk_readonly(root, cache->key.objectid)) { in btrfs_read_block_groups()
9458 set_block_group_ro(cache, 1); in btrfs_read_block_groups()
9459 } else if (btrfs_block_group_used(&cache->item) == 0) { in btrfs_read_block_groups()
9462 if (list_empty(&cache->bg_list)) { in btrfs_read_block_groups()
9463 btrfs_get_block_group(cache); in btrfs_read_block_groups()
9464 list_add_tail(&cache->bg_list, in btrfs_read_block_groups()
9483 list_for_each_entry(cache, in btrfs_read_block_groups()
9486 set_block_group_ro(cache, 1); in btrfs_read_block_groups()
9487 list_for_each_entry(cache, in btrfs_read_block_groups()
9490 set_block_group_ro(cache, 1); in btrfs_read_block_groups()
9538 struct btrfs_block_group_cache *cache; in btrfs_make_block_group() local
9544 cache = btrfs_create_block_group_cache(root, chunk_offset, size); in btrfs_make_block_group()
9545 if (!cache) in btrfs_make_block_group()
9548 btrfs_set_block_group_used(&cache->item, bytes_used); in btrfs_make_block_group()
9549 btrfs_set_block_group_chunk_objectid(&cache->item, chunk_objectid); in btrfs_make_block_group()
9550 btrfs_set_block_group_flags(&cache->item, type); in btrfs_make_block_group()
9552 cache->flags = type; in btrfs_make_block_group()
9553 cache->last_byte_to_unpin = (u64)-1; in btrfs_make_block_group()
9554 cache->cached = BTRFS_CACHE_FINISHED; in btrfs_make_block_group()
9555 ret = exclude_super_stripes(root, cache); in btrfs_make_block_group()
9561 free_excluded_extents(root, cache); in btrfs_make_block_group()
9562 btrfs_put_block_group(cache); in btrfs_make_block_group()
9566 add_new_free_space(cache, root->fs_info, chunk_offset, in btrfs_make_block_group()
9569 free_excluded_extents(root, cache); in btrfs_make_block_group()
9571 ret = btrfs_add_block_group_cache(root->fs_info, cache); in btrfs_make_block_group()
9573 btrfs_remove_free_space_cache(cache); in btrfs_make_block_group()
9574 btrfs_put_block_group(cache); in btrfs_make_block_group()
9578 ret = update_space_info(root->fs_info, cache->flags, size, bytes_used, in btrfs_make_block_group()
9579 &cache->space_info); in btrfs_make_block_group()
9581 btrfs_remove_free_space_cache(cache); in btrfs_make_block_group()
9583 rb_erase(&cache->cache_node, in btrfs_make_block_group()
9585 RB_CLEAR_NODE(&cache->cache_node); in btrfs_make_block_group()
9587 btrfs_put_block_group(cache); in btrfs_make_block_group()
9592 spin_lock(&cache->space_info->lock); in btrfs_make_block_group()
9593 cache->space_info->bytes_readonly += cache->bytes_super; in btrfs_make_block_group()
9594 spin_unlock(&cache->space_info->lock); in btrfs_make_block_group()
9596 __link_block_group(cache->space_info, cache); in btrfs_make_block_group()
9598 list_add_tail(&cache->bg_list, &trans->new_bgs); in btrfs_make_block_group()
10086 struct btrfs_block_group_cache *cache = NULL; in btrfs_trim_fs() local
10098 cache = btrfs_lookup_first_block_group(fs_info, range->start); in btrfs_trim_fs()
10100 cache = btrfs_lookup_block_group(fs_info, range->start); in btrfs_trim_fs()
10102 while (cache) { in btrfs_trim_fs()
10103 if (cache->key.objectid >= (range->start + range->len)) { in btrfs_trim_fs()
10104 btrfs_put_block_group(cache); in btrfs_trim_fs()
10108 start = max(range->start, cache->key.objectid); in btrfs_trim_fs()
10110 cache->key.objectid + cache->key.offset); in btrfs_trim_fs()
10113 if (!block_group_cache_done(cache)) { in btrfs_trim_fs()
10114 ret = cache_block_group(cache, 0); in btrfs_trim_fs()
10116 btrfs_put_block_group(cache); in btrfs_trim_fs()
10119 ret = wait_block_group_cache_done(cache); in btrfs_trim_fs()
10121 btrfs_put_block_group(cache); in btrfs_trim_fs()
10125 ret = btrfs_trim_block_group(cache, in btrfs_trim_fs()
10133 btrfs_put_block_group(cache); in btrfs_trim_fs()
10138 cache = next_block_group(fs_info->tree_root, cache); in btrfs_trim_fs()