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