extent-tree.h 5.3 KB

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