| 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 |
|
| 34 |
/* Where to start the search inside the bg */ |
| 35 |
u64 search_start; |
| 36 |
|
| 37 |
/* For clustered allocation */ |
| 38 |
u64 empty_cluster; |
| 39 |
struct btrfs_free_cluster *last_ptr; |
| 40 |
bool use_cluster; |
| 41 |
|
| 42 |
bool delalloc; |
| 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 |
/* |
| 53 |
* Set to true if we're retrying the allocation on this block group |
| 54 |
* after waiting for caching progress, this is so that we retry only |
| 55 |
* once before moving on to another block group. |
| 56 |
*/ |
| 57 |
bool retry_uncached; |
| 58 |
|
| 59 |
/* Whether or not the allocator is currently following a hint. */ |
| 60 |
bool hinted; |
| 61 |
|
| 62 |
/* RAID index, converted from flags */ |
| 63 |
int index; |
| 64 |
|
| 65 |
/* |
| 66 |
* Current loop number, check find_free_extent_update_loop() for details |
| 67 |
*/ |
| 68 |
int loop; |
| 69 |
|
| 70 |
/* If current block group is cached */ |
| 71 |
int cached; |
| 72 |
|
| 73 |
/* Max contiguous hole found */ |
| 74 |
u64 max_extent_size; |
| 75 |
|
| 76 |
/* Total free space from free space cache, not always contiguous */ |
| 77 |
u64 total_free_space; |
| 78 |
|
| 79 |
/* Found result */ |
| 80 |
u64 found_offset; |
| 81 |
|
| 82 |
/* Hint where to start looking for an empty space */ |
| 83 |
u64 hint_byte; |
| 84 |
|
| 85 |
/* Allocation policy */ |
| 86 |
enum btrfs_extent_allocation_policy policy; |
| 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 |
const 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 btrfs_pin_extent_for_log_replay(struct btrfs_trans_handle *trans, |
| 115 |
const struct extent_buffer *eb); |
| 116 |
int btrfs_exclude_logged_extents(struct extent_buffer *eb); |
| 117 |
int btrfs_cross_ref_exist(struct btrfs_inode *inode, u64 offset, u64 bytenr, |
| 118 |
struct btrfs_path *path); |
| 119 |
struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, |
| 120 |
struct btrfs_root *root, |
| 121 |
u64 parent, u64 root_objectid, |
| 122 |
const struct btrfs_disk_key *key, |
| 123 |
int level, u64 hint, |
| 124 |
u64 empty_size, |
| 125 |
u64 reloc_src_root, |
| 126 |
enum btrfs_lock_nesting nest); |
| 127 |
int btrfs_free_tree_block(struct btrfs_trans_handle *trans, |
| 128 |
u64 root_id, |
| 129 |
struct extent_buffer *buf, |
| 130 |
u64 parent, int last_ref); |
| 131 |
int btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans, |
| 132 |
struct btrfs_root *root, u64 owner, |
| 133 |
u64 offset, u64 ram_bytes, |
| 134 |
struct btrfs_key *ins); |
| 135 |
int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans, |
| 136 |
u64 root_objectid, u64 owner, u64 offset, |
| 137 |
struct btrfs_key *ins); |
| 138 |
int btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes, u64 num_bytes, |
| 139 |
u64 min_alloc_size, u64 empty_size, u64 hint_byte, |
| 140 |
struct btrfs_key *ins, bool is_data, bool delalloc); |
| 141 |
int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
| 142 |
struct extent_buffer *buf, bool full_backref); |
| 143 |
int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
| 144 |
struct extent_buffer *buf, bool full_backref); |
| 145 |
int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, |
| 146 |
struct extent_buffer *eb, u64 flags); |
| 147 |
int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref); |
| 148 |
|
| 149 |
u64 btrfs_get_extent_owner_root(struct btrfs_fs_info *fs_info, |
| 150 |
struct extent_buffer *leaf, int slot); |
| 151 |
int btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info, u64 start, u64 len, |
| 152 |
bool is_delalloc); |
| 153 |
int btrfs_pin_reserved_extent(struct btrfs_trans_handle *trans, |
| 154 |
const struct extent_buffer *eb); |
| 155 |
int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans); |
| 156 |
int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, struct btrfs_ref *generic_ref); |
| 157 |
int btrfs_drop_snapshot(struct btrfs_root *root, bool update_ref, bool for_reloc); |
| 158 |
int btrfs_drop_subtree(struct btrfs_trans_handle *trans, |
| 159 |
struct btrfs_root *root, |
| 160 |
struct extent_buffer *node, |
| 161 |
struct extent_buffer *parent); |
| 162 |
void btrfs_error_unpin_extent_range(struct btrfs_fs_info *fs_info, u64 start, u64 end); |
| 163 |
int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr, |
| 164 |
u64 num_bytes, u64 *actual_bytes, bool do_remap); |
| 165 |
int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range); |
| 166 |
void btrfs_handle_fully_remapped_bgs(struct btrfs_fs_info *fs_info); |
| 167 |
int btrfs_complete_bg_remapping(struct btrfs_block_group *bg); |
| 168 |
|
| 169 |
#endif |