1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef BTRFS_EXTENT_TREE_H
4 #define BTRFS_EXTENT_TREE_H
6 #include <linux/types.h>
8 #include "block-group.h"
12 struct btrfs_free_cluster;
17 struct btrfs_disk_key;
18 struct btrfs_delayed_ref_head;
19 struct btrfs_delayed_ref_root;
20 struct btrfs_extent_inline_ref;
22 enum btrfs_extent_allocation_policy {
23 BTRFS_EXTENT_ALLOC_CLUSTERED,
24 BTRFS_EXTENT_ALLOC_ZONED,
27 struct find_free_extent_ctl {
28 /* Basic allocation info */
36 /* Where to start the search inside the bg */
39 /* For clustered allocation */
41 struct btrfs_free_cluster *last_ptr;
45 bool orig_have_caching_bg;
47 /* Allocation is called for tree-log */
50 /* Allocation is called for data relocation */
53 /* RAID index, converted from flags */
57 * Current loop number, check find_free_extent_update_loop() for details
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.
68 /* If current block group is cached */
71 /* Max contiguous hole found */
74 /* Total free space from free space cache, not always contiguous */
80 /* Hint where to start looking for an empty space */
83 /* Allocation policy */
84 enum btrfs_extent_allocation_policy policy;
86 /* Whether or not the allocator is currently following a hint */
89 /* Size class of block groups to prefer in early loops */
90 enum btrfs_block_group_size_class size_class;
93 enum btrfs_inline_ref_type {
94 BTRFS_REF_TYPE_INVALID,
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);
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,
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,
112 u64 offset, int metadata, u64 *refs, u64 *flags,
114 int btrfs_pin_extent(struct btrfs_trans_handle *trans, u64 bytenr, u64 num,
116 int btrfs_pin_extent_for_log_replay(struct btrfs_trans_handle *trans,
117 const struct extent_buffer *eb);
118 int btrfs_exclude_logged_extents(struct extent_buffer *eb);
119 int btrfs_cross_ref_exist(struct btrfs_inode *inode, u64 offset, u64 bytenr,
120 struct btrfs_path *path);
121 struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
122 struct btrfs_root *root,
123 u64 parent, u64 root_objectid,
124 const struct btrfs_disk_key *key,
128 enum btrfs_lock_nesting nest);
129 int btrfs_free_tree_block(struct btrfs_trans_handle *trans,
131 struct extent_buffer *buf,
132 u64 parent, int last_ref);
133 int btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans,
134 struct btrfs_root *root, u64 owner,
135 u64 offset, u64 ram_bytes,
136 struct btrfs_key *ins);
137 int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans,
138 u64 root_objectid, u64 owner, u64 offset,
139 struct btrfs_key *ins);
140 int btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes, u64 num_bytes,
141 u64 min_alloc_size, u64 empty_size, u64 hint_byte,
142 struct btrfs_key *ins, int is_data, int delalloc);
143 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
144 struct extent_buffer *buf, int full_backref);
145 int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
146 struct extent_buffer *buf, int full_backref);
147 int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans,
148 struct extent_buffer *eb, u64 flags);
149 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref);
151 u64 btrfs_get_extent_owner_root(struct btrfs_fs_info *fs_info,
152 struct extent_buffer *leaf, int slot);
153 int btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info,
154 u64 start, u64 len, int delalloc);
155 int btrfs_pin_reserved_extent(struct btrfs_trans_handle *trans,
156 const struct extent_buffer *eb);
157 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans);
158 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, struct btrfs_ref *generic_ref);
159 int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref,
161 int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
162 struct btrfs_root *root,
163 struct extent_buffer *node,
164 struct extent_buffer *parent);
165 void btrfs_error_unpin_extent_range(struct btrfs_fs_info *fs_info, u64 start, u64 end);
166 int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr,
167 u64 num_bytes, u64 *actual_bytes);
168 int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range);