162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci#ifndef BTRFS_EXTENT_TREE_H 462306a36Sopenharmony_ci#define BTRFS_EXTENT_TREE_H 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#include "misc.h" 762306a36Sopenharmony_ci#include "block-group.h" 862306a36Sopenharmony_ci 962306a36Sopenharmony_cistruct btrfs_free_cluster; 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_cienum btrfs_extent_allocation_policy { 1262306a36Sopenharmony_ci BTRFS_EXTENT_ALLOC_CLUSTERED, 1362306a36Sopenharmony_ci BTRFS_EXTENT_ALLOC_ZONED, 1462306a36Sopenharmony_ci}; 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_cistruct find_free_extent_ctl { 1762306a36Sopenharmony_ci /* Basic allocation info */ 1862306a36Sopenharmony_ci u64 ram_bytes; 1962306a36Sopenharmony_ci u64 num_bytes; 2062306a36Sopenharmony_ci u64 min_alloc_size; 2162306a36Sopenharmony_ci u64 empty_size; 2262306a36Sopenharmony_ci u64 flags; 2362306a36Sopenharmony_ci int delalloc; 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci /* Where to start the search inside the bg */ 2662306a36Sopenharmony_ci u64 search_start; 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci /* For clustered allocation */ 2962306a36Sopenharmony_ci u64 empty_cluster; 3062306a36Sopenharmony_ci struct btrfs_free_cluster *last_ptr; 3162306a36Sopenharmony_ci bool use_cluster; 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci bool have_caching_bg; 3462306a36Sopenharmony_ci bool orig_have_caching_bg; 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci /* Allocation is called for tree-log */ 3762306a36Sopenharmony_ci bool for_treelog; 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci /* Allocation is called for data relocation */ 4062306a36Sopenharmony_ci bool for_data_reloc; 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci /* RAID index, converted from flags */ 4362306a36Sopenharmony_ci int index; 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci /* 4662306a36Sopenharmony_ci * Current loop number, check find_free_extent_update_loop() for details 4762306a36Sopenharmony_ci */ 4862306a36Sopenharmony_ci int loop; 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci /* 5162306a36Sopenharmony_ci * Set to true if we're retrying the allocation on this block group 5262306a36Sopenharmony_ci * after waiting for caching progress, this is so that we retry only 5362306a36Sopenharmony_ci * once before moving on to another block group. 5462306a36Sopenharmony_ci */ 5562306a36Sopenharmony_ci bool retry_uncached; 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci /* If current block group is cached */ 5862306a36Sopenharmony_ci int cached; 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci /* Max contiguous hole found */ 6162306a36Sopenharmony_ci u64 max_extent_size; 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci /* Total free space from free space cache, not always contiguous */ 6462306a36Sopenharmony_ci u64 total_free_space; 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci /* Found result */ 6762306a36Sopenharmony_ci u64 found_offset; 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci /* Hint where to start looking for an empty space */ 7062306a36Sopenharmony_ci u64 hint_byte; 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci /* Allocation policy */ 7362306a36Sopenharmony_ci enum btrfs_extent_allocation_policy policy; 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci /* Whether or not the allocator is currently following a hint */ 7662306a36Sopenharmony_ci bool hinted; 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci /* Size class of block groups to prefer in early loops */ 7962306a36Sopenharmony_ci enum btrfs_block_group_size_class size_class; 8062306a36Sopenharmony_ci}; 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_cienum btrfs_inline_ref_type { 8362306a36Sopenharmony_ci BTRFS_REF_TYPE_INVALID, 8462306a36Sopenharmony_ci BTRFS_REF_TYPE_BLOCK, 8562306a36Sopenharmony_ci BTRFS_REF_TYPE_DATA, 8662306a36Sopenharmony_ci BTRFS_REF_TYPE_ANY, 8762306a36Sopenharmony_ci}; 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ciint btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb, 9062306a36Sopenharmony_ci struct btrfs_extent_inline_ref *iref, 9162306a36Sopenharmony_ci enum btrfs_inline_ref_type is_data); 9262306a36Sopenharmony_ciu64 hash_extent_data_ref(u64 root_objectid, u64 owner, u64 offset); 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ciint btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, unsigned long count); 9562306a36Sopenharmony_civoid btrfs_cleanup_ref_head_accounting(struct btrfs_fs_info *fs_info, 9662306a36Sopenharmony_ci struct btrfs_delayed_ref_root *delayed_refs, 9762306a36Sopenharmony_ci struct btrfs_delayed_ref_head *head); 9862306a36Sopenharmony_ciint btrfs_lookup_data_extent(struct btrfs_fs_info *fs_info, u64 start, u64 len); 9962306a36Sopenharmony_ciint btrfs_lookup_extent_info(struct btrfs_trans_handle *trans, 10062306a36Sopenharmony_ci struct btrfs_fs_info *fs_info, u64 bytenr, 10162306a36Sopenharmony_ci u64 offset, int metadata, u64 *refs, u64 *flags); 10262306a36Sopenharmony_ciint btrfs_pin_extent(struct btrfs_trans_handle *trans, u64 bytenr, u64 num, 10362306a36Sopenharmony_ci int reserved); 10462306a36Sopenharmony_ciint btrfs_pin_extent_for_log_replay(struct btrfs_trans_handle *trans, 10562306a36Sopenharmony_ci u64 bytenr, u64 num_bytes); 10662306a36Sopenharmony_ciint btrfs_exclude_logged_extents(struct extent_buffer *eb); 10762306a36Sopenharmony_ciint btrfs_cross_ref_exist(struct btrfs_root *root, 10862306a36Sopenharmony_ci u64 objectid, u64 offset, u64 bytenr, bool strict, 10962306a36Sopenharmony_ci struct btrfs_path *path); 11062306a36Sopenharmony_cistruct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, 11162306a36Sopenharmony_ci struct btrfs_root *root, 11262306a36Sopenharmony_ci u64 parent, u64 root_objectid, 11362306a36Sopenharmony_ci const struct btrfs_disk_key *key, 11462306a36Sopenharmony_ci int level, u64 hint, 11562306a36Sopenharmony_ci u64 empty_size, 11662306a36Sopenharmony_ci enum btrfs_lock_nesting nest); 11762306a36Sopenharmony_civoid btrfs_free_tree_block(struct btrfs_trans_handle *trans, 11862306a36Sopenharmony_ci u64 root_id, 11962306a36Sopenharmony_ci struct extent_buffer *buf, 12062306a36Sopenharmony_ci u64 parent, int last_ref); 12162306a36Sopenharmony_ciint btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans, 12262306a36Sopenharmony_ci struct btrfs_root *root, u64 owner, 12362306a36Sopenharmony_ci u64 offset, u64 ram_bytes, 12462306a36Sopenharmony_ci struct btrfs_key *ins); 12562306a36Sopenharmony_ciint btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans, 12662306a36Sopenharmony_ci u64 root_objectid, u64 owner, u64 offset, 12762306a36Sopenharmony_ci struct btrfs_key *ins); 12862306a36Sopenharmony_ciint btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes, u64 num_bytes, 12962306a36Sopenharmony_ci u64 min_alloc_size, u64 empty_size, u64 hint_byte, 13062306a36Sopenharmony_ci struct btrfs_key *ins, int is_data, int delalloc); 13162306a36Sopenharmony_ciint btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, 13262306a36Sopenharmony_ci struct extent_buffer *buf, int full_backref); 13362306a36Sopenharmony_ciint btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, 13462306a36Sopenharmony_ci struct extent_buffer *buf, int full_backref); 13562306a36Sopenharmony_ciint btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, 13662306a36Sopenharmony_ci struct extent_buffer *eb, u64 flags); 13762306a36Sopenharmony_ciint btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref); 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ciint btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info, 14062306a36Sopenharmony_ci u64 start, u64 len, int delalloc); 14162306a36Sopenharmony_ciint btrfs_pin_reserved_extent(struct btrfs_trans_handle *trans, u64 start, u64 len); 14262306a36Sopenharmony_ciint btrfs_finish_extent_commit(struct btrfs_trans_handle *trans); 14362306a36Sopenharmony_ciint btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, struct btrfs_ref *generic_ref); 14462306a36Sopenharmony_ciint __must_check btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, 14562306a36Sopenharmony_ci int for_reloc); 14662306a36Sopenharmony_ciint btrfs_drop_subtree(struct btrfs_trans_handle *trans, 14762306a36Sopenharmony_ci struct btrfs_root *root, 14862306a36Sopenharmony_ci struct extent_buffer *node, 14962306a36Sopenharmony_ci struct extent_buffer *parent); 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci#endif 152