1 /* SPDX-License-Identifier: GPL-2.0 */ 2 3 #ifndef BTRFS_EXTENT_TREE_H 4 #define BTRFS_EXTENT_TREE_H 5 6 #include <linux/types.h> 7 #include "block-group.h" 8 #include "locking.h" 9 10 struct extent_buffer; 11 struct btrfs_free_cluster; 12 struct btrfs_fs_info; 13 struct btrfs_root; 14 struct btrfs_path; 15 struct btrfs_ref; 16 struct btrfs_disk_key; 17 struct btrfs_delayed_ref_head; 18 struct btrfs_delayed_ref_root; 19 struct btrfs_extent_inline_ref; 20 21 enum btrfs_extent_allocation_policy { 22 BTRFS_EXTENT_ALLOC_CLUSTERED, 23 BTRFS_EXTENT_ALLOC_ZONED, 24 }; 25 26 struct find_free_extent_ctl { 27 /* Basic allocation info */ 28 u64 ram_bytes; 29 u64 num_bytes; 30 u64 min_alloc_size; 31 u64 empty_size; 32 u64 flags; 33 int delalloc; 34 35 /* Where to start the search inside the bg */ 36 u64 search_start; 37 38 /* For clustered allocation */ 39 u64 empty_cluster; 40 struct btrfs_free_cluster *last_ptr; 41 bool use_cluster; 42 43 bool have_caching_bg; 44 bool orig_have_caching_bg; 45 46 /* Allocation is called for tree-log */ 47 bool for_treelog; 48 49 /* Allocation is called for data relocation */ 50 bool for_data_reloc; 51 52 /* RAID index, converted from flags */ 53 int index; 54 55 /* 56 * Current loop number, check find_free_extent_update_loop() for details 57 */ 58 int loop; 59 60 /* 61 * Set to true if we're retrying the allocation on this block group 62 * after waiting for caching progress, this is so that we retry only 63 * once before moving on to another block group. 64 */ 65 bool retry_uncached; 66 67 /* If current block group is cached */ 68 int cached; 69 70 /* Max contiguous hole found */ 71 u64 max_extent_size; 72 73 /* Total free space from free space cache, not always contiguous */ 74 u64 total_free_space; 75 76 /* Found result */ 77 u64 found_offset; 78 79 /* Hint where to start looking for an empty space */ 80 u64 hint_byte; 81 82 /* Allocation policy */ 83 enum btrfs_extent_allocation_policy policy; 84 85 /* Whether or not the allocator is currently following a hint */ 86 bool hinted; 87 88 /* Size class of block groups to prefer in early loops */ 89 enum btrfs_block_group_size_class size_class; 90 }; 91 92 enum btrfs_inline_ref_type { 93 BTRFS_REF_TYPE_INVALID, 94 BTRFS_REF_TYPE_BLOCK, 95 BTRFS_REF_TYPE_DATA, 96 BTRFS_REF_TYPE_ANY, 97 }; 98 99 int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb, 100 struct btrfs_extent_inline_ref *iref, 101 enum btrfs_inline_ref_type is_data); 102 u64 hash_extent_data_ref(u64 root_objectid, u64 owner, u64 offset); 103 104 int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, u64 min_bytes); 105 u64 btrfs_cleanup_ref_head_accounting(struct btrfs_fs_info *fs_info, 106 struct btrfs_delayed_ref_root *delayed_refs, 107 struct btrfs_delayed_ref_head *head); 108 int btrfs_lookup_data_extent(struct btrfs_fs_info *fs_info, u64 start, u64 len); 109 int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans, 110 struct btrfs_fs_info *fs_info, u64 bytenr, 111 u64 offset, int metadata, u64 *refs, u64 *flags, 112 u64 *owner_root); 113 int btrfs_pin_extent(struct btrfs_trans_handle *trans, u64 bytenr, u64 num, 114 int reserved); 115 int btrfs_pin_extent_for_log_replay(struct btrfs_trans_handle *trans, 116 const struct extent_buffer *eb); 117 int btrfs_exclude_logged_extents(struct extent_buffer *eb); 118 int btrfs_cross_ref_exist(struct btrfs_inode *inode, u64 offset, u64 bytenr, 119 struct btrfs_path *path); 120 struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, 121 struct btrfs_root *root, 122 u64 parent, u64 root_objectid, 123 const struct btrfs_disk_key *key, 124 int level, u64 hint, 125 u64 empty_size, 126 u64 reloc_src_root, 127 enum btrfs_lock_nesting nest); 128 int btrfs_free_tree_block(struct btrfs_trans_handle *trans, 129 u64 root_id, 130 struct extent_buffer *buf, 131 u64 parent, int last_ref); 132 int btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans, 133 struct btrfs_root *root, u64 owner, 134 u64 offset, u64 ram_bytes, 135 struct btrfs_key *ins); 136 int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans, 137 u64 root_objectid, u64 owner, u64 offset, 138 struct btrfs_key *ins); 139 int btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes, u64 num_bytes, 140 u64 min_alloc_size, u64 empty_size, u64 hint_byte, 141 struct btrfs_key *ins, int is_data, int delalloc); 142 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, 143 struct extent_buffer *buf, int full_backref); 144 int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, 145 struct extent_buffer *buf, int full_backref); 146 int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, 147 struct extent_buffer *eb, u64 flags); 148 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref); 149 150 u64 btrfs_get_extent_owner_root(struct btrfs_fs_info *fs_info, 151 struct extent_buffer *leaf, int slot); 152 int btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info, u64 start, u64 len, 153 bool is_delalloc); 154 int btrfs_pin_reserved_extent(struct btrfs_trans_handle *trans, 155 const struct extent_buffer *eb); 156 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans); 157 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, struct btrfs_ref *generic_ref); 158 int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, 159 int for_reloc); 160 int btrfs_drop_subtree(struct btrfs_trans_handle *trans, 161 struct btrfs_root *root, 162 struct extent_buffer *node, 163 struct extent_buffer *parent); 164 void btrfs_error_unpin_extent_range(struct btrfs_fs_info *fs_info, u64 start, u64 end); 165 int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr, 166 u64 num_bytes, u64 *actual_bytes); 167 int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range); 168 169 #endif 170