162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci#ifndef BTRFS_BLOCK_GROUP_H 462306a36Sopenharmony_ci#define BTRFS_BLOCK_GROUP_H 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#include "free-space-cache.h" 762306a36Sopenharmony_ci 862306a36Sopenharmony_cienum btrfs_disk_cache_state { 962306a36Sopenharmony_ci BTRFS_DC_WRITTEN, 1062306a36Sopenharmony_ci BTRFS_DC_ERROR, 1162306a36Sopenharmony_ci BTRFS_DC_CLEAR, 1262306a36Sopenharmony_ci BTRFS_DC_SETUP, 1362306a36Sopenharmony_ci}; 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_cienum btrfs_block_group_size_class { 1662306a36Sopenharmony_ci /* Unset */ 1762306a36Sopenharmony_ci BTRFS_BG_SZ_NONE, 1862306a36Sopenharmony_ci /* 0 < size <= 128K */ 1962306a36Sopenharmony_ci BTRFS_BG_SZ_SMALL, 2062306a36Sopenharmony_ci /* 128K < size <= 8M */ 2162306a36Sopenharmony_ci BTRFS_BG_SZ_MEDIUM, 2262306a36Sopenharmony_ci /* 8M < size < BG_LENGTH */ 2362306a36Sopenharmony_ci BTRFS_BG_SZ_LARGE, 2462306a36Sopenharmony_ci}; 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci/* 2762306a36Sopenharmony_ci * This describes the state of the block_group for async discard. This is due 2862306a36Sopenharmony_ci * to the two pass nature of it where extent discarding is prioritized over 2962306a36Sopenharmony_ci * bitmap discarding. BTRFS_DISCARD_RESET_CURSOR is set when we are resetting 3062306a36Sopenharmony_ci * between lists to prevent contention for discard state variables 3162306a36Sopenharmony_ci * (eg. discard_cursor). 3262306a36Sopenharmony_ci */ 3362306a36Sopenharmony_cienum btrfs_discard_state { 3462306a36Sopenharmony_ci BTRFS_DISCARD_EXTENTS, 3562306a36Sopenharmony_ci BTRFS_DISCARD_BITMAPS, 3662306a36Sopenharmony_ci BTRFS_DISCARD_RESET_CURSOR, 3762306a36Sopenharmony_ci}; 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci/* 4062306a36Sopenharmony_ci * Control flags for do_chunk_alloc's force field CHUNK_ALLOC_NO_FORCE means to 4162306a36Sopenharmony_ci * only allocate a chunk if we really need one. 4262306a36Sopenharmony_ci * 4362306a36Sopenharmony_ci * CHUNK_ALLOC_LIMITED means to only try and allocate one if we have very few 4462306a36Sopenharmony_ci * chunks already allocated. This is used as part of the clustering code to 4562306a36Sopenharmony_ci * help make sure we have a good pool of storage to cluster in, without filling 4662306a36Sopenharmony_ci * the FS with empty chunks 4762306a36Sopenharmony_ci * 4862306a36Sopenharmony_ci * CHUNK_ALLOC_FORCE means it must try to allocate one 4962306a36Sopenharmony_ci * 5062306a36Sopenharmony_ci * CHUNK_ALLOC_FORCE_FOR_EXTENT like CHUNK_ALLOC_FORCE but called from 5162306a36Sopenharmony_ci * find_free_extent() that also activaes the zone 5262306a36Sopenharmony_ci */ 5362306a36Sopenharmony_cienum btrfs_chunk_alloc_enum { 5462306a36Sopenharmony_ci CHUNK_ALLOC_NO_FORCE, 5562306a36Sopenharmony_ci CHUNK_ALLOC_LIMITED, 5662306a36Sopenharmony_ci CHUNK_ALLOC_FORCE, 5762306a36Sopenharmony_ci CHUNK_ALLOC_FORCE_FOR_EXTENT, 5862306a36Sopenharmony_ci}; 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci/* Block group flags set at runtime */ 6162306a36Sopenharmony_cienum btrfs_block_group_flags { 6262306a36Sopenharmony_ci BLOCK_GROUP_FLAG_IREF, 6362306a36Sopenharmony_ci BLOCK_GROUP_FLAG_REMOVED, 6462306a36Sopenharmony_ci BLOCK_GROUP_FLAG_TO_COPY, 6562306a36Sopenharmony_ci BLOCK_GROUP_FLAG_RELOCATING_REPAIR, 6662306a36Sopenharmony_ci BLOCK_GROUP_FLAG_CHUNK_ITEM_INSERTED, 6762306a36Sopenharmony_ci BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, 6862306a36Sopenharmony_ci BLOCK_GROUP_FLAG_ZONED_DATA_RELOC, 6962306a36Sopenharmony_ci /* Does the block group need to be added to the free space tree? */ 7062306a36Sopenharmony_ci BLOCK_GROUP_FLAG_NEEDS_FREE_SPACE, 7162306a36Sopenharmony_ci /* Indicate that the block group is placed on a sequential zone */ 7262306a36Sopenharmony_ci BLOCK_GROUP_FLAG_SEQUENTIAL_ZONE, 7362306a36Sopenharmony_ci /* 7462306a36Sopenharmony_ci * Indicate that block group is in the list of new block groups of a 7562306a36Sopenharmony_ci * transaction. 7662306a36Sopenharmony_ci */ 7762306a36Sopenharmony_ci BLOCK_GROUP_FLAG_NEW, 7862306a36Sopenharmony_ci}; 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_cienum btrfs_caching_type { 8162306a36Sopenharmony_ci BTRFS_CACHE_NO, 8262306a36Sopenharmony_ci BTRFS_CACHE_STARTED, 8362306a36Sopenharmony_ci BTRFS_CACHE_FINISHED, 8462306a36Sopenharmony_ci BTRFS_CACHE_ERROR, 8562306a36Sopenharmony_ci}; 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_cistruct btrfs_caching_control { 8862306a36Sopenharmony_ci struct list_head list; 8962306a36Sopenharmony_ci struct mutex mutex; 9062306a36Sopenharmony_ci wait_queue_head_t wait; 9162306a36Sopenharmony_ci struct btrfs_work work; 9262306a36Sopenharmony_ci struct btrfs_block_group *block_group; 9362306a36Sopenharmony_ci /* Track progress of caching during allocation. */ 9462306a36Sopenharmony_ci atomic_t progress; 9562306a36Sopenharmony_ci refcount_t count; 9662306a36Sopenharmony_ci}; 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci/* Once caching_thread() finds this much free space, it will wake up waiters. */ 9962306a36Sopenharmony_ci#define CACHING_CTL_WAKE_UP SZ_2M 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_cistruct btrfs_block_group { 10262306a36Sopenharmony_ci struct btrfs_fs_info *fs_info; 10362306a36Sopenharmony_ci struct inode *inode; 10462306a36Sopenharmony_ci spinlock_t lock; 10562306a36Sopenharmony_ci u64 start; 10662306a36Sopenharmony_ci u64 length; 10762306a36Sopenharmony_ci u64 pinned; 10862306a36Sopenharmony_ci u64 reserved; 10962306a36Sopenharmony_ci u64 used; 11062306a36Sopenharmony_ci u64 delalloc_bytes; 11162306a36Sopenharmony_ci u64 bytes_super; 11262306a36Sopenharmony_ci u64 flags; 11362306a36Sopenharmony_ci u64 cache_generation; 11462306a36Sopenharmony_ci u64 global_root_id; 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci /* 11762306a36Sopenharmony_ci * The last committed used bytes of this block group, if the above @used 11862306a36Sopenharmony_ci * is still the same as @commit_used, we don't need to update block 11962306a36Sopenharmony_ci * group item of this block group. 12062306a36Sopenharmony_ci */ 12162306a36Sopenharmony_ci u64 commit_used; 12262306a36Sopenharmony_ci /* 12362306a36Sopenharmony_ci * If the free space extent count exceeds this number, convert the block 12462306a36Sopenharmony_ci * group to bitmaps. 12562306a36Sopenharmony_ci */ 12662306a36Sopenharmony_ci u32 bitmap_high_thresh; 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci /* 12962306a36Sopenharmony_ci * If the free space extent count drops below this number, convert the 13062306a36Sopenharmony_ci * block group back to extents. 13162306a36Sopenharmony_ci */ 13262306a36Sopenharmony_ci u32 bitmap_low_thresh; 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci /* 13562306a36Sopenharmony_ci * It is just used for the delayed data space allocation because 13662306a36Sopenharmony_ci * only the data space allocation and the relative metadata update 13762306a36Sopenharmony_ci * can be done cross the transaction. 13862306a36Sopenharmony_ci */ 13962306a36Sopenharmony_ci struct rw_semaphore data_rwsem; 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci /* For raid56, this is a full stripe, without parity */ 14262306a36Sopenharmony_ci unsigned long full_stripe_len; 14362306a36Sopenharmony_ci unsigned long runtime_flags; 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ci unsigned int ro; 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci int disk_cache_state; 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci /* Cache tracking stuff */ 15062306a36Sopenharmony_ci int cached; 15162306a36Sopenharmony_ci struct btrfs_caching_control *caching_ctl; 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_ci struct btrfs_space_info *space_info; 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci /* Free space cache stuff */ 15662306a36Sopenharmony_ci struct btrfs_free_space_ctl *free_space_ctl; 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_ci /* Block group cache stuff */ 15962306a36Sopenharmony_ci struct rb_node cache_node; 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ci /* For block groups in the same raid type */ 16262306a36Sopenharmony_ci struct list_head list; 16362306a36Sopenharmony_ci 16462306a36Sopenharmony_ci refcount_t refs; 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_ci /* 16762306a36Sopenharmony_ci * List of struct btrfs_free_clusters for this block group. 16862306a36Sopenharmony_ci * Today it will only have one thing on it, but that may change 16962306a36Sopenharmony_ci */ 17062306a36Sopenharmony_ci struct list_head cluster_list; 17162306a36Sopenharmony_ci 17262306a36Sopenharmony_ci /* 17362306a36Sopenharmony_ci * Used for several lists: 17462306a36Sopenharmony_ci * 17562306a36Sopenharmony_ci * 1) struct btrfs_fs_info::unused_bgs 17662306a36Sopenharmony_ci * 2) struct btrfs_fs_info::reclaim_bgs 17762306a36Sopenharmony_ci * 3) struct btrfs_transaction::deleted_bgs 17862306a36Sopenharmony_ci * 4) struct btrfs_trans_handle::new_bgs 17962306a36Sopenharmony_ci */ 18062306a36Sopenharmony_ci struct list_head bg_list; 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci /* For read-only block groups */ 18362306a36Sopenharmony_ci struct list_head ro_list; 18462306a36Sopenharmony_ci 18562306a36Sopenharmony_ci /* 18662306a36Sopenharmony_ci * When non-zero it means the block group's logical address and its 18762306a36Sopenharmony_ci * device extents can not be reused for future block group allocations 18862306a36Sopenharmony_ci * until the counter goes down to 0. This is to prevent them from being 18962306a36Sopenharmony_ci * reused while some task is still using the block group after it was 19062306a36Sopenharmony_ci * deleted - we want to make sure they can only be reused for new block 19162306a36Sopenharmony_ci * groups after that task is done with the deleted block group. 19262306a36Sopenharmony_ci */ 19362306a36Sopenharmony_ci atomic_t frozen; 19462306a36Sopenharmony_ci 19562306a36Sopenharmony_ci /* For discard operations */ 19662306a36Sopenharmony_ci struct list_head discard_list; 19762306a36Sopenharmony_ci int discard_index; 19862306a36Sopenharmony_ci u64 discard_eligible_time; 19962306a36Sopenharmony_ci u64 discard_cursor; 20062306a36Sopenharmony_ci enum btrfs_discard_state discard_state; 20162306a36Sopenharmony_ci 20262306a36Sopenharmony_ci /* For dirty block groups */ 20362306a36Sopenharmony_ci struct list_head dirty_list; 20462306a36Sopenharmony_ci struct list_head io_list; 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_ci struct btrfs_io_ctl io_ctl; 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ci /* 20962306a36Sopenharmony_ci * Incremented when doing extent allocations and holding a read lock 21062306a36Sopenharmony_ci * on the space_info's groups_sem semaphore. 21162306a36Sopenharmony_ci * Decremented when an ordered extent that represents an IO against this 21262306a36Sopenharmony_ci * block group's range is created (after it's added to its inode's 21362306a36Sopenharmony_ci * root's list of ordered extents) or immediately after the allocation 21462306a36Sopenharmony_ci * if it's a metadata extent or fallocate extent (for these cases we 21562306a36Sopenharmony_ci * don't create ordered extents). 21662306a36Sopenharmony_ci */ 21762306a36Sopenharmony_ci atomic_t reservations; 21862306a36Sopenharmony_ci 21962306a36Sopenharmony_ci /* 22062306a36Sopenharmony_ci * Incremented while holding the spinlock *lock* by a task checking if 22162306a36Sopenharmony_ci * it can perform a nocow write (incremented if the value for the *ro* 22262306a36Sopenharmony_ci * field is 0). Decremented by such tasks once they create an ordered 22362306a36Sopenharmony_ci * extent or before that if some error happens before reaching that step. 22462306a36Sopenharmony_ci * This is to prevent races between block group relocation and nocow 22562306a36Sopenharmony_ci * writes through direct IO. 22662306a36Sopenharmony_ci */ 22762306a36Sopenharmony_ci atomic_t nocow_writers; 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_ci /* Lock for free space tree operations. */ 23062306a36Sopenharmony_ci struct mutex free_space_lock; 23162306a36Sopenharmony_ci 23262306a36Sopenharmony_ci /* 23362306a36Sopenharmony_ci * Number of extents in this block group used for swap files. 23462306a36Sopenharmony_ci * All accesses protected by the spinlock 'lock'. 23562306a36Sopenharmony_ci */ 23662306a36Sopenharmony_ci int swap_extents; 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_ci /* 23962306a36Sopenharmony_ci * Allocation offset for the block group to implement sequential 24062306a36Sopenharmony_ci * allocation. This is used only on a zoned filesystem. 24162306a36Sopenharmony_ci */ 24262306a36Sopenharmony_ci u64 alloc_offset; 24362306a36Sopenharmony_ci u64 zone_unusable; 24462306a36Sopenharmony_ci u64 zone_capacity; 24562306a36Sopenharmony_ci u64 meta_write_pointer; 24662306a36Sopenharmony_ci struct map_lookup *physical_map; 24762306a36Sopenharmony_ci struct list_head active_bg_list; 24862306a36Sopenharmony_ci struct work_struct zone_finish_work; 24962306a36Sopenharmony_ci struct extent_buffer *last_eb; 25062306a36Sopenharmony_ci enum btrfs_block_group_size_class size_class; 25162306a36Sopenharmony_ci}; 25262306a36Sopenharmony_ci 25362306a36Sopenharmony_cistatic inline u64 btrfs_block_group_end(struct btrfs_block_group *block_group) 25462306a36Sopenharmony_ci{ 25562306a36Sopenharmony_ci return (block_group->start + block_group->length); 25662306a36Sopenharmony_ci} 25762306a36Sopenharmony_ci 25862306a36Sopenharmony_cistatic inline bool btrfs_is_block_group_used(const struct btrfs_block_group *bg) 25962306a36Sopenharmony_ci{ 26062306a36Sopenharmony_ci lockdep_assert_held(&bg->lock); 26162306a36Sopenharmony_ci 26262306a36Sopenharmony_ci return (bg->used > 0 || bg->reserved > 0 || bg->pinned > 0); 26362306a36Sopenharmony_ci} 26462306a36Sopenharmony_ci 26562306a36Sopenharmony_cistatic inline bool btrfs_is_block_group_data_only( 26662306a36Sopenharmony_ci struct btrfs_block_group *block_group) 26762306a36Sopenharmony_ci{ 26862306a36Sopenharmony_ci /* 26962306a36Sopenharmony_ci * In mixed mode the fragmentation is expected to be high, lowering the 27062306a36Sopenharmony_ci * efficiency, so only proper data block groups are considered. 27162306a36Sopenharmony_ci */ 27262306a36Sopenharmony_ci return (block_group->flags & BTRFS_BLOCK_GROUP_DATA) && 27362306a36Sopenharmony_ci !(block_group->flags & BTRFS_BLOCK_GROUP_METADATA); 27462306a36Sopenharmony_ci} 27562306a36Sopenharmony_ci 27662306a36Sopenharmony_ci#ifdef CONFIG_BTRFS_DEBUG 27762306a36Sopenharmony_ciint btrfs_should_fragment_free_space(struct btrfs_block_group *block_group); 27862306a36Sopenharmony_ci#endif 27962306a36Sopenharmony_ci 28062306a36Sopenharmony_cistruct btrfs_block_group *btrfs_lookup_first_block_group( 28162306a36Sopenharmony_ci struct btrfs_fs_info *info, u64 bytenr); 28262306a36Sopenharmony_cistruct btrfs_block_group *btrfs_lookup_block_group( 28362306a36Sopenharmony_ci struct btrfs_fs_info *info, u64 bytenr); 28462306a36Sopenharmony_cistruct btrfs_block_group *btrfs_next_block_group( 28562306a36Sopenharmony_ci struct btrfs_block_group *cache); 28662306a36Sopenharmony_civoid btrfs_get_block_group(struct btrfs_block_group *cache); 28762306a36Sopenharmony_civoid btrfs_put_block_group(struct btrfs_block_group *cache); 28862306a36Sopenharmony_civoid btrfs_dec_block_group_reservations(struct btrfs_fs_info *fs_info, 28962306a36Sopenharmony_ci const u64 start); 29062306a36Sopenharmony_civoid btrfs_wait_block_group_reservations(struct btrfs_block_group *bg); 29162306a36Sopenharmony_cistruct btrfs_block_group *btrfs_inc_nocow_writers(struct btrfs_fs_info *fs_info, 29262306a36Sopenharmony_ci u64 bytenr); 29362306a36Sopenharmony_civoid btrfs_dec_nocow_writers(struct btrfs_block_group *bg); 29462306a36Sopenharmony_civoid btrfs_wait_nocow_writers(struct btrfs_block_group *bg); 29562306a36Sopenharmony_civoid btrfs_wait_block_group_cache_progress(struct btrfs_block_group *cache, 29662306a36Sopenharmony_ci u64 num_bytes); 29762306a36Sopenharmony_ciint btrfs_cache_block_group(struct btrfs_block_group *cache, bool wait); 29862306a36Sopenharmony_civoid btrfs_put_caching_control(struct btrfs_caching_control *ctl); 29962306a36Sopenharmony_cistruct btrfs_caching_control *btrfs_get_caching_control( 30062306a36Sopenharmony_ci struct btrfs_block_group *cache); 30162306a36Sopenharmony_ciint btrfs_add_new_free_space(struct btrfs_block_group *block_group, 30262306a36Sopenharmony_ci u64 start, u64 end, u64 *total_added_ret); 30362306a36Sopenharmony_cistruct btrfs_trans_handle *btrfs_start_trans_remove_block_group( 30462306a36Sopenharmony_ci struct btrfs_fs_info *fs_info, 30562306a36Sopenharmony_ci const u64 chunk_offset); 30662306a36Sopenharmony_ciint btrfs_remove_block_group(struct btrfs_trans_handle *trans, 30762306a36Sopenharmony_ci u64 group_start, struct extent_map *em); 30862306a36Sopenharmony_civoid btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info); 30962306a36Sopenharmony_civoid btrfs_mark_bg_unused(struct btrfs_block_group *bg); 31062306a36Sopenharmony_civoid btrfs_reclaim_bgs_work(struct work_struct *work); 31162306a36Sopenharmony_civoid btrfs_reclaim_bgs(struct btrfs_fs_info *fs_info); 31262306a36Sopenharmony_civoid btrfs_mark_bg_to_reclaim(struct btrfs_block_group *bg); 31362306a36Sopenharmony_ciint btrfs_read_block_groups(struct btrfs_fs_info *info); 31462306a36Sopenharmony_cistruct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *trans, 31562306a36Sopenharmony_ci u64 type, 31662306a36Sopenharmony_ci u64 chunk_offset, u64 size); 31762306a36Sopenharmony_civoid btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans); 31862306a36Sopenharmony_ciint btrfs_inc_block_group_ro(struct btrfs_block_group *cache, 31962306a36Sopenharmony_ci bool do_chunk_alloc); 32062306a36Sopenharmony_civoid btrfs_dec_block_group_ro(struct btrfs_block_group *cache); 32162306a36Sopenharmony_ciint btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans); 32262306a36Sopenharmony_ciint btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans); 32362306a36Sopenharmony_ciint btrfs_setup_space_cache(struct btrfs_trans_handle *trans); 32462306a36Sopenharmony_ciint btrfs_update_block_group(struct btrfs_trans_handle *trans, 32562306a36Sopenharmony_ci u64 bytenr, u64 num_bytes, bool alloc); 32662306a36Sopenharmony_ciint btrfs_add_reserved_bytes(struct btrfs_block_group *cache, 32762306a36Sopenharmony_ci u64 ram_bytes, u64 num_bytes, int delalloc, 32862306a36Sopenharmony_ci bool force_wrong_size_class); 32962306a36Sopenharmony_civoid btrfs_free_reserved_bytes(struct btrfs_block_group *cache, 33062306a36Sopenharmony_ci u64 num_bytes, int delalloc); 33162306a36Sopenharmony_ciint btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags, 33262306a36Sopenharmony_ci enum btrfs_chunk_alloc_enum force); 33362306a36Sopenharmony_ciint btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, u64 type); 33462306a36Sopenharmony_civoid check_system_chunk(struct btrfs_trans_handle *trans, const u64 type); 33562306a36Sopenharmony_civoid btrfs_reserve_chunk_metadata(struct btrfs_trans_handle *trans, 33662306a36Sopenharmony_ci bool is_item_insertion); 33762306a36Sopenharmony_ciu64 btrfs_get_alloc_profile(struct btrfs_fs_info *fs_info, u64 orig_flags); 33862306a36Sopenharmony_civoid btrfs_put_block_group_cache(struct btrfs_fs_info *info); 33962306a36Sopenharmony_ciint btrfs_free_block_groups(struct btrfs_fs_info *info); 34062306a36Sopenharmony_ciint btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start, 34162306a36Sopenharmony_ci u64 physical, u64 **logical, int *naddrs, int *stripe_len); 34262306a36Sopenharmony_ci 34362306a36Sopenharmony_cistatic inline u64 btrfs_data_alloc_profile(struct btrfs_fs_info *fs_info) 34462306a36Sopenharmony_ci{ 34562306a36Sopenharmony_ci return btrfs_get_alloc_profile(fs_info, BTRFS_BLOCK_GROUP_DATA); 34662306a36Sopenharmony_ci} 34762306a36Sopenharmony_ci 34862306a36Sopenharmony_cistatic inline u64 btrfs_metadata_alloc_profile(struct btrfs_fs_info *fs_info) 34962306a36Sopenharmony_ci{ 35062306a36Sopenharmony_ci return btrfs_get_alloc_profile(fs_info, BTRFS_BLOCK_GROUP_METADATA); 35162306a36Sopenharmony_ci} 35262306a36Sopenharmony_ci 35362306a36Sopenharmony_cistatic inline u64 btrfs_system_alloc_profile(struct btrfs_fs_info *fs_info) 35462306a36Sopenharmony_ci{ 35562306a36Sopenharmony_ci return btrfs_get_alloc_profile(fs_info, BTRFS_BLOCK_GROUP_SYSTEM); 35662306a36Sopenharmony_ci} 35762306a36Sopenharmony_ci 35862306a36Sopenharmony_cistatic inline int btrfs_block_group_done(struct btrfs_block_group *cache) 35962306a36Sopenharmony_ci{ 36062306a36Sopenharmony_ci smp_mb(); 36162306a36Sopenharmony_ci return cache->cached == BTRFS_CACHE_FINISHED || 36262306a36Sopenharmony_ci cache->cached == BTRFS_CACHE_ERROR; 36362306a36Sopenharmony_ci} 36462306a36Sopenharmony_ci 36562306a36Sopenharmony_civoid btrfs_freeze_block_group(struct btrfs_block_group *cache); 36662306a36Sopenharmony_civoid btrfs_unfreeze_block_group(struct btrfs_block_group *cache); 36762306a36Sopenharmony_ci 36862306a36Sopenharmony_cibool btrfs_inc_block_group_swap_extents(struct btrfs_block_group *bg); 36962306a36Sopenharmony_civoid btrfs_dec_block_group_swap_extents(struct btrfs_block_group *bg, int amount); 37062306a36Sopenharmony_ci 37162306a36Sopenharmony_cienum btrfs_block_group_size_class btrfs_calc_block_group_size_class(u64 size); 37262306a36Sopenharmony_ciint btrfs_use_block_group_size_class(struct btrfs_block_group *bg, 37362306a36Sopenharmony_ci enum btrfs_block_group_size_class size_class, 37462306a36Sopenharmony_ci bool force_wrong_size_class); 37562306a36Sopenharmony_cibool btrfs_block_group_should_use_size_class(struct btrfs_block_group *bg); 37662306a36Sopenharmony_ci 37762306a36Sopenharmony_ci#endif /* BTRFS_BLOCK_GROUP_H */ 378