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