extent-tree.h 5.7 KB

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