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